Compare commits
No commits in common. "0cf59eb7f1bd58d8f85aa1117a476916cded4f2c" and "af1b4ff9d8e30a1acae1d5b0bf544b7559ba6b11" have entirely different histories.
0cf59eb7f1
...
af1b4ff9d8
19
.vscode/launch.json
vendored
19
.vscode/launch.json
vendored
@ -1,19 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "bicycle-statistics",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/bicycle_statistics/__main__.py",
|
||||
"console": "integratedTerminal",
|
||||
"args": [
|
||||
"/home/tkl/Nextcloud/Bicycle",
|
||||
"${workspaceFolder}"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -13,7 +13,6 @@ import os
|
||||
import pandas as pd
|
||||
import collections
|
||||
from gpx_parser import Tracks
|
||||
import pytz
|
||||
|
||||
MONTH_LABELS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
|
||||
|
||||
@ -55,8 +54,9 @@ def plot_line_chart(values, ticklabels, title, xlabel, ylabel, filename, xtick_r
|
||||
Args:
|
||||
values (dict): key: line name
|
||||
value (list): line values
|
||||
ticklabels (list): Names for the tick labels.
|
||||
ticklabels (list): Names for the tick labels (must be same length as value list).
|
||||
title (str): Title of the chart.
|
||||
|
||||
'''
|
||||
fig = plt.figure()
|
||||
ax1 = fig.add_subplot(111)
|
||||
@ -66,27 +66,27 @@ def plot_line_chart(values, ticklabels, title, xlabel, ylabel, filename, xtick_r
|
||||
ax1.spines["left"].set_visible(False)
|
||||
ax1.spines["right"].set_visible(False)
|
||||
|
||||
step = len(values[min(values.keys())]) / len(ticklabels)
|
||||
ax1.set_xticks(numpy.arange(1, len(ticklabels) * step, step))
|
||||
ax1.set_xticklabels(ticklabels, rotation=xtick_rotation)
|
||||
|
||||
plt.title(title)
|
||||
plt.xlabel(xlabel)
|
||||
plt.ylabel(ylabel)
|
||||
|
||||
for key in values.keys():
|
||||
plt.plot(values[key], label=key)
|
||||
if len(ticklabels) == len(values[key]):
|
||||
plt.plot(ticklabels, values[key], label=key)
|
||||
else:
|
||||
short_ticklabels = list()
|
||||
for i in range(0, len(values[key])):
|
||||
short_ticklabels.append(ticklabels[i])
|
||||
plt.plot(short_ticklabels, values[key], label=key)
|
||||
|
||||
x_base = numpy.arange(len(ticklabels))
|
||||
plt.xticks(x_base, ticklabels, rotation=xtick_rotation)
|
||||
|
||||
plt.legend()
|
||||
plt.savefig(filename)
|
||||
plt.close('all')
|
||||
|
||||
|
||||
def generate_date_list(start_date, end_date):
|
||||
r = (end_date + datetime.timedelta(days=1) - start_date).days
|
||||
return[start_date + datetime.timedelta(days=i) for i in range(r)]
|
||||
|
||||
|
||||
class Gpx2Html(object):
|
||||
def __init__(self, infolder, outfolder, logger):
|
||||
self.logger = logger
|
||||
@ -122,36 +122,26 @@ class Gpx2Html(object):
|
||||
os.path.join(self.outfolder, 'avg_spd.png'))
|
||||
|
||||
# Accumulated distance:
|
||||
accumulated_distance = dict()
|
||||
for year in self.tracks.years():
|
||||
acc_year_dist = list()
|
||||
start_date = datetime.datetime(year, 1, 1)
|
||||
now = datetime.datetime.now()
|
||||
end_date = datetime.datetime(year, 12, 31)
|
||||
if year == now.year:
|
||||
end_date = now
|
||||
tracks = self.tracks.tracks(start_date, end_date)
|
||||
for date in generate_date_list(start_date, end_date):
|
||||
for track in tracks:
|
||||
if track.start_time.month == date.month and track.start_time.day == date.day:
|
||||
if len(acc_year_dist) < date.timetuple().tm_yday:
|
||||
acc_year_dist.append(track.distance / 1000)
|
||||
else:
|
||||
acc_year_dist.append(track.distance / 1000 + acc_year_dist[-1])
|
||||
elif len(acc_year_dist) < date.timetuple().tm_yday:
|
||||
if len(acc_year_dist) > 0:
|
||||
acc_year_dist.append(acc_year_dist[-1])
|
||||
else:
|
||||
acc_year_dist.append(0)
|
||||
if len(acc_year_dist) == 365:
|
||||
acc_year_dist.append(acc_year_dist[-1])
|
||||
accumulated_distance[year] = acc_year_dist
|
||||
plot_line_chart(accumulated_distance, MONTH_LABELS,
|
||||
"Accumulated Distance", 'Month', 'km',
|
||||
accumulated_distances = dict()
|
||||
for year in distances_dict.keys():
|
||||
accumulated_distance = list()
|
||||
accumulated_distance.append(0)
|
||||
for i in range(0, len(distances_dict[year])):
|
||||
accumulated_distance.append(accumulated_distance[i] + distances_dict[year][i])
|
||||
accumulated_distances[year] = accumulated_distance
|
||||
|
||||
current_year = datetime.datetime.today().year
|
||||
current_month = datetime.datetime.today().month
|
||||
current_year_distance = list()
|
||||
self.logger.info("Current month: %s", current_month)
|
||||
for i in range(0, current_month + 1):
|
||||
current_year_distance.append(accumulated_distances[current_year][i])
|
||||
accumulated_distances[current_year] = current_year_distance
|
||||
|
||||
plot_line_chart(accumulated_distances, [""] + MONTH_LABELS,
|
||||
"accumulated distance", 'Month', 'km',
|
||||
os.path.join(self.outfolder, 'acc_dist.png'))
|
||||
|
||||
|
||||
|
||||
end_date = datetime.datetime.today()
|
||||
start_date = end_date - datetime.timedelta(days=14)
|
||||
last_n_tracks = self.tracks.tracks(start_date, end_date)
|
||||
|
Loading…
Reference in New Issue
Block a user