From 581b492b91dcf804a89dc86fe6233b5c14d5c62a Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 18:29:15 -0700 Subject: [PATCH 001/198] Function to create 100% Stacked Bar Chart --- viz_scripts/plots.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index c27e94f..3c5eef3 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -130,6 +130,35 @@ def func(pct, values): plt.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') plt.show() +def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): + + fig, ax = plt.subplots(1,1, figsize=(18,6)) + width = 0.8 + + running_total_long = [0] * num_bars + + for mode in pd.unique(df.Mode): + long = df[df['Mode'] == mode] + + if not long.empty: + labels = long['Trip Type'] + vals = long['Proportion'] + bar_labels = long['Count'] + vals_str = [f'{y:.1f} %\n({x:.0f})' if y>4 else '' for x, y in zip(bar_labels, vals)] + bar = ax.barh(labels, vals, width, left=running_total_long, label=mode) + ax.bar_label(bar, label_type='center', labels=vals_str, rotation=90, fontsize=16) + running_total_long = [total + val for total, val in zip(running_total_long, vals)] + else: + print(f"{mode} is unavailable.") + ax.set_title(plot_title, fontsize=25) + ax.legend(bbox_to_anchor=(1, 1), fancybox=True, shadow=True) + ax.tick_params(axis='y', labelsize=18) + ax.tick_params(axis='x', labelsize=18) + plt.subplots_adjust(bottom=0.25) + + fig.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') + plt.show() + def energy_impact(x,y,color,plot_title,file_name): color = color.map({True: 'green', False: 'red'}) objects = ('Energy Savings', 'Energy Loss') From d6f1b8269b7da5b4013193148eb8d32be03f64c7 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 18:36:38 -0700 Subject: [PATCH 002/198] Add calculate_pct(labels, values) to calculate the proportion. --- viz_scripts/plots.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index 3c5eef3..7737ad6 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -130,6 +130,15 @@ def func(pct, values): plt.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') plt.show() +def calculate_pct(labels, values): + v2l_df = pd.DataFrame({"vals": values}, index=labels) + + # Calculate % for all the values + vs = v2l_df.vals.sum() + v2l_df["pct"] = v2l_df.vals.apply(lambda x: (x/vs) * 100) + + return (v2l_df.index.to_list(),v2l_df.vals.to_list(), v2l_df.pct.to_list()) + def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): fig, ax = plt.subplots(1,1, figsize=(18,6)) From 5ddc396d8292c1ef8afd8be7ae2cea1833803ebb Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 18:41:04 -0700 Subject: [PATCH 003/198] Introduce a process_trip_data() to create a dataframe with cols Mode, Count and Proportion. --- viz_scripts/plots.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index 7737ad6..fa64bfc 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -139,6 +139,14 @@ def calculate_pct(labels, values): return (v2l_df.index.to_list(),v2l_df.vals.to_list(), v2l_df.pct.to_list()) +# Create dataframe with cols: 'Mode' 'Count' and 'Proportion' +def process_trip_data(labels, values, trip_type): + m_labels, m_values, m_pct = calculate_pct(labels, values) + data_trip = {'Mode': m_labels, 'Count': m_values, 'Proportion': m_pct} + df_total_trip = pd.DataFrame(data_trip) + df_total_trip['Trip Type'] = trip_type + return df_total_trip + def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): fig, ax = plt.subplots(1,1, figsize=(18,6)) From 1165562179c122716f83fe5433d25a94a2597a69 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 18:45:11 -0700 Subject: [PATCH 004/198] Merge list of all dataframes into one. --- viz_scripts/plots.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index fa64bfc..254283f 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt import seaborn as sns from matplotlib.patches import Patch +from itertools import product sns.set_style("whitegrid") sns.set() @@ -147,6 +148,20 @@ def process_trip_data(labels, values, trip_type): df_total_trip['Trip Type'] = trip_type return df_total_trip +# Input: List of all dataframes +# Ouput: A single dataframe such that Trip Type has all Mode +def merge_dataframes(all_data_frames): + # Concatenate DataFrames + df = pd.concat(all_data_frames, ignore_index=True) + + # Create DataFrame with unique combinations of 'Trip Type' and 'Mode' + unique_combinations = pd.DataFrame(list(product(df['Trip Type'].unique(), df['Mode'].unique())), columns=['Trip Type', 'Mode']) + + # Merge the original DataFrame with the unique combinations DataFrame + merged_df = pd.merge(unique_combinations, df, on=['Trip Type', 'Mode'], how='left').fillna(0) + + return merged_df + def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): fig, ax = plt.subplots(1,1, figsize=(18,6)) From 2e9ad7dedb1344e5a6d2b0f77d40b5d9aa15cff1 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 18:49:00 -0700 Subject: [PATCH 005/198] Remove functions related with Pie Chart from plots.py. --- viz_scripts/plots.py | 111 ------------------------------------------- 1 file changed, 111 deletions(-) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index 254283f..c5cf78d 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -20,117 +20,6 @@ SAVE_DIR="/plots/" - -def merge_small_entries(labels, values): - v2l_df = pd.DataFrame({"vals": values}, index=labels) - - # Calculate % for all the values - vs = v2l_df.vals.sum() - v2l_df["pct"] = v2l_df.vals.apply(lambda x: (x/vs) * 100) - disp.display(v2l_df) - - # Find small chunks to combine - small_chunk = v2l_df.where(lambda x: x.pct <= 2).dropna() - misc_count = small_chunk.sum() - - v2l_df = v2l_df.drop(small_chunk.index) - disp.display(v2l_df) - - # This part if a bit tricky - # We could have already had a non-zero other, and it could be small or large - if "Other" not in v2l_df.index: - # zero other will end up with misc_count - v2l_df.loc["Other"] = misc_count - elif "Other" in small_chunk.index: - # non-zero small other will already be in misc_count - v2l_df.loc["Other"] = misc_count - else: - # non-zero large other, will not already be in misc_count - v2l_df.loc["Other"] = v2l_df.loc["Other"] + misc_count - disp.display(v2l_df) - - return (v2l_df.index.to_list(),v2l_df.vals.to_list()) - - -def format_pct(pct, values): - total = sum(values) - absolute = int(round(pct*total/100.0)) - return "{:.1f}%\n({:d})".format(pct, absolute) if pct > 4 else'' - - -def pie_chart_mode(plot_title,labels,values,file_name): - - colours = dict(zip(labels, plt.cm.tab20.colors[:len(labels)])) - fig, ax = plt.subplots(figsize=(10, 10), subplot_kw=dict(aspect="equal")) - - m_labels, m_values = merge_small_entries(labels, values) - - wedges, texts, autotexts = ax.pie(m_values, - labels = m_labels, - colors=[colours[key] for key in labels], - pctdistance=0.75, - autopct= lambda pct: format_pct(pct, values), - textprops={'size': 23}) - - ax.set_title(plot_title, size=25) - plt.text(-1.3,-1.3,f"Last updated {arrow.get()}", fontsize=10) - plt.setp(autotexts, **{'color':'white', 'weight':'bold', 'fontsize':20}) - plt.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') - plt.show() - -def pie_chart_sensed_mode(plot_title,labels,values,file_name): - all_labels= ['IN_VEHICLE', - 'UNKNOWN', - 'WALKING', - 'AIR_OR_HSR', - 'BICYCLING', - 'OTHER'] - - val2labeldf = pd.DataFrame({"labels": labels, "values": values}) - - colours = dict(zip(all_labels, plt.cm.tab10.colors[:len(all_labels)])) - fig, ax = plt.subplots(figsize=(10, 10), subplot_kw=dict(aspect="equal")) - - m_labels, m_values = merge_small_entries(labels, values) - - wedges, texts, autotexts = ax.pie(m_values, - labels = m_labels, - colors=[colours[key] for key in labels], - pctdistance=0.75, - autopct= lambda pct: format_pct(pct, values), - textprops={'size': 23}) - - ax.set_title(plot_title, size=25) - plt.text(-1.3,-1.3,f"Last updated {arrow.get()}", fontsize=10) - plt.setp(autotexts, **{'color':'white', 'weight':'bold', 'fontsize':20}) - plt.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') - plt.show() - -def pie_chart_purpose(plot_title,labels,values,file_name): - - colours = dict(zip(labels, plt.cm.tab20.colors[:len(labels)])) - fig, ax = plt.subplots(figsize=(10, 10), subplot_kw=dict(aspect="equal")) - - m_labels, m_values = merge_small_entries(labels, values) - - def func(pct, values): - total = sum(values) - absolute = int(round(pct*total/100.0)) - return "{:.1f}%\n({:d})".format(pct, absolute) if pct > 3 else'' - - wedges, texts, autotexts = ax.pie(m_values, - labels = m_labels, - colors=[colours[key] for key in labels], - pctdistance=0.85, - autopct=lambda pct: func(pct, values), - textprops={'size': 23}) - - ax.set_title(plot_title, size=25) - plt.text(-1.3,-1.3,f"Last updated {arrow.get()}", fontsize=10) - plt.setp(autotexts, **{'color':'white', 'weight':'bold', 'fontsize':20}) - plt.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') - plt.show() - def calculate_pct(labels, values): v2l_df = pd.DataFrame({"vals": values}, index=labels) From a55e9f64330c616dfedeeed79d346ae833d2fcc5 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 18:55:48 -0700 Subject: [PATCH 006/198] Remove code and markdown blocks related with Pie Chart from generic_metrics notebook. --- viz_scripts/generic_metrics.ipynb | 182 ------------------------------ 1 file changed, 182 deletions(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 55c6768..1273477 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -107,188 +107,6 @@ "## Generic Metrics" ] }, - { - "cell_type": "markdown", - "id": "distributed-peace", - "metadata": {}, - "source": [ - "### Distribution of Mode_confirm attribute" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "tracked-serbia", - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "file_name='ntrips_mode_confirm%s' % file_suffix\n", - "plot_title_no_quality= \"Number of trips for each mode (selected by users)\"\n", - "try:\n", - " labels_mc = expanded_ct['Mode_confirm'].value_counts(dropna=True).keys().tolist()\n", - " values_mc = expanded_ct['Mode_confirm'].value_counts(dropna=True).tolist() \n", - " plot_title = plot_title_no_quality+\"\\n\"+quality_text\n", - " pie_chart_mode(plot_title,labels_mc,values_mc,file_name)\n", - " alt_text = store_alt_text_pie(pd.DataFrame(values_mc, labels_mc), file_name, plot_title)\n", - " print(expanded_ct['Mode_confirm'].value_counts(dropna=True))\n", - "except:\n", - " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", - " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "about-seafood", - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "plot_title_no_quality= \"Number of commute trips for each mode (selected by users)\"\n", - "file_name= 'ntrips_commute_mode_confirm%s' % file_suffix\n", - "\n", - "try:\n", - " if (len(dynamic_labels)):\n", - " purpose_map_label = scaffolding.mapping_labels(dynamic_labels, \"PURPOSE\")\n", - " translation_work = purpose_map_label['work']\n", - " trip_purpose_query = f\"Trip_purpose == '{translation_work}'\"\n", - " else:\n", - " trip_purpose_query = \"Trip_purpose == 'Work'\"\n", - "\n", - " labels_mc = expanded_ct.query(trip_purpose_query).Mode_confirm.value_counts(dropna=True).keys().tolist()\n", - " values_mc = expanded_ct.query(trip_purpose_query).Mode_confirm.value_counts(dropna=True).tolist()\n", - " commute_quality_text = scaffolding.get_quality_text(expanded_ct, expanded_ct.query(trip_purpose_query), \"commute\", include_test_users)\n", - " plot_title= plot_title_no_quality+\"\\n\"+commute_quality_text\n", - " pie_chart_mode(plot_title,labels_mc,values_mc,file_name)\n", - " alt_text = store_alt_text_pie(pd.DataFrame(values_mc, labels_mc), file_name, plot_title)\n", - "except:\n", - " debug_df.loc[\"Commute_trips\"] = len(expanded_ct.query(trip_purpose_query)) if \"Trip_purpose\" in expanded_ct.columns else 0\n", - " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", - " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" - ] - }, - { - "cell_type": "markdown", - "id": "careful-spencer", - "metadata": {}, - "source": [ - "### Distribution of Trip_purpose attribute" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "conservative-september", - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "plot_title_no_quality=\"Number of trips for each purpose (selected by users)\"\n", - "file_name= 'ntrips_purpose%s' % file_suffix\n", - "\n", - "try:\n", - " labels_tp = expanded_ct['Trip_purpose'].value_counts(dropna=True).keys().tolist()\n", - " values_tp = expanded_ct['Trip_purpose'].value_counts(dropna=True).tolist()\n", - " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", - " pie_chart_purpose(plot_title,labels_tp,values_tp,file_name)\n", - " alt_text = store_alt_text_pie(pd.DataFrame(values_tp, labels_tp), file_name, plot_title)\n", - " print(expanded_ct['Trip_purpose'].value_counts(dropna=True))\n", - "except:\n", - " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", - " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" - ] - }, - { - "cell_type": "markdown", - "id": "crucial-keyboard", - "metadata": {}, - "source": [ - "### Mode choice for trips under 80% mark" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "identified-replica", - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "file_name ='ntrips_under10miles_mode_confirm%s' % file_suffix\n", - "\n", - "try:\n", - " #determine 80th percentile\n", - " cutoff = expanded_ct.distance.quantile(0.8)\n", - " if pd.isna(cutoff):\n", - " cutoff = 0\n", - " dist_threshold = expanded_ct[distance_col].quantile(0.8).round(1)\n", - " dist_threshold = str(dist_threshold) \n", - "\n", - " plot_title_no_quality=\"Mode confirmations for trips under \" + dist_threshold + \" \" + label_units_lower\n", - " plot_title_no_quality=plot_title_no_quality+\"\\n[\"+dist_threshold + \" \" + label_units_lower+\" represents 80th percentile of trip length]\"\n", - "\n", - " labels_d10 = expanded_ct.loc[(expanded_ct['distance'] <= cutoff)].Mode_confirm.value_counts(dropna=True).keys().tolist()\n", - " values_d10 = expanded_ct.loc[(expanded_ct['distance'] <= cutoff)].Mode_confirm.value_counts(dropna=True).tolist()\n", - " d10_quality_text = scaffolding.get_quality_text(expanded_ct, expanded_ct[expanded_ct['distance'] <= cutoff], \"< \" + dist_threshold + \" \" + label_units_lower, include_test_users)\n", - " plot_title = plot_title_no_quality+\"\\n\"+d10_quality_text\n", - " pie_chart_mode(plot_title,labels_d10,values_d10,file_name)\n", - " alt_text = store_alt_text_pie(pd.DataFrame(values_d10, labels_d10), file_name, plot_title)\n", - " print(expanded_ct.loc[(expanded_ct['distance'] <= cutoff)].Mode_confirm.value_counts(dropna=True))\n", - "\n", - "except:\n", - " d10_df = expanded_ct.query(\"distance <= \" + str(cutoff)) if \"distance\" in expanded_ct.columns else expanded_ct\n", - " debug_df.loc[\"Trips_less_than_80th_pct\"] = scaffolding.trip_label_count(\"Mode_confirm\", d10_df)\n", - " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", - " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" - ] - }, - { - "cell_type": "markdown", - "id": "dominant-company", - "metadata": {}, - "source": [ - "### Miles per chosen transport mode" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "satisfied-sharing", - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "plot_title_no_quality= label_units + \" for each mode (selected by users)\"\n", - "plot_title=plot_title_no_quality + '\\n' + quality_text\n", - "file_name ='miles_mode_confirm%s' % file_suffix\n", - "\n", - "try:\n", - " dist = expanded_ct.groupby('Mode_confirm').agg({distance_col: ['sum', 'count' , 'mean']})\n", - " dist.columns = ['Total ('+label_units_lower+')', 'Count', 'Average ('+label_units_lower+')']\n", - " dist = dist.reset_index()\n", - " dist =dist.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", - " dist_dict = dict(zip(dist['Mode_confirm'], dist['Total ('+label_units_lower+')']))\n", - " \n", - " labels_m = []\n", - " values_m = []\n", - " \n", - " for x, y in dist_dict.items():\n", - " labels_m.append(x)\n", - " values_m.append(y)\n", - "\n", - " pie_chart_mode(plot_title,labels_m,values_m,file_name)\n", - " alt_text = store_alt_text_pie(pd.DataFrame(values_m, labels_m), file_name, plot_title)\n", - "except:\n", - " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", - " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality) " - ] - }, { "cell_type": "markdown", "id": "demanding-franklin", From 7e71308461be61bb22d8e7bb9f27e4d31fd675db Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 18:57:20 -0700 Subject: [PATCH 007/198] Add sensed_algo_prefix for generic_metrics notebook. --- viz_scripts/generic_metrics.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 1273477..a5b27de 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -32,7 +32,8 @@ "mode_of_interest = None\n", "include_test_users = False\n", "dynamic_labels = {}\n", - "use_imperial = False" + "use_imperial = False\n", + "sensed_algo_prefix = \"cleaned\"" ] }, { From 45db963e3657635313b39a049999143d46b7869d Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:00:54 -0700 Subject: [PATCH 008/198] Added load_viz_notebook_sensor_inference_data() function in generic metrics notebook. --- viz_scripts/generic_metrics.ipynb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index a5b27de..069a932 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -100,6 +100,28 @@ " include_test_users=include_test_users)" ] }, + { + "cell_type": "markdown", + "id": "6d44c87e", + "metadata": {}, + "source": [ + "## Collect Data from Database for Sensed Metrics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55ec383b", + "metadata": {}, + "outputs": [], + "source": [ + "expanded_ct_sensed, file_suffix_sensed, quality_text_sensed, debug_df_sensed = scaffolding.load_viz_notebook_sensor_inference_data(year,\n", + " month,\n", + " program,\n", + " include_test_users,\n", + " sensed_algo_prefix)" + ] + }, { "cell_type": "markdown", "id": "modified-skiing", From ec9037b098504059b3b687305aa21dd13d34bd2d Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:03:40 -0700 Subject: [PATCH 009/198] Filter for mode_of_interest. --- viz_scripts/generic_metrics.ipynb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 069a932..7cc058d 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -80,7 +80,7 @@ "id": "intellectual-columbus", "metadata": {}, "source": [ - "## Collect Data From Database" + "## Collect Data From Database for Generic Metrics" ] }, { @@ -122,6 +122,25 @@ " sensed_algo_prefix)" ] }, + { + "cell_type": "markdown", + "id": "7f42f272", + "metadata": {}, + "source": [ + "## Metrics for Specific Mode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "657d7e18", + "metadata": {}, + "outputs": [], + "source": [ + "data_eb = expanded_ct.query(f\"mode_confirm == '{mode_of_interest}'\") if \"mode_confirm\" in expanded_ct.columns else expanded_ct\n", + "quality_text_specific = scaffolding.get_quality_text(expanded_ct, data_eb, mode_of_interest, include_test_users)" + ] + }, { "cell_type": "markdown", "id": "modified-skiing", From ebeb9ddb981879011e051ae22f170d5b21069e42 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:05:02 -0700 Subject: [PATCH 010/198] Remove Generic Metrics markdown. --- viz_scripts/generic_metrics.ipynb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 7cc058d..62d083a 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -141,14 +141,6 @@ "quality_text_specific = scaffolding.get_quality_text(expanded_ct, data_eb, mode_of_interest, include_test_users)" ] }, - { - "cell_type": "markdown", - "id": "modified-skiing", - "metadata": {}, - "source": [ - "## Generic Metrics" - ] - }, { "cell_type": "markdown", "id": "demanding-franklin", From a1283bbaea9f5bfad5deb05c778a9815807418eb Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:08:49 -0700 Subject: [PATCH 011/198] Markdown and code for 100% Stacked Bar Charts based on Number of Trips. --- viz_scripts/generic_metrics.ipynb | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 62d083a..0df97de 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -141,6 +141,43 @@ "quality_text_specific = scaffolding.get_quality_text(expanded_ct, data_eb, mode_of_interest, include_test_users)" ] }, + { + "cell_type": "markdown", + "id": "e50959c1", + "metadata": {}, + "source": [ + "### 1. 100% Stacked Bar Charts (Based on Number of Trips)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aef741fe", + "metadata": {}, + "outputs": [], + "source": [ + "file_name = f'ntrips_mode_confirm{file_suffix}'\n", + "plot_title_no_quality= \"Number of trips for each mode (selected by users)\"\n", + "\n", + "try:\n", + " labels_mc = expanded_ct['Mode_confirm'].value_counts(dropna=True).keys().tolist()\n", + " values_mc = expanded_ct['Mode_confirm'].value_counts(dropna=True).tolist()\n", + " df_confirmed_tc = process_trip_data(labels_mc, values_mc, \"Labeled by user \\n (Based on Confirmed Trips)\")\n", + " \n", + " labels_pm_sensed = expanded_ct_sensed['primary_mode'].value_counts(dropna=True).keys().tolist()\n", + " values_pm_sensed = expanded_ct_sensed['primary_mode'].value_counts(dropna=True).tolist()\n", + " df_sensed_tc = process_trip_data(labels_pm_sensed, values_pm_sensed, \"Sensed by OpenPATH \\n (Based on Total Trips)\")\\\n", + " \n", + " all_data_frames = [df_confirmed_tc,df_sensed_tc]\n", + " result_df = merge_dataframes(all_data_frames)\n", + "\n", + " plot_title = plot_title_no_quality + \"\\n\" + quality_text\n", + " stacked_bar_chart_generic(plot_title, result_df, file_name, 2) \n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", From 441019c5199cddae7aca2f485cf2fb2ccaabd8a8 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:15:03 -0700 Subject: [PATCH 012/198] 2. 100% Stacked Bar Charts representing 80th of number of trips. --- viz_scripts/generic_metrics.ipynb | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 0df97de..835f221 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -178,6 +178,55 @@ " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, + { + "cell_type": "markdown", + "id": "8fc63a45", + "metadata": {}, + "source": [ + "### 2. 100% Stacked Bar Charts (Represents 80th of the Number of Trips)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "77ece8ee", + "metadata": {}, + "outputs": [], + "source": [ + "file_name = f'ntrips_mode_under80{file_suffix}'\n", + "plot_title_no_quality= \"Number of trips for 80th percentile for each mode (selected by users):\"\n", + "\n", + "try:\n", + " cutoff = expanded_ct.distance.quantile(0.8)\n", + " if pd.isna(cutoff):\n", + " cutoff = 0\n", + " dist_threshold = expanded_ct[distance_col].quantile(0.8).round(1)\n", + " dist_threshold = str(dist_threshold)\n", + " labels_mc_u80 = expanded_ct.loc[(expanded_ct['distance'] <= cutoff)].Mode_confirm.value_counts(dropna=True).keys().tolist()\n", + " values_mc_u80 = expanded_ct.loc[(expanded_ct['distance'] <= cutoff)].Mode_confirm.value_counts(dropna=True).tolist()\n", + " u80_quality_text = scaffolding.get_quality_text(expanded_ct, expanded_ct[expanded_ct['distance'] <= cutoff], \"< \" + dist_threshold + \" \" + short_label, include_test_users)\n", + " df_confirmed_tc_u80 = process_trip_data(labels_mc_u80, values_mc_u80, \"Labeled by user \\n (Based on Confirmed Trips)\")\n", + "\n", + " cutoff_sensed = expanded_ct_sensed.distance.quantile(0.8)\n", + " if pd.isna(cutoff_sensed):\n", + " cutoff_sensed = 0\n", + " dist_threshold_sensed = expanded_ct_sensed[distance_col].quantile(0.8).round(1)\n", + " dist_threshold_sensed = str(dist_threshold_sensed)\n", + " labels_pm_u80 = expanded_ct_sensed.loc[(expanded_ct_sensed['distance'] <= cutoff_sensed)].primary_mode.value_counts(dropna=True).keys().tolist()\n", + " values_pm_u80 = expanded_ct_sensed.loc[(expanded_ct_sensed['distance'] <= cutoff_sensed)].primary_mode.value_counts(dropna=True).tolist()\n", + " u80_quality_text_sensed = scaffolding.get_quality_text_sensed(expanded_ct_sensed[expanded_ct_sensed['distance'] <= cutoff_sensed], \"<= \" + dist_threshold_sensed + \" \" + short_label , include_test_users)\n", + " df_sensed_tc_u80 = process_trip_data(labels_pm_u80, values_pm_u80,\"Sensed by OpenPATH \\n (Based on Total Trips)\")\n", + "\n", + " all_data_frames_u80 = [df_confirmed_tc_u80, df_sensed_tc_u80]\n", + " result_df_u80 = merge_dataframes(all_data_frames_u80)\n", + "\n", + " plot_title = plot_title_no_quality + \"\\n\" + \"For Sensed: \" + u80_quality_text_sensed + \"\\n\" + \"For Labeled: \" + u80_quality_text\n", + " stacked_bar_chart_generic(plot_title, result_df_u80, file_name, 2)\n", + "except Exception as e:\n", + " generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", From e53c0cc709a83c8d165ad7bcedb386d9c166371e Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:19:32 -0700 Subject: [PATCH 013/198] 3. 100% Stacked Bar Charts representing commute trips. --- viz_scripts/generic_metrics.ipynb | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 835f221..8c221d1 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -227,6 +227,46 @@ " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, + { + "cell_type": "markdown", + "id": "7fa4f3da", + "metadata": {}, + "source": [ + "### 3. 100% Stacked Bar Charts (Representing Commute Trips) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5c6cd4cf", + "metadata": {}, + "outputs": [], + "source": [ + "file_name = \"ntrips_commute_mode_confirm{file_suffix}\"\n", + "plot_title_no_quality= \"Number of commute trips for each mode (selected by users)\"\n", + "\n", + "try:\n", + " # Number of commute trips\n", + "\n", + " if (len(dynamic_labels)):\n", + " purpose_map_label = scaffolding.mapping_labels(dynamic_labels, \"PURPOSE\")\n", + " translation_work = purpose_map_label['work']\n", + " trip_purpose_query = f\"Trip_purpose == '{translation_work}'\"\n", + " else:\n", + " trip_purpose_query = \"Trip_purpose == 'Work'\"\n", + "\n", + " labels_mc_commute = expanded_ct.query(trip_purpose_query).Mode_confirm.value_counts(dropna=True).keys().tolist()\n", + " values_mc_commute = expanded_ct.query(trip_purpose_query).Mode_confirm.value_counts(dropna=True).tolist()\n", + " commute_quality_text = scaffolding.get_quality_text(expanded_ct, expanded_ct.query(trip_purpose_query), \"commute\", include_test_users)\n", + " df_total_trip_commute = process_trip_data(labels_mc_commute, values_mc_commute, \"Labeled by user \\n (Based on Confirmed Trips)\")\n", + " \n", + " plot_title = plot_title_no_quality + \"\\n\" + commute_quality_text\n", + " stacked_bar_chart_generic(plot_title, df_total_trip_commute, file_name, 1)\n", + "except Exception as e:\n", + " generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", @@ -242,8 +282,8 @@ "metadata": {}, "outputs": [], "source": [ - "plot_title_no_quality=\"Average \"+ label_units+\" for each mode with > 3 entries\"\n", "file_name ='average_miles_mode_confirm%s' % file_suffix\n", + "plot_title_no_quality=\"Average \"+ label_units+\" for each mode with > 3 entries\"\n", "\n", "try:\n", " x='Mode_confirm'\n", From eb3dcfc28a164679181f2504154c7300840456c6 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:20:34 -0700 Subject: [PATCH 014/198] Clean up. --- viz_scripts/generic_metrics.ipynb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 8c221d1..058613b 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -232,7 +232,7 @@ "id": "7fa4f3da", "metadata": {}, "source": [ - "### 3. 100% Stacked Bar Charts (Representing Commute Trips) " + "### 3. 100% Stacked Bar Charts (Represents Commute Trips) " ] }, { @@ -246,8 +246,6 @@ "plot_title_no_quality= \"Number of commute trips for each mode (selected by users)\"\n", "\n", "try:\n", - " # Number of commute trips\n", - "\n", " if (len(dynamic_labels)):\n", " purpose_map_label = scaffolding.mapping_labels(dynamic_labels, \"PURPOSE\")\n", " translation_work = purpose_map_label['work']\n", From e582011f6ead4b70b1cdf26a7f71853ad3419e6d Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:26:52 -0700 Subject: [PATCH 015/198] 4. 100% Stacked Bar Charts representing Distance by Mode. --- viz_scripts/generic_metrics.ipynb | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 058613b..558c625 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -265,6 +265,72 @@ " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, + { + "cell_type": "markdown", + "id": "b560cb32", + "metadata": {}, + "source": [ + "### 4. 100% Stacked Bar Charts (Represents Distance by Mode)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ffccb96f", + "metadata": {}, + "outputs": [], + "source": [ + "file_name ='distance_mode%s' % file_suffix\n", + "plot_title_no_quality = label_units + \" for each mode\"\n", + "\n", + "try:\n", + " dist = expanded_ct.groupby('Mode_confirm').agg({distance_col: ['sum', 'count' , 'mean']})\n", + " dist.columns = ['Total ('+label_units_lower+')', 'Count', 'Average ('+label_units_lower+')']\n", + " dist = dist.reset_index()\n", + " dist =dist.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", + " dist_dict = dict(zip(dist['Mode_confirm'], dist['Total ('+label_units_lower+')']))\n", + " labels_mc_dist = []\n", + " values_mc_dist = []\n", + " for x, y in dist_dict.items():\n", + " labels_mc_dist.append(x)\n", + " values_mc_dist.append(y) \n", + " df_confirm_dist = process_trip_data(labels_mc_dist, values_mc_dist, \"Labeled by user \\n Trip distance\")\n", + "\n", + " dist_sensed = expanded_ct_sensed.groupby('primary_mode').agg({distance_col: ['sum', 'count' , 'mean']})\n", + " dist_sensed.columns = ['Total ('+label_units_lower+')', 'Count', 'Average ('+label_units_lower+')']\n", + " dist_sensed = dist_sensed.reset_index()\n", + " dist_sensed = dist_sensed.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", + " dist_dict_sensed = dict(zip(dist_sensed['primary_mode'], dist_sensed['Total ('+label_units_lower+')']))\n", + " labels_pm_dist = []\n", + " values_pm_dist = []\n", + " for x, y in dist_dict_sensed.items():\n", + " labels_pm_dist.append(x)\n", + " values_pm_dist.append(y)\n", + " df_sensed_dist = process_trip_data(labels_pm_dist, values_pm_dist, \"Sensed by OpenPATH \\n Trip distance (Overall)\")\n", + " plot_title = plot_title_no_quality + \"\\n\" + quality_text\n", + "\n", + " dist_sensed_land = expanded_ct_sensed.groupby('primary_mode').agg({distance_col: ['sum', 'count' , 'mean']})\n", + " dist_sensed_land.columns = ['Total ('+label_units_lower+')', 'Count', 'Average ('+label_units_lower+')']\n", + " dist_sensed_land = dist_sensed_land.reset_index()\n", + " dist_sensed_land =dist_sensed_land.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", + " dist_dict_sensed_land = dict(zip(dist_sensed_land['primary_mode'], dist_sensed_land['Total ('+label_units_lower+')']))\n", + " labels_pm_dist_land = []\n", + " values_pm_dist_land = []\n", + " for x, y in dist_dict_sensed_land.items():\n", + " if x != \"AIR_OR_HSR\":\n", + " labels_pm_dist_land.append(x)\n", + " values_pm_dist_land.append(y)\n", + " df_sensed_dist_land = process_trip_data(labels_pm_dist_land, values_pm_dist_land, \"Sensed by OpenPATH \\n Trips distance (Land)\")\n", + " \n", + " all_data_frames = [df_confirm_dist,df_sensed_dist, df_sensed_dist_land]\n", + " result_df = merge_dataframes(all_data_frames)\n", + "\n", + " stacked_bar_chart_generic(plot_title_no_quality, result_df, file_name, 3)\n", + "except Exception as e:\n", + " generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", From 5fedbb043f4cd138740aaa3414834f146ead0784 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:29:20 -0700 Subject: [PATCH 016/198] 5. 100% Stacked Bar Charts representing Count by Purpose. --- viz_scripts/generic_metrics.ipynb | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 558c625..7a30b77 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -331,6 +331,42 @@ " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, + { + "cell_type": "markdown", + "id": "ffb2df0b", + "metadata": {}, + "source": [ + "### 5. 100% Stacked Bar Charts (Count by Purpose)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46474ada", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=\"Number of trips for each purpose (selected by users)\"\n", + "file_name= 'ntrips_purpose%s' % file_suffix\n", + "\n", + "try:\n", + " labels_tp = expanded_ct['Trip_purpose'].value_counts(dropna=True).keys().tolist()\n", + " values_tp = expanded_ct['Trip_purpose'].value_counts(dropna=True).tolist()\n", + " df_purpose_trip = process_trip_data(labels_tp, values_tp, \"Labeled by user \\n All Purpose Trips\")\n", + " \n", + " labels_tp_eb = data_eb['Trip_purpose'].value_counts(dropna=True).keys().tolist()\n", + " values_tp_eb = data_eb['Trip_purpose'].value_counts(dropna=True).tolist()\n", + " df_purpose_trip_eb = process_trip_data(labels_tp_eb, values_tp_eb, \"Labeled by user \\n e-bike specific Purpose Trips\")\n", + " \n", + " all_tp_data_frames = [df_purpose_trip,df_purpose_trip_eb]\n", + " result_tp_df = merge_dataframes(all_tp_data_frames)\n", + " \n", + " stacked_bar_chart_generic(plot_title_no_quality, result_tp_df, file_name, 2)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", From f31e43e01313fa21c5d0046a4a2a002e2bdd5e45 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:32:02 -0700 Subject: [PATCH 017/198] 6. 100% Stacked Bar Charts representing Replaced mode. --- viz_scripts/generic_metrics.ipynb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 7a30b77..af2811f 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -367,6 +367,36 @@ " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, + { + "cell_type": "markdown", + "id": "3e2e8d8c", + "metadata": {}, + "source": [ + "### 6. 100% Stacked Bar Charts (Represents Rep)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4cc86684", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=f\"Number of trips for each replaced mode by {mode_of_interest} only\"\n", + "file_name= f'ntrips_{mode_of_interest}_replace%s' % file_suffix\n", + "\n", + "try:\n", + " labels_eb = data_eb.Replaced_mode.value_counts(dropna=True).keys().tolist()\n", + " values_eb = data_eb.Replaced_mode.value_counts(dropna=True).tolist()\n", + "\n", + " df_replaced_trip = process_trip_data(labels_eb, values_eb, \"Replaced number of trips by e-bike\")\n", + "\n", + " stacked_bar_chart_generic(plot_title, df_replaced_trip, file_name, 1)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", From 7b6cef22c1d2e88830579600673297c3a4edc1ac Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:33:29 -0700 Subject: [PATCH 018/198] Update markdown for 6. --- viz_scripts/generic_metrics.ipynb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index af2811f..e5bc558 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -372,7 +372,7 @@ "id": "3e2e8d8c", "metadata": {}, "source": [ - "### 6. 100% Stacked Bar Charts (Represents Rep)" + "### 6. 100% Stacked Bar Charts (Represents Replaced mode)" ] }, { @@ -397,6 +397,14 @@ " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, + { + "cell_type": "markdown", + "id": "b20f1b4b", + "metadata": {}, + "source": [ + "7. 100% Stacked Bar Charts ()" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", From 428982cf146ae080bbc6254db7c0dbd985545ae5 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:35:19 -0700 Subject: [PATCH 019/198] 7. 100% Stacked Bar Charts representing Trip Distance based on Replaced mode. --- viz_scripts/generic_metrics.ipynb | 41 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index e5bc558..6a109b5 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -372,7 +372,7 @@ "id": "3e2e8d8c", "metadata": {}, "source": [ - "### 6. 100% Stacked Bar Charts (Represents Replaced mode)" + "### 6. 100% Stacked Bar Charts (Represents Number of trips based on Replaced mode)" ] }, { @@ -399,10 +399,45 @@ }, { "cell_type": "markdown", - "id": "b20f1b4b", + "id": "f5575b8d", "metadata": {}, "source": [ - "7. 100% Stacked Bar Charts ()" + "### 7. 100% Stacked Bar Charts (Represents Trip Distance based on Replaced mode ) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "48c131c7", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=f\"Distribution of \"+label_units+f\" Replaced by {mode_of_interest}\"\n", + "file_name =f'miles_{mode_of_interest}_replaced_mode%s' % file_suffix\n", + "\n", + "try:\n", + " dg=data_eb.groupby('Replaced_mode').agg({distance_col: ['sum', 'count' , 'mean']},)\n", + " dg.columns = ['Total ('+label_units_lower+')', 'Count' ,'Average ('+label_units_lower+')']\n", + " dg = dg.reset_index()\n", + " dg = dg.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", + "\n", + " dg_dict = dict(zip(dg['Replaced_mode'], dg['Total ('+label_units_lower+')']))\n", + " \n", + " labels_m = []\n", + " values_m = []\n", + "\n", + " for x, y in dg_dict.items():\n", + " labels_m.append(x)\n", + " values_m.append(y)\n", + "\n", + " df_replaced_dist = process_trip_data(labels_m, values_m, \"Replaced distance by e-bike\")\n", + "\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + " stacked_bar_chart_generic(plot_title, df_replaced_dist, file_name, 1)\n", + " alt_text = store_alt_text_pie(pd.DataFrame(values_m, labels_m), file_name, plot_title)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, { From 119d707bccd23141cb7665b84bf260171aa062ba Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:39:46 -0700 Subject: [PATCH 020/198] Update Markdown text. --- viz_scripts/generic_metrics.ipynb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 6a109b5..6180518 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -440,6 +440,14 @@ " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] }, + { + "cell_type": "markdown", + "id": "bcef1f6a", + "metadata": {}, + "source": [ + "## Generic Metrics (Bar Charts)" + ] + }, { "cell_type": "markdown", "id": "demanding-franklin", From 1c5e00a330d5d4c6de92663e3c5e5af925d44464 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:46:15 -0700 Subject: [PATCH 021/198] Copied the bar plots from generic_metrics_sensed notebook to generic_metrics notebook. --- viz_scripts/generic_metrics.ipynb | 120 ++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 6180518..3c107aa 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -552,6 +552,126 @@ " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality) " ] + }, + { + "cell_type": "markdown", + "id": "94454e8f", + "metadata": {}, + "source": [ + "## Sensed Metrics (Bar Charts)" + ] + }, + { + "cell_type": "markdown", + "id": "1ae3bf80", + "metadata": {}, + "source": [ + "### Average miles per transport mode selected (primary_mode)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "882c0891", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=\" Average Miles for each mode with > 3 entries\\n(inferred by OpenPATH from phone sensors)\"\n", + "file_name ='average_miles_sensed_mode%s' % file_suffix\n", + "\n", + "try:\n", + " dist = expanded_ct_sensed.groupby('primary_mode').agg({distance_col: ['sum', 'count' , 'mean']})\n", + " print(f\"{dist}\")\n", + " dist.columns = ['Total ('+label_units_lower+')', 'Count', 'Average ('+label_units_lower+')']\n", + " dist = dist.reset_index()\n", + " dist =dist.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", + " \n", + " print(f\"{dist}\")\n", + " data = dist.drop((dist.query(\"Count < 3\").index)).sort_values(by=['Average ('+label_units_lower+')'], ascending=False)\n", + " x='primary_mode'\n", + " y='Average ('+label_units_lower+')'\n", + " \n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + " \n", + " barplot_mode(data,x,y,plot_title, expanded_ct_sensed['primary_mode'].dropna().unique().tolist(), file_name)\n", + " alt_text = store_alt_text_bar(pd.DataFrame(data['Average ('+label_units_lower+')'].values, data['primary_mode']), file_name, plot_title)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality) " + ] + }, + { + "cell_type": "markdown", + "id": "782926ff", + "metadata": {}, + "source": [ + "### Number of trips by day¶" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6b51c4e", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=\"Number of trips by day\\n(inferred by OpenPATH from phone sensors)\"\n", + "file_name ='ntrips_sensed_per_day%s' % file_suffix\n", + "\n", + "try:\n", + " fq_days = expanded_ct_sensed.groupby(['start_local_dt_day']).agg({'start_local_dt_day': ['sum', 'count']})\n", + " fq_days = fq_days.reset_index()\n", + " fq_days.columns = ['Day of the Month', 'Total', 'Number of Trips']\n", + "\n", + " data = fq_days\n", + " x = 'Day of the Month'\n", + " y = 'Number of Trips'\n", + " \n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + "\n", + " barplot_day(data,x,y,plot_title,file_name)\n", + " alt_text = store_alt_text_bar(pd.DataFrame(data['Number of Trips'].values, data['Day of the Month']), file_name, plot_title)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, + { + "cell_type": "markdown", + "id": "5d403785", + "metadata": {}, + "source": [ + "### Number of trips by day of week¶" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b9789a8", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=\"Number of trips by weekday\\n(inferred by OpenPATH from phone sensors)\"\n", + "file_name ='ntrips_sensed_per_weekday%s' % file_suffix\n", + "try:\n", + " fq_weekdays = expanded_ct_sensed.groupby(['start_local_dt_weekday']).agg({'start_local_dt_weekday': ['sum', 'count']})\n", + " fq_weekdays = fq_weekdays.reset_index()\n", + " fq_weekdays.columns = ['Weekday', 'Total', 'Number of Trips']\n", + " weekday_labels = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"]\n", + " fq_weekdays[\"Weekday\"] = fq_weekdays.Weekday.apply(lambda x: weekday_labels[x])\n", + "\n", + " data = fq_weekdays\n", + " x = 'Weekday'\n", + " y = 'Number of Trips'\n", + "\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + " \n", + " barplot_day(data,x,y,plot_title,file_name)\n", + " alt_text = store_alt_text_bar(pd.DataFrame(data['Number of Trips'].values, data['Weekday']), file_name, plot_title)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] } ], "metadata": { From 4d58d4c3fc778c401556529231ecf111554a5af0 Mon Sep 17 00:00:00 2001 From: iantei Date: Sun, 25 Feb 2024 19:48:40 -0700 Subject: [PATCH 022/198] Copied the bar plots from mode_specific_metrics notebook to generic_metrics notebook. --- viz_scripts/generic_metrics.ipynb | 118 ++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 3c107aa..f4de75a 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -672,6 +672,124 @@ " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" ] + }, + { + "cell_type": "markdown", + "id": "881f2170", + "metadata": {}, + "source": [ + "## Mode Specific (Bar Charts)" + ] + }, + { + "cell_type": "markdown", + "id": "601057fe", + "metadata": {}, + "source": [ + "### Average miles per trip for specified mode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24dccf66", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=\"Average \" + label_units + \" for each replaced mode with > 3 entries\\n'Other' represents trips with a non-standard or missing replacement\"\n", + "file_name ='average_miles_replaced_mode%s' % file_suffix\n", + "\n", + "try:\n", + " dg=data_eb.groupby('Replaced_mode').agg({distance_col: ['sum', 'count' , 'mean']},)\n", + " dg.columns = ['Total ('+label_units_lower+')', 'Count' ,'Average ('+label_units_lower+')']\n", + " dg = dg.reset_index()\n", + " dg = dg.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", + " data = dg.drop((dg.query(\"Count < 3\").index)).sort_values(by=['Average ('+label_units_lower+')'], ascending=False) \n", + " \n", + " x='Replaced_mode'\n", + " y='Average ('+label_units_lower+')'\n", + " y2 = \"Count\"\n", + "\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + " barplot_mode(data,x,y,plot_title, expanded_ct['Replaced_mode'].dropna().unique().tolist(), file_name)\n", + " alt_text = store_alt_text_bar(pd.DataFrame(data['Average ('+label_units_lower+')'].values, data.Replaced_mode), file_name, plot_title)\n", + "\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, + { + "cell_type": "markdown", + "id": "14650196", + "metadata": {}, + "source": [ + "### Number of trips by day for specified mode" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ef2fe77", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=f\"Number of {mode_of_interest} trips by day\"\n", + "file_name =f'ntrips_{mode_of_interest}_per_day%s' % file_suffix\n", + "\n", + "try:\n", + " fq_days = data_eb.groupby(['start_local_dt_day']).agg({'start_local_dt_day': ['sum', 'count']})\n", + " fq_days = fq_days.reset_index()\n", + " fq_days.columns = ['Day of the Month', 'Total', 'Number of Trips']\n", + "\n", + " data = fq_days\n", + " x = 'Day of the Month'\n", + " y = 'Number of Trips'\n", + "\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + " barplot_day(data,x,y,plot_title,file_name)\n", + " alt_text = store_alt_text_bar(pd.DataFrame(data['Number of Trips'].values, data['Day of the Month'].values), file_name, plot_title)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] + }, + { + "cell_type": "markdown", + "id": "e807c0f1", + "metadata": {}, + "source": [ + "### Number of trips by day of week¶" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8085e9a1", + "metadata": {}, + "outputs": [], + "source": [ + "plot_title_no_quality=f\"Number of {mode_of_interest} trips by weekday\"\n", + "file_name =f'ntrips_{mode_of_interest}_per_weekday%s' % file_suffix\n", + "\n", + "try:\n", + " fq_weekdays = data_eb.groupby(['start_local_dt_weekday']).agg({'start_local_dt_weekday': ['sum', 'count']})\n", + " fq_weekdays = fq_weekdays.reset_index()\n", + " fq_weekdays.columns = ['Weekday', 'Total', 'Number of Trips']\n", + " weekday_labels = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"]\n", + " fq_weekdays[\"Weekday\"] = fq_weekdays.Weekday.apply(lambda x: weekday_labels[x])\n", + "\n", + " data = fq_weekdays\n", + " x = 'Weekday'\n", + " y = 'Number of Trips'\n", + "\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + " barplot_day(data,x,y,plot_title,file_name)\n", + " alt_text = store_alt_text_bar(pd.DataFrame(data['Number of Trips'].values, data['Weekday'].values), file_name, plot_title)\n", + "except:\n", + " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", + " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" + ] } ], "metadata": { From 7f31c5d6456583a7bf993ae8992f4261ef887f99 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 14:36:19 -0700 Subject: [PATCH 023/198] Added Store alt text function for stacked bar charts. Added html table structure. --- viz_scripts/plots.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index c5cf78d..54f6abf 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -292,6 +292,22 @@ def store_alt_text_bar(df, chart_name, var_name): alt_text = access_alt_text(alt_text, chart_name) return alt_text +def store_alt_text_stacked_bar_chart(df, chart_name, var_name): + """ Inputs: + df = dataframe with index of item names, first column is counts + chart_name = what to label chart by in the dictionary + var_name = the variable being analyzed across pie slices + """ + # Fill out the alt text based on components of the chart and passed data + alt_text = "" + + for i in range(len(df)): + alt_text += f"{df['Trip Type'].iloc[i]}{df['Mode'].iloc[i]}{df['Count'].iloc[i]}{df['Proportion'].iloc[i]}" + + alt_text = access_alt_html(alt_text, chart_name, var_name) + + return alt_text + def store_alt_text_pie(df, chart_name, var_name): """ Inputs: df = dataframe with index of item names, first column is counts @@ -319,6 +335,39 @@ def store_alt_text_timeseries(df, chart_name, var_name): alt_text = access_alt_text(alt_text, chart_name) return alt_text +# Creating html table with col as Trip Type, Mode, Count, and Proportion +def access_alt_html(alt_text, chart_name, var_name): + """ Inputs: + alt_text = the text describing the chart + chart_name = the alt text file to save or update + var_name = the variable being analyzed across bars + """ + html_content = f""" + + + + {chart_name} + + +

{chart_name}

+

{var_name}

+ + + + + + + + {alt_text} +
Trip TypeModeCountProportion
+ + + """ + with open(SAVE_DIR + chart_name + ".html", 'w') as f: + f.write(html_content) + + return alt_text + def generate_missing_plot(plot_title,debug_df,file_name): f, ax = plt.subplots(figsize=(10,10)) From 338825885ea527270070cc38349ebca8cfafb2e9 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 14:41:03 -0700 Subject: [PATCH 024/198] Added alt_text for stacked bar charts in generic metric notebook. --- viz_scripts/generic_metrics.ipynb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index f4de75a..01c70f6 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -172,7 +172,9 @@ " result_df = merge_dataframes(all_data_frames)\n", "\n", " plot_title = plot_title_no_quality + \"\\n\" + quality_text\n", - " stacked_bar_chart_generic(plot_title, result_df, file_name, 2) \n", + " stacked_bar_chart_generic(plot_title, result_df, file_name, 2)\n", + "\n", + " alt_text = store_alt_text_stacked_bar_chart(result_df[result_df['Count'] > 0], \"100% Stacked Bar Charts\", plot_title) \n", "except:\n", " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" @@ -222,6 +224,8 @@ "\n", " plot_title = plot_title_no_quality + \"\\n\" + \"For Sensed: \" + u80_quality_text_sensed + \"\\n\" + \"For Labeled: \" + u80_quality_text\n", " stacked_bar_chart_generic(plot_title, result_df_u80, file_name, 2)\n", + "\n", + " alt_text = store_alt_text_stacked_bar_chart(result_df_u80[result_df_u80['Count'] > 0], file_name, plot_title)\n", "except Exception as e:\n", " generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" @@ -260,6 +264,8 @@ " \n", " plot_title = plot_title_no_quality + \"\\n\" + commute_quality_text\n", " stacked_bar_chart_generic(plot_title, df_total_trip_commute, file_name, 1)\n", + "\n", + " alt_text = store_alt_text_stacked_bar_chart(df_total_trip_commute, file_name, plot_title)\n", "except Exception as e:\n", " generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" @@ -326,6 +332,8 @@ " result_df = merge_dataframes(all_data_frames)\n", "\n", " stacked_bar_chart_generic(plot_title_no_quality, result_df, file_name, 3)\n", + "\n", + " alt_text = store_alt_text_stacked_bar_chart(result_df[result_df['Count'] > 0], file_name, plot_title)\n", "except Exception as e:\n", " generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" @@ -362,6 +370,7 @@ " result_tp_df = merge_dataframes(all_tp_data_frames)\n", " \n", " stacked_bar_chart_generic(plot_title_no_quality, result_tp_df, file_name, 2)\n", + " alt_text = store_alt_text_stacked_bar_chart(result_tp_df[result_tp_df['Count'] > 0], file_name, plot_title)\n", "except:\n", " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" @@ -392,6 +401,7 @@ " df_replaced_trip = process_trip_data(labels_eb, values_eb, \"Replaced number of trips by e-bike\")\n", "\n", " stacked_bar_chart_generic(plot_title, df_replaced_trip, file_name, 1)\n", + " alt_text = store_alt_text_stacked_bar_chart(df_replaced_trip, file_name, plot_title)\n", "except:\n", " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" @@ -434,7 +444,7 @@ "\n", " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", " stacked_bar_chart_generic(plot_title, df_replaced_dist, file_name, 1)\n", - " alt_text = store_alt_text_pie(pd.DataFrame(values_m, labels_m), file_name, plot_title)\n", + " alt_text = store_alt_text_stacked_bar_chart(df_replaced_dist, file_name, plot_title)\n", "except:\n", " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" From 11345f6129a044289e3f9ff3c3d691c080b556fe Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 14:43:25 -0700 Subject: [PATCH 025/198] Retrieve htmlFile in index.html. --- frontend/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/index.html b/frontend/index.html index a7e3ac1..abd7cd2 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -531,6 +531,7 @@ // and without this change, even if we set the dateVal to '' // we would try to load ntrips_purpose__default.png const imgFile = "plots/" + metric + "_" + dateVal + program + ".png"; + const htmlFile = "plots/" + metric + "_" + dateVal + program + ".html"; const altTextFile = "plots/" + metric + "_" + dateVal + program + ".txt"; const altText = loadFile(altTextFile); const nw = ["
  • " From 2f7b0da4338485dfc7049a1c20075d701b23f80f Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 14:46:39 -0700 Subject: [PATCH 026/198] Update data-sizex to 8 from 4 for ntrips_mode_confirm. --- frontend/metrics_program.html | 4 ++-- frontend/metrics_program_withoutEnergyMetrics.html | 4 ++-- frontend/metrics_study.html | 2 +- frontend/metrics_study_withoutEnergyMetrics.html | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/metrics_program.html b/frontend/metrics_program.html index d54d04a..c379a84 100644 --- a/frontend/metrics_program.html +++ b/frontend/metrics_program.html @@ -1,5 +1,5 @@ - + @@ -20,7 +20,7 @@ - + diff --git a/frontend/metrics_program_withoutEnergyMetrics.html b/frontend/metrics_program_withoutEnergyMetrics.html index e820cc9..ede4933 100644 --- a/frontend/metrics_program_withoutEnergyMetrics.html +++ b/frontend/metrics_program_withoutEnergyMetrics.html @@ -1,6 +1,6 @@ - + @@ -20,7 +20,7 @@ - + diff --git a/frontend/metrics_study.html b/frontend/metrics_study.html index 79bf1f0..2808b0b 100644 --- a/frontend/metrics_study.html +++ b/frontend/metrics_study.html @@ -1,5 +1,5 @@ - + diff --git a/frontend/metrics_study_withoutEnergyMetrics.html b/frontend/metrics_study_withoutEnergyMetrics.html index 4a2137e..87948ab 100644 --- a/frontend/metrics_study_withoutEnergyMetrics.html +++ b/frontend/metrics_study_withoutEnergyMetrics.html @@ -1,6 +1,6 @@ - + From c17027dd18b97251e635cdcccaa107e1b5302276 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 18:23:01 -0700 Subject: [PATCH 027/198] Add X and Y axis labels. --- viz_scripts/plots.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index 54f6abf..3a943a7 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -52,8 +52,8 @@ def merge_dataframes(all_data_frames): return merged_df def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): - - fig, ax = plt.subplots(1,1, figsize=(18,6)) + sns.set(font_scale=1.5) + fig, ax = plt.subplots(1,1, figsize=(15,6)) width = 0.8 running_total_long = [0] * num_bars @@ -77,6 +77,8 @@ def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): ax.tick_params(axis='x', labelsize=18) plt.subplots_adjust(bottom=0.25) + ax.set_xlabel('Proportion (Count)', fontsize=20) + ax.set_ylabel('Trip Types', fontsize=20) fig.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') plt.show() From 5d83605586d20746fdc945f0ddd5eeb31ada3525 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 18:25:55 -0700 Subject: [PATCH 028/198] Update the quality text for sensed in scaffolding.py --- viz_scripts/scaffolding.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/viz_scripts/scaffolding.py b/viz_scripts/scaffolding.py index 6f21989..b779676 100644 --- a/viz_scripts/scaffolding.py +++ b/viz_scripts/scaffolding.py @@ -275,10 +275,10 @@ def get_quality_text(before_df, after_df, mode_of_interest=None, include_test_us print(quality_text) return quality_text -def get_quality_text_sensed(df, include_test_users=False): +def get_quality_text_sensed(df, cutoff_text="", include_test_users=False): cq = (len(df), unique_users(df)) user_str = 'testers and participants' if include_test_users else 'users' - quality_text = f"Based on %s trips from %d {user_str}" % cq + quality_text = f"Based on %s trips ({cutoff_text}) from %d {user_str}" % cq if cutoff_text else f"Based on %s trips from %d {user_str}" % cq print(quality_text) return quality_text From f91f379f9e7c83fe3076e97f2380876ae7eac014 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 19:22:37 -0700 Subject: [PATCH 029/198] Update the default loaded configs. --- frontend/index.html | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index abd7cd2..e66c01b 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -422,11 +422,9 @@ const unitConfigured = configuredResponse.replaceAll("${data.display_config.use_imperial}", dist_units); $('#metric').append(unitConfigured); addPreconfiguredMetrics([ - "ntrips_mode_confirm", - "miles_mode_confirm", - "ntrips_sensed_mode", - "miles_sensed_mode", - `ntrips_${data.intro.mode_studied}_purpose`, + "ntrips_total", + "distance_mode", + "ntrips_purpose", `ntrips_${data.intro.mode_studied}_per_weekday`, `sketch_CO2impact_${data.intro.mode_studied}` ]); @@ -450,10 +448,8 @@ const unitConfigured = response.replaceAll("${data.display_config.use_imperial}", dist_units); $('#metric').append(unitConfigured); addPreconfiguredMetrics([ - "ntrips_mode_confirm", - "miles_mode_confirm", - "ntrips_sensed_mode", - "miles_sensed_mode", + "ntrips_total", + "distance_mode", "ntrips_purpose", "ntrips_sensed_per_weekday", "ts_emissions_user" From 339f0cdd2d5652a514d6492c06ca8c5978d843d0 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 19:35:29 -0700 Subject: [PATCH 030/198] Remove older file names and option values associated with it. Update data-sizex to 10 from 4 to adjust horizonatal length of the stacked bar charts. Update with new option values. --- frontend/metrics_program.html | 17 +++++++---------- .../metrics_program_withoutEnergyMetrics.html | 14 +++++--------- frontend/metrics_study.html | 14 +++++--------- .../metrics_study_withoutEnergyMetrics.html | 14 +++++--------- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/frontend/metrics_program.html b/frontend/metrics_program.html index c379a84..54e5d9d 100644 --- a/frontend/metrics_program.html +++ b/frontend/metrics_program.html @@ -1,13 +1,9 @@ - - - - - - - - - + + + + + @@ -20,7 +16,8 @@ - + + diff --git a/frontend/metrics_program_withoutEnergyMetrics.html b/frontend/metrics_program_withoutEnergyMetrics.html index ede4933..f243854 100644 --- a/frontend/metrics_program_withoutEnergyMetrics.html +++ b/frontend/metrics_program_withoutEnergyMetrics.html @@ -1,14 +1,10 @@ - - - - - - - - - + + + + + diff --git a/frontend/metrics_study.html b/frontend/metrics_study.html index 2808b0b..207d620 100644 --- a/frontend/metrics_study.html +++ b/frontend/metrics_study.html @@ -1,13 +1,9 @@ - - - - - - - - - + + + + + diff --git a/frontend/metrics_study_withoutEnergyMetrics.html b/frontend/metrics_study_withoutEnergyMetrics.html index 87948ab..b42f480 100644 --- a/frontend/metrics_study_withoutEnergyMetrics.html +++ b/frontend/metrics_study_withoutEnergyMetrics.html @@ -1,14 +1,10 @@ - - - - - - - - - + + + + + From 1cc1254eb792243e313e56b68d2ff8844bf53112 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 19:38:54 -0700 Subject: [PATCH 031/198] Update the file names. Remove print statements. --- viz_scripts/generic_metrics.ipynb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 01c70f6..29e04cb 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -29,7 +29,7 @@ "month = 11\n", "program = \"default\"\n", "study_type = \"study\"\n", - "mode_of_interest = None\n", + "mode_of_interest = \"None\"\n", "include_test_users = False\n", "dynamic_labels = {}\n", "use_imperial = False\n", @@ -156,7 +156,7 @@ "metadata": {}, "outputs": [], "source": [ - "file_name = f'ntrips_mode_confirm{file_suffix}'\n", + "file_name = f'ntrips_total{file_suffix}'\n", "plot_title_no_quality= \"Number of trips for each mode (selected by users)\"\n", "\n", "try:\n", @@ -195,7 +195,7 @@ "metadata": {}, "outputs": [], "source": [ - "file_name = f'ntrips_mode_under80{file_suffix}'\n", + "file_name = f'ntrips_under80{file_suffix}'\n", "plot_title_no_quality= \"Number of trips for 80th percentile for each mode (selected by users):\"\n", "\n", "try:\n", @@ -208,7 +208,7 @@ " values_mc_u80 = expanded_ct.loc[(expanded_ct['distance'] <= cutoff)].Mode_confirm.value_counts(dropna=True).tolist()\n", " u80_quality_text = scaffolding.get_quality_text(expanded_ct, expanded_ct[expanded_ct['distance'] <= cutoff], \"< \" + dist_threshold + \" \" + short_label, include_test_users)\n", " df_confirmed_tc_u80 = process_trip_data(labels_mc_u80, values_mc_u80, \"Labeled by user \\n (Based on Confirmed Trips)\")\n", - "\n", + " \n", " cutoff_sensed = expanded_ct_sensed.distance.quantile(0.8)\n", " if pd.isna(cutoff_sensed):\n", " cutoff_sensed = 0\n", @@ -392,7 +392,7 @@ "outputs": [], "source": [ "plot_title_no_quality=f\"Number of trips for each replaced mode by {mode_of_interest} only\"\n", - "file_name= f'ntrips_{mode_of_interest}_replace%s' % file_suffix\n", + "file_name= f'ntrips_{mode_of_interest}_replaced%s' % file_suffix\n", "\n", "try:\n", " labels_eb = data_eb.Replaced_mode.value_counts(dropna=True).keys().tolist()\n", @@ -591,12 +591,10 @@ "\n", "try:\n", " dist = expanded_ct_sensed.groupby('primary_mode').agg({distance_col: ['sum', 'count' , 'mean']})\n", - " print(f\"{dist}\")\n", " dist.columns = ['Total ('+label_units_lower+')', 'Count', 'Average ('+label_units_lower+')']\n", " dist = dist.reset_index()\n", " dist =dist.sort_values(by=['Total ('+label_units_lower+')'], ascending=False)\n", " \n", - " print(f\"{dist}\")\n", " data = dist.drop((dist.query(\"Count < 3\").index)).sort_values(by=['Average ('+label_units_lower+')'], ascending=False)\n", " x='primary_mode'\n", " y='Average ('+label_units_lower+')'\n", From c2c0576a480d82e19044a62b9f97aa91df934345 Mon Sep 17 00:00:00 2001 From: iantei Date: Mon, 26 Feb 2024 20:46:54 -0700 Subject: [PATCH 032/198] Rotate the X- axis ticks by 90, and provide last updated text below X-axis. --- viz_scripts/plots.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index 3a943a7..274762e 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -72,13 +72,14 @@ def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): else: print(f"{mode} is unavailable.") ax.set_title(plot_title, fontsize=25) - ax.legend(bbox_to_anchor=(1, 1), fancybox=True, shadow=True) - ax.tick_params(axis='y', labelsize=18) - ax.tick_params(axis='x', labelsize=18) - plt.subplots_adjust(bottom=0.25) - ax.set_xlabel('Proportion (Count)', fontsize=20) ax.set_ylabel('Trip Types', fontsize=20) + ax.tick_params(axis='y', labelsize=18) + ax.tick_params(axis='x', labelsize=18, rotation=90) + # The Last updated text is placed just right below the X-axis + plt.text(0,ax.xaxis.get_label().get_position()[0] - 1,f"Last updated {arrow.get()}", fontsize=12) + ax.legend(bbox_to_anchor=(1, 1), fancybox=True, shadow=True) + plt.subplots_adjust(bottom=0.25) fig.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') plt.show() From c639d89ee872006d170400125d554660f1eb13b3 Mon Sep 17 00:00:00 2001 From: iantei Date: Tue, 27 Feb 2024 11:36:14 -0700 Subject: [PATCH 033/198] For Stacked Bar Charts: 1. Update the plots title. 2. rename file from mile to distance for stacked bar chart. 3. Fix the file name for commute trip. --- viz_scripts/generic_metrics.ipynb | 33 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/viz_scripts/generic_metrics.ipynb b/viz_scripts/generic_metrics.ipynb index 29e04cb..f27c36f 100644 --- a/viz_scripts/generic_metrics.ipynb +++ b/viz_scripts/generic_metrics.ipynb @@ -174,7 +174,7 @@ " plot_title = plot_title_no_quality + \"\\n\" + quality_text\n", " stacked_bar_chart_generic(plot_title, result_df, file_name, 2)\n", "\n", - " alt_text = store_alt_text_stacked_bar_chart(result_df[result_df['Count'] > 0], \"100% Stacked Bar Charts\", plot_title) \n", + " alt_text = store_alt_text_stacked_bar_chart(result_df[result_df['Count'] > 0], file_name, plot_title) \n", "except:\n", " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", " alt_text = store_alt_text_missing(debug_df, file_name, plot_title_no_quality)" @@ -246,7 +246,7 @@ "metadata": {}, "outputs": [], "source": [ - "file_name = \"ntrips_commute_mode_confirm{file_suffix}\"\n", + "file_name = f\"ntrips_commute_mode_confirm{file_suffix}\"\n", "plot_title_no_quality= \"Number of commute trips for each mode (selected by users)\"\n", "\n", "try:\n", @@ -300,7 +300,7 @@ " for x, y in dist_dict.items():\n", " labels_mc_dist.append(x)\n", " values_mc_dist.append(y) \n", - " df_confirm_dist = process_trip_data(labels_mc_dist, values_mc_dist, \"Labeled by user \\n Trip distance\")\n", + " df_confirm_dist = process_trip_data(labels_mc_dist, values_mc_dist, \"Labeled by user \\n Trip distance \\n (Based on Confirmed Trips)\")\n", "\n", " dist_sensed = expanded_ct_sensed.groupby('primary_mode').agg({distance_col: ['sum', 'count' , 'mean']})\n", " dist_sensed.columns = ['Total ('+label_units_lower+')', 'Count', 'Average ('+label_units_lower+')']\n", @@ -312,7 +312,7 @@ " for x, y in dist_dict_sensed.items():\n", " labels_pm_dist.append(x)\n", " values_pm_dist.append(y)\n", - " df_sensed_dist = process_trip_data(labels_pm_dist, values_pm_dist, \"Sensed by OpenPATH \\n Trip distance (Overall)\")\n", + " df_sensed_dist = process_trip_data(labels_pm_dist, values_pm_dist, \"Sensed by OpenPATH \\n Trip distance (Overall) \\n (Based on Total Trips)\")\n", " plot_title = plot_title_no_quality + \"\\n\" + quality_text\n", "\n", " dist_sensed_land = expanded_ct_sensed.groupby('primary_mode').agg({distance_col: ['sum', 'count' , 'mean']})\n", @@ -326,12 +326,12 @@ " if x != \"AIR_OR_HSR\":\n", " labels_pm_dist_land.append(x)\n", " values_pm_dist_land.append(y)\n", - " df_sensed_dist_land = process_trip_data(labels_pm_dist_land, values_pm_dist_land, \"Sensed by OpenPATH \\n Trips distance (Land)\")\n", + " df_sensed_dist_land = process_trip_data(labels_pm_dist_land, values_pm_dist_land, \"Sensed by OpenPATH \\n Trips distance (Land) \\n (Based on Total Trips)\")\n", " \n", " all_data_frames = [df_confirm_dist,df_sensed_dist, df_sensed_dist_land]\n", " result_df = merge_dataframes(all_data_frames)\n", - "\n", - " stacked_bar_chart_generic(plot_title_no_quality, result_df, file_name, 3)\n", + " print(plot_title)\n", + " stacked_bar_chart_generic(plot_title, result_df, file_name, 3)\n", "\n", " alt_text = store_alt_text_stacked_bar_chart(result_df[result_df['Count'] > 0], file_name, plot_title)\n", "except Exception as e:\n", @@ -360,16 +360,17 @@ "try:\n", " labels_tp = expanded_ct['Trip_purpose'].value_counts(dropna=True).keys().tolist()\n", " values_tp = expanded_ct['Trip_purpose'].value_counts(dropna=True).tolist()\n", - " df_purpose_trip = process_trip_data(labels_tp, values_tp, \"Labeled by user \\n All Purpose Trips\")\n", + " df_purpose_trip = process_trip_data(labels_tp, values_tp, \"Labeled by user \\n (Based on Total Purpose Trips )\")\n", " \n", " labels_tp_eb = data_eb['Trip_purpose'].value_counts(dropna=True).keys().tolist()\n", " values_tp_eb = data_eb['Trip_purpose'].value_counts(dropna=True).tolist()\n", - " df_purpose_trip_eb = process_trip_data(labels_tp_eb, values_tp_eb, \"Labeled by user \\n e-bike specific Purpose Trips\")\n", + " df_purpose_trip_eb = process_trip_data(labels_tp_eb, values_tp_eb, f\"Labeled by user for {mode_of_interest} \\n (Based on {mode_of_interest} related Purpose Trips)\")\n", " \n", " all_tp_data_frames = [df_purpose_trip,df_purpose_trip_eb]\n", " result_tp_df = merge_dataframes(all_tp_data_frames)\n", " \n", - " stacked_bar_chart_generic(plot_title_no_quality, result_tp_df, file_name, 2)\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text + \"\\n\" + quality_text_specific\n", + " stacked_bar_chart_generic(plot_title, result_tp_df, file_name, 2)\n", " alt_text = store_alt_text_stacked_bar_chart(result_tp_df[result_tp_df['Count'] > 0], file_name, plot_title)\n", "except:\n", " generate_missing_plot(plot_title_no_quality,debug_df,file_name)\n", @@ -397,9 +398,9 @@ "try:\n", " labels_eb = data_eb.Replaced_mode.value_counts(dropna=True).keys().tolist()\n", " values_eb = data_eb.Replaced_mode.value_counts(dropna=True).tolist()\n", + " df_replaced_trip = process_trip_data(labels_eb, values_eb, f\"Labeled by user for {mode_of_interest} \\n (Based on Replaced mode)\")\n", "\n", - " df_replaced_trip = process_trip_data(labels_eb, values_eb, \"Replaced number of trips by e-bike\")\n", - "\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text_specific\n", " stacked_bar_chart_generic(plot_title, df_replaced_trip, file_name, 1)\n", " alt_text = store_alt_text_stacked_bar_chart(df_replaced_trip, file_name, plot_title)\n", "except:\n", @@ -422,8 +423,8 @@ "metadata": {}, "outputs": [], "source": [ - "plot_title_no_quality=f\"Distribution of \"+label_units+f\" Replaced by {mode_of_interest}\"\n", - "file_name =f'miles_{mode_of_interest}_replaced_mode%s' % file_suffix\n", + "plot_title_no_quality=f\"Distribution of \"+label_units+f\" replaced by {mode_of_interest}\"\n", + "file_name =f'distance_{mode_of_interest}_replaced_mode%s' % file_suffix\n", "\n", "try:\n", " dg=data_eb.groupby('Replaced_mode').agg({distance_col: ['sum', 'count' , 'mean']},)\n", @@ -440,9 +441,9 @@ " labels_m.append(x)\n", " values_m.append(y)\n", "\n", - " df_replaced_dist = process_trip_data(labels_m, values_m, \"Replaced distance by e-bike\")\n", + " df_replaced_dist = process_trip_data(labels_m, values_m, f\"Labeled by user for {mode_of_interest} \\n (Based on Replaced mode distance)\")\n", "\n", - " plot_title= plot_title_no_quality+\"\\n\"+quality_text\n", + " plot_title= plot_title_no_quality+\"\\n\"+quality_text_specific\n", " stacked_bar_chart_generic(plot_title, df_replaced_dist, file_name, 1)\n", " alt_text = store_alt_text_stacked_bar_chart(df_replaced_dist, file_name, plot_title)\n", "except:\n", From 687633f4b78515800c4e077f9c11faf2bec5d9c4 Mon Sep 17 00:00:00 2001 From: iantei Date: Tue, 27 Feb 2024 11:37:48 -0700 Subject: [PATCH 034/198] Experiment with adding html file in the same widget as image. --- frontend/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/index.html b/frontend/index.html index e66c01b..8be0e8b 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -534,6 +534,7 @@ + labelText + "" + "" + altText + "" + + "" + "
  • ", sizex, sizey]; gridster.add_widget.apply(gridster, nw); From 66cb274afd694c58d2dbf8bb57c31a34445ca142 Mon Sep 17 00:00:00 2001 From: iantei Date: Tue, 27 Feb 2024 11:39:20 -0700 Subject: [PATCH 035/198] Changed the option value from miles_ to distance for Stacked Bar Chart. --- frontend/metrics_program.html | 2 +- frontend/metrics_program_withoutEnergyMetrics.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/metrics_program.html b/frontend/metrics_program.html index 54e5d9d..661e492 100644 --- a/frontend/metrics_program.html +++ b/frontend/metrics_program.html @@ -18,7 +18,7 @@ - + diff --git a/frontend/metrics_program_withoutEnergyMetrics.html b/frontend/metrics_program_withoutEnergyMetrics.html index f243854..8018d45 100644 --- a/frontend/metrics_program_withoutEnergyMetrics.html +++ b/frontend/metrics_program_withoutEnergyMetrics.html @@ -17,7 +17,7 @@ - + From ddcfb1c8fef4d2bdd60ec64819a41e2457f19e74 Mon Sep 17 00:00:00 2001 From: iantei Date: Wed, 28 Feb 2024 21:44:57 -0700 Subject: [PATCH 036/198] Added new widget for the additional information table with a checkbox selection. --- frontend/index.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/index.html b/frontend/index.html index 8be0e8b..96e1812 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -156,6 +156,10 @@
  • +
  • + + Additional Details +
  • @@ -534,10 +538,19 @@ + labelText + "" + "" + altText + "" - + "" + // + "" + "", sizex, sizey]; gridster.add_widget.apply(gridster, nw); + if ($('.js-add-new-checkbox').is(':checked')) { + const nw_1 = ["
  • " + + labelText + + "" + + "" + + "
  • ", + sizex, sizey]; + gridster.add_widget.apply(gridster, nw_1); + } }); $('body').on("click", ".gridster ul > li .remove", function () { From a95225a6e13478a289d3f6a2e712e7a2ca323003 Mon Sep 17 00:00:00 2001 From: iantei Date: Wed, 28 Feb 2024 21:46:33 -0700 Subject: [PATCH 037/198] Round up the pct values in the table to one decimal place, and format the table a bit. --- viz_scripts/plots.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index 274762e..9753105 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -25,7 +25,7 @@ def calculate_pct(labels, values): # Calculate % for all the values vs = v2l_df.vals.sum() - v2l_df["pct"] = v2l_df.vals.apply(lambda x: (x/vs) * 100) + v2l_df["pct"] = v2l_df.vals.apply(lambda x: round((x/vs) * 100, 1)) return (v2l_df.index.to_list(),v2l_df.vals.to_list(), v2l_df.pct.to_list()) @@ -349,12 +349,11 @@ def access_alt_html(alt_text, chart_name, var_name): - {chart_name} + {var_name} -

    {chart_name}

    {var_name}

    - +
    From cad3b1d451a14bda336083b7a7ab2dd165f2a854 Mon Sep 17 00:00:00 2001 From: iantei Date: Wed, 28 Feb 2024 21:48:01 -0700 Subject: [PATCH 038/198] Update the data-sizex for distance_ option value. --- frontend/metrics_program.html | 2 +- frontend/metrics_program_withoutEnergyMetrics.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/metrics_program.html b/frontend/metrics_program.html index 661e492..b37d151 100644 --- a/frontend/metrics_program.html +++ b/frontend/metrics_program.html @@ -18,7 +18,7 @@ - + diff --git a/frontend/metrics_program_withoutEnergyMetrics.html b/frontend/metrics_program_withoutEnergyMetrics.html index 8018d45..6e6f0fc 100644 --- a/frontend/metrics_program_withoutEnergyMetrics.html +++ b/frontend/metrics_program_withoutEnergyMetrics.html @@ -17,7 +17,7 @@ - + From 328c1858192346b5f2234db96163dc3f81563771 Mon Sep 17 00:00:00 2001 From: iantei Date: Thu, 29 Feb 2024 01:02:31 -0700 Subject: [PATCH 039/198] Update the legend to showcase (Sensed) for all the Sensed modes. Added color palette tab20.colors for different labels. --- viz_scripts/plots.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/viz_scripts/plots.py b/viz_scripts/plots.py index 9753105..086eb7d 100644 --- a/viz_scripts/plots.py +++ b/viz_scripts/plots.py @@ -48,7 +48,6 @@ def merge_dataframes(all_data_frames): # Merge the original DataFrame with the unique combinations DataFrame merged_df = pd.merge(unique_combinations, df, on=['Trip Type', 'Mode'], how='left').fillna(0) - return merged_df def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): @@ -58,15 +57,28 @@ def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): running_total_long = [0] * num_bars - for mode in pd.unique(df.Mode): + mode_mapping = { + "IN_VEHICLE": "IN_VEHICLE (Sensed)", + "UNKNOWN": "UNKNOWN (Sensed)", + "OTHER": "OTHER (Sensed)", + "BICYCLING": "BICYCLING (Sensed)", + "WALKING": "WALKING (Sensed)", + "AIR_OR_HSR": "AIR_OR_HSR (Sensed)" + } + + colors = plt.cm.tab20.colors[:len(pd.unique(df['Mode']))] + + for idx, mode in enumerate(pd.unique(df.Mode)): long = df[df['Mode'] == mode] if not long.empty: labels = long['Trip Type'] vals = long['Proportion'] bar_labels = long['Count'] + + mode = mode_mapping.get(mode, mode) vals_str = [f'{y:.1f} %\n({x:.0f})' if y>4 else '' for x, y in zip(bar_labels, vals)] - bar = ax.barh(labels, vals, width, left=running_total_long, label=mode) + bar = ax.barh(labels, vals, width, left=running_total_long, label=mode, color = colors[idx]) ax.bar_label(bar, label_type='center', labels=vals_str, rotation=90, fontsize=16) running_total_long = [total + val for total, val in zip(running_total_long, vals)] else: @@ -78,6 +90,7 @@ def stacked_bar_chart_generic(plot_title, df, file_name, num_bars): ax.tick_params(axis='x', labelsize=18, rotation=90) # The Last updated text is placed just right below the X-axis plt.text(0,ax.xaxis.get_label().get_position()[0] - 1,f"Last updated {arrow.get()}", fontsize=12) + ax.legend(bbox_to_anchor=(1, 1), fancybox=True, shadow=True) plt.subplots_adjust(bottom=0.25) fig.savefig(SAVE_DIR+file_name+".png", bbox_inches='tight') From 07b08c81f5b7e510f3ad9eec6c7908dadb52fa38 Mon Sep 17 00:00:00 2001 From: iantei Date: Thu, 29 Feb 2024 10:25:42 -0700 Subject: [PATCH 040/198] Enable the checkbox only for the Stacked Bar Charts. --- frontend/index.html | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frontend/index.html b/frontend/index.html index 96e1812..75acee8 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -495,6 +495,36 @@
    Trip Type Mode