Compare commits

..

No commits in common. "0cf59eb7f1bd58d8f85aa1117a476916cded4f2c" and "af1b4ff9d8e30a1acae1d5b0bf544b7559ba6b11" have entirely different histories.

2 changed files with 30 additions and 59 deletions

19
.vscode/launch.json vendored
View File

@ -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}"
]
}
]
}

View File

@ -13,7 +13,6 @@ import os
import pandas as pd import pandas as pd
import collections import collections
from gpx_parser import Tracks from gpx_parser import Tracks
import pytz
MONTH_LABELS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] 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: Args:
values (dict): key: line name values (dict): key: line name
value (list): line values 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. title (str): Title of the chart.
''' '''
fig = plt.figure() fig = plt.figure()
ax1 = fig.add_subplot(111) 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["left"].set_visible(False)
ax1.spines["right"].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.title(title)
plt.xlabel(xlabel) plt.xlabel(xlabel)
plt.ylabel(ylabel) plt.ylabel(ylabel)
for key in values.keys(): 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.legend()
plt.savefig(filename) plt.savefig(filename)
plt.close('all') 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): class Gpx2Html(object):
def __init__(self, infolder, outfolder, logger): def __init__(self, infolder, outfolder, logger):
self.logger = logger self.logger = logger
@ -122,36 +122,26 @@ class Gpx2Html(object):
os.path.join(self.outfolder, 'avg_spd.png')) os.path.join(self.outfolder, 'avg_spd.png'))
# Accumulated distance: # Accumulated distance:
accumulated_distance = dict() accumulated_distances = dict()
for year in self.tracks.years(): for year in distances_dict.keys():
acc_year_dist = list() accumulated_distance = list()
start_date = datetime.datetime(year, 1, 1) accumulated_distance.append(0)
now = datetime.datetime.now() for i in range(0, len(distances_dict[year])):
end_date = datetime.datetime(year, 12, 31) accumulated_distance.append(accumulated_distance[i] + distances_dict[year][i])
if year == now.year: accumulated_distances[year] = accumulated_distance
end_date = now
tracks = self.tracks.tracks(start_date, end_date) current_year = datetime.datetime.today().year
for date in generate_date_list(start_date, end_date): current_month = datetime.datetime.today().month
for track in tracks: current_year_distance = list()
if track.start_time.month == date.month and track.start_time.day == date.day: self.logger.info("Current month: %s", current_month)
if len(acc_year_dist) < date.timetuple().tm_yday: for i in range(0, current_month + 1):
acc_year_dist.append(track.distance / 1000) current_year_distance.append(accumulated_distances[current_year][i])
else: accumulated_distances[current_year] = current_year_distance
acc_year_dist.append(track.distance / 1000 + acc_year_dist[-1])
elif len(acc_year_dist) < date.timetuple().tm_yday: plot_line_chart(accumulated_distances, [""] + MONTH_LABELS,
if len(acc_year_dist) > 0: "accumulated distance", 'Month', 'km',
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',
os.path.join(self.outfolder, 'acc_dist.png')) os.path.join(self.outfolder, 'acc_dist.png'))
end_date = datetime.datetime.today() end_date = datetime.datetime.today()
start_date = end_date - datetime.timedelta(days=14) start_date = end_date - datetime.timedelta(days=14)
last_n_tracks = self.tracks.tracks(start_date, end_date) last_n_tracks = self.tracks.tracks(start_date, end_date)