Commit ed0e53cf authored by Branko Kokanovic's avatar Branko Kokanovic

Adding code that created funnels

parent 92c9dfff
# Najbitniji linkovi
* [Registar stambenih zajednica](https://data.gov.rs/sr/datasets/registar-stambenikh-zajednitsa-2/)
* [Analiza rezultata u Jupyeter-u](https://notebooks.azure.com/brankokokanovic/projects/stambene-zajednice/html/StambeneZajednice.ipynb)
* [Analiza rezultata u Jupyter-u](https://notebooks.azure.com/brankokokanovic/projects/stambene-zajednice/html/StambeneZajednice.ipynb)
* [Thread na OSM forumu](https://forum.openstreetmap.org/viewtopic.php?id=66945)
* [Tabela (avgust 2019.) sa spojenim podacima (PAŽNJA: veličina je 25MB!)](https://stambenezajednice.z6.web.core.windows.net/avgust2019.html)
* [CSV (avgust 2019.) sa spojenim podacima](https://stambenezajednice.z6.web.core.windows.net/avgust2019.csv)
......
geopy==1.20.0
overpy==0.4
Jinja2==2.8.1
osmium==2.15.2
\ No newline at end of file
osmium==2.15.2
plotly==4.1.1
\ No newline at end of file
......@@ -518,27 +518,6 @@ def main():
sz['building_tag_present'] = sz_output['building_tag_present']
sz['building_is_apartments'] = sz_output['building_is_apartments']
break
with open(output_file) as csvfile:
reader = csv.DictReader(csvfile)
i = 0
for row in reader:
logger.info('Processing row {0}'.format(i))
i += 1
if row['processed'] != 'True':
continue
for sz in stambene_zajednice:
if sz['district'] == row['district'] and\
sz['municipality'] == row['municipality'] and sz['street'] == row['street'] and\
sz['number'] == row['number']:
sz['processed'] = True
sz['node'] = [] if len(row['node']) <= 2 else [int(i) for i in row['node'][1:-1].split(',')]
sz['way'] = [] if len(row['way']) <= 2 else [int(i) for i in row['way'][1:-1].split(',')]
sz['relation'] = [] if len(row['relation']) <= 2 else\
[int(i) for i in row['relation'][1:-1].split(',')]
sz['multiple_entities_same_housenumber'] = row['multiple_entities_same_housenumber'] == 'True'
sz['building_tag_present'] = row['building_tag_present'] == 'True'
sz['building_is_apartments'] = row['building_is_apartments'] == 'True'
break
with open(progress_file, 'wb') as h:
pickle.dump(stambene_zajednice, h, protocol=pickle.DEFAULT_PROTOCOL)
sleep(5)
......
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
from plotly import graph_objects as go
def has_elements(text):
return len(np.fromstring(text[1:-1], sep=',', dtype=int)) > 0
def get_values(csvfile, belgrade_only=False, format_v2=False):
df = pd.read_csv(csvfile)
if format_v2:
has_elements_v = np.vectorize(has_elements)
df['node'] = df['node'].apply(has_elements_v)
df['way'] = df['way'].apply(has_elements_v)
df['relation'] = df['relation'].apply(has_elements_v)
processed = df[df.processed == True]
if belgrade_only:
processed = processed[processed.district == 'ГРАД БЕОГРАД']
if format_v2:
processed = processed.assign(entity_found=(processed.node | processed.way | processed.relation))
else:
processed = processed.assign(entity_found=((~processed.node.isnull()) | (~processed.way.isnull())))
entity_found = processed[processed.entity_found == True]
if format_v2:
have_way = entity_found[entity_found.way == True]
else:
have_way = entity_found[(~entity_found.way.isnull())]
is_way_building = have_way[have_way.building_tag_present == True]
is_building_apartments = is_way_building[is_way_building.building_is_apartments == True]
return [len(processed), len(entity_found), len(have_way), len(is_way_building), len(is_building_apartments)]
def main():
# avgust-result.csv can be found at https://stambenezajednice.z6.web.core.windows.net/avgust2019.csv
x = get_values('avgust-result.csv', belgrade_only=False, format_v2=False)
fig = go.Figure(go.Funnel(
x=x,
y=["In RGZ", "Found in OSM", "Tagged as ways", "Tagged as building", "Tagged as apartments"],
textinfo="label+value+percent initial",
marker={"color": [
"rgb(118,42,131)", "rgb(175,141,195)", "rgb(231,212,232)", "rgb(127,191,123)", "rgb(27,120,55)"]},
textfont={"size": 18}
))
fig.show()
x = get_values('avgust-result.csv', belgrade_only=True, format_v2=False)
fig = go.Figure(go.Funnel(
x=x,
y=["In RGZ", "Found in OSM", "Tagged as ways", "Tagged as building", "Tagged as apartments"],
textinfo="label+value+percent initial",
marker={"color": [
"rgb(118,42,131)", "rgb(175,141,195)", "rgb(231,212,232)", "rgb(127,191,123)", "rgb(27,120,55)"]},
textfont={"size": 18}
))
fig.show()
# oktobar-result.csv can be found at https://stambenezajednice.z6.web.core.windows.net/oktobar2019.csv
x = get_values('oktobar-result.csv', belgrade_only=False, format_v2=True)
fig = go.Figure(go.Funnel(
x=x,
y=["In RGZ", "Found in OSM", "Tagged as ways", "Tagged as building", "Tagged as apartments"],
textinfo="label+value+percent initial",
marker={"color": [
"rgb(118,42,131)", "rgb(175,141,195)", "rgb(231,212,232)", "rgb(127,191,123)", "rgb(27,120,55)"]},
textfont={"size": 18}
))
fig.show()
x = get_values('output.csv', belgrade_only=True, format_v2=True)
fig = go.Figure(go.Funnel(
x=x,
y=["In RGZ", "Found in OSM", "Tagged as ways", "Tagged as building", "Tagged as apartments"],
textinfo="label+value+percent initial",
marker={"color": [
"rgb(118,42,131)", "rgb(175,141,195)", "rgb(231,212,232)", "rgb(127,191,123)", "rgb(27,120,55)"]},
textfont={"size": 18}
))
fig.show()
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment