示例#1
0
def parallel_pace_charts(Raceday):

    #For the 2012 season, give the model something to start with
    Raceday = max(Raceday, 20130710)

    """
    Time Candidates
    """
    Parallel_Chart = pd.DataFrame()
    min_time = max(0, Extraction_Database("""
                                   Select * from
                                   (Select min(RESS1) from RaceDb where RESS1 > 0),
                                   (Select min(RESS2) from RaceDb where RESS2 > 0),
                                   (Select min(RESS3) from RaceDb where RESS3 > 0),
                                   (Select min(RESS4) from RaceDb where RESS4 > 0),
                                   (Select min(RESS5) from RaceDb where RESS5 > 0),
                                   (Select min(RESS6) from RaceDb where RESS6 > 0)
                                   """.format(Raceday = Raceday)).values.min())
    max_time = Extraction_Database("""
                                   Select * from
                                   (Select max(RESS1) from RaceDb where RESS1 > 0),
                                   (Select max(RESS2) from RaceDb where RESS2 > 0),
                                   (Select max(RESS3) from RaceDb where RESS3 > 0),
                                   (Select max(RESS4) from RaceDb where RESS4 > 0),
                                   (Select max(RESS5) from RaceDb where RESS5 > 0),
                                   (Select max(RESS6) from RaceDb where RESS6 > 0)
                                   """.format(Raceday = Raceday)).values.max()
    Parallel_Chart.loc[:,'time_vector'] = [round(i,2) for i in np.arange(min_time-10, max_time+3, 0.01)]

    """
    Equivalent Time
    """
    equivalent_time = Extraction_Database("""Select RADIS, RATRA, RALOC, round(avg(RESS1),2) S1_eq_time, round(avg(RESS2),2) S2_eq_time,
                                          round(avg(RESS3),2) S3_eq_time, round(avg(RESS4),2) S4_eq_time, round(avg(RESS5),2) S5_eq_time,
                                          round(avg(RESS6),2) S6_eq_time from RaceDb
                                          where RADAT < {Raceday}
                                          group by RADIS, RATRA, RALOC""".format(Raceday = Raceday))
    equivalent_time.loc[:,'RADIS'] = equivalent_time.loc[:,'RADIS'].map(str)
    equivalent_time.loc[:,'profile'] = equivalent_time.loc[:,['RALOC', 'RADIS', 'RATRA']].agg('_'.join, axis=1)
    equivalent_time.loc[:,'RADIS'] = equivalent_time.loc[:,'RADIS'].map(int)

    Distance_List = equivalent_time.loc[:,'RADIS'].unique()
    for distance in Distance_List:
        condition = equivalent_time.loc[:,'RADIS'] == distance
        equivalent_time.loc[condition,'S1_1s'] = round(Sectional_Dict[distance][0] / (equivalent_time.loc[condition,'S1_eq_time'] * 1), 3)
        equivalent_time.loc[condition,'S2_1s'] = round(Sectional_Dict[distance][1] / (equivalent_time.loc[condition,'S2_eq_time'] * 1), 3)
        equivalent_time.loc[condition,'S3_1s'] = round(Sectional_Dict[distance][2] / (equivalent_time.loc[condition,'S3_eq_time'] * 1), 3)
        try :
            equivalent_time.loc[condition,'S4_1s'] = round(Sectional_Dict[distance][3] / (equivalent_time.loc[condition,'S4_eq_time'] * 1), 3)
            equivalent_time.loc[condition,'S5_1s'] = round(Sectional_Dict[distance][4] / (equivalent_time.loc[condition,'S5_eq_time'] * 1), 3)
            equivalent_time.loc[condition,'S6_1s'] = round(Sectional_Dict[distance][5] / (equivalent_time.loc[condition,'S6_eq_time'] * 1), 3)
        except :
            pass

    """
    Parallel Charts
    """
    for index, row in equivalent_time.iterrows():
        for Section in ['S1', 'S2', 'S3', 'S4', 'S5', 'S6']:
            Time_DF = []
            eq_time = row[Section+'_eq_time']
            increment = row[Section+'_1s']
            if eq_time != 0:
                #Top Half
                for i in np.arange(eq_time, max_time, 0.01):
                    Time_DF.append([round(i,2), round(80 - (round(i,2) - eq_time) * increment, 3)])
                #Botton Half
                for i in np.arange(min_time, eq_time, 0.01):
                    Time_DF.append([round(i,2), round(80 + (eq_time - round(i,2)) * increment, 3)])

                #Merging to Parallel Chart
                Parallel_Chart = Parallel_Chart.merge(pd.DataFrame(Time_DF, columns=['time', row['profile']+'_'+Section]), how='left',left_on='time_vector',right_on='time')
                Parallel_Chart.drop(columns=['time'], inplace = True)

    """
    Uploading to Database
    """
    #Create Connection
    with sqlite3.connect('Data.db') as db:
        sql = db.cursor()
        db.commit()

    sql.execute("drop table if exists Parallel_PaceDb")
    db.commit()
    sql.execute("""
                Create Table Parallel_PaceDb(
                time_vector real, HV_1000_T_S1 real, HV_1000_T_S2 real, HV_1000_T_S3 real, ST_1000_T_S1 real, ST_1000_T_S2 real, ST_1000_T_S3 real,
                ST_1200_AW_S1 real, ST_1200_AW_S2 real, ST_1200_AW_S3 real, HV_1200_T_S1 real, HV_1200_T_S2 real, HV_1200_T_S3 real, ST_1200_T_S1 real,
                ST_1200_T_S2 real, ST_1200_T_S3 real, ST_1400_T_S1 real, ST_1400_T_S2 real, ST_1400_T_S3 real, ST_1400_T_S4 real, ST_1600_T_S1 real,
                ST_1600_T_S2 real, ST_1600_T_S3 real, ST_1600_T_S4 real, ST_1650_AW_S1 real, ST_1650_AW_S2 real, ST_1650_AW_S3 real, ST_1650_AW_S4 real,
                HV_1650_T_S1 real, HV_1650_T_S2 real, HV_1650_T_S3 real, HV_1650_T_S4 real, ST_1800_AW_S1 real, ST_1800_AW_S2 real, ST_1800_AW_S3 real,
                ST_1800_AW_S4 real, ST_1800_AW_S5 real, HV_1800_T_S1 real, HV_1800_T_S2 real, HV_1800_T_S3 real, HV_1800_T_S4 real, HV_1800_T_S5 real,
                ST_1800_T_S1 real, ST_1800_T_S2 real, ST_1800_T_S3 real, ST_1800_T_S4 real, ST_1800_T_S5 real,ST_2000_T_S1 real, ST_2000_T_S2 real,
                ST_2000_T_S3 real, ST_2000_T_S4 real, ST_2000_T_S5 real, HV_2200_T_S1 real, HV_2200_T_S2 real, HV_2200_T_S3 real, HV_2200_T_S4 real,
                HV_2200_T_S5 real, HV_2200_T_S6 real, ST_2200_T_S1 real, ST_2200_T_S2 real, ST_2200_T_S3 real, ST_2200_T_S4 real, ST_2200_T_S5 real,
                ST_2200_T_S6 real, ST_2400_T_S1 real, ST_2400_T_S2 real, ST_2400_T_S3 real, ST_2400_T_S4 real, ST_2400_T_S5 real, ST_2400_T_S6 real)
                """)
    db.commit()

    #Closing Connection
    sql.close()
    db.close()

    Load_Dataset_toDatabase('Parallel_PaceDb', Parallel_Chart)

    return None
