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
# Script
data = None
# Get data
data = Nones
if file_path is None:
print("Fetching data ...")
data = requests.get(history_url)
data = data.json()
else:
print("Reading data ...")
with open(file_path, "r") as fp:
data = json.load(fp)
# Experiment: Solving for missing foot with known total weight
bed_weight = 81
person_weight = 63
known_total_weight = bed_weight + person_weight
print("Processing data ...")
# Get rough value for empty bed weight per leg
rough_bed_weight = 80
bed_only_weight = {}
for d in data:
if d["total"] < bed_weight:
if d["total"] < rough_bed_weight:
bed_only_weight = {
"tl": d["tl"],
"tr": d["tr"],
@ -35,29 +36,28 @@ for d in data:
}
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
min_length = 100
skip = 0
for d in data:
t = d["total"]
if t >= threshhold:
if in_bed_data is None:
in_bed_data = []
in_bed_data.append(d)
elif in_bed_data is not None and len(in_bed_data) > 0:
if skip > 0:
in_bed_data = []
skip -= 1
elif len(in_bed_data) < min_length:
in_bed_data = []
else:
break
if not is_in_bed_sequence:
in_bed_datas.append([])
is_in_bed_sequence = True
in_bed_datas[-1].append(d)
elif is_in_bed_sequence:
is_in_bed_sequence = False
# 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 = [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)
left_bed_only = bed_only_weight["tl"] + bed_only_weight["bl"]
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 = []
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(
(
bed_size[0] * (l - left_bed_only) / person_weight,
bed_size[1] * (t - top_bed_only) / person_weight,
bed_size[0] * (l - left_bed_only) / horizontal_weight,
bed_size[1] * (t - top_bed_only) / vertical_weight,
)
)