Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

adds officeid filter; closes #320 #326

Merged
merged 2 commits into from
Jul 9, 2018

Conversation

vv-qian
Copy link
Contributor

@vv-qian vv-qian commented Jun 18, 2018

No description provided.

Copy link
Contributor

@mileswwatkins mileswwatkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking solid in general, I'll also work to figure out what's up with the test cases.

Additional recommendation: proudly add yourself to AUTHORS.rst!

CHANGELOG.rst Outdated
@@ -1,3 +1,8 @@
2.4.1 (hold) - June 13, 2018
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically repo owners will do publishing and versioning; as a feature creator you don't need to edit CHANGELOG or equivalent files, so I'd remove them from the PR.

docs/cli.rst Outdated
@@ -88,7 +88,8 @@ Commands and flags
--batch-name BATCH_NAME
Specify a value for a `batchname` column to append to
each row.

--officeids OFFICEIDS Specify officeids to parse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this higher up in the order, nearer to similar settings like --results-level and --raceids. Think of the UX from the perspective of a new dev learning the settings from elex --help.

@@ -876,6 +876,7 @@ def __init__(self, **kwargs):
self.setzerocounts = kwargs.get('setzerocounts', False)

self.raceids = kwargs.get('raceids', [])
self.officeids = kwargs.get('officeids', "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here to explain why officeids are being handled as a string instead of a list of strings; this may not be clear to future devs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should the default value be "", or None? I genuinely don't know; you have a better grasp on how requests will submit this querystring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second comment - After poking around a little more, I don't think it matters at this particular point because this particular line is executed before the command line args are parsed. But I do think None is a cleaner default value!

@@ -98,7 +98,6 @@ def api_request(path, **params):
params = sorted(params.items()) # Sort for consistent caching

url = '{0}{1}'.format(elex.BASE_URL, path.replace('//', '/'))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to make this change to a file you aren't otherwise editing; think this is probably here because of a debug print we were doing earlier.

elex/cli/app.py Outdated
@@ -90,6 +90,11 @@ class Meta:
action='store',
help='Specify a value for a `batchname` column to append to each row.',
)),
(['--officeids'], dict(
action='store',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why store instead of store_true? I haven't looked into what action does, would be curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store stores officeids specified by the user and has no default value like store_true does. store would issue an error before executing any code if a user tried to run elex races 2016-11-08 --officeids and failed to specify office IDs because arguments are required if the --officeids flag is included. store_true would in this example result in officeids being a True, which would cause the code to fail when it tries to parse officeids. Here's more info!

elex/cli/app.py Outdated
@@ -90,6 +90,11 @@ class Meta:
action='store',
help='Specify a value for a `batchname` column to append to each row.',
)),
(['--officeids'], dict(
action='store',
help='Specify officeids to parse',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other options' help text ends in a period.

elex/cli/app.py Outdated
(['--officeids'], dict(
action='store',
help='Specify officeids to parse',
default=[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default to [] or "" or None?

@@ -28,6 +30,14 @@ def add_election_hook(app):
if app.pargs.raceids:
app.election.raceids = [x.strip() for x in app.pargs.raceids.split(',')]

if app.pargs.officeids:
invalid_officeids = [x.strip() for x in app.pargs.officeids.split(',') if x.strip() not in maps.OFFICE_NAMES]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the values being stripped? It doesn't look like the processing of the office IDs elsewhere in the code is being stripped. But I'm not super familiar with arg parsing, so defer to you if this is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, you're right. It's unnecessary, particularly since adding a bunch of spaces in front of P,H,G in elex races 2016-11-08 --officeids P,H,G doesn't cause officeids to reflect those spaces, and elex races 2016-11-08 --officeids P, H, G errors out and doesn't run.

text = '{0} is/are invalid officeID(s). Here is a list of valid officeIDs: {1}'
app.log.error(text.format(", ".join(invalid_officeids), ", ".join(maps.OFFICE_NAMES.keys())))
app.close(1)
app.election.officeids = app.pargs.officeids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe stash this in an else: clause, would make it read a bit easier to me.

testresults=False,
liveresults=True,
is_test=False,
officeids='N,ABC,PS'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this test to not use multi-letter fake office IDs, to make it more reasonable.

@vv-qian vv-qian changed the title WIP adds officeid filter; closes #320 adds officeid filter; closes #320 Jun 18, 2018
@vv-qian
Copy link
Contributor Author

vv-qian commented Jun 18, 2018

@palewire Ready for you!

@jeremyjbowers jeremyjbowers merged commit b7953d7 into newsdev:master Jul 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants