-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'break_out_yearly_data'
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
Showing
2 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |