Exemplo n.º 1
0
def getSegmentEffortStream(id, type):
    'Get a specific stream of a specific activity'
    # type can be distance, altitude or time
    url = urlbase + "/segment_efforts/" + str(id) + "/streams/" + type

    params = dict(access_token=at, resolution='high')
    r = gf.getRequest(url, params)
    return r
Exemplo n.º 2
0
def getSegmentDetails(id):
    'Get distance and altitude of a segment'
    url = urlbase + "/segments/" + str(id) + "/streams/altitude"
    params = dict(access_token=at, resolution='low')

    r = gf.getRequest(url, params)
    # logger.debug(r.text)
    return r
Exemplo n.º 3
0
def getSegmentEffortsByType(id, atype):
    'Get a specific stream (speed) of multiple efforts'
    # need to add a function to retrieve more than 200 results in the future
    logger.info(
        "Getting speed efforts for the Holdeurn segment (hardcoded segment id)")
    #df = pd.DataFrame
    url = urlbase + "/segments/" + str(id) + "/all_efforts"

    logger.info("Getting segment details")
    d = getSegmentDetails(id)

    dist = d.json()[0]["data"]
    dist.insert(0, "distance")

    alt = d.json()[1]["data"]
    alt.insert(0, "altitude")
    params = dict(access_token=at, resolution='high',
                  athlete_id=549238, per_page=200)
    r = gf.getRequest(url, params)
    # logger.debug(r.text)
    ac = r.json()
    aList = []
    aList.append(dist)
    aList.append(alt)

    if (len(ac) > 0):
        logger.info(
            str(len(ac)) + " Efforts found for segment name:" + ac[0]['name'])
        # for i in range(len(a)):
        for i in range(0, 2):
            logger.info(ac[i]['start_date'])
            effortID = str(ac[i]["id"])
            logger.debug("Effort id is : " + str(ac[i]["id"]))
            req = getSegmentEffortStream(ac[i]["id"], atype)

            result = req.json()[1]["data"]
            result.insert(0, 'effort' + str(i))

            aList.append(result)

        writeListStreamToCsv(atype + '.csv', aList)