Fix expected distance chart month end

This commit is contained in:
Thomas Klaehn 2020-01-08 11:31:10 +01:00
parent ae4cfa3a6d
commit d65eeaf0fd

View File

@ -15,6 +15,8 @@ import collections
from gpx_parser import Tracks from gpx_parser import Tracks
import pytz import pytz
import calendar
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']
@ -75,6 +77,9 @@ def plot_line_chart(values, ticklabels, title, xlabel, ylabel, filename, xtick_r
plt.ylabel(ylabel) plt.ylabel(ylabel)
for key in values.keys(): for key in values.keys():
if key == 'blind':
plt.plot(values[key], linestyle='None')
else:
plt.plot(values[key], label=key) plt.plot(values[key], label=key)
plt.legend() plt.legend()
@ -168,17 +173,27 @@ class Gpx2Html(object):
tracks = self.tracks.tracks(start_date, end_date) tracks = self.tracks.tracks(start_date, end_date)
acc_year_dist = list() acc_year_dist = list()
exp_year_dist = list() exp_year_dist = list()
blind_line = list()
for date in generate_date_list(start_date, end_date): for date in generate_date_list(start_date, end_date):
date_distance = get_distance_by_date(tracks, date) date_distance = get_distance_by_date(tracks, date)
blind_line.append(0)
try: try:
acc_year_dist.append(date_distance + acc_year_dist[-1]) acc_year_dist.append(date_distance + acc_year_dist[-1])
except IndexError: except IndexError:
acc_year_dist.append(date_distance) acc_year_dist.append(date_distance)
expexted_distance = acc_year_dist[-1] / date.timetuple().tm_yday * 365 expexted_distance = acc_year_dist[-1] / date.timetuple().tm_yday * 365
exp_year_dist.append(expexted_distance) exp_year_dist.append(expexted_distance)
today = datetime.date.today()
last_month_day = today.replace(day=calendar.monthrange(today.year, today.month)[1])
diff = last_month_day - today
for i in range(diff.days):
blind_line.append(0)
xyz = dict() xyz = dict()
xyz['driven'] = acc_year_dist xyz['driven'] = acc_year_dist
xyz['expected @ year end'] = exp_year_dist xyz['expected @ year end'] = exp_year_dist
xyz['blind'] = blind_line
plot_line_chart(xyz, MONTH_LABELS[:now.month], "Distance", 'Month', plot_line_chart(xyz, MONTH_LABELS[:now.month], "Distance", 'Month',
'km/year', os.path.join(self.outfolder, 'exp_dist.png')) 'km/year', os.path.join(self.outfolder, 'exp_dist.png'))