def period(dictionary, Sunday, Monday): dict_1 = dictionary.copy() #if key is newer than last sunday, remove it for key in dictionary: if key > get_time.LS(Sunday): del dict_1[key] for key in dictionary: if key < get_time.LM(Monday): del dict_1[key] past_dict_rev = { k: dict_1[k] for k in list(reversed(sorted(dict_1.keys()))) } past_dict = { k: past_dict_rev[k] for k in list(sorted(past_dict_rev.keys())) } past_run_count = calc.activity_count(past_dict) past_mile_list = [] for i in past_dict: past_mile_list.append(float(past_dict[i]['distance_miles'])) past_miles = ("{0:.2f}".format(sum(past_mile_list))) past_ten_percent = ("{0:.2f}".format(float(past_miles) * .1)) past_run_title_label = [] for i in list(sorted(past_dict)): past_run_title_label.append(past_dict[i]['weekday_short_date']) past_run_mile_label = [] for i in list(sorted(past_dict)): past_run_mile_label.append(past_dict[i]['distance_miles']) past_run_pace_label = [] for i in list(sorted(past_dict)): past_run_pace_label.append(past_dict[i]['pace']) past_run_elapsed_label = [] for i in list(sorted(past_dict)): past_run_elapsed_label.append(str(past_dict[i]['elapsed'])) past_run_treadmill_label = [] for i in list(sorted(past_dict)): past_run_treadmill_label.append(str(past_dict[i]['treadmill_flagged'])) remaining(past_ten_percent, past_miles) print("past run") print(past_run_count) print(past_miles) print(past_ten_percent) print(past_run_title_label) print(past_run_mile_label) print(past_run_pace_label) print(past_run_elapsed_label) print(past_run_treadmill_label)
master_dict = get_data.my_filtered_activities() diff = datetime.datetime.now() - datetime.datetime(2017, 1, 1) weeks_back = int(diff.days / 7) weeks_to_calculate = list(range(1, weeks_back)) #calculate 0 to 17 week_dict = {} for week in weeks_to_calculate: week_dict[week] = master_dict.copy( ) #make a master dict for each week to calculate for week in week_dict: for key in list(week_dict[week]): #for each key in each master dictionary if key < get_time.LM( week ): #if older than last monday (0 is 1, 1 is 2,2 mondays ago) del week_dict[week][key] for key in list(week_dict[week]): if key > get_time.LS(week - 1): #if newer than last sunday (0 is 1) del week_dict[week][key] #Mileage miles_dict = {} pace_dict = {} hr_dict = {} cad_dict = {} tred_dict = {} count_dict = {} for week in week_dict: if week_dict[week]: #check to see if any activites exist in the given week mile_list = [] for activity in week_dict[week]: mile_list.append(float(
def previous_previous_period(dictionary): dict_1 = dictionary.copy() #if key is newer than last sunday, remove it for key in dictionary: if key > get_time.LS(0): del dict_1[key] for key in dictionary: if key < get_time.LM(3): del dict_1[key] past_dict_rev = {k: dict_1[k] for k in list(reversed(sorted(dict_1.keys())))[:8]} past_dict = {k: past_dict_rev[k] for k in list(sorted(past_dict_rev.keys()))[:4]} past_run_count = calc.activity_count(past_dict) past_mile_list = [] for i in past_dict: past_mile_list.append(float(past_dict[i]['distance_miles'])) past_miles = ("{0:.2f}".format(sum(past_mile_list))) past_ten_percent = ("{0:.2f}".format(float(past_miles) * .1)) past_run_title_label = [] for i in list(sorted(past_dict)): past_run_title_label.append(past_dict[i]['weekday_full_date']) past_run_mile_label = [] for i in list(sorted(past_dict)): past_run_mile_label.append(past_dict[i]['distance_miles']) past_run_pace_label = [] for i in list(sorted(past_dict)): past_run_pace_label.append(past_dict[i]['pace']) past_run_elapsed_label = [] for i in list(sorted(past_dict)): past_run_elapsed_label.append(str(past_dict[i]['elapsed'])) past_run_partner_label = [] for i in list(sorted(past_dict)): past_run_partner_label.append(str(past_dict[i]['athlete_count'])) # print("past past run") # print(past_run_count) # print(past_miles) # print(past_ten_percent) # print(past_run_title_label) # print(past_run_mile_label) # print(past_run_pace_label) # print(past_run_elapsed_label) # print(past_run_partner_label) label1= v['label1'] label1.text = (get_time.convert_weekday_full(get_time.LM(3)) + " - " + get_time.convert_weekday_full(get_time.LS(0))) label2= v['label2'] label2.text = str(past_run_count) label3= v['label3'] label3.text = str(past_miles) label4= v['label4'] label4.text = str(past_ten_percent) label5= v['label5'] label5.text = ("\n".join(past_run_mile_label)) label6= v['label6'] label6.text = ("\n".join(past_run_title_label)) label19= v['label19'] label19.text = ("\n".join(past_run_pace_label)) label20= v['label20'] label20.text = ("\n".join(past_run_elapsed_label)) label21= v['label21'] label21.text = ("\n".join(past_run_partner_label)) remaining_period(past_ten_percent,past_miles)
def graph(master_dict,unit): #elapsed_time, distance_miles, average_speed, kudos_count, max_heartrate, average_heartrate, max_speed, pace_dec, total_elevation_gain, #athlete_count, average_temp, achivement_count input1 = 7 input2 = 'distance_miles' x_list = [] y_list = [] x2_list = [] y2_list = [] x3_list = [] y3_list = [] x4_list = [] y4_list = [] graph_dict = calc.full_running_totals(master_dict,input1,input2) graph_dict1 = graph_dict.copy() graph_dict2 = graph_dict.copy() graph_dict3 = graph_dict.copy() graph_dict4 = graph_dict.copy() for key in list(graph_dict1): if key < get_time.LM(0): #if time is greater than now del graph_dict1[key] # for key in list(graph_dict1): # if key > get_time.LS(0): # del graph_dict1[key] for key in sorted(graph_dict1.keys()): x_list.append(key) y_list.append(graph_dict1[key]) len_x = len(x_list) x_list2 = range(len_x) for key in list(graph_dict2): if key < get_time.LM(1): del graph_dict2[key] for key in list(graph_dict2): if key > get_time.LS(0): del graph_dict2[key] for key in sorted(graph_dict2.keys()): x2_list.append(key) y2_list.append(graph_dict2[key]) len_x2 = len(x2_list) x2_list2 = range(len_x2) for key in list(graph_dict3): if key < get_time.LM(2): del graph_dict3[key] for key in list(graph_dict3): if key > get_time.LS(1): del graph_dict3[key] for key in sorted(graph_dict3.keys()): x3_list.append(key) y3_list.append(graph_dict3[key]) len_x3 = len(x3_list) x3_list2 = range(len_x3) for key in list(graph_dict4): if key < get_time.LM(3): del graph_dict4[key] for key in list(graph_dict4): if key > get_time.LS(2): del graph_dict4[key] for key in sorted(graph_dict4.keys()): x4_list.append(key) y4_list.append(graph_dict4[key]) len_x4 = len(x4_list) x4_list2 = range(len_x4) #x_list2 = x2_list2 = x3_list2 = x4_list2 = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] plt.style.use('dark_background') #plt.axis('off') plt.rcParams['lines.linewidth'] = 2 plt.plot(x_list2,y_list, color='red') plt.plot(x2_list2,y2_list, color='blue') plt.plot(x3_list2,y3_list, color='green') plt.plot(x4_list2,y4_list, color='yellow') plt.title('Previous 4 Weeks (Monday - Sunday) - ' + str(input1) + ' days total, Unit: ' + input2) #plt.ylim(ymin=0) label1 = calc.month_day(get_time.LM(0))+" - "+calc.month_day(get_time.LS(-1)) label2 = calc.month_day(get_time.LM(1))+" - "+calc.month_day(get_time.LS(0)) label3 = calc.month_day(get_time.LM(2))+" - "+calc.month_day(get_time.LS(1)) label4 = calc.month_day(get_time.LM(3))+" - "+calc.month_day(get_time.LS(2)) #print(plt.style.available) plt.legend([label1, label2, label3, label4], loc='best') plt.show()
def weekly_compare(): diff = datetime.datetime.now() - datetime.datetime( 2018, 1, 1) #when to start the graph weeks_back = int(diff.days / 7) weeks_to_calculate = list(range(0, weeks_back)) #calculate 0 to 17 week_dict = {} for week in weeks_to_calculate: week_dict[week] = master_dict.copy( ) #make a master dict for each week to calculate for week in week_dict: for key in list( week_dict[week]): #for each key in each master dictionary if key < get_time.LM( week ): #if older than last monday (0 is 1, 1 is 2,2 mondays ago) del week_dict[week][key] for key in list(week_dict[week]): if key > get_time.LS(week - 1): #if newer than last sunday (0 is 1) del week_dict[week][key] #Mileage miles_dict = {} pace_dict = {} hr_dict = {} ele_dict = {} tred_dict = {} count_dict = {} partner_dict = {} for week in week_dict: #this creates the lists of y values for the below graphs if week_dict[ week]: #check to see if any activites exist in the given week mile_list = [] pace_list = [] hr_list = [] ele_list = [] tred_list = [] count_list = [] partner_list = [] for activity in week_dict[week]: count_list.append(1) mile_list.append( float(week_dict[week][activity]['distance_miles'])) pace_list.append(float(week_dict[week][activity]['pace_dec'])) if float(week_dict[week][activity]['average_heartrate'] ) != 0: #don't cound the 0's in runs i manually enter hr_list.append( float(week_dict[week][activity]['average_heartrate'])) #print(week_dict[week][activity]['average_heartrate']) if 'total_elevation_feet' in week_dict[week][activity]: ele_list.append( float( week_dict[week][activity]['total_elevation_feet'])) ele_dict[get_time.LM(week)] = sum( ele_list) #/len(ele_list) # else: # ele_dict[get_time.LM(week)] = 0 if 'treadmill_flagged' in week_dict[week][activity]: if week_dict[week][activity]['treadmill_flagged'] == 'yes': tred_list.append(1) if 'athlete_count' in week_dict[week][activity]: if week_dict[week][activity]['athlete_count'] > 1: partner_list.append(1) # else: # tred_list.append(0) hr_dict[get_time.LM(week)] = sum(hr_list) / len(hr_list) miles_dict[get_time.LM(week)] = sum(mile_list) pace_dict[get_time.LM(week)] = sum(pace_list) / len(pace_list) tred_dict[get_time.LM(week)] = sum(tred_list) count_dict[get_time.LM(week)] = sum(count_list) # else: # miles_dict[get_time.LM(week)] = 0 # pace_dict[get_time.LM(week)] = 0 # hr_dict[get_time.LM(week)] = 0 # count_dict[get_time.LM(week)] = 0 x_list = [] y_list = [] for month in miles_dict: x_list.append(month) y_list.append(miles_dict[month]) x2_list = [] y2_list = [] for month in pace_dict: x2_list.append(month) y2_list.append(pace_dict[month]) x3_list = [] y3_list = [] for month in hr_dict: x3_list.append(month) y3_list.append(hr_dict[month]) x4_list = [] y4_list = [] for month in ele_dict: x4_list.append(month) y4_list.append(ele_dict[month]) x5_list = [] y5_list = [] for month in tred_dict: x5_list.append(month) y5_list.append(tred_dict[month]) x6_list = [] y6_list = [] for month in count_dict: x6_list.append(month) y6_list.append(count_dict[month]) x7_list = [] y7_list = [] for month in partner_dict: x7_list.append(month) y7_list.append(partner_dict[month]) ######## fig, (ax1, ax2, ax4, ax5) = plt.subplots(nrows=4, figsize=(13, 8)) #figsize sets window myFmt = mdates.DateFormatter('%m/%d') # Miles Ran ax1df = trend_line(x_list, y_list) ax1.bar(x_list, y_list, align='center', width=6, label="Total: " + format_number(sum(y_list))) ax1slope = format_number( float(ax1df['y_trend'].iloc[0]) - float(ax1df['y_trend'].iloc[-1])) ax1.plot_date(ax1df.dates, ax1df.y_trend, 'red', ls='--', marker='None', label=ax1slope) ax1.set_ylabel('Miles Ran', color='b') ax1.set_yticks(range(int(max(y_list)) + 1), 3) ax1.set_xticks(x_list) ax1.tick_params('y', colors='b') ax1.yaxis.grid(True) ax1.legend() labels = ax1.set_xticklabels(x_list) for i, label in enumerate(labels): #if (i % 3) == 1: label.set_label(" ") #if (i % 3) == 2: label.set_label(" ") #label.set_label(" ") label.set_y( label.get_position()[1] - (i % 3) * 0.9 ) #this offsets every other (or 3rd) label by .9 vertically, essentially removing ax1.xaxis.set_major_formatter(myFmt) # Pace vs HR ax2.plot(x2_list, y2_list, color='g', linewidth=2, label='Pace: ' + format_number(sum(y2_list) / len(y2_list))) ax2.set_ylabel('Pace (Decimal)', color='g') ax2.tick_params('y', colors='g') ax2.yaxis.grid(True) ax2.set_xticks(x2_list) labels = ax2.set_xticklabels(x2_list) for i, label in enumerate(labels): label.set_y(label.get_position()[1] - (i % 2) * 0.09) ax2.xaxis.set_major_formatter(myFmt) ax2.legend() ax3 = ax2.twinx() ax3.plot(x3_list, y3_list, color='r', label='Avg HR') ax3.set_ylabel('Avg of Avg HR', color='r') ax3.tick_params('y', colors='r') #Outside/partner/treadmill ax4.bar(x6_list, y6_list, align='center', width=6, color='b', label='Outdoor') #total runs ax4.bar(x5_list, y5_list, align='center', width=6, color='#fc5e02', label=('Treadmill: ' + str(sum(y5_list)))) #treadmill runs ax4.bar(x7_list, y7_list, align='center', width=6, color='#f442e2', label=('Partner: ' + str(sum(y7_list)))) #treadmill runs ax4.set_ylabel('Runs Per Week', color='b') ax4.set_yticks(range(max(y6_list) + 1)) ax4.set_xticks(x5_list) labels = ax4.set_xticklabels(x5_list) for i, label in enumerate(labels): label.set_y(label.get_position()[1] - (i % 3) * 0.09) ax4.xaxis.set_major_formatter(myFmt) ax4.tick_params('y', colors='b') ax4.yaxis.grid(True) #ax4.legend() #COMMENT THIS LINE OUT this causes issues on linux system #elevation ax5.plot(x4_list, y4_list, label='Total: ' + format_number(sum(y4_list))) ax5.set_ylabel('Total Elevation (Feet)') #ax5.set_yticks(range(int(max(y4_list)+1)),20) ax5.set_xticks(x4_list) labels = ax5.set_xticklabels(x4_list) for i, label in enumerate(labels): label.set_y(label.get_position()[1] - (i % 3) * 0.09) ax5.xaxis.set_major_formatter(myFmt) ax5.yaxis.grid(True) ax5.legend() plt.setp(ax1.get_xticklabels(), rotation=0, horizontalalignment='center') plt.setp(ax2.get_xticklabels(), rotation=0, horizontalalignment='center') plt.setp(ax4.get_xticklabels(), rotation=0, horizontalalignment='center') plt.setp(ax5.get_xticklabels(), rotation=0, horizontalalignment='center') fig.tight_layout() fig.subplots_adjust(hspace=0.3) #plt.show() append_image("Weekly_Compare", plt)
def period(dictionary, Sunday, Monday): dict_1 = dictionary.copy() for key in dictionary: if key > get_time.LS(Sunday): del dict_1[key] for key in dictionary: if key < get_time.LM(Monday): del dict_1[key] past_dict_rev = { k: dict_1[k] for k in list(reversed(sorted(dict_1.keys()))) } past_dict = { k: past_dict_rev[k] for k in list(sorted(past_dict_rev.keys())) } past_run_count = calc.activity_count(past_dict) past_mile_list = [] for i in past_dict: past_mile_list.append(float(past_dict[i]['distance_miles'])) past_miles = ("{0:.2f}".format(sum(past_mile_list))) past_ten_percent = ("{0:.2f}".format(float(past_miles) * .1)) past_run_title_label = [] for i in list(sorted(past_dict)): past_run_title_label.append(past_dict[i]['weekday_short_date']) past_run_mile_label = [] for i in list(sorted(past_dict)): past_run_mile_label.append(past_dict[i]['distance_miles']) past_run_pace_label = [] for i in list(sorted(past_dict)): past_run_pace_label.append(past_dict[i]['pace']) past_run_elapsed_label = [] for i in list(sorted(past_dict)): past_run_elapsed_label.append(str(past_dict[i]['elapsed'])) past_run_treadmill_label = [] for i in list(sorted(past_dict)): past_run_treadmill_label.append(str(past_dict[i]['treadmill_flagged'])) remaining(past_ten_percent, past_miles) label1 = v['label1'] label1.text = (get_time.convert_weekday_full(get_time.LM(Monday)) + " - " + get_time.convert_weekday_full(get_time.LS(Sunday))) label2 = v['label2'] label2.text = str(past_miles) # label3= v['label3'] # label3.text = str(past_run_count) label4 = v['label4'] label4.text = str(past_ten_percent) label5 = v['label5'] label5.text = ("\n".join(past_run_title_label)) label6 = v['label6'] label6.text = ("\n".join(past_run_mile_label)) label7 = v['label7'] label7.text = ("\n".join(past_run_pace_label)) label8 = v['label8'] label8.text = ("\n".join(past_run_elapsed_label)) label9 = v['label9'] label9.text = ("\n".join(past_run_treadmill_label))
def main(): global button_2_status button_2_status = "All" my_dataset = dataset.copy() global dict_time_dist global dict_time_pace dict_time_dist,dict_time_pace = calc.filter(my_dataset) running_week_dict = calc.var_calc_loop_single(get_time.running_week(0),my_dataset) this_week_dict = calc.var_calc_loop_single(get_time.LM(0),my_dataset) last_week_dict = calc.var_calc_loop_double(get_time.LM(1),get_time.LS(0),my_dataset) this_month_dict = calc.var_calc_loop_single(get_time.FOM(0),my_dataset) last_month_dict = calc.var_calc_loop_double(get_time.FOM(1),get_time.LOM(1),my_dataset) YTD_dict = calc.var_calc_loop_single(get_time.FOY(),my_dataset) label1= v['label1'] label1.text = this_week_dict['miles'] label2= v['label2'] label2.text = this_week_dict['pace'] label3= v['label3'] label3.text = this_week_dict['count'] label4= v['label4'] label4.text = this_month_dict['miles'] label5= v['label5'] label5.text = this_month_dict['pace'] label6= v['label6'] label6.text = this_month_dict['count'] label7= v['label7'] label7.text = running_week_dict['miles'] label8= v['label8'] label8.text = running_week_dict['pace'] label9= v['label9'] label9.text = running_week_dict['count'] label11= v['label11'] label11.text = last_week_dict['miles'] label12= v['label12'] label12.text = last_week_dict['pace'] label13= v['label13'] label13.text = last_week_dict['count'] label14= v['label14'] label14.text = last_month_dict['miles'] label15= v['label15'] label15.text = last_month_dict['pace'] label16= v['label16'] label16.text = last_month_dict['count'] label17= v['label17'] label17.text = YTD_dict['miles'] label18= v['label18'] label18.text = YTD_dict['pace'] label19= v['label19'] label19.text = YTD_dict['count'] label81= v['label81'] label81.text = this_week_dict['date'] label82= v['label82'] label82.text = this_month_dict['date'] label82= v['label83'] label82.text = running_week_dict['date'] label83= v['label84'] label83.text = last_week_dict['date'] label84= v['label85'] label84.text = last_month_dict['date'] label85= v['label86'] label85.text = YTD_dict['date']
def button_action_1(sender): if button1.selected_index == 0: #red is 90, blue is 91 - current month is red past month is blue v['label90'].text = "This Week" v['label91'].text = "Last Week" v['label92'].text = button_2_status b = graph_dual_dictionary(calc.running_totals_single(dict_time_dist,button_3_status,get_time.LM(0)),calc.running_totals_double(dict_time_dist,button_3_status,get_time.LM(2),get_time.LS(1))) v['imageview1'].image = ui.Image.from_data(b.getvalue()) if button1.selected_index == 1: v['label90'].text ='This Month' v['label91'].text ='Last Month' v['label92'].text = button_2_status b = graph_dual_dictionary(calc.running_totals_single(dict_time_dist,button_3_status,get_time.FOM(0)),calc.running_totals_double(dict_time_dist,button_3_status,get_time.FOM(1),get_time.LOM(1))) v['imageview1'].image = ui.Image.from_data(b.getvalue()) elif button1.selected_index == 2: v['label90'].text ='2017 To Date' v['label91'].text ='' v['label92'].text = button_2_status b = graph_single_dictionary(calc.running_totals_single(dict_time_dist,button_3_status,get_time.FOY())) v['imageview1'].image = ui.Image.from_data(b.getvalue())
def period(dictionary, Sunday, Monday): dict_1 = dictionary.copy() for key in dictionary: if key > get_time.LS(Sunday): del dict_1[key] for key in dictionary: if key < get_time.LM(Monday): del dict_1[key] past_dict_rev = { k: dict_1[k] for k in list(reversed(sorted(dict_1.keys()))) } past_dict = { k: past_dict_rev[k] for k in list(sorted(past_dict_rev.keys())) } past_run_count = calc.activity_count(past_dict) past_mile_list = [] for i in past_dict: past_mile_list.append(float(past_dict[i]['distance_miles'])) past_miles = ("{0:.2f}".format(sum(past_mile_list))) past_ten_percent = ("{0:.2f}".format(float(past_miles) * .1)) past_run_title_label = [] for i in list(sorted(past_dict)): past_run_title_label.append(past_dict[i]['weekday_short_date']) past_run_mile_label = [] for i in list(sorted(past_dict)): past_run_mile_label.append(past_dict[i]['distance_miles']) past_run_pace_label = [] for i in list(sorted(past_dict)): past_run_pace_label.append(past_dict[i]['pace']) past_run_elapsed_label = [] for i in list(sorted(past_dict)): past_run_elapsed_label.append(str(past_dict[i]['elapsed'])) past_run_treadmill_label = [] for i in list(sorted(past_dict)): past_run_treadmill_label.append( str(past_dict[i]['total_elevation_feet'])) remaining(past_ten_percent, past_miles, runs_per_week) label1 = v['label1'] label1.text = (get_time.convert_weekday_full(get_time.LM(Monday)) + " - " + get_time.convert_weekday_full(get_time.LS(Sunday))) label2 = v['label2'] label2.text = str(past_miles) # label3= v['label3'] # label3.text = str(past_run_count) label4 = v['label4'] label4.text = str(past_ten_percent) label5 = v['label5'] label5.text = ("\n".join(past_run_title_label)) label6 = v['label6'] label6.text = ("\n".join(past_run_mile_label)) label7 = v['label7'] label7.text = ("\n".join(past_run_pace_label)) label8 = v['label8'] label8.text = ("\n".join(past_run_elapsed_label)) label9 = v['label9'] label9.text = ("\n".join(past_run_treadmill_label)) #totals at bottom dec_pace_list = [] for i in list(sorted(past_dict)): dec_pace_list.append(past_dict[i]['pace_dec']) current_pace_average = get_data.convert_dec_time( sum(dec_pace_list) / len(dec_pace_list)) label504 = v['label504'] label504.text = str(current_pace_average) seconds_elapsed_list = [] for i in list(sorted(past_dict)): seconds_elapsed_list.append(past_dict[i]['elapsed_time']) total_elapsed_seconds = sum(seconds_elapsed_list) current_duration_total = get_data.convert_seconds_to_minutes( total_elapsed_seconds) label505 = v['label505'] label505.text = str(current_duration_total) current_elevation_list = [] for i in list(sorted(past_dict)): current_elevation_list.append( float(past_dict[i]['total_elevation_feet'])) current_elevation_total = sum(current_elevation_list) label506 = v['label506'] label506.text = str(current_elevation_total)