Skip to content

New get stat functions#142

Merged
tjann merged 12 commits intodatacommonsorg:masterfrom
tjann:new-get-stat
Aug 20, 2020
Merged

New get stat functions#142
tjann merged 12 commits intodatacommonsorg:masterfrom
tjann:new-get-stat

Conversation

@tjann
Copy link
Copy Markdown
Contributor

@tjann tjann commented Aug 20, 2020

No description provided.

@tjann tjann requested a review from shifucun August 20, 2020 07:12
@tjann tjann marked this pull request as ready for review August 20, 2020 07:12
@tjann tjann requested review from beets and pradh August 20, 2020 07:16
Comment thread datacommons/examples/statvar.py Outdated
from __future__ import print_function

import sys
sys.path.append('../')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure if this is best practice. Can you check see how people think. I remember we used to run, in the top level folder, python -m datacommons.examples.xxx

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed and added that to readme.

Comment thread datacommons/examples/statvar.py Outdated


def main():
# Dcid for Santa Clara County.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you make the entire example parameterized:

data = [{place: xx, stat_var = xxx, xx}, {},{}]
for d in data:
print(xx)
print(dc.get())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread datacommons/statvar.py Outdated
unit (:obj:`str`): Optional, the dcid of the preferred `unit` value.
scaling_factor (:obj:`int`): Optional, the preferred `scalingFactor` value.
Returns:
A :obj:`double` the value of :code:`stat_var` for :code:`place`, filtered
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

in python it should be "float" instead of double

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, changed

Copy link
Copy Markdown
Contributor

@shifucun shifucun left a comment

Choose a reason for hiding this comment

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

thanks for the change!

},
{
'place':
'nuts/HU22',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no need to newline here and below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is from yapf formatting, will keep since we plan to enforce google pylint later.

Comment thread datacommons/examples/statvar.py Outdated


def main():
data = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider naming this something more specific -- params, etc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread datacommons/examples/statvar.py Outdated

for d in data:
print('\n>>> get_stat_value: ',
[param for param in d.values() if param])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the "if param" required? i think it'll be nice to format this as:

get_stat_value(place=geoid/foo, stat_var=statVarFoo)
<<< ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,99 @@
# Copyright 2020 Google Inc.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: should this file name be "get_stat.py"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe discuss later? If we do that, probably should do that in a future PR, since in py lib, the file names are all like
Screen Shot 2020-08-20 at 11 38 28 AM

It's the functions that are like "get_stat*"

Comment thread datacommons/statvar.py
@@ -0,0 +1,147 @@
# Copyright 2020 Google Inc.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: ditto re: filename. maybe statvars or stat_vars or stats to mirror the other module names?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can make it plural

Comment thread datacommons/statvar.py Outdated
import datacommons.utils as utils


def _send_get_stat_req(url):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems mostly identical with _send_request -- does that not work for this module?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

_send_request is expecting a payload keyword, but the REST API does not have that for /stat. It's an open item for discussion.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i wouldn't fork just for that reason. can we add support for non-payload requests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1-- discussed with Bo, he wants to move away from payload
2-- discussed with Bo, decided to add a use_payload arg to _send_request, so the code now reuses the function.

@tjann tjann merged commit 6f5d229 into datacommonsorg:master Aug 20, 2020
@tjann tjann deleted the new-get-stat branch August 20, 2020 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants