Compare commits
2 Commits
af1b4ff9d8
...
0cf59eb7f1
Author | SHA1 | Date | |
---|---|---|---|
|
0cf59eb7f1 | ||
|
38f496dd8d |
19
.vscode/launch.json
vendored
Normal file
19
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
// 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,6 +13,7 @@ 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']
|
||||||
|
|
||||||
@ -54,9 +55,8 @@ 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 (must be same length as value list).
|
ticklabels (list): Names for the tick labels.
|
||||||
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():
|
||||||
if len(ticklabels) == len(values[key]):
|
plt.plot(values[key], label=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,26 +122,36 @@ class Gpx2Html(object):
|
|||||||
os.path.join(self.outfolder, 'avg_spd.png'))
|
os.path.join(self.outfolder, 'avg_spd.png'))
|
||||||
|
|
||||||
# Accumulated distance:
|
# Accumulated distance:
|
||||||
accumulated_distances = dict()
|
accumulated_distance = dict()
|
||||||
for year in distances_dict.keys():
|
for year in self.tracks.years():
|
||||||
accumulated_distance = list()
|
acc_year_dist = list()
|
||||||
accumulated_distance.append(0)
|
start_date = datetime.datetime(year, 1, 1)
|
||||||
for i in range(0, len(distances_dict[year])):
|
now = datetime.datetime.now()
|
||||||
accumulated_distance.append(accumulated_distance[i] + distances_dict[year][i])
|
end_date = datetime.datetime(year, 12, 31)
|
||||||
accumulated_distances[year] = accumulated_distance
|
if year == now.year:
|
||||||
|
end_date = now
|
||||||
current_year = datetime.datetime.today().year
|
tracks = self.tracks.tracks(start_date, end_date)
|
||||||
current_month = datetime.datetime.today().month
|
for date in generate_date_list(start_date, end_date):
|
||||||
current_year_distance = list()
|
for track in tracks:
|
||||||
self.logger.info("Current month: %s", current_month)
|
if track.start_time.month == date.month and track.start_time.day == date.day:
|
||||||
for i in range(0, current_month + 1):
|
if len(acc_year_dist) < date.timetuple().tm_yday:
|
||||||
current_year_distance.append(accumulated_distances[current_year][i])
|
acc_year_dist.append(track.distance / 1000)
|
||||||
accumulated_distances[current_year] = current_year_distance
|
else:
|
||||||
|
acc_year_dist.append(track.distance / 1000 + acc_year_dist[-1])
|
||||||
plot_line_chart(accumulated_distances, [""] + MONTH_LABELS,
|
elif len(acc_year_dist) < date.timetuple().tm_yday:
|
||||||
"accumulated distance", 'Month', 'km',
|
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',
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user