Skip to content

Commit

Permalink
Merge branch 'break_out_yearly_data'
Browse files Browse the repository at this point in the history
This branch breaks the 'data' array of Field entries into its own file
and adds a bunch of nice command line options to generate_pdf.py.
  • Loading branch information
philsc committed May 4, 2013
2 parents 09586d8 + 5f3182c commit d4eb3e5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 19 deletions.
21 changes: 21 additions & 0 deletions data_2013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python2

from scantron import Field

data = [
Field('auton_high', 'Auton High', int),
Field('auton_mid', 'Auton Mid', int),
Field('auton_low', 'Auton Low', int),
Field('high', 'High', int),
Field('mid', 'Mid', int),
Field('low', 'Low', int),
Field('pyramid', 'Pyramid', int),
Field('missed', 'Missed', int),
Field('fouls', 'Fouls', int),
Field('tech_fouls', 'Tech fouls', int),
Field('defense', 'Defense', bool),
Field('pickup', 'Pickup', bool),
Field('noshow', 'Noshow', bool),
Field('brokedown', 'Brokedown', bool),
Field('dq', 'DQ', bool),
]
60 changes: 41 additions & 19 deletions generate_pdf.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
#!/usr/bin/env python2

import os
import sys
from argparse import ArgumentParser
from scantron import *

data = [
Field('auton_high', 'Auton High', int),
Field('auton_mid', 'Auton Mid', int),
Field('auton_low', 'Auton Low', int),
Field('high', 'High', int),
Field('mid', 'Mid', int),
Field('low', 'Low', int),
Field('pyramid', 'Pyramid', int),
Field('missed', 'Missed', int),
Field('fouls', 'Fouls', int),
Field('tech_fouls', 'Tech fouls', int),
Field('defense', 'Defense', bool),
Field('pickup', 'Pickup', bool),
Field('noshow', 'Noshow', bool),
Field('brokedown', 'Brokedown', bool),
Field('dq', 'DQ', bool),
]
# Make this file easier to use by adding nice arguments
parser = ArgumentParser(description='Generate scantron PDFs.')
parser.add_argument(
'-o', '--output',
action='store', default='form.pdf',
metavar='FILE',
help='Filename to use for generated scantrons. Defaults to forms.pdf.')
parser.add_argument(
'-n', '--num-matches',
action='store', default=1,
metavar='NUMBER', type=int,
help='Number of matches to generate sheets for. Defaults to 1.')
parser.add_argument(
'data',
metavar='input_data',
help='File where the field data is stored. ' +
'This must be a python script with an array called "data" ' +
'of Field entries.')

st = Scantron('form.pdf', spacing=0.3*inch)
args = parser.parse_args()

# If the file has a .py extension, we should still accept it
if args.data.endswith('.py'):
args.data = os.path.splitext(args.data)[0]

# Import the file specified on the command line
try:
__import__(args.data)
data = sys.modules[args.data].data
except ImportError:
print('Failed to import %s.' % args.data)
quit(1)
except AttributeError:
print('Could not find data array.')
quit(1)

# If everything went well, proceed to generate the PDF
st = Scantron(args.output, spacing=0.3*inch)
st.set_box_sizes(box_size=0.2*inch, box_spacing=0.3*inch)
st.populate(data, matches=3)
st.populate(data, matches=args.num_matches)
st.save()

0 comments on commit d4eb3e5

Please sign in to comment.