54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
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",
|
|
)
|