def population(): rows = [] cols = [] for item in db_aurin.view('views/population', group=True, group_level=1): rows.append({'c': [{'v': " ".join(item.key)}, {'v': item.value}]}) pairs = [('', 'Population', 'string'), ('', 'Amount', 'number')] for pair in pairs: cols.append({'id': pair[0], 'label': pair[1], 'type': pair[2]}) response = {'cols': cols, 'rows': rows} return jsonify(response)
def ages(): df = {} rows = [] cols = [] for item in db_aurin.view('views/ages', group=True, group_level=2): city = item.key[0] category = item.key[1] value = item.value if category != None: if city not in df: df[city] = [value] else: df[city] += [value] for key, value in df.items(): total = value[0] + value[1] + value[2] + value[3] + value[4] age_9 = value[0] / total age_19 = value[1] / total age_39 = value[2] / total age_59 = value[3] / total age_60 = value[4] / total rows.append({ 'c': [{ 'v': key }, { 'v': age_9 }, { 'v': age_19 }, { 'v': age_39 }, { 'v': age_59 }, { 'v': age_60 }] }) pairs = [('', 'Age', 'string'), ('', '0-9', 'number'), ('', '10-19', 'number'), ('', '20-39', 'number'), ('', '40-59', 'number'), ('', 'over60', 'number')] for pair in pairs: cols.append({'id': pair[0], 'label': pair[1], 'type': pair[2]}) response = {'cols': cols, 'rows': rows} return jsonify(response)
def employment_rate(): df = {} rows = [] cols = [] for item in db_aurin.view('views/employment_rate', group=True, group_level=2): city = item.key[0] category = item.key[1] value = item.value if category != None: if city not in df: df[city] = [value] else: df[city] += [value] for key, value in df.items(): total = value[0] + value[1] + value[2] fulltime = value[0] / total parttime = value[1] / total un = value[2] / total rows.append( {'c': [{ 'v': key }, { 'v': fulltime }, { 'v': parttime }, { 'v': un }]}) pairs = [('', 'employment_rate', 'string'), ('', 'employment full time Proportion', 'number'), ('', 'employment part time Proportion', 'number'), ('', 'unemployed Proportion', 'number')] for pair in pairs: cols.append({'id': pair[0], 'label': pair[1], 'type': pair[2]}) response = {'cols': cols, 'rows': rows} return jsonify(response)
def occupation(): df = {} rows = [] cols = [] for item in db_aurin.view('views/occupation', group=True, group_level=2): city = item.key[0] category = item.key[1] value = item.value if category != None: if city not in df: df[city] = [value] else: df[city] += [value] for key, value in df.items(): total = value[0] + value[1] + value[2] Mental_worker = value[0] / total Physical_worker = value[1] / total Service_worker = value[2] / total rows.append({ 'c': [{ 'v': key }, { 'v': Mental_worker }, { 'v': Physical_worker }, { 'v': Service_worker }] }) pairs = [('', 'Occupation', 'string'), ('', 'Mental worker', 'number'), ('', 'Physical worker', 'number'), ('', 'Service worker', 'number')] for pair in pairs: cols.append({'id': pair[0], 'label': pair[1], 'type': pair[2]}) response = {'cols': cols, 'rows': rows} return jsonify(response)