feat: zlepšení šablon, přidány osobní údaje a spánkový režim
This commit is contained in:
1 parent
a5711f3e1e
commit
21b01528e9
51 files changed
+3739
-504
No files matched your search
@@ -79,12 +79,25 @@ export type NormalizedActivityInput = {
|
||||
date: string;
|
||||
name: string;
|
||||
unit: ActivityUnit;
|
||||
/** Množství na jednu sérii. */
|
||||
quantity: number;
|
||||
/** Počet sérií; nevyplněno znamená jednu. */
|
||||
sets?: number;
|
||||
caloriesPer100Units?: number;
|
||||
calories?: number;
|
||||
note?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Vrátí celkové množství aktivity, tedy počet sérií krát množství v jedné.
|
||||
*
|
||||
* Série se drží odděleně, protože 3 × 40 opakování s pauzami je jiný trénink
|
||||
* než 120 opakování v kuse — spálené kalorie jsou ale stejné, takže do výpočtu
|
||||
* jde součin.
|
||||
*/
|
||||
export const getTotalQuantity = (quantity: number, sets?: number): number =>
|
||||
quantity * Math.max(sets ?? 1, 1);
|
||||
|
||||
/**
|
||||
* Dopočte spálené kalorie z množství a sazby na 100 jednotek.
|
||||
*
|
||||
@@ -93,7 +106,7 @@ export type NormalizedActivityInput = {
|
||||
*/
|
||||
export function deriveActivityCalories(input: NormalizedActivityInput): NormalizedActivityInput {
|
||||
const calories = input.caloriesPer100Units
|
||||
? Math.round(input.quantity / 100 * input.caloriesPer100Units)
|
||||
? Math.round(getTotalQuantity(input.quantity, input.sets) / 100 * input.caloriesPer100Units)
|
||||
: input.calories;
|
||||
return { ...input, calories };
|
||||
}
|
||||
@@ -115,11 +128,14 @@ export function normalizeActivityInput(input: unknown): NormalizedActivityInput
|
||||
if (quantity == null) {
|
||||
throw new BadRequestError("Nebylo předáno množství aktivity");
|
||||
}
|
||||
const sets = normalizeNumber(value.sets, 'sets');
|
||||
return deriveActivityCalories({
|
||||
date: value.date,
|
||||
name,
|
||||
unit: value.unit,
|
||||
quantity,
|
||||
// Jedna série je výchozí stav, ukládat ji zvlášť nemá smysl
|
||||
...(sets && sets > 1 ? { sets } : {}),
|
||||
caloriesPer100Units: normalizeNumber(value.caloriesPer100Units, 'caloriesPer100Units'),
|
||||
calories: normalizeNumber(value.calories, 'calories'),
|
||||
note: normalizeText(value.note, 'note'),
|
||||
@@ -193,6 +209,7 @@ export async function updateActivity(login: string, id: unknown, input: unknown)
|
||||
const updated: ActivityEntry = {
|
||||
...original,
|
||||
...normalized,
|
||||
sets: normalized.sets,
|
||||
caloriesPer100Units: normalized.caloriesPer100Units,
|
||||
calories: normalized.calories,
|
||||
note: normalized.note,
|
||||
|
||||
Reference in new issue
Block a user