Fix expected distance chart month end
This commit is contained in:
parent
ae4cfa3a6d
commit
d65eeaf0fd
@ -15,6 +15,8 @@ import collections
|
||||
from gpx_parser import Tracks
|
||||
import pytz
|
||||
|
||||
import calendar
|
||||
|
||||
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)
|
||||
|
||||
for key in values.keys():
|
||||
if key == 'blind':
|
||||
plt.plot(values[key], linestyle='None')
|
||||
else:
|
||||
plt.plot(values[key], label=key)
|
||||
|
||||
plt.legend()
|
||||
@ -168,17 +173,27 @@ class Gpx2Html(object):
|
||||
tracks = self.tracks.tracks(start_date, end_date)
|
||||
acc_year_dist = list()
|
||||
exp_year_dist = list()
|
||||
blind_line = list()
|
||||
for date in generate_date_list(start_date, end_date):
|
||||
date_distance = get_distance_by_date(tracks, date)
|
||||
blind_line.append(0)
|
||||
try:
|
||||
acc_year_dist.append(date_distance + acc_year_dist[-1])
|
||||
except IndexError:
|
||||
acc_year_dist.append(date_distance)
|
||||
expexted_distance = acc_year_dist[-1] / date.timetuple().tm_yday * 365
|
||||
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['driven'] = acc_year_dist
|
||||
xyz['expected @ year end'] = exp_year_dist
|
||||
xyz['blind'] = blind_line
|
||||
plot_line_chart(xyz, MONTH_LABELS[:now.month], "Distance", 'Month',
|
||||
'km/year', os.path.join(self.outfolder, 'exp_dist.png'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user