-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |