Spaces:
Sleeping
Sleeping
Commit ·
882717c
1
Parent(s): a638a7e
add more plots
Browse filesFiles changed (2)
- app.py+24-11
- requirements.txt-2
37 unmodified lines383940414243444510 unmodified lines5657585960616263646566676824 unmodified lines939495969798991001011021 unmodified line10410510610710810911011111211311437 unmodified linesrequest = RunReportRequest(property=f"properties/{PROPERTY_ID}",dimensions=[Dimension(name="hour"),Dimension(name="nthDay"),Dimension(name='eventName'),Dimension(name="continent"),Dimension(name="country"),10 unmodified linesres = {'day': [], 'jumps': [], 'continent': [], 'country': [], 'iso': []}for row in response.rows:date = row.dimension_values[0].value # YYYMMDD (e.g 20230715)day = int(row.dimension_values[1].value)event_name = row.dimension_values[2].valuecontinent = row.dimension_values[3].valuecountry = row.dimension_values[4].valuecountry_iso = row.dimension_values[5].valueif event_name == FINISHED_EXERCISE:event_value = float(row.metric_values[0].value)total_jumps += int(event_value)res['day'].append(day)24 unmodified linestotal_map = px.choropleth(country_df, locations="iso",color="jumps",hover_name="country", # column to add to hover informationcolor_discrete_map="Reds",template="plotly_dark")return f"## Total Jumps: {total_jumps:,}", total, avg, total_mapwith gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:1 unmodified linetotal_jumps_label = gr.Markdown("Total Jumps: 0")with gr.Row():map_fig = gr.Plot(label="Map")with gr.Row():total_plot = gr.Plot(label="Total Jumps")avg_plot = gr.Plot(label="Average Jumps per Day")outputs = [total_jumps_label, total_plot, avg_plot, map_fig]dep = demo.load(full_report, None, outputs)if __name__ == "__main__":37 unmodified lines3839404142434410 unmodified lines55565758596061626364656624 unmodified lines9192939495969798991001011021031041051061071081091101111121 unmodified line11411511611711811912012112212312412512612737 unmodified linesrequest = RunReportRequest(property=f"properties/{PROPERTY_ID}",dimensions=[Dimension(name="nthDay"),Dimension(name='eventName'),Dimension(name="continent"),Dimension(name="country"),10 unmodified linesres = {'day': [], 'jumps': [], 'continent': [], 'country': [], 'iso': []}for row in response.rows:event_name = row.dimension_values[1].valueif event_name == FINISHED_EXERCISE:day = int(row.dimension_values[0].value)continent = row.dimension_values[2].valuecountry = row.dimension_values[3].valuecountry_iso = row.dimension_values[4].valueevent_value = float(row.metric_values[0].value)total_jumps += int(event_value)res['day'].append(day)24 unmodified linestotal_map = px.choropleth(country_df, locations="iso",color="jumps",hover_name="country", # column to add to hover informationcolor_continuous_scale ="plasma",projection='natural earth',template="plotly_dark")# remove the legendtotal_map.update_layout(showlegend=False)total_map.update(layout_coloraxis_showscale=False)df = df.groupby(['day', 'continent']).sum().reset_index()df = df.sort_values(by=['day'])df['total_jumps'] = df.groupby('continent')['jumps'].cumsum()jumps_over_time = px.line(df, x='day',y='total_jumps',color='continent',template="plotly_dark")return f"## Total Jumps: {total_jumps:,}", total, avg, total_map, jumps_over_timewith gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:1 unmodified linetotal_jumps_label = gr.Markdown("Total Jumps: 0")with gr.Row():map_fig = gr.Plot(label="Map")with gr.Row():jumps_over_time = gr.Plot(label="Jumps Over Time")with gr.Row():total_plot = gr.Plot(label="Total Jumps")with gr.Row():avg_plot = gr.Plot(label="Average Jumps per Day")outputs = [total_jumps_label, total_plot, avg_plot, map_fig, jumps_over_time]dep = demo.load(full_report, None, outputs)if __name__ == "__main__":
12345google-analytics-datapandas<2.0.0seabornmatplotlibplotly123google-analytics-datapandas<2.0.0plotly
app.py+24-11
requirements.txt-2