def monthly_daily_totals(dictionary, time_input, unit_input): #for use with masterdict (get_data.my_filtered_activities()) #01.29.18 #takes in number for how many months ago. Ex 0 is current, 1 is last month x_list = [] y_list = [] #filters out only dates needed for key in list(dictionary): if key < get_time.FOM(time_input): #if older than first of month del dictionary[key] for key in list(dictionary): if key > get_time.LOM(time_input): #if newer than first of month del dictionary[key] calculation_day_count = ( get_time.LOM(time_input) - get_time.FOM(time_input)).days #how many days in the month calculation_day_range = list( range(1, calculation_day_count + 2)) #range of 1 to the days in the month - calculation days mile_count = 0 mile_count_list = [] #list of miles day_count_list = [] #list of days miles occurred for day in calculation_day_range: #ex 1-31 for activity in dictionary: if activity.day == day: #if the day of the activity matches the day in the list mile_count = mile_count + float( dictionary[activity][unit_input]) mile_count_list.append(mile_count) #add mile count day_count_list.append(activity.day) #add day that count occurs return dict(zip(day_count_list, mile_count_list))
def graph_per_month_running(master_dict,choice_dict,unit_dict,days_total): input1 = days_total input2 = 'distance_miles' graph_dict = {} for choice in choice_dict: graph_dict[choice] = calc.full_running_totals(master_dict.copy(),input1,input2) #duplicates data dictionary into number of months given for date_range,choice in zip(graph_dict,choice_dict): for key in list(graph_dict[date_range].keys()): if key < get_time.FOM(choice_dict[choice]) or key > get_time.LOM(choice_dict[choice]): # del graph_dict[date_range][key] #eliminates keys older or newer than specified for each month y_list = [] for key in sorted(graph_dict[date_range].keys()): y_list.append(graph_dict[date_range][key]) #gets y values x_list = list(range(1,len(list(graph_dict[date_range].keys()))+1)) #calculates x values based on y values plt.plot(x_list,y_list,label=(get_time.what_month(get_time.FOM(choice_dict[choice]).month)+" "+str(get_time.FOM(choice_dict[choice]).year))) plt.style.use('dark_background') plt.rcParams['lines.linewidth'] = 1 plt.ylim(ymin=0) plt.title('Running Total - ' + str(input1) + ' days, Unit: ' + input2) plt.legend() plt.show()
return df weeks_to_calculate = list(range(0, 14)) 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.FOM(week): del week_dict[week][key] for key in list(week_dict[week]): if key > get_time.LOM(week): del week_dict[week][key] #Mileage miles_dict = {} pace_dict = {} hr_dict = {} ele_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
import numpy as np from pprint import pprint master_dict = get_data.my_filtered_activities() #grabs dictionary of strava information input1 = 90 #Blue input4 = 365 #Red input2 = 'distance_miles' input3 = 12 #months back to graph graph_dict_1 = {} graph_dict_1 = calc.full_running_totals(master_dict.copy(),input1,input2) for key in list(graph_dict_1.keys()): if key < get_time.FOM(input3): del graph_dict_1[key] graph_dict_2 = {} graph_dict_2 = calc.full_running_totals(master_dict.copy(),input4,input2) for key in list(graph_dict_2.keys()): if key < get_time.FOM(input3): del graph_dict_2[key] fig, (ax1,ax3,ax4) = plt.subplots(nrows=3, figsize=(13,9)) #figsize sets window #plots top plot with shared x but different scale Y
def graph_per_month_total(master_dict,choice_dict,unit_dict): input2 = 'distance_miles' graph_dict = {} for choice in choice_dict: graph_dict[choice] = calc.monthly_daily_totals(master_dict.copy(),choice_dict[choice],input2) #calculates monthly totals for number of months chosen #returns dictionary of all computed values - keys eliminated in the monthly_daily_totals function for date_range,choice in zip(graph_dict,choice_dict): #for each month, graph values. Choice dict used for labels plt.plot(list(graph_dict[date_range].keys()),list(graph_dict[date_range].values()),label=(get_time.what_month(get_time.FOM(choice_dict[choice]).month)+" "+str(get_time.FOM(choice_dict[choice]).year))) plt.style.use('dark_background') plt.rcParams['lines.linewidth'] = 1 plt.ylim(ymin=0) plt.title('Monthly Totals - '+' Unit: ' + input2) plt.legend() plt.show()
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.FOM(0): del graph_dict1[key] for key in list(graph_dict1): if key > get_time.LOM(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.FOM(1): del graph_dict2[key] for key in list(graph_dict2): if key > get_time.LOM(1): 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.FOM(2): del graph_dict3[key] for key in list(graph_dict3): if key > get_time.LOM(2): 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.FOM(3): del graph_dict4[key] for key in list(graph_dict4): if key > get_time.LOM(3): 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) plt.style.use('dark_background') #plt.axis('off') plt.rcParams['lines.linewidth'] = 1 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.ylim(ymin=0) plt.title('Previous 4 Months - ' + str(input1) + ' days total, Unit: ' + input2) #print(plt.style.available) plt.legend([get_time.what_month(get_time.FOM(0).month), get_time.what_month(get_time.FOM(1).month), get_time.what_month(get_time.FOM(2).month), get_time.what_month(get_time.FOM(3).month)], loc='best') plt.show()
plt.plot(x_list,y_list,label=(get_time.what_month(get_time.FOM(choice_dict[choice]).month)+" "+str(get_time.FOM(choice_dict[choice]).year))) plt.style.use('dark_background') plt.rcParams['lines.linewidth'] = 1 plt.ylim(ymin=0) plt.title('Running Total - ' + str(input1) + ' days, Unit: ' + input2) plt.legend() plt.show() unit_dict = {1:'distance_miles', 2:'elapsed_time', 3:'average_speed', 4:'kudos_count', 5:'max_heartrate', 6:'average_heartrate', 7:'max_speed', 8:'pace_dec', 9:'total_elevation_gain', \ 10:'athlete_count', 11:'average_temp', 12:'achivement_count'} list1 = list(range(0,30)) #past 15 months list2 = [] for x in list1: list2.append(str(get_time.what_month(get_time.FOM(x).month)) +" "+str(get_time.FOM(x).year)) #generates month and years for x,y in zip(list1,list2): print(str(x)+" - "+str(y)) #prints out nice list q2 = int(input("Running Graph or Total? \n 1 - Total \n 2 - Running \n")) q1 = int(input("How many months would you like to graph? ")) #for option in unit_dict: #print(str(option)+" - "+unit_dict[option]) choice_dict = {} full_choice_dict = {1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,10:9,11:10,12:11,13:12,14:13,15:14} chosen_unit_dict = {} if q1 == 15: if q2 == 1: #total choice
input1 = 365 #Blue input2 = 90 #Red input3 = 30 # input4 = 8 # input5 = 7 input6 = 1 months_back = 15 graph_dict_1 = {} graph_dict_1 = calc.full_running_totals(master_dict.copy(), input1, 'distance_miles') for key in list(graph_dict_1.keys()): if key < get_time.FOM(months_back): del graph_dict_1[key] # graph_dict_2 = {} graph_dict_2 = calc.full_running_totals(master_dict.copy(), input2, 'distance_miles') for key in list(graph_dict_2.keys()): if key < get_time.FOM(months_back): del graph_dict_2[key] # graph_dict_3 = {} graph_dict_3 = calc.full_running_totals(master_dict.copy(), input3, 'distance_miles')
def running_totals(): input1 = 365 #Blue input2 = 90 #Red input3 = 30 # input4 = 8 # input5 = 7 input6 = 1 months_back = 15 graph_dict_1 = {} graph_dict_1 = calc.full_running_totals(master_dict.copy(), input1, 'distance_miles') for key in list(graph_dict_1.keys()): if key < get_time.FOM(months_back): del graph_dict_1[key] # graph_dict_2 = {} graph_dict_2 = calc.full_running_totals(master_dict.copy(), input2, 'distance_miles') for key in list(graph_dict_2.keys()): if key < get_time.FOM(months_back): del graph_dict_2[key] # graph_dict_3 = {} graph_dict_3 = calc.full_running_totals(master_dict.copy(), input3, 'distance_miles') for key in list(graph_dict_3.keys()): if key < get_time.FOM(months_back): del graph_dict_3[key] # graph_dict_4 = {} graph_dict_4 = calc.full_running_totals(master_dict.copy(), input4, 'distance_miles') for key in list(graph_dict_4.keys()): if key < get_time.FOM(months_back): del graph_dict_4[key] # graph_dict_5 = {} graph_dict_5 = calc.full_running_totals(master_dict.copy(), input5, 'distance_miles') for key in list(graph_dict_5.keys()): if key < get_time.FOM(months_back): del graph_dict_5[key] # graph_dict_6 = {} graph_dict_6 = calc.full_running_totals(master_dict.copy(), input6, 'distance_miles') for key in list(graph_dict_6.keys()): if key < get_time.FOM(months_back): del graph_dict_6[key] fig, (ax1, ax2, ax3, ax4, ax5, ax6) = plt.subplots(nrows=6, figsize=mass_figsize) #figsize sets window ax1.plot(list(graph_dict_1.keys()), list(graph_dict_1.values()), 'red') ax1.set_title(str(input1) + " Running Days Total") ax1.grid(True) ax2.plot(list(graph_dict_2.keys()), list(graph_dict_2.values()), 'blue') #set up third ax2.set_title(str(input2) + " Running Days Total") ax2.grid(True) ax3.plot(list(graph_dict_3.keys()), list(graph_dict_3.values()), 'green') #set up fourth graph ax3.set_title(str(input3) + " Running Days Total") ax3.grid(True) ax4.plot(list(graph_dict_4.keys()), list(graph_dict_4.values()), 'red') #set up fourth graph ax4.set_title(str(input4) + " Running Days Total") ax4.grid(True) ax5.plot(list(graph_dict_5.keys()), list(graph_dict_5.values()), 'blue') #set up fourth graph ax5.set_title(str(input5) + " Running Days Total") ax5.grid(True) ax6.plot(list(graph_dict_6.keys()), list(graph_dict_6.values()), 'green') #set up fourth graph ax6.set_title(str(input6) + " Running Days Total") ax6.grid(True) fig.subplots_adjust(hspace=0.3) fig.tight_layout() append_image("Running_Totals", plt)
def monthly_compare(): weeks_to_calculate = list(range(0, 14)) 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.FOM(week): del week_dict[week][key] for key in list(week_dict[week]): if key > get_time.LOM(week): del week_dict[week][key] #Mileage miles_dict = {} pace_dict = {} hr_dict = {} ele_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 = [] pace_list = [] hr_list = [] ele_list = [] tred_list = [] count_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.FOM(week)] = sum( ele_list) #/len(ele_list) # else: # ele_dict[get_time.FOM(week)] = 0 if 'treadmill_flagged' in week_dict[week][activity]: if week_dict[week][activity]['treadmill_flagged'] == 'yes': tred_list.append(1) # else: # tred_list.append(0) hr_dict[get_time.FOM(week)] = sum(hr_list) / len(hr_list) miles_dict[get_time.FOM(week)] = sum(mile_list) pace_dict[get_time.FOM(week)] = sum(pace_list) / len(pace_list) tred_dict[get_time.FOM(week)] = sum(tred_list) count_dict[get_time.FOM(week)] = sum(count_list) # else: # miles_dict[get_time.FOM(week)] = 0 # pace_dict[get_time.FOM(week)] = 0 # hr_dict[get_time.FOM(week)] = 0 # count_dict[get_time.FOM(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]) ######## fig, (ax1, ax2, ax4, ax5) = plt.subplots(nrows=4, figsize=(13, 8)) #figsize sets window myFmt = mdates.DateFormatter('%m/%y') ax1df = trend_line(x_list, y_list) ax1.bar(x_list, y_list, align='center', width=25) 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.tick_params('y', colors='b') ax1.yaxis.grid(True) ax1.legend() ax1.set_xticks(x_list) labels = ax1.set_xticklabels(x_list) for i, label in enumerate(labels): label.set_y(label.get_position()[1] - (i % 2) * 0.09) ax1.xaxis.set_major_formatter(myFmt) ax2.plot(x2_list, y2_list, color='g', label='Pace', linewidth=2) ax2.set_ylabel('Pace (Decimal)', color='g') ax2.tick_params('y', colors='g') ax2.yaxis.grid(True) 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') 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) ax4.bar(x6_list, y6_list, align='center', width=25, color='b', label='Outdoor') #total runs ax4.bar(x5_list, y5_list, align='center', width=25, color='#fc5e02', label='Treadmill') #treadmill runs ax4.set_ylabel('Runs Per Week', color='b') ax4.set_yticks(range(max(y6_list) + 1)) ax4.tick_params('y', colors='b') ax4.yaxis.grid(True) ax4.legend() ax4.set_xticks(x5_list) labels = ax4.set_xticklabels(x6_list) for i, label in enumerate(labels): label.set_y(label.get_position()[1] - (i % 2) * 0.09) ax4.xaxis.set_major_formatter(myFmt) ax5.plot(x4_list, y4_list, label='Total') ax5.set_ylabel('Total Elevation (Feet)') #ax5.set_yticks(range(int(max(y4_list)+1)),20) ax5.yaxis.grid(True) ax5.legend() 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 % 2) * 0.09) ax5.xaxis.set_major_formatter(myFmt) 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) append_image("Monthly_Compare", plt)
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())