Spaces:
Running
Running
Commit ·
ae86a17
1
Parent(s): 70d9b00
add weekly stats
Browse files
app.py
CHANGED
|
@@ -140,6 +140,21 @@ def full_report():
|
|
| 140 |
template="plotly_dark")
|
| 141 |
total.update_layout(showlegend=False)
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
city_df = df.groupby(['city', 'iso']).sum().reset_index()
|
| 144 |
city_df = city_df.sort_values(by=['jumps'], ascending=False)
|
| 145 |
city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
|
@@ -182,8 +197,25 @@ def full_report():
|
|
| 182 |
height=800,
|
| 183 |
template="plotly_dark")
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
avg.update_layout(showlegend=False)
|
| 186 |
avg.update(layout_coloraxis_showscale=False)
|
|
|
|
|
|
|
| 187 |
|
| 188 |
country_df['rank'] = country_df['jumps'].rank(ascending=False)
|
| 189 |
total_map = px.choropleth(country_df, locations="iso",
|
|
@@ -238,7 +270,8 @@ def full_report():
|
|
| 238 |
trendline_scope='overall',
|
| 239 |
template="plotly_dark")
|
| 240 |
|
| 241 |
-
return f"# {total_jumps:,} total jumps in {unique_cities:,} cities across {unique_countries:,} countries",
|
|
|
|
| 242 |
|
| 243 |
|
| 244 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
@@ -249,9 +282,13 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
| 249 |
with gr.Row():
|
| 250 |
jumps_over_time = gr.Plot(label="Jumps Over Time")
|
| 251 |
with gr.Row():
|
| 252 |
-
total_plot = gr.Plot(label="Top
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
with gr.Row():
|
| 254 |
-
|
| 255 |
with gr.Row():
|
| 256 |
icicle_fig = gr.Plot(label="Treemap")
|
| 257 |
with gr.Row():
|
|
@@ -259,7 +296,7 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
| 259 |
with gr.Row():
|
| 260 |
county_map = gr.Plot(label="US Map")
|
| 261 |
|
| 262 |
-
outputs = [total_jumps_label, total_plot, avg_plot, map_fig, icicle_fig, jumps_over_time, county_map, per_day_plot]
|
| 263 |
dep = demo.load(full_report, None, outputs)
|
| 264 |
|
| 265 |
if __name__ == "__main__":
|
|
|
|
| 140 |
template="plotly_dark")
|
| 141 |
total.update_layout(showlegend=False)
|
| 142 |
|
| 143 |
+
country_df_to_plot_weekly = df[df['day'] >= df['day'].max() - 7].groupby(['country', 'iso']).sum().reset_index()
|
| 144 |
+
country_df_to_plot_weekly = country_df_to_plot_weekly.sort_values(by=['jumps'], ascending=False)
|
| 145 |
+
top_5_weekly = country_df_to_plot_weekly.iloc[:10]['country'].tolist()
|
| 146 |
+
country_df_to_plot_weekly = country_df_to_plot_weekly[country_df_to_plot_weekly['country'].isin(top_5_weekly)].reset_index(drop=True)
|
| 147 |
+
country_df_to_plot_weekly = country_df_to_plot_weekly.sort_values(by=['jumps'], ascending=True)
|
| 148 |
+
total_weekly = px.bar(country_df_to_plot_weekly,
|
| 149 |
+
y='country', x='jumps',
|
| 150 |
+
color='country',
|
| 151 |
+
title='Top Countries This Week',
|
| 152 |
+
orientation='h',
|
| 153 |
+
category_orders={'country': top_5_weekly},
|
| 154 |
+
height=500,
|
| 155 |
+
template="plotly_dark")
|
| 156 |
+
total_weekly.update_layout(showlegend=False)
|
| 157 |
+
|
| 158 |
city_df = df.groupby(['city', 'iso']).sum().reset_index()
|
| 159 |
city_df = city_df.sort_values(by=['jumps'], ascending=False)
|
| 160 |
city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
|
|
|
| 197 |
height=800,
|
| 198 |
template="plotly_dark")
|
| 199 |
|
| 200 |
+
city_df_weekly = df[df['day'] >= df['day'].max() - 7].groupby(['city', 'iso']).sum().reset_index()
|
| 201 |
+
city_df_weekly = city_df_weekly[city_df_weekly['city'] != '(not set)']
|
| 202 |
+
city_df_weekly['city'] = city_df_weekly.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
| 203 |
+
city_df_weekly = city_df_weekly.sort_values(by=['jumps'], ascending=False)
|
| 204 |
+
top_5_weekly = city_df_weekly.iloc[:10]['city'].tolist()
|
| 205 |
+
city_df_weekly = city_df_weekly[city_df_weekly['city'].isin(top_5_weekly)].reset_index(drop=True)
|
| 206 |
+
city_df_weekly = city_df_weekly.sort_values(by=['jumps'], ascending=True)
|
| 207 |
+
avg_weekly = px.bar(city_df_weekly,
|
| 208 |
+
y='city', x='jumps', color='city',
|
| 209 |
+
title='Top Cities This Week',
|
| 210 |
+
orientation='h',
|
| 211 |
+
category_orders={'city': top_5_weekly},
|
| 212 |
+
height=500,
|
| 213 |
+
template="plotly_dark")
|
| 214 |
+
|
| 215 |
avg.update_layout(showlegend=False)
|
| 216 |
avg.update(layout_coloraxis_showscale=False)
|
| 217 |
+
avg_weekly.update_layout(showlegend=False)
|
| 218 |
+
avg_weekly.update(layout_coloraxis_showscale=False)
|
| 219 |
|
| 220 |
country_df['rank'] = country_df['jumps'].rank(ascending=False)
|
| 221 |
total_map = px.choropleth(country_df, locations="iso",
|
|
|
|
| 270 |
trendline_scope='overall',
|
| 271 |
template="plotly_dark")
|
| 272 |
|
| 273 |
+
return f"# {total_jumps:,} total jumps in {unique_cities:,} cities across {unique_countries:,} countries", \
|
| 274 |
+
total, total_weekly, avg, avg_weekly, total_map, icicle, jumps_over_time, county_map, per_day_plot
|
| 275 |
|
| 276 |
|
| 277 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
|
|
| 282 |
with gr.Row():
|
| 283 |
jumps_over_time = gr.Plot(label="Jumps Over Time")
|
| 284 |
with gr.Row():
|
| 285 |
+
total_plot = gr.Plot(label="Top Countries (All Time)")
|
| 286 |
+
with gr.Row():
|
| 287 |
+
total_plot_weekly = gr.Plot(label="Top Countries (This Week)")
|
| 288 |
+
with gr.Row():
|
| 289 |
+
avg_plot = gr.Plot(label="Top Cities (All Time)")
|
| 290 |
with gr.Row():
|
| 291 |
+
avg_plot_weekly = gr.Plot(label="Top Cities (This Week)")
|
| 292 |
with gr.Row():
|
| 293 |
icicle_fig = gr.Plot(label="Treemap")
|
| 294 |
with gr.Row():
|
|
|
|
| 296 |
with gr.Row():
|
| 297 |
county_map = gr.Plot(label="US Map")
|
| 298 |
|
| 299 |
+
outputs = [total_jumps_label, total_plot, total_plot_weekly, avg_plot, avg_plot_weekly, map_fig, icicle_fig, jumps_over_time, county_map, per_day_plot]
|
| 300 |
dep = demo.load(full_report, None, outputs)
|
| 301 |
|
| 302 |
if __name__ == "__main__":
|