示例#2
0
def parallel_speed_charts(Raceday):

    #For the 2012 season, give the model something to start with
    Raceday = max(Raceday, 20130710)

    """
    Time Candidates
    """
    Parallel_Chart = pd.DataFrame()
    Parallel_Chart['time_vector'] = [round(i,2) for i in np.arange(45, 175, 0.01)]

    """
    Equivalent Time
    """
    equivalent_time = Extraction_Database("""Select round(avg(RESFT),2) eq_time, RADIS, RATRA, RALOC from RaceDb
                                          where RADAT < {Raceday}
                                          group by RADIS, RATRA, RALOC""".format(Raceday = Raceday))
    equivalent_time.loc[:,'RADIS'] = equivalent_time['RADIS'].map(str)
    equivalent_time.loc[:,'profile'] = equivalent_time.loc[:,['RALOC', 'RADIS', 'RATRA']].agg('_'.join, axis=1)
    equivalent_time.loc[:,'RADIS'] = equivalent_time.loc[:,'RADIS'].map(int)
    equivalent_time.loc[:,'1s'] = round(equivalent_time.loc[:,'RADIS'] / (equivalent_time.loc[:,'eq_time'] * 1), 3)

    """
    Parallel Charts
    """
    for index, row in equivalent_time.iterrows():

        Dist_DF = []
        eq_time = row['eq_time']
        increment = row['1s']

        #Top Half
        for i in np.arange(eq_time, 175, 0.01):
            Dist_DF.append([round(i,2), round(80 - (round(i,2) - eq_time) * increment, 3)])

        #Botton Half
        for i in np.arange(45, eq_time, 0.01):
            Dist_DF.append([round(i,2), round(80 + (eq_time - round(i,2)) * increment, 3)])

        #Merging to Parallel Chart
        Parallel_Chart = Parallel_Chart.merge(pd.DataFrame(Dist_DF, columns=['time', row['profile']]), how='left',left_on='time_vector',right_on='time')
        Parallel_Chart.drop(columns=['time'], inplace = True)

    """
    Uploading to Database
    """
    #Create Connection
    with sqlite3.connect('Data.db') as db:
        sql = db.cursor()
        db.commit()

    sql.execute("drop table if exists Parallel_SpeedDb")
    db.commit()
    sql.execute("""
                Create Table Parallel_SpeedDb(
                time_vector real, HV_1000_T real, ST_1000_T real, ST_1200_AW real, HV_1200_T real, ST_1200_T real, ST_1400_T real, ST_1600_T real,
                ST_1650_AW real, HV_1650_T real, ST_1800_AW real, HV_1800_T real, ST_1800_T real, ST_2000_T real, HV_2200_T real, ST_2200_T real, ST_2400_T real)
                """)
    db.commit()

    #Closing Connection
    sql.close()
    db.close()

    Load_Dataset_toDatabase('Parallel_SpeedDb', Parallel_Chart)

    return None #print("---- Parallel_SpeedDb is Created ----")