Spaces:
Sleeping
Sleeping
Commit ·
fb236d2
1
Parent(s): 031d4e9
update bars
Browse files
app.py
CHANGED
|
@@ -27,6 +27,9 @@ try:
|
|
| 27 |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.join(os.path.dirname(__file__), 'credentials.json')
|
| 28 |
except KeyError: # running locally
|
| 29 |
pass
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
iso = pd.read_csv('iso.tsv', sep='\t')
|
| 32 |
iso['Alpha-2 code'] = iso['Alpha-2 code'].str.strip()
|
|
@@ -120,12 +123,12 @@ def full_report():
|
|
| 120 |
country_df = country_df.sort_values(by=['jumps'], ascending=False)
|
| 121 |
top_10_countries = country_df.iloc[:10]['country'].tolist()
|
| 122 |
|
| 123 |
-
country_df_to_plot = df.groupby(['country', 'iso'
|
| 124 |
country_df_to_plot = country_df_to_plot[country_df_to_plot['country'].isin(top_10_countries)].reset_index(drop=True)
|
| 125 |
-
country_df_to_plot = country_df_to_plot.sort_values(by=['
|
| 126 |
total = px.bar(country_df_to_plot,
|
| 127 |
y='country', x='jumps',
|
| 128 |
-
color='
|
| 129 |
title='Total Jumps by Country/City',
|
| 130 |
orientation='h',
|
| 131 |
category_orders={'country': top_10_countries},
|
|
@@ -137,14 +140,14 @@ def full_report():
|
|
| 137 |
city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
| 138 |
top_10_cities = city_df.iloc[:10]['city'].tolist()
|
| 139 |
|
| 140 |
-
city_df = df.groupby(['city', 'iso'
|
| 141 |
city_df = city_df[city_df['city'] != '(not set)']
|
| 142 |
city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
| 143 |
city_df = city_df[city_df['city'].isin(top_10_cities)].reset_index(drop=True)
|
| 144 |
-
city_df = city_df.sort_values(by=['
|
| 145 |
|
| 146 |
avg = px.bar(city_df,
|
| 147 |
-
y='city', x='jumps', color='
|
| 148 |
title='Total Jumps by City/Day',
|
| 149 |
orientation='h',
|
| 150 |
category_orders={'city': top_10_cities},
|
|
|
|
| 27 |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.join(os.path.dirname(__file__), 'credentials.json')
|
| 28 |
except KeyError: # running locally
|
| 29 |
pass
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"Error loading credentials: {e}")
|
| 32 |
+
pass
|
| 33 |
|
| 34 |
iso = pd.read_csv('iso.tsv', sep='\t')
|
| 35 |
iso['Alpha-2 code'] = iso['Alpha-2 code'].str.strip()
|
|
|
|
| 123 |
country_df = country_df.sort_values(by=['jumps'], ascending=False)
|
| 124 |
top_10_countries = country_df.iloc[:10]['country'].tolist()
|
| 125 |
|
| 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',
|
| 132 |
title='Total Jumps by Country/City',
|
| 133 |
orientation='h',
|
| 134 |
category_orders={'country': top_10_countries},
|
|
|
|
| 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)']
|
| 145 |
city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
|
| 146 |
city_df = city_df[city_df['city'].isin(top_10_cities)].reset_index(drop=True)
|
| 147 |
+
city_df = city_df.sort_values(by=['jumps'], ascending=True)
|
| 148 |
|
| 149 |
avg = px.bar(city_df,
|
| 150 |
+
y='city', x='jumps', color='city',
|
| 151 |
title='Total Jumps by City/Day',
|
| 152 |
orientation='h',
|
| 153 |
category_orders={'city': top_10_cities},
|