def full_running_totals(dictionary1, days, unit): #creadted for use with master_dict #newest and working #limit days after this calculation for range #shitty and just returns two lists, not full dictionary due to keys being days and not activities calculation_range_time = [] final_list = [] dictionary = dictionary1.copy() x = days #time functions now = datetime.datetime.now() start_of_today = datetime.datetime(now.year, now.month, now.day, hour=0, minute=0, second=0) end_of_today = datetime.datetime(now.year, now.month, now.day, hour=23, minute=59, second=59) difference = start_of_today - get_time.FOY() calculation_range = list(range( 0, (difference.days + 1))) #creates list from past date(given) to current date calculation_range_rev = list(reversed(calculation_range)) calculation_range_time = [ end_of_today - datetime.timedelta(days=x) for x in range(0, (difference.days + 1)) ] for i, f in zip( calculation_range_time, calculation_range): #for every calculation day ex 1,2,3,4,5 back dictionary_1 = dictionary.copy() #create a new dictionary oldest_time = end_of_today - (datetime.timedelta(days=(x + f))) for key in list(dictionary_1): if key > i: del dictionary_1[key] #delete keys newer than calculation day for key in list(dictionary_1): if key < oldest_time: #delete keys older than oldest time del dictionary_1[key] value_list = [] for key in dictionary_1: value_list.append(float( dictionary_1[key][unit])) #adds variables to list list_sum = sum(value_list) final_list.append(list_sum) new_date_list = [] for i in calculation_range: #create list of days going backwards from today new_day = get_time.day(i) new_date_list.append(new_day) new_dict = dict(zip(new_date_list, final_list)) return new_dict
def all_running_totals(dictionary1, days): #used by Noteables2 to get dictionary of running totals and datetime for keys calculation_range_time = [] final_list = [] dictionary = dictionary1.copy() x = days #time functions now = datetime.datetime.now() start_of_today = datetime.datetime(now.year, now.month, now.day, hour=0, minute=0, second=0) end_of_today = datetime.datetime(now.year, now.month, now.day, hour=23, minute=59, second=59) difference = start_of_today - get_time.FOY() calculation_range = list(range( 0, (difference.days + 1))) #creates list from past date(given) to current date calculation_range_rev = list(reversed(calculation_range)) calculation_range_time = [ end_of_today - datetime.timedelta(days=x) for x in range(0, (difference.days + 1)) ] for i, f in zip( calculation_range_time, calculation_range): #for every calculation day ex 1,2,3,4,5 back dictionary_1 = dictionary.copy() #create a new dictionary oldest_time = end_of_today - (datetime.timedelta(days=(x + f))) for key in list(dictionary_1): if key > i: del dictionary_1[key] #delete keys newer than calculation day for key in list(dictionary_1): if key < oldest_time: #delete keys older than oldest time del dictionary_1[key] value_list = (dictionary_1.values()) #grabs x values from list meters = sum(value_list) miles = meters_to_miles(meters) final_list.append(float(miles)) #new_dict = dict(zip(calculation_range_rev, final_list)) new_date_list = [] for i in calculation_range: #create list of days going backwards from today new_day = get_time.day(i) new_date_list.append(new_day) #print(final_list) new_dict = dict(zip(new_date_list, final_list)) return new_dict
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 print_statements(master_dict): now = datetime.datetime.now() past = datetime.datetime(now.year, now.month - (0 - 1), 1) - (datetime.timedelta(days=1)) LOM = datetime.datetime(past.year, past.month, past.day, hour=23, minute=59, second=59) days_remaining = LOM.day - now.day runs_per_week = 3 this_month_full = calc.monthly_daily_totals(master_dict.copy(), 0, 'distance_miles') last_month_full = calc.monthly_daily_totals(master_dict.copy(), 1, 'distance_miles') this_month = MTD(master_dict.copy(), 0) last_month = MTD(master_dict.copy(), 1) month_difference = this_month - last_month runs_remain = math.ceil(days_remaining * (runs_per_week / 7)) monthly_dict = calc.monthly_stats(master_dict.copy()) max_miles = 0 for month in monthly_dict: if monthly_dict[month]['miles_ran'] > max_miles: max_miles = int(monthly_dict[month]['miles_ran']) most_miles_month = month print("MONTHLY") print("**********") print("Miles Ran This Month: " + str(this_month)) print("Runs This Month: " + str(len(this_month_full))) print("Miles Ran Last Month: " + str(last_month)) print("Runs Last Month: " + str(len(last_month_full))) print("Days in Month Remaining: " + str(days_remaining)) print("Last Month vs This Month: " + str("{0:.2f}".format(month_difference))) print("Runs Remain in Month (" + str(runs_per_week) + " per week): " + str(runs_remain)) print() print("GOALS") print("Goal of 50 Miles per Month: " + str("{0:.2f}".format(this_month - 50))) print("MPR to Match 50m Goal: " + str("{0:.2f}".format((50 - this_month) / runs_remain))) print("MPR to Match Last Month: " + str("{0:.2f}".format(abs(month_difference / runs_remain)))) print("Most Mile Month: " + monthly_dict[most_miles_month]['date_human']) print("Most Miles Ran in a month: " + str(max_miles)) print("MPR to Match Highest Month: " + str("{0:.2f}".format((max_miles - this_month) / runs_remain))) weekly_dict = calc.weekly_stats(master_dict.copy()) max_weekly_miles = 0 for week in weekly_dict: if weekly_dict[week]['miles_ran'] > max_weekly_miles: max_weekly_miles = int(weekly_dict[week]['miles_ran']) most_miles_week = week print() print("WEEKLY") print("********") print("Miles This Week: " + str(current_miles)) print("Most Mile Week: " + str(weekly_dict[most_miles_week]['date_human'])) print("Most Miles Run in a Week: " + str(max_weekly_miles)) print("Miles to Match Highest Week: " + str(float(max_weekly_miles) - float(current_miles))) #this year ytd_dict = master_dict.copy() for key in list(ytd_dict): if key < get_time.FOY(): del ytd_dict[key] ytd_miles = [] for run in ytd_dict: ytd_miles.append(float(ytd_dict[run]['distance_miles'])) miles_this_year = sum(ytd_miles) #last year timestamp = datetime.datetime.now() past_ytd_dict = master_dict.copy() for key in list(past_ytd_dict): if key < get_time.PFOY(): del past_ytd_dict[key] if key > datetime.datetime( timestamp.year - 1, timestamp.month, timestamp.day): #get date this time last year del past_ytd_dict[key] pytd_miles = [] for run in past_ytd_dict: pytd_miles.append(float(past_ytd_dict[run]['distance_miles'])) miles_last_year_this_time = sum(pytd_miles) goal_2018 = 600 MPD = goal_2018 / 365 day_of_year = LOM.timetuple().tm_yday target_miles = MPD * day_of_year remaining_ytd_miles = miles_this_year - target_miles print() print("YEAR TO DATE") print("**********") print("Miles Ran This Year: " + str(miles_this_year)) print("Miles Ran Last Year by now: " + str(miles_last_year_this_time)) print("Miles Behind Last Year: " + str("{0:.2f}".format(miles_this_year - miles_last_year_this_time))) print("2018 Goal for today: " + str(("{0:.2f}".format(target_miles)))) print("Miles Behind YTD Goal: " + str(("{0:.2f}".format(remaining_ytd_miles)))) print("MPR to YTD Goal by End of Month: " + str(("{0:.2f}".format(abs(remaining_ytd_miles) / runs_remain))))
def Yearly(dictionary, runs_per_week): #this year now = datetime.datetime.now() past = datetime.datetime(now.year, now.month - (0 - 1), 1) - (datetime.timedelta(days=1)) LOM = datetime.datetime(past.year, past.month, past.day, hour=23, minute=59, second=59) end_of_year = datetime.datetime(now.year, 12, 31) days_remaining = LOM.day - now.day #runs_per_week = 3 ytd_dict = master_dict.copy() for key in list(ytd_dict): if key < get_time.FOY(): del ytd_dict[key] ytd_miles = [] for run in ytd_dict: ytd_miles.append(float(ytd_dict[run]['distance_miles'])) miles_this_year = sum(ytd_miles) #last year timestamp = datetime.datetime.now() past_ytd_dict = master_dict.copy() for key in list(past_ytd_dict): if key < get_time.PFOY(): del past_ytd_dict[key] if key > datetime.datetime( timestamp.year - 1, timestamp.month, timestamp.day): #get date this time last year del past_ytd_dict[key] pytd_miles = [] for run in past_ytd_dict: pytd_miles.append(float(past_ytd_dict[run]['distance_miles'])) miles_last_year_this_time = sum(pytd_miles) goal_2018 = 600 MPD = goal_2018 / 365 #miels per day starting 1/1 day_of_year = now.timetuple().tm_yday #numerical value of day in the year #day_of_year = LOM.timetuple().tm_yday #found the day of the last of month for some reason, changed to above target_miles = MPD * day_of_year #what my current target_miles should be - NOT year long goal remaining_ytd_miles = miles_this_year - target_miles #why is this named like this? days_remaining_in_year = (end_of_year - now).days print("Days remaining in year: " + str(days_remaining_in_year)) #new 3.6.18 goal_miles_left_in_year = goal_2018 - miles_this_year #reverse of remaining_ytd_miles for some reason goal_miles_per_day_now = goal_miles_left_in_year / days_remaining_in_year goal_miles_per_week_now = goal_miles_per_day_now * 7 goal_miles_per_run_now = goal_miles_per_week_now / runs_per_week label111 = v['label111'] label111.text = str("YTD Miles") label112 = v['label112'] label112.text = str("") label113 = v['label113'] label113.text = str("Last YTD by now") label114 = v['label114'] label114.text = str("Difference") label115 = v['label115'] label115.text = str("") label116 = v['label116'] label116.text = str("") label117 = v['label117'] label117.text = str("") # label121 = v['label121'] label121.text = format_text(miles_this_year) label122 = v['label122'] label122.text = str("") label123 = v['label123'] label123.text = format_text(miles_last_year_this_time) label124 = v['label124'] label124.text = format_text(miles_this_year - miles_last_year_this_time) label125 = v['label125'] label125.text = str("") label126 = v['label126'] label126.text = str("") label127 = v['label127'] label127.text = str("") # label131 = v['label131'] label131.text = str("18 Goal by today") label132 = v['label132'] label132.text = str("Difference") label133 = v['label133'] label133.text = str("Miles Per Day") label134 = v['label134'] label134.text = str("Miles Per Week") label135 = v['label135'] label135.text = str("Miles Per Run") label136 = v['label136'] label136.text = str() label137 = v['label137'] label137.text = str() label141 = v['label141'] label141.text = format_text(target_miles) label142 = v['label142'] label142.text = format_text(remaining_ytd_miles) label143 = v['label143'] label143.text = format_text(goal_miles_per_day_now) label144 = v['label144'] label144.text = format_text(goal_miles_per_week_now) label145 = v['label145'] label145.text = format_text(goal_miles_per_run_now) label146 = v['label146'] label146.text = str() label147 = v['label147'] label147.text = str()