Spaces:
Sleeping
Sleeping
Commit ·
1885f5b
1
Parent(s): d7787fb
add treemap
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import gradio as gr
|
|
| 11 |
import os
|
| 12 |
import json
|
| 13 |
import time
|
|
|
|
| 14 |
import pandas as pd
|
| 15 |
import plotly.express as px
|
| 16 |
|
|
@@ -126,6 +127,9 @@ def full_report():
|
|
| 126 |
country_df_to_plot = df.groupby(['country', 'iso']).sum().reset_index()
|
| 127 |
country_df_to_plot = country_df_to_plot[country_df_to_plot['country'].isin(top_10_countries)].reset_index(drop=True)
|
| 128 |
country_df_to_plot = country_df_to_plot.sort_values(by=['jumps'], ascending=True)
|
|
|
|
|
|
|
|
|
|
| 129 |
total = px.bar(country_df_to_plot,
|
| 130 |
y='country', x='jumps',
|
| 131 |
color='country',
|
|
@@ -139,6 +143,27 @@ def full_report():
|
|
| 139 |
city_df = city_df.sort_values(by=['jumps'], ascending=False)
|
| 140 |
city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
| 141 |
top_10_cities = city_df.iloc[:10]['city'].tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
city_df = df.groupby(['city', 'iso']).sum().reset_index()
|
| 144 |
city_df = city_df[city_df['city'] != '(not set)']
|
|
@@ -209,7 +234,7 @@ def full_report():
|
|
| 209 |
trendline_scope='overall',
|
| 210 |
template="plotly_dark")
|
| 211 |
|
| 212 |
-
return f"# {total_jumps:,} total jumps in {unique_cities:,} cities across {unique_countries:,} countries", total, avg, total_map, jumps_over_time, county_map, per_day_plot
|
| 213 |
|
| 214 |
|
| 215 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
@@ -223,12 +248,14 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
| 223 |
total_plot = gr.Plot(label="Top 10 Countries")
|
| 224 |
with gr.Row():
|
| 225 |
avg_plot = gr.Plot(label="Top 10 Cities")
|
|
|
|
|
|
|
| 226 |
with gr.Row():
|
| 227 |
per_day_plot = gr.Plot(label="Jumps per Day")
|
| 228 |
with gr.Row():
|
| 229 |
county_map = gr.Plot(label="US Map")
|
| 230 |
|
| 231 |
-
outputs = [total_jumps_label, total_plot, avg_plot, map_fig, jumps_over_time, county_map, per_day_plot]
|
| 232 |
dep = demo.load(full_report, None, outputs)
|
| 233 |
|
| 234 |
if __name__ == "__main__":
|
|
|
|
| 11 |
import os
|
| 12 |
import json
|
| 13 |
import time
|
| 14 |
+
import math
|
| 15 |
import pandas as pd
|
| 16 |
import plotly.express as px
|
| 17 |
|
|
|
|
| 127 |
country_df_to_plot = df.groupby(['country', 'iso']).sum().reset_index()
|
| 128 |
country_df_to_plot = country_df_to_plot[country_df_to_plot['country'].isin(top_10_countries)].reset_index(drop=True)
|
| 129 |
country_df_to_plot = country_df_to_plot.sort_values(by=['jumps'], ascending=True)
|
| 130 |
+
df['rank'] = df['jumps'].rank(ascending=False)
|
| 131 |
+
df['world'] = 'Earth'
|
| 132 |
+
|
| 133 |
total = px.bar(country_df_to_plot,
|
| 134 |
y='country', x='jumps',
|
| 135 |
color='country',
|
|
|
|
| 143 |
city_df = city_df.sort_values(by=['jumps'], ascending=False)
|
| 144 |
city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
| 145 |
top_10_cities = city_df.iloc[:10]['city'].tolist()
|
| 146 |
+
|
| 147 |
+
icicle_df = df.groupby(['world', 'continent', 'country', 'city']).sum().reset_index()
|
| 148 |
+
#icicle_df['log10_jumps'] = icicle_df['jumps'].apply(lambda x: math.log10(x) if x > 0 else 0)
|
| 149 |
+
|
| 150 |
+
# icicle = px.icicle(icicle_df, path=['world', 'continent', 'country', 'city'],
|
| 151 |
+
# values='jumps',
|
| 152 |
+
# title='Jumps by Continent/Country',
|
| 153 |
+
# template="plotly_dark",
|
| 154 |
+
# color_continuous_scale='OrRd',
|
| 155 |
+
# maxdepth=7,
|
| 156 |
+
# branchvalues='remainder',
|
| 157 |
+
# color='jumps')
|
| 158 |
+
|
| 159 |
+
icicle = px.treemap(icicle_df, path=['world', 'continent', 'country', 'city'],
|
| 160 |
+
values='jumps',
|
| 161 |
+
title='Jumps by Continent/Country/City',
|
| 162 |
+
template="plotly_dark",
|
| 163 |
+
color_continuous_scale='OrRd',
|
| 164 |
+
branchvalues='total',
|
| 165 |
+
height=800,
|
| 166 |
+
color='jumps')
|
| 167 |
|
| 168 |
city_df = df.groupby(['city', 'iso']).sum().reset_index()
|
| 169 |
city_df = city_df[city_df['city'] != '(not set)']
|
|
|
|
| 234 |
trendline_scope='overall',
|
| 235 |
template="plotly_dark")
|
| 236 |
|
| 237 |
+
return f"# {total_jumps:,} total jumps in {unique_cities:,} cities across {unique_countries:,} countries", total, avg, total_map, icicle, jumps_over_time, county_map, per_day_plot
|
| 238 |
|
| 239 |
|
| 240 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
|
|
| 248 |
total_plot = gr.Plot(label="Top 10 Countries")
|
| 249 |
with gr.Row():
|
| 250 |
avg_plot = gr.Plot(label="Top 10 Cities")
|
| 251 |
+
with gr.Row():
|
| 252 |
+
icicle_fig = gr.Plot(label="Treemap")
|
| 253 |
with gr.Row():
|
| 254 |
per_day_plot = gr.Plot(label="Jumps per Day")
|
| 255 |
with gr.Row():
|
| 256 |
county_map = gr.Plot(label="US Map")
|
| 257 |
|
| 258 |
+
outputs = [total_jumps_label, total_plot, avg_plot, map_fig, icicle_fig, jumps_over_time, county_map, per_day_plot]
|
| 259 |
dep = demo.load(full_report, None, outputs)
|
| 260 |
|
| 261 |
if __name__ == "__main__":
|