Skip to content

Instantly share code, notes, and snippets.

@cfangmeier
Last active August 29, 2015 14:04
Show Gist options
  • Save cfangmeier/2af2eed84479b01f61a1 to your computer and use it in GitHub Desktop.
Save cfangmeier/2af2eed84479b01f61a1 to your computer and use it in GitHub Desktop.
graphs weight over time, recorded daily using jrnl
#!/usr/bin/env python3
import matplotlib as mat
import matplotlib.pyplot as plt
import subprocess
import datetime
if __name__ == '__main__':
raw = subprocess.check_output('jrnl @weight'.split())
data = raw.decode('ascii').splitlines()
data = [d.split(' ') for d in data]
data = [(d[0],d[3]) for d in data if len(d) == 4]
data = [(datetime.datetime.strptime(d[0],'%Y-%m-%d'),d[1]) for d in data]
weights = [float(d[1]) for d in data]
dates = [d[0].date() for d in data]
min_weight = min(weights)
min_date = dates[weights.index(min_weight)]
print("Min: {0} on {1}".format(min_weight, min_date))
max_weight = max(weights)
max_date = dates[weights.index(max_weight)]
print("Max: {0} on {1}".format(max_weight, max_date))
weight_lost = max_weight - min_weight
print("Weight lost: {0}".format(weight_lost))
matdates = mat.dates.date2num([d[0] for d in data])
plt.plot_date(matdates,weights)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment