forked from yihong0618/running_page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_to_csv.py
38 lines (27 loc) · 891 Bytes
/
data_to_csv.py
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
import sqlite3
try:
import pandas as pd
except:
raise Exception("please install pandas run: pip3 install pandas")
from math import floor
data = sqlite3.connect("run_page/data.db")
df = pd.read_sql_query("SELECT * FROM activities", data)
def apply_duration_time(d):
try:
return d.split()[1].split(".")[0]
except:
return ""
# we do not need polyline in csv
df = df.drop("summary_polyline", axis=1)
df["elapsed_time"] = df["elapsed_time"].apply(apply_duration_time)
df["moving_time"] = df["moving_time"].apply(apply_duration_time)
def format_pace(d):
if not d:
return "0"
pace = (1000.0 / 60.0) * (1.0 / d)
minutes = floor(pace)
seconds = floor((pace - minutes) * 60.0)
return f"{minutes}''{seconds}"
df["average_speed"] = df["average_speed"].apply(format_pace)
df = df.sort_values(by=["start_date"])
df.to_csv("data.csv")