-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (47 loc) · 1.83 KB
/
app.py
File metadata and controls
63 lines (47 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
source .venv/Scripts/activate
export FLASK_DEBUG=1
flask run
"""
from flask import Flask, render_template, make_response
import csv, re
import matplotlib.pyplot as plt
import pandas as pd
import datetime
def data_wrangle():
df = pd.read_csv('strava_activities.csv')
# distance to numeric format
df['distance'] = pd.to_numeric(df['distance'])
# distance to km
df['distance'] = df['distance']/1000
df['elapsed_time'] = df['elapsed_time']/(60*60)
df['speed'] = df['distance']/df['elapsed_time']
# start_date_local to date format
df['start_date_local'] = pd.to_datetime(df['start_date_local'])
df.replace("VirtualRide", "Ride")
df.replace("VirtualRun", "Run")
df.loc[~df["type"].isin(['Ride', 'Run', 'Swim']), "type"] = "Other"
df.loc[(df['start_date_local'] >= '2024-01-01')]
df = df.set_index('start_date_local')
summed_df = df.groupby([pd.Grouper(freq='ME'), 'type']).sum()\
.reset_index().pivot(index='start_date_local', columns='type', values='elapsed_time')
summed_df = df.groupby([pd.Grouper(freq='ME'), 'type'])['speed'].mean()\
.reset_index().pivot(index='start_date_local', columns='type', values='speed')
summed_df.plot()
plt.show()
"Create some categories and basic work"
category = ["Health", "Sports", "Socio-demographic", "Nutrition", "Social habits"]
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
return render_template('base.html', category=category)
@app.route('/admin')
def admin():
data = "import something from csv"
return render_template(f'admin.html', category=category)
@app.route('/<cat>')
def display(cat):
data = "import something from csv"
return make_response(render_template(f'category.html', cat=cat, category=category))
if __name__ == '__main__':
app.run(debug=True)