Skip to content

Commit

Permalink
Add two helpers for weekly review
Browse files Browse the repository at this point in the history
  • Loading branch information
za3k committed Feb 1, 2020
1 parent aa90dbd commit 00665a6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ battery
---
Displays the current battery percentage as a short string for displays

budget_summary
---
Helper for za3k only. Summarizes budget categories typed in from my logbook

changed-files
---
In Arch Linux, lists the config files which have been altered from the default.
Expand Down Expand Up @@ -316,6 +320,14 @@ setop
---
Command-line program for performing basic set operations on lines in files. `comm` can be used for some of this on sorted files but it's a little stronger.

sleep_summary
---
Gives a summary of average and standard deviation of sleep times.

Example:

sleep_summary 8h40m 5h20m 7h

static-ip
---
Set up a static ip on linux
Expand Down
27 changes: 27 additions & 0 deletions budget_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python3
import datetime
import re

current_date=str(datetime.date.today())
with open("blog2.za3k.com/_posts/{}-weekly-review.md".format(current_date), "r") as f:
lines = list(line for line in f)

budget_start = re.compile("^\\| Date")
budget_end = re.compile("^$")
start_line, end_line = None, None
for i, line in enumerate(lines):
if start_line is None and budget_start.match(line):
start_line = i
if end_line is None and start_line is not None and budget_end.match(line):
end_line = i
budget = lines[start_line:end_line]
lines = []
for line in budget[2:]:
date, place, amount, category, thing = [x.strip() for x in line.split("|")[1:]]
lines.append((float(amount), category))
print("{: <12} {}".format("Total:", sum(amount for (amount, category) in lines)))
print("{: <12} {}".format("Total (no rent):", sum(amount for (amount, category) in lines if category != "Rent")))
categories = sorted(set(category for (amount, category) in lines))
print()
for category in categories:
print("{: <12} {}".format(category+":", sum(amount for (amount, c) in lines if category == c)))
37 changes: 37 additions & 0 deletions sleep_summary
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/python3
import sys, statistics, math, re

def usage():
print("Usage: sleep_summary DAY...")
print("DAY format should be one of:")
print(" 8h")
print(" 8.5h")
print(" 8h30m")

if len(sys.argv)<=1:
usage()
exit(0)

times_m = []
for arg in sys.argv[1:]:
m1 = re.fullmatch('(\d+(?:\.\d+)?)h', arg) # hour or fractional hour
m2 = re.fullmatch('(\d\d?)h(\d\d?)m', arg) # hours and minutes
if m1:
hours = float(m1.group(1))
times_m.append(hours*60)
elif m2:
hours, minutes = int(m2.group(1)), int(m2.group(2))
times_m.append(hours*60+minutes)
else:
print("Unexpected argument format: {}".format(arg))
print()
usage()
exit(1)
avg_m = statistics.mean(times_m)
stddev_m = math.sqrt(statistics.variance(times_m))
avg_h, stddev_h = avg_m/60, stddev_m/60

print("{} days".format(len(times_m)))
print("Mean {}m, stddev {}m".format(round(avg_m,0), round(stddev_m, 0)))
print("Mean {}h, stddev {}h".format(round(avg_h,1), round(stddev_h, 1)))
print("Mean {}h{}m, stddev {}h".format(int(avg_m//60), round(avg_m%60), round(stddev_h, 1)))

0 comments on commit 00665a6

Please sign in to comment.