コード例 #1
0
ファイル: calc.py プロジェクト: jhavens12/Pythonista
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))
コード例 #2
0
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()
コード例 #3
0
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 = []
コード例 #4
0
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()
コード例 #5
0
ファイル: Email.py プロジェクト: jhavens12/Running_Graphs
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)
コード例 #6
0
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']
コード例 #7
0
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())