dylanplummer commited on
Commit
882717c
·
1 Parent(s): a638a7e

add more plots

Browse files
Files changed (2) hide show
  1. app.py +24 -11
  2. requirements.txt +0 -2
app.py CHANGED
@@ -38,8 +38,7 @@ def full_report():
38
 
39
  request = RunReportRequest(
40
  property=f"properties/{PROPERTY_ID}",
41
- dimensions=[Dimension(name="hour"),
42
- Dimension(name="nthDay"),
43
  Dimension(name='eventName'),
44
  Dimension(name="continent"),
45
  Dimension(name="country"),
@@ -56,13 +55,12 @@ def full_report():
56
  res = {'day': [], 'jumps': [], 'continent': [], 'country': [], 'iso': []}
57
 
58
  for row in response.rows:
59
- date = row.dimension_values[0].value # YYYMMDD (e.g 20230715)
60
- day = int(row.dimension_values[1].value)
61
- event_name = row.dimension_values[2].value
62
- continent = row.dimension_values[3].value
63
- country = row.dimension_values[4].value
64
- country_iso = row.dimension_values[5].value
65
  if event_name == FINISHED_EXERCISE:
 
 
 
 
66
  event_value = float(row.metric_values[0].value)
67
  total_jumps += int(event_value)
68
  res['day'].append(day)
@@ -93,10 +91,22 @@ def full_report():
93
  total_map = px.choropleth(country_df, locations="iso",
94
  color="jumps",
95
  hover_name="country", # column to add to hover information
96
- color_discrete_map="Reds",
 
97
  template="plotly_dark")
 
 
 
98
 
99
- return f"## Total Jumps: {total_jumps:,}", total, avg, total_map
 
 
 
 
 
 
 
 
100
 
101
 
102
  with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
@@ -104,11 +114,14 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
104
  total_jumps_label = gr.Markdown("Total Jumps: 0")
105
  with gr.Row():
106
  map_fig = gr.Plot(label="Map")
 
 
107
  with gr.Row():
108
  total_plot = gr.Plot(label="Total Jumps")
 
109
  avg_plot = gr.Plot(label="Average Jumps per Day")
110
 
111
- outputs = [total_jumps_label, total_plot, avg_plot, map_fig]
112
  dep = demo.load(full_report, None, outputs)
113
 
114
  if __name__ == "__main__":
 
38
 
39
  request = RunReportRequest(
40
  property=f"properties/{PROPERTY_ID}",
41
+ dimensions=[Dimension(name="nthDay"),
 
42
  Dimension(name='eventName'),
43
  Dimension(name="continent"),
44
  Dimension(name="country"),
 
55
  res = {'day': [], 'jumps': [], 'continent': [], 'country': [], 'iso': []}
56
 
57
  for row in response.rows:
58
+ event_name = row.dimension_values[1].value
 
 
 
 
 
59
  if event_name == FINISHED_EXERCISE:
60
+ day = int(row.dimension_values[0].value)
61
+ continent = row.dimension_values[2].value
62
+ country = row.dimension_values[3].value
63
+ country_iso = row.dimension_values[4].value
64
  event_value = float(row.metric_values[0].value)
65
  total_jumps += int(event_value)
66
  res['day'].append(day)
 
91
  total_map = px.choropleth(country_df, locations="iso",
92
  color="jumps",
93
  hover_name="country", # column to add to hover information
94
+ color_continuous_scale ="plasma",
95
+ projection='natural earth',
96
  template="plotly_dark")
97
+ # remove the legend
98
+ total_map.update_layout(showlegend=False)
99
+ total_map.update(layout_coloraxis_showscale=False)
100
 
101
+ df = df.groupby(['day', 'continent']).sum().reset_index()
102
+ df = df.sort_values(by=['day'])
103
+ df['total_jumps'] = df.groupby('continent')['jumps'].cumsum()
104
+ jumps_over_time = px.line(df, x='day',
105
+ y='total_jumps',
106
+ color='continent',
107
+ template="plotly_dark")
108
+
109
+ return f"## Total Jumps: {total_jumps:,}", total, avg, total_map, jumps_over_time
110
 
111
 
112
  with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
 
114
  total_jumps_label = gr.Markdown("Total Jumps: 0")
115
  with gr.Row():
116
  map_fig = gr.Plot(label="Map")
117
+ with gr.Row():
118
+ jumps_over_time = gr.Plot(label="Jumps Over Time")
119
  with gr.Row():
120
  total_plot = gr.Plot(label="Total Jumps")
121
+ with gr.Row():
122
  avg_plot = gr.Plot(label="Average Jumps per Day")
123
 
124
+ outputs = [total_jumps_label, total_plot, avg_plot, map_fig, jumps_over_time]
125
  dep = demo.load(full_report, None, outputs)
126
 
127
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -1,5 +1,3 @@
1
  google-analytics-data
2
  pandas<2.0.0
3
- seaborn
4
- matplotlib
5
  plotly
 
1
  google-analytics-data
2
  pandas<2.0.0
 
 
3
  plotly