diff --git a/dashboard/statistics_funcs.py b/dashboard/statistics_funcs.py
index cdd1621..2c9b52e 100644
--- a/dashboard/statistics_funcs.py
+++ b/dashboard/statistics_funcs.py
@@ -74,39 +74,65 @@ def create_barchartV2(
input_gdf,
fieldname,
title,
+ filter_out_opt="?", # value to filter out
+ filter_out_opt_text='Include "?" (Unknown)',
str_to_append=" type",
title_fontsize=24,
len_field="length(km)",
):
+ import altair as alt
- # bind = alt.selection_interval(bind='scales')
- # .add_selection(bind)
-
+ # Create a modified fieldname for plotting
fieldname_v2 = fieldname + str_to_append
+ # add a dummy "count" if no len_field
+ if not len_field:
+ input_gdf["count"] = 1
+ len_field = "count"
+
+ # Define the fields to plot
+ fields_to_plot = [fieldname, len_field]
+
+ # aggregation fields:
+ agg_fields = {fieldname: "count", len_field: "sum"}
+
+ # Aggregate the data for plotting
data_to_plot = (
- input_gdf[[len_field, fieldname]]
+ input_gdf[fields_to_plot]
.groupby([fieldname])
- .agg({fieldname: "count", len_field: "sum"})
+ .agg(agg_fields)
.rename(columns={fieldname: "feature count"})
.reset_index()
.rename(columns={fieldname: fieldname_v2})
)
- return (
+ # Create an interactive selection for filtering (boolean checkbox)
+ filter_checkbox = alt.binding_checkbox(name=filter_out_opt_text)
+ selection = alt.param(
+ name="include_filter_out_opt", bind=filter_checkbox, value=True
+ )
+
+ # Create the bar chart with conditional filtering
+ chart = (
alt.Chart(data_to_plot, title=title)
.mark_bar()
.encode(
x=alt.X(fieldname_v2, sort="-y"),
y=len_field,
- tooltip=len_field,
+ tooltip=[fieldname_v2, len_field, "feature count"],
color="feature count",
)
.properties(width=650, height=300)
.configure_title(fontSize=title_fontsize)
+ .add_params(selection)
+ .transform_filter(
+ f"include_filter_out_opt || datum['{fieldname_v2}'] != '{filter_out_opt}'"
+ )
.interactive()
)
+ return chart
+
def print_relevant_columnames(
input_df, not_include=("score", "geometry", "type", "id")
diff --git a/dashboard/statistics_generation.py b/dashboard/statistics_generation.py
index 59873bc..09bc870 100644
--- a/dashboard/statistics_generation.py
+++ b/dashboard/statistics_generation.py
@@ -135,7 +135,7 @@
category_homepage = get_url(generated_list_dict[category][0])
- topbar += f'{category.capitalize()} Charts\n'
+ topbar += f'{category.replace("_", " ").title()} Charts\n'
topbar += """
diff --git a/dashboard/statistics_specs.py b/dashboard/statistics_specs.py
index b149340..9a6bf31 100644
--- a/dashboard/statistics_specs.py
+++ b/dashboard/statistics_specs.py
@@ -27,7 +27,7 @@
"yh2": "smoothness",
"hcolor": "length(km)",
"fontsize": 24,
- "tooltip_fields": ["element_type", "id"],
+ "tooltip_fields": ["id"],
},
"title": "Surface x Smoothness",
},
@@ -92,7 +92,7 @@
"df": gdfs_dict["sidewalks"],
"column": "age",
"boxplot_title": "Sidewalks Age",
- "tooltip_fields": ["element_type", "id"],
+ "tooltip_fields": ["id"],
},
"title": "Sidewalks Age",
},
@@ -102,28 +102,38 @@
"df": gdfs_dict["sidewalks"],
"column": "length(km)",
"boxplot_title": "Sidewalks Length (km)",
- "tooltip_fields": ["element_type", "id"],
+ "tooltip_fields": ["id"],
},
"title": "Sidewalks Length (km)",
},
- "sidewalks_yr_moth_update": {
- "function": create_barchart,
+ "sidewalks_n_revs": {
+ "function": create_linked_boxplot_histogram,
"params": {
- "input_df": updating_dicts["sidewalks"],
- "fieldname": "year_month",
- "title": "Year and Month Of Update (Sidewalks)",
+ "df": gdfs_dict["sidewalks"],
+ "column": "n_revs",
+ "boxplot_title": "Sidewalks Number of Revisions",
+ "tooltip_fields": ["id"],
},
- "title": "Year and Month Of Update",
+ "title": "Number of Revisions",
},
- "sidewalks_number_revisions": {
+ "sidewalks_yr_moth_update": {
"function": create_barchart,
"params": {
"input_df": updating_dicts["sidewalks"],
- "fieldname": "n_revs",
+ "fieldname": "year_month",
"title": "Year and Month Of Update (Sidewalks)",
},
- "title": "Number Of Revisions",
+ "title": "Year and Month Of Update",
},
+ # "sidewalks_number_revisions": {
+ # "function": create_barchart,
+ # "params": {
+ # "input_df": updating_dicts["sidewalks"],
+ # "fieldname": "n_revs",
+ # "title": "Number of Revisions (Sidewalks)",
+ # },
+ # "title": "Number Of Revisions",
+ # },
},
"crossings": {
"crossing_types": {
@@ -135,14 +145,25 @@
},
"title": "Crossing Type",
},
+ # "crossing_surface": {
+ # "function": create_barchart,
+ # "params": {
+ # "input_df": gdfs_dict["crossings"],
+ # "fieldname": "surface",
+ # "title": "Crossing Surface",
+ # },
+ # "title": "Crossing Surface",
+ # },
"crossing_surface": {
- "function": create_barchart,
+ "function": create_barchartV2,
"params": {
- "input_df": gdfs_dict["crossings"],
+ "input_gdf": gdfs_dict["crossings"],
"fieldname": "surface",
- "title": "Crossing Surface",
+ "title": "Crossings Surface Type",
+ "str_to_append": " type",
+ "title_fontsize": 24,
},
- "title": "Crossing Surface",
+ "title": "Surface Type",
},
"crossings_smoothness_x_surface": {
"function": create_double_scatter_bar,
@@ -157,7 +178,7 @@
"yh2": "smoothness",
"hcolor": "crossing",
"fontsize": 24,
- "tooltip_fields": ["element_type", "id"],
+ "tooltip_fields": ["id"],
},
"title": "Surface x Smoothness",
},
@@ -175,7 +196,7 @@
"params": {
"input_df": updating_dicts["crossings"],
"fieldname": "n_revs",
- "title": "Year and Month Of Update (crossings)",
+ "title": "Number of Revisions (crossings)",
},
"title": "Number Of Revisions",
},
@@ -194,7 +215,7 @@
"yh2": "tactile_paving",
"hcolor": "wheelchair",
"fontsize": 24,
- "tooltip_fields": ["element_type", "id"],
+ "tooltip_fields": ["id"],
},
"title": "Surface x Smoothness",
},
@@ -225,6 +246,18 @@
},
"title": "Wheelchair Acessibility",
},
+ "kerbs_surface": {
+ "function": create_barchartV2,
+ "params": {
+ "input_gdf": gdfs_dict["kerbs"],
+ "fieldname": "surface",
+ "title": "Kerbs Surface Type",
+ "str_to_append": " type",
+ "title_fontsize": 24,
+ "len_field": None,
+ },
+ "title": "Surface Type",
+ },
"kerbs_yr_moth_update": {
"function": create_barchart,
"params": {
@@ -254,14 +287,25 @@
},
"title": "Incline Values",
},
+ # "other_footways_surface": {
+ # "function": create_barchart,
+ # "params": {
+ # "input_df": gdfs_dict["other_footways"],
+ # "fieldname": "surface",
+ # "title": "other_footways Surface",
+ # },
+ # "title": "Other Footways Surface",
+ # },
"other_footways_surface": {
- "function": create_barchart,
+ "function": create_barchartV2,
"params": {
- "input_df": gdfs_dict["other_footways"],
+ "input_gdf": gdfs_dict["other_footways"],
"fieldname": "surface",
- "title": "other_footways Surface",
+ "title": "Other Footways Surface Type",
+ "str_to_append": " type",
+ "title_fontsize": 24,
},
- "title": "Other Footways Surface",
+ "title": "Surface Type",
},
"other_footways_smoothness_x_surface": {
"function": create_double_scatter_bar,
@@ -276,7 +320,7 @@
"yh2": "smoothness",
"hcolor": "crossing",
"fontsize": 24,
- "tooltip_fields": ["element_type", "id"],
+ "tooltip_fields": ["id"],
},
"title": "Surface x Smoothness",
},