Beispiel #1
0
def main(path):
    from act_parser import ActParser
    print "Reading activity data from %s..." % (path),
    ap = ActParser(path)
    print "done"
    for n, s in enumerate(normalize(ap.samples())):
        print "%6d: %s" % (n, s)
    return 0
def main(path):
    from act_parser import ActParser
    print "Reading activity data from %s..." % (path),
    ap = ActParser(path)
    print "done"
    distances = [0.0, 0.0]
    for n, d in enumerate(ActSampleDiff.diffs_between_samples(ap.samples())):
        distances[0] += d.gps_d
        distances[1] += d.d
        print "%6d: %s" % (n, d)
    print "Total distance: %5.2fm vs. %5.2fm" % (distances[0], distances[1])
    return 0
Beispiel #3
0
def main(path1, path2):
    print "Reading activity data from %s..." % (path1),
    p1 = ActParser(path1)
    print "done"
    print "Reading activity data from %s..." % (path2),
    p2 = ActParser(path2)
    print "done"

    compfunc = ActSample.comparator(alt=0.25, d=0.1, v=0.1, hr=0.1, cad=0.1)
    for s1, s2 in zip(p1.samples(), p2.samples()):
        if compfunc(s1, s2):
            print "-%s" % (s1)
            print "+%s" % (s2)
    return 0
Beispiel #4
0
def main(path1, path2):
    from act_parser import ActParser
    print "# Reading activity data from %s..." % (path1),
    p1 = ActParser(path1)
    l1 = list(normalize(p1.samples(), ignore_gps=True))
    print "done, read %d samples" % (len(l1))
    print "# Reading activity data from %s..." % (path2),
    p2 = ActParser(path2)
    l2 = list(normalize(p2.samples(), ignore_gps=True))
    print "done, read %d samples" % (len(l2))

    by_hr = by_key(lambda x: x.hr)
    for i, (a, b) in enumerate(correlated_samples(l1, l2, score=by_hr)):
        print "%6d: %s"  % (i, a)
        print "        %s" % (b)
Beispiel #5
0
def main(path1, path2, smooth=1, skip=0, stop=sys.maxint, low=0, high=9999):
    from act_parser import ActParser
    print "# Reading activity data from %s..." % (path1),
    p1 = ActParser(path1)
    l1 = list(normalize(p1.samples(), ignore_gps=True))
    print "done, read %d samples" % (len(l1))
    print "# Reading activity data from %s..." % (path2),
    p2 = ActParser(path2)
    l2 = list(normalize(p2.samples(), ignore_gps=True))
    print "done, read %d samples" % (len(l2))

    smooth = int(smooth)
    assert smooth >= 1
    skip = parse_seconds(skip)
    assert skip >= 0
    stop = parse_seconds(stop)
    assert stop > skip
    low = int(low)
    high = int(high)
    assert high > low

    # Correlate by HR (assumes both activities picked up the same HR data.)
    by_hr = by_key(lambda x: x.hr)
    sum1 = sum2 = 0
    n = 0
    for i, (pwr1, pwr2) in enumerate(smoother(extract_pwr(l1, l2, score=by_hr), smooth)):
        if i < skip or (pwr1 + pwr2 < 2 * low) or (pwr1 + pwr2 > 2 * high):
            continue
        if i >= stop:
            break
        sum1 += pwr1
        sum2 += pwr2
        n += 1
        try:
            percent = float(pwr2) / pwr1 * 100
        except ZeroDivisionError:
            percent = float("inf")
        print "%6d: %4dW, %4dW => %3.1f%%"  % (i, pwr1, pwr2, percent)
    percent = float(sum2) / sum1 * 100
    print "Average across %d samples: %4.2fW, %4.2fW => %3.3f%%" % (
        n,
        float(sum1) / n,
        float(sum2) / n,
        percent)
    print "Difference from %s to %s: %4.2fW/%3.3f%%" % (
        path1, path2,
        float(sum2) / n - float(sum1) / n, percent - 100)
def main(path1, path2, logfile=None):
    from act_parser import ActParser
    from act_sample_norm import normalize

    print_samples = False
    if logfile:
        log = open(logfile, "w")

        def log_score_enabled(o, s):
            print >> log, o, s

        global log_score
        log_score = log_score_enabled
    else:
        log = sys.stdout
        print_samples = True

    print >> log, "# Reading activity data from %s..." % (path1),
    p1 = ActParser(path1)
    l1 = list(normalize(p1.samples()))
    print >> log, "done, read %d samples" % (len(l1))
    print >> log, "# Reading activity data from %s..." % (path2),
    p2 = ActParser(path2)
    l2 = list(normalize(p2.samples()))
    print >> log, "done, read %d samples" % (len(l2))

    o = int(l1[0].t - l2[0].t)
    print >> log, "# Timestamps are offset by %ds" % (o)
    if abs(o) > min(len(l1), len(l2)):
        print >> log, "# Offset is too big. Assuming clocks out-of-whack..."
        o = 0
    o, score = find_local_max_correlation_offset(l1, l2, o)
    print >> log, "# Minimum score at offset %d is %.2f m" % (o, score)

    if print_samples:
        for s, t in zip_samples_at_offset(l1, l2, o):
            print >> log, "{}\n\t{}\n\t{}".format(geodistance(s, t), s, t)

    return 0
Beispiel #7
0
def main(path):
    print "Reading activity data from %s..." % (path),
    ap = ActParser(path)
    print "done"
    seconds, records = 0, 0
    gps_dist, int_dist = 0, 0
    dist_diff = 0
    for d in ActSampleDiff.diffs_between_samples(ap.samples()):
        if d.t > 1:
            logger.warn("Lost %ds after %ds" % (d.t - 1, seconds))
        records += 1
        seconds += d.t
        gps_dist += d.gps_d
        int_dist += d.d
        dd = gps_dist - int_dist
        if abs(dd - dist_diff) > 1:
            print "GPS - Int. distance -> %.1fm after %ds" % (dd, seconds)
            dist_diff = dd
    missing = seconds - records
    print "Found %d records in %ds, %d records (=%.2f%%) missing)" % (
        records, seconds, missing, 100.0 * missing / seconds)
    print "Internal distance: %.3fkm" % (int_dist / 1000.0)
    print "Calc. distance from GPS coords: %.3fkm" % (gps_dist / 1000.0)
    print "Int./GPS distance is %.2f%%" % (100.0 * int_dist / gps_dist)