diff --git a/gpx2html/__init__.py b/gpx2html/__init__.py index ebc3c49..402e92f 100755 --- a/gpx2html/__init__.py +++ b/gpx2html/__init__.py @@ -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,7 +77,10 @@ def plot_line_chart(values, ticklabels, title, xlabel, ylabel, filename, xtick_r plt.ylabel(ylabel) for key in values.keys(): - plt.plot(values[key], label=key) + if key == 'blind': + plt.plot(values[key], linestyle='None') + else: + plt.plot(values[key], label=key) plt.legend() plt.savefig(filename) @@ -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'))