@@ -352,36 +352,34 @@ def get_pop_obs(dcid):
352352 url = utils ._API_ROOT + utils ._API_ENDPOINTS ['get_pop_obs' ] + '?dcid={}' .format (dcid )
353353 return utils ._send_request (url , compress = True , post = False )
354354
355- def get_place_obs (place_type , population_type , constraining_properties = {}):
356- """ Returns all :obj:`StatisticalPopulation`'s and :obj:` Observation`'s for \
357- all places of the given :code:`place_type` .
355+ def get_place_obs (place_type , observation_date , population_type , constraining_properties = {}):
356+ """ Returns all :obj:`Observation`'s for all places given the place type,
357+ observation date and the :obj:`StatisticalPopulation` constraints .
358358
359359 Args:
360360 place_type (:obj:`str`): The type of places to query
361361 :obj:`StatisticalPopulation`'s and :obj:`Observation`'s for.
362+ observation_date (:obj:`str`): The observation date in ISO-8601 format.
362363 population_type (:obj:`str`): The population type of the
363364 :obj:`StatisticalPopulation`
364365 constraining_properties (:obj:`map` from :obj:`str` to :obj:`str`, optional):
365366 A map from constraining property to the value that the
366367 :obj:`StatisticalPopulation` should be constrained by.
367368
368369 Returns:
369- Given a :code:`Place` type (i.e. :obj:`State`, :obj:`County`, :obj:`City`),
370- a :code:`population_type` (i.e. :obj:`Person`), and optionally a set of
371- constraining properties defining the `obj`:`StatisticalPopulation`, this
372- function returns *all* :obj:`StatisticalPopulation`'s and
373- :obj:`Observation`'s for all places of the given type. See examples for more
374- details on how the format of the return value is structured.
370+ A list of dictionaries, with each dictionary containng *all*
371+ :obj:`Observation`'s of a place that conform to the :obj:`StatisticalPopulation`
372+ constraints. See examples for more details on how the format of the
373+ return value is structured.
375374
376375 Raises:
377- ValueError: If the payload returned by the Data Commons REST API is
378- malformed.
376+ ValueError: If the payload is malformed.
379377
380378 Examples:
381379 We would like to get all :obj:`StatisticalPopulation` and
382- :obj:`Observations` for all places of type :obj:`City` where the populations
383- have a population type of :obj:`Person` is specified by the following
384- constraining properties.
380+ :obj:`Observations` for all places of type :obj:`City` in year 2017 where
381+ the populations have a population type of :obj:`Person` is specified by the
382+ following constraining properties.
385383
386384 - Persons should have `age <https://browser.datacommons.org/kg?dcid=age>`_
387385 with value `Years5To17 <https://browser.datacommons.org/kg?dcid=Years5To17>`_
@@ -392,7 +390,7 @@ def get_place_obs(place_type, population_type, constraining_properties={}):
392390 ... 'age': 'Years5To17',
393391 ... 'placeOfBirth': 'BornInOtherStateInTheUnitedStates'
394392 ... }
395- >>> get_place_obs('City', 'Person', constraining_properties=props)
393+ >>> get_place_obs('City', '2017', Person', constraining_properties=props)
396394 [
397395 {
398396 'name': 'Marcus Hook borough',
@@ -401,68 +399,33 @@ def get_place_obs(place_type, population_type, constraining_properties={}):
401399 'dc/p/pq6frs32sfvk': {
402400 'observations': [
403401 {
404- 'id': 'dc/o/0005qml1el8qh',
405402 'marginOfError': 39,
406403 'measuredProp': 'count',
407404 'measuredValue': 67,
408- 'measurementMethod': 'CensusACS5yrSurvey',
409- 'observationDate': '2014',
410- 'provenanceId': 'dc/3j71hj1',
411- 'type': 'Observation'
412- },
413- {
414- 'id': 'dc/o/wvskpk5vyjkhb',
415- 'marginOfError': 33,
416- 'measuredProp': 'count',
417- 'measuredValue': 58,
418- 'measurementMethod': 'CensusACS5yrSurvey',
419- 'observationDate': '2015',
420- 'provenanceId': 'dc/3j71hj1',
421- 'type': 'Observation'
422- },
423- {
424- 'id': 'dc/o/3h44trf3vyrm3',
425- 'marginOfError': 36,
426- 'measuredProp': 'count',
427- 'measuredValue': 42,
428- 'measurementMethod': 'CensusACS5yrSurvey',
429- 'observationDate': '2011',
430- 'provenanceId': 'dc/3j71hj1',
431405 'type': 'Observation'
432406 },
433407 # More observations...
434408 ],
435- 'provenanceId': 'dc/3j71hj1'
436409 }
437410 }
438411 },
439412 # Entries for more cities...
440413 ]
441414
442415 The value returned by :code:`get_place_obs` is a :obj:`list` of
443- :obj:`dict`'s. Each dictionary corresponds to :obj:`StatisticalPopulation`'s
416+ :obj:`dict`'s. Each dictionary corresponds to a :obj:`StatisticalPopulation`
444417 matching the given :code:`population_type` and
445418 :code:`constraining_properties` for a single place of the given
446419 :code:`place_type`. The dictionary contains the following keys.
447420
448421 - :code:`name`: The name of the place being described.
449422 - :code:`place`: The dcid associated with the place being described.
450423 - :code:`populations`: A :obj:`dict` mapping :code:`StatisticalPopulation`
451- dcids to a a :obj:`dict` with a list of :code:`observations` and a the
452- :code:`provenanceId` identifying the source that defined the
453- :code:`StatisticalPopulation`.
424+ dcids to a a :obj:`dict` with a list of :code:`observations`.
454425
455426 Each :obj:`Observation` is represented by a :obj:`dict` with the following
456427 keys.
457-
458- - :code:`id`: The :code:`dcid` identifying the :obj:`Observation`.
459- - :code:`provenanceId`: The dcid identifying the source that defined this
460- :obj:`Observation`.
461- - :code:`type`: The type associated with the :obj:`Observation`.
462428 - :code:`measuredProp`: The property measured by the :obj:`Observation`.
463- - :code:`observationDate`: The date when the :obj:`Observation` was made.
464- - :code:`observationPeriod` (optional): The period over which the
465- :obj:`Observation` was made.
466429 - :code:`measurementMethod` (optional): A field identifying how the
467430 :obj:`Observation` was made
468431 - Additional fields that denote values measured by the :obj:`Observation`.
@@ -475,6 +438,7 @@ def get_place_obs(place_type, population_type, constraining_properties={}):
475438 url = utils ._API_ROOT + utils ._API_ENDPOINTS ['get_place_obs' ]
476439 payload = utils ._send_request (url , req_json = {
477440 'place_type' : place_type ,
441+ 'observation_date' : observation_date ,
478442 'population_type' : population_type ,
479443 'pvs' : pv ,
480444 }, compress = True )
0 commit comments