|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Make a legend for specific lines. |
| 4 | +from pylab import * |
| 5 | + |
| 6 | +import time |
| 7 | +from datetime import datetime as d |
| 8 | +from datetime import timedelta as dt |
| 9 | + |
| 10 | +start_date = d(2012, 9, 22) |
| 11 | +end_date = d(2012, 11, 10) |
| 12 | + |
| 13 | + |
| 14 | +squat = [ |
| 15 | + (d(2012,9,24), 175, 5, 1), |
| 16 | + (d(2012,9,27), 180, 2, 1), |
| 17 | + (d(2012,10,2), 180, 5, 1), |
| 18 | + (d(2012,10,4), 170, 1, 1), |
| 19 | + (d(2012,10,9), 190, 3, 1), |
| 20 | + (d(2012,10,13), 190, 1, 1), |
| 21 | + (d(2012,10,16), 195, 2, 1), |
| 22 | + (d(2012,10,18), 170, 1, 1), |
| 23 | + (d(2012,10,23), 200, 2, 1), |
| 24 | + (d(2012,10,30), 200, 1, 1), |
| 25 | + (d(2012,11,01), 205, 1, 1), |
| 26 | + (d(2012,11,10), 210, 1, 1) |
| 27 | +] |
| 28 | + |
| 29 | +dead = [ |
| 30 | + (d(2012,9,22), 180, 5, 3), # 210x1 |
| 31 | + (d(2012,9,28), 190, 5, 2), # 215x1 |
| 32 | + (d(2012,10,4), 200, 3, 3), # 220x1 |
| 33 | + (d(2012,10,6), 225, 1, 1), # TSC |
| 34 | + (d(2012,10,11), 210, 3, 1), # 230x1 |
| 35 | + (d(2012,10,17), 220, 2, 1), # 235x1 |
| 36 | + (d(2012,10,27), 245, 1, 1), |
| 37 | + (d(2012,11,10), 250, 1, 1) |
| 38 | +] |
| 39 | + |
| 40 | +def fill_values(lifts): |
| 41 | + """ |
| 42 | + [("yyyy-mm-dd", weight, reps, sets), ...] |
| 43 | + """ |
| 44 | + |
| 45 | + vs = [] |
| 46 | + date = start_date |
| 47 | + one_day = dt(days=1) |
| 48 | + while date != end_date: |
| 49 | + vs.append([date, 0, 0]) # (date.strftime("%Y-%m-%d"), 0, 0)) |
| 50 | + date += one_day |
| 51 | + # and end date |
| 52 | + vs.append([date, 0, 0]) # (date.strftime("%Y-%m-%d"), 0, 0)) |
| 53 | + |
| 54 | + for dtime, w, r, s in lifts: |
| 55 | + for i in range(len(vs)): |
| 56 | + if vs[i][0] == dtime: |
| 57 | + if r == 1: |
| 58 | + cw = w |
| 59 | + else: |
| 60 | + cw = w*(1 + 0.033*r) |
| 61 | + vs[i][1] = cw |
| 62 | + vs[i][2] = s |
| 63 | + break |
| 64 | + |
| 65 | + # smooth out between values where 0 |
| 66 | + i = 0 |
| 67 | + j = 0 |
| 68 | + s = 0 |
| 69 | + e = 0 |
| 70 | + |
| 71 | + # skip past any initial zeroes |
| 72 | + while i < len(vs) and vs[i][1] == 0: |
| 73 | + i += 1 |
| 74 | + |
| 75 | + while i < len(vs): |
| 76 | + |
| 77 | + while i < len(vs) and vs[i][1] != 0: |
| 78 | + i += 1 |
| 79 | + |
| 80 | + s = i-1 |
| 81 | + |
| 82 | + while i < len(vs) and vs[i][1] == 0: |
| 83 | + i += 1 |
| 84 | + |
| 85 | + if i >= len(vs): |
| 86 | + break |
| 87 | + |
| 88 | + e = i |
| 89 | + |
| 90 | + start, end = vs[s][1], vs[e][1] |
| 91 | + delta = (end - start) / float(e - s) |
| 92 | + print s, e, start, end, delta |
| 93 | + |
| 94 | + v = start + delta |
| 95 | + for j in range(s+1, e): |
| 96 | + vs[j][1] = v |
| 97 | + v += delta |
| 98 | + |
| 99 | + print "----------------------------" |
| 100 | + for v in vs: |
| 101 | + print v |
| 102 | + |
| 103 | + return vs |
| 104 | + |
| 105 | +deads = fill_values(dead); plot([x[0] for x in deads], [x[1] for x in deads], "r-") |
| 106 | +squats = fill_values(squat); plot([x[0] for x in squats], [x[1] for x in squats], "g-") |
| 107 | + |
| 108 | +#t1 = array([dobj.tm_yday for dateprint, dobj in range(day_count)]) |
| 109 | + |
| 110 | +# note that plot returns a list of lines. The "l1, = plot" usage |
| 111 | +# extracts the first element of the list inot l1 using tuple |
| 112 | +# unpacking. So l1 is a Line2D instance, not a sequence of lines |
| 113 | + |
| 114 | +#l1, = plot(t1, exp(-t1), 'r-') |
| 115 | +#l2, = plot(t1, exp(-t1/2), '--g') |
| 116 | + |
| 117 | +#plot(t1, t1) |
| 118 | + |
| 119 | +#locs, labels = xticks() |
| 120 | + |
| 121 | +#l2, l3 = plot(t2, sin(2*pi*t2), '--go', t1, log(1+t1), '.') |
| 122 | +#l4, = plot(t2, exp(-t2)*sin(2*pi*t2), 'rs-.') |
| 123 | + |
| 124 | +#legend( (l2, l4), ('oscillatory', 'damped'), 'upper right', shadow=True) |
| 125 | +#xlabel('time') |
| 126 | +#ylabel('volts') |
| 127 | +#title('Damped oscillation') |
| 128 | +#axis([0,2,-1,1]) |
| 129 | + |
| 130 | +axis(ymin=160, ymax=260) |
| 131 | + |
| 132 | +show() |
| 133 | + |
0 commit comments