def test_get_included_area(get_sample_geodata): df = gp.GeoDataFrame(get_sample_geodata) df[['geometry']] = df.geometry.apply(shapely.wkt.loads) area, included = map_fi_plot.get_included_area(df, how="intersection", orig_name="Vattuniemi", range_km=0, target="Vattuniemi") included.drop_duplicates(subset="pono", inplace=True) included.loc[:, "pono"] = [str(x).rjust(5, '0') for x in included.pono] assert included.pono.values == "00210" area, included = map_fi_plot.get_included_area(df, how="difference", orig_name="Vattuniemi", range_km=10, target="Vattuniemi") included.drop_duplicates(subset="pono", inplace=True) included.loc[:, "pono"] = [str(x).rjust(5, '0') for x in included.pono] array_res = np.array([ '00690', '00390', '00410', '00420', '00430', '00560', '00680', '00700', '00710', '00720', '00730', '00740', '00800', '00750', '00760', '00770', '00780', '00790', '00910', '00820', '00920', '00930', '00830', '00940', '00950', '00960', '00840', '00850', '00860', '00880', '00970', '00980', '00890', '00900', '00990', '00670', '00640', '00650', '00660', '00210' ], dtype=object) assert (included.pono.values == array_res).all()
def update_table(origin_name, move_type, range_km, n_most, max_price, target): df_filtered = similarity.filter_w_price(df, max_price, [origin_name, target]) # transform values to ranks for easy understanding df_filtered_ranks = similarity.full_df_to_ranks(df_filtered, bins=10) df_origin = df.loc[df['nimi'] == origin_name, :] if move_type == 'difference': target = origin_name area, included = map_fi_plot.get_included_area(df_filtered, move_type, origin_name, range_km, target) NA, included_ranks = map_fi_plot.get_included_area(df_filtered_ranks, move_type, origin_name, range_km, target) X, y, target_names = viz.get_pca_data(included, 2018, 5) target_names.index = range(len(target_names)) X_pca = pipe.transform(X) d = similarity.pairwise_distances(X_pca, X_pca, 'euclidean') similar = similarity.get_similar_in_geo_area(included, origin_name, d, target_names, n_most) tb = viz.table_similar_with_names(included_ranks, origin_name, similar, target_names, X_pca, ['pono', 'nimi', 'he_kika', 'ra_asunn', 'te_laps', 'te_as_valj', 'tp_tyopy', 'tr_mtu', 'yliopistot', 'amk'], tail=False) tb = tb.drop_duplicates() tb = format_numeric_table_cols(tb, numcols=['dist']) cols = [x for x in tb.columns.values if x not in ['geometry', 'kunta', 'kuntanro', 'pono', 'pono.level', 'nimi', 'nimi_x', 'vuosi', 'dist', 'rakennukset_bin']] # tb.loc[:, cols] = tb.loc[:, cols].applymap(lambda x: similarity.value_to_plusses(x)) trace = go.Table( header=dict(values=list( ['Pono', 'Nimi', 'Keski-ikä', 'Asunnot', 'Lapsitaloudet', 'Työpaikat', 'Mediaanitulo', 'Yliopistot', 'AMK', 'Dist']), fill=dict(color='#C2D4FF'), align=['left'] * 5, height=40), cells=dict(values=[tb.pono, tb.nimi, tb.he_kika, tb.ra_asunn, tb.te_laps, tb.tp_tyopy, tb.tr_mtu, tb.yliopistot, tb.amk, tb.dist], fill=dict(color='#F5F8FF'), align=['left'] * 5, height=30) ) # py.plot([trace], 'test.html') return {'data': [trace], 'layout': dict(autosize=True, margin=dict( t=0, b=0, r=0, l=0 ) ) }
def update_graph(origin_name, move_type, range_km, n_most, max_price, target): df_filtered = similarity.filter_w_price(df, max_price, [origin_name, target]) df_origin = df.loc[df['nimi'] == origin_name, :] if move_type == 'difference': target = origin_name area, included = map_fi_plot.get_included_area(df_filtered, move_type, origin_name, range_km, target) X, y, target_names = viz.get_pca_data(included, 2018, 5) target_names.index = range(len(target_names)) X_pca = pipe.transform(X) d = similarity.pairwise_distances(X_pca, X_pca, 'euclidean') similar = similarity.get_similar_in_geo_area(included, origin_name, d, target_names, n_most) df_comparison = df.loc[df['nimi'].isin(similar), :] coords_max = { 'miny': df.bounds.miny.min(), 'minx': df.bounds.minx.min(), 'maxy': df.bounds.miny.max(), 'maxx': df.bounds.miny.max() } layout = define_layout() return { # 'data': set_fill_colors_for_origin_and_comp(plot_data4, origin_name, similar, target), 'data': set_fill_colors_for_origin_and_comp(make_graph_data(included), origin_name, similar, target), 'layout': layout }