コード例 #1
0
def getTrackBounds(filename):
    extension = os.path.splitext(filename)[1]
    print("at -getTrackBounds-", extension)

    if 'gpx' in extension:
        df = gpxtricks.GPXtoDataFrame(filename)
    elif 'tcx' in extension:
        df = gpxtricks.TCXtoDataFrame(filename)

    return gpxtricks.getTrackBounds(df)
コード例 #2
0
def getTrainingData(filename, skip=False):
    """ Returns dict with summary of training data """
    extension = os.path.splitext(filename)[1]

    if 'gpx' in extension:
        df = gpxtricks.GPXtoDataFrame(filename)
    elif 'tcx' in extension:
        df = gpxtricks.TCXtoDataFrame(filename)

    gpxdict = gpxtricks.getmainInfo(df)
    gpxdict['filename'] = os.path.basename(filename)

    # Remove some kommunetopp specific details.
    del gpxdict['elediff']
    del gpxdict['climbingrate']
    del gpxdict['steepness']
    del gpxdict['stop_time']
    del gpxdict['kupert_faktor']
    del gpxdict['pause_faktor']
    del gpxdict['topptur_faktor']

    # Add some empty columns for spreadsheet
    gpxdict['comment'] = ''
    gpxdict['health'] = ''
    gpxdict['activity'] = ''

    # Add hr data if any
    zonelist = ['sone1', 'sone2', 'sone3', 'sone4', 'sone5']
    hrdata = gpxtricks.heartZone(df)
    if hrdata != -1:
        for i, item in enumerate(zonelist):
            gpxdict[item] = hrdata[i]
    else:
        for item in zonelist:
            gpxdict[item] = ''

    # Add best speed data
    bt = gpxtricks.findBestTempo2(df)
    bt2 = dict()

    for itm in bt:
        bt2['speed_{:0>5}'.format(itm)] = float('{:.2f}'.format(bt[itm][0] *
                                                                3.6))

    gpxdict.update(bt2)
    print(gpxdict)

    if not skip:
        gpxtricks.plotHeartZone(df, 'C:/python/resc/pRect2.png')
        gpxtricks.plotElevationProfile2(df,
                                        'C:/python/resc/elevationProfile.png')
        gpxtricks.plotSpeedProfile(df, 'C:/python/resc/speedProfile.png')
        gpxtricks.plotHeartrateProfile(df, 'C:/python/resc/hrProfile.png')

    return gpxdict
コード例 #3
0
def getTrackData(filename):
    extension = os.path.splitext(filename)[1]
    print("at -getTrackData-", extension)

    if 'gpx' in extension:
        df = gpxtricks.GPXtoDataFrame(filename)
    elif 'tcx' in extension:
        df = gpxtricks.TCXtoDataFrame(filename)

    df_dat = gpxtricks.exportRedPoints(df)
    print(df_dat)
    return df_dat
コード例 #4
0
def segmentAnalyzer(filename, segList):
    """ Reset for new file"""
    for seg in segList:
        seg.resetCounter()

    try:
        df = gpxtricks.GPXtoDataFrame(filename)
    except:
        df = gpxtricks.TCXtoDataFrame(filename)

    p1 = list(df.iloc[0][['lat', 'lon', 'time']])

    for row in df.iterrows():
        p2 = [row[1]['lat'], row[1]['lon'], row[1]['time']]
        if p2[0] != 0.0 and p2[1] != 0.0:
            for seg in segList:
                seg.runNewPoint(filename, p1, p2)
            p1 = p2
コード例 #5
0
def toPointCloud(datafolder, outputfile):
    i = 0
    for filename in glob.glob(datafolder):

        if os.path.isfile(filename):
            f = open(outputfile, 'a')
        else:
            f = open(outputfile, 'w')

        print(filename)
        extension = os.path.splitext(filename)[1]

        if 'gpx' in extension:
            df = gpxtricks.GPXtoDataFrame(filename)
        elif 'tcx' in extension:
            df = gpxtricks.TCXtoDataFrame(filename)

        for row in df.iterrows():
            if row[1].lat > 10:
                s = '{};{};{}\n'.format(i, row[1].lat, row[1].lon)
                i += 1
                f.write(s)

        f.close()
