Beispiel #1
0
def api_similar_places_helper(dcid, stats_var):
    triples = dc.get_triples([stats_var])[stats_var]
    population_type = None
    measured_property = None
    stat_type = None
    measurement_method = None
    pvs = {}
    for t in triples:
        if t[1] in ["provenance", "typeOf"]:
            continue
        if t[1] == "statType":
            stat_type = t[2]
        elif t[1] == "populationType":
            population_type = t[2]
        elif t[1] == "measurementMethod":
            measurement_method = t[2]
        elif t[1] == "measuredProperty":
            measured_property = t[2]
        else:
            pvs[t[1]] = t[2]
    return dc.get_related_place([dcid],
                                population_type,
                                measured_property,
                                stat_type,
                                pvs=pvs,
                                measurement_method=measurement_method,
                                same_place_type=True).get(dcid, {})
Beispiel #2
0
def get_related_place(dcid,
                      stat_vars_string,
                      within_place=None,
                      is_per_capita=None):
    stat_vars = stat_vars_string.split('^')
    return dc.get_related_place(dcid,
                                stat_vars,
                                within_place=within_place,
                                is_per_capita=is_per_capita)
Beispiel #3
0
def get_related_place(dcid,
                      population_type,
                      measured_property,
                      stat_type,
                      pvs_string='',
                      measurement_method=None,
                      same_place_type=None,
                      within_place=None,
                      is_per_capita=None):
    pv_tokens = pvs_string.split('^')
    pvs = {}
    for i in range(len(pv_tokens) // 2):
        pvs[pv_tokens[i * 2]] = pv_tokens[i * 2 + 1]
    return dc.get_related_place([dcid],
                                population_type,
                                measured_property,
                                stat_type,
                                pvs=pvs,
                                measurement_method=measurement_method,
                                same_place_type=same_place_type,
                                within_place=within_place,
                                is_per_capita=is_per_capita).get(dcid, {})
Beispiel #4
0
def api_similar_places(stats_var, dcid):
    """
    Get the similar places for a given place by stats var.
    """
    return dc.get_related_place(dcid, [stats_var],
                                same_place_type=True).get(stats_var, {})