bettwaage-sidequest #2

Merged
m.giller merged 38 commits from bettwaage-sidequest into master 2024-06-07 23:38:56 +02:00
Showing only changes of commit a6bbf7ef4d - Show all commits

View file

@ -9,24 +9,25 @@ history_url = "http://192.168.178.84:9587/bettwaage/history"
convert_time_to_seconds = True convert_time_to_seconds = True
# Script # Get data
data = None data = Nones
if file_path is None: if file_path is None:
print("Fetching data ...")
data = requests.get(history_url) data = requests.get(history_url)
data = data.json() data = data.json()
else: else:
print("Reading data ...")
with open(file_path, "r") as fp: with open(file_path, "r") as fp:
data = json.load(fp) data = json.load(fp)
# Experiment: Solving for missing foot with known total weight print("Processing data ...")
bed_weight = 81
person_weight = 63 # Get rough value for empty bed weight per leg
known_total_weight = bed_weight + person_weight rough_bed_weight = 80
bed_only_weight = {} bed_only_weight = {}
for d in data: for d in data:
if d["total"] < bed_weight: if d["total"] < rough_bed_weight:
bed_only_weight = { bed_only_weight = {
"tl": d["tl"], "tl": d["tl"],
"tr": d["tr"], "tr": d["tr"],
@ -35,29 +36,28 @@ for d in data:
} }
break break
in_bed_data = None # Collect all coherent sequences of someone being in bed
in_bed_datas: list[list[dict]] = []
is_in_bed_sequence = False
threshhold = 100.0 threshhold = 100.0
min_length = 100
skip = 0
for d in data: for d in data:
t = d["total"] t = d["total"]
if t >= threshhold: if t >= threshhold:
if in_bed_data is None: if not is_in_bed_sequence:
in_bed_data = [] in_bed_datas.append([])
in_bed_data.append(d) is_in_bed_sequence = True
elif in_bed_data is not None and len(in_bed_data) > 0: in_bed_datas[-1].append(d)
if skip > 0: elif is_in_bed_sequence:
in_bed_data = [] is_in_bed_sequence = False
skip -= 1
elif len(in_bed_data) < min_length:
in_bed_data = []
else:
break
# data = in_bed_data # Pick latest with minimum length/duration
min_length = 100
for sequence in in_bed_datas:
if len(sequence) >= min_length:
data = sequence
# Array data # Prepare data for plotting
x = [d["timestamp"] for d in data] x = [d["timestamp"] for d in data]
x = [datetime.strptime(d, "%Y-%m-%d %H:%M:%S.%f") for d in x] x = [datetime.strptime(d, "%Y-%m-%d %H:%M:%S.%f") for d in x]
@ -80,12 +80,16 @@ right = [t + b for t, b in zip(tr, br)]
bed_size = (140, 200) bed_size = (140, 200)
left_bed_only = bed_only_weight["tl"] + bed_only_weight["bl"] left_bed_only = bed_only_weight["tl"] + bed_only_weight["bl"]
top_bed_only = bed_only_weight["tr"] + bed_only_weight["tl"] top_bed_only = bed_only_weight["tr"] + bed_only_weight["tl"]
right_bed_only = bed_only_weight["tr"] + bed_only_weight["br"]
bottom_bed_only = bed_only_weight["br"] + bed_only_weight["bl"]
position_over_time = [] position_over_time = []
for t, l in zip(top, left): for t, b, l, r in zip(top, bottom, left, right):
horizontal_weight = l - left_bed_only + r - right_bed_only
vertical_weight = t - top_bed_only + b - bottom_bed_only
position_over_time.append( position_over_time.append(
( (
bed_size[0] * (l - left_bed_only) / person_weight, bed_size[0] * (l - left_bed_only) / horizontal_weight,
bed_size[1] * (t - top_bed_only) / person_weight, bed_size[1] * (t - top_bed_only) / vertical_weight,
) )
) )