コード例 #6
0
def createWebpages():
    """ Load the rapport template """
    my_dir = os.path.dirname(__file__)
    template_dir = os.path.join(my_dir, 'res\\templates')
    myloader = FileSystemLoader(template_dir)
    env = Environment(loader=myloader)
    template_rapport = env.get_template('template_rapport.html')
    template_stat = env.get_template('template_stat.html')
    template_stat_expl = env.get_template('template_stat_forklaring.html')

    besteget = gpxtricks.get_besteget_kommuner(
        my_dir +
        '\\res\\kommunetopplisteV2.xml')  # links to previous and next kommune.
    bC = 2

    kommune_selected = gpxtricks.get_selected_kommune(
        my_dir + '\\res\\kommunetopplisteV2.xml')

    ## Create a dict for each kommune
    komm_data = []
    # Create placeholders for tot stat data
    totstat = createTotStat()

    # Create placeholders for individual stat
    stat = createDetailedStat()

    for kom in gpxtricks.readkommunexml(my_dir +
                                        '\\res\\kommunetopplisteV2.xml'):

        # links to previuous and next kommune, updated select list,
        kom['neste_kommune'] = besteget[bC]
        kom['forrige_kommune'] = besteget[bC - 2]
        bC += 1
        print(kom)
        kom['select_fylkeliste'] = gpxtricks.get_selected_fylke(
            kom['kommunenr'])
        kom['select_kommuneliste'] = kommune_selected

        if kom['besteget'] == 'True':
            totstat['tot_antall_besteget'] += 1

        # Info from GPX file, if the file exist
        gpxfile = my_dir + "\\res\\gpx\\{0}.gpx".format(kom['kommunenr'])
        if os.path.isfile(gpxfile):

            gpx_df = gpxtricks.GPXtoDataFrame(gpxfile)
            kom['stoplocations'] = gpxtricks.exportStopLoc(gpx_df)
            kom['tripcoordinates'] = gpxtricks.exportRedPoints(gpx_df)
            gpxtricks.plotElevationProfile(
                gpx_df,
                'C:\\python\\kommuner\\outdata\\profile2\\{}.png'.format(
                    kom['kommunenr']))
            mainInfo = gpxtricks.getmainInfo(gpx_df)
            kom.update(mainInfo)

            stat = updateDetailedStat(stat, mainInfo, kom)

            totstat['tot_length'] += mainInfo['length']
            totstat['tot_elevation'] += mainInfo['climbing']
            totstat['tot_tottid'] += mainInfo['tottime']

        else:
            gpxfile_ex = my_dir + "\\res\\gpx\\{0}_ex.gpx".format(
                kom['kommunenr'])
            if os.path.isfile(gpxfile_ex):
                gpx_df = gpxtricks.GPXtoDataFrame(gpxfile_ex)
                kom['stoplocations'] = gpxtricks.exportStopLoc(gpx_df)
                kom['tripcoordinates'] = gpxtricks.exportRedPoints(gpx_df)
                gpxtricks.plotElevationProfile(
                    gpx_df,
                    'C:\\python\\kommuner\\outdata\\profile2\\{}.png'.format(
                        kom['kommunenr']))
                mainInfo = gpxtricks.getmainInfo(gpx_df)
                kom.update(mainInfo)

                stat = updateDetailedStat(stat, mainInfo, kom)

        komm_data.append(kom)
        print(kom['kommunenavn'])

    totstat1 = modTotStat(totstat)
    siste_rapporter = siste_rapporter_HTML(stat['Dato'])
    # Creating the actual reports

    print("Starting creating reports!")

    for komm in komm_data:
        komm.update(totstat1)
        komm.update(siste_rapporter)

        file = open('C:\\python\\kommuner\\outdata\\{}.html'.format(
            komm['kommunenr']),
                    'w',
                    encoding='utf-8')
        file.write(template_rapport.render(komm))
        file.close()

    print("Finished creating reports!")

    # Lage forklaring til statistikk sidene.
    newStatExpl = dict()
    newStatExpl['select_fylkeliste'] = gpxtricks.get_selected_fylke('00')
    newStatExpl['select_kommuneliste'] = kommune_selected
    newStatExpl.update(totstat1)
    newStatExpl.update(siste_rapporter)
    file = open('C:\\python\\kommuner\\outdata\\stat_forklaring.html',
                'w',
                encoding='utf-8')

    newStat = dict()
    newStat['stat_select_list'] = select_statistikk_overskrifter()
    newStat.update(totstat1)
    newStat.update(siste_rapporter)

    for i, key in enumerate(statistikk_overskrifter()):
        newStat['stat_overskrift'] = key
        newStat['stat_detaljer'] = create_stat_details(stat[key])
        newStat['stat_komm_grenser'] = create_stat_komm_grenser(stat[key])

        file = open('C:\\python\\kommuner\\outdata\\stat{:0>2}.html'.format(i),
                    'w',
                    encoding='utf-8')
        file.write(template_stat.render(newStat))
        file.close()