This commit is contained in:
Thies Lennart Alff 2024-09-19 20:13:12 +02:00
parent 50e60e38a9
commit 85490e8b59
Signed by: lennartalff
GPG key ID: 4EC67D34D594104D
4 changed files with 59 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
__pycache__/
*.py[cod]
venv/
gc_wrapper/GC_DATA/

View file

@ -1,5 +1,5 @@
try:
from GC_Wrapper import GC_wrapper as GC
from gc_wrapper.GC_Wrapper import GC_wrapper as GC
except ImportError:
pass

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
plotly
pandas

54
weight_trend.py Normal file
View file

@ -0,0 +1,54 @@
import pandas as pd
import numpy as np
WEIGHT_RANGE = [75, 85]
def get_weight_measures():
# query non-zero
data = pd.DataFrame(GC.seasonMeasures(group="Body")).query("WEIGHTKG != 0.0")[
["date", "WEIGHTKG"]
]
weight = data["WEIGHTKG"].to_numpy().flatten()
weight_shifted = data["WEIGHTKG"].shift(periods=1)
weight_shifted.loc[0] = 0.0
weight_shifted = weight_shifted.to_numpy().flatten()
change = weight - weight_shifted
indices = np.argwhere(change != 0.0).flatten()
weight = weight[indices]
date = (
data["date"].loc[indices] - pd.to_datetime("1900-01-01").date()
).dt.days.to_numpy()
return pd.DataFrame(
np.hstack([date.reshape([-1, 1]), weight.reshape([-1, 1])]),
columns=["date", "WEIGHTKG"],
)
weight_data = get_weight_measures()
GC.setChart(
type=GC.CHART_LINE,
orientation=GC_VERTICAL,
legpos=GC_ALIGN_RIGHT,
stack=False,
animate=True,
)
settings = {
"symbol": GC_SYMBOL_CIRCLE,
"line": GC_LINE_SOLID,
"color": "red",
"opacity": 100,
"xaxis": "Date",
"yaxis": "Weight",
"size": 3,
"opengl": False,
}
GC.addCurve(name="Weight", x=weight_data["date"], y=weight_data["WEIGHTKG"], **settings)
GC.setAxis("Date", type=GC.AXIS_DATE)
GC.setAxis(
"Weight",
type=GC.AXIS_CONTINUOUS,
min=WEIGHT_RANGE[0],
max=WEIGHT_RANGE[1],
color="red",
)