feat(insights): added kbju fetching for analitics

This commit is contained in:
misha
2026-11-10 12:21:53 +03:00
parent 45d072cff4
commit 8c33f033ff
30 changed files with 1910 additions and 118 deletions

View File

@@ -17,11 +17,20 @@ class FakeInsightsRepository extends Fake implements InsightsRepository {
InsightsPayloadModel payload;
/// Ответ [fetchIntra] по запрошенной дате (`YYYY-MM-DD`); для остальных дат
/// берётся `payload.intra`.
final Map<String, IntraChartModel> intraByDate = {};
/// Если задан — выбрасывается из [fetchIntra].
Object? intraError;
/// Если задан — выбрасывается из [getInsights] (например, [InsightsForbidden]).
Object? error;
int? heightCm;
final List<({String? slug, BodyPeriod period})> insightsRequests = [];
final List<({String? slug, BodyPeriod bodyPeriod, DailyPeriod dailyPeriod, String? intraDate})> serverRequests = [];
final List<({String? slug, String? date})> intraRequests = [];
final List<double> addedWeights = [];
final List<({int chest, int waist, int hip})> addedCircumferences = [];
@@ -38,6 +47,31 @@ class FakeInsightsRepository extends Fake implements InsightsRepository {
return payload;
}
@override
Future<InsightsPayloadModel> fetchInsights({
String? slug,
required BodyPeriod bodyPeriod,
required DailyPeriod dailyPeriod,
String? intraDate,
}) async {
serverRequests.add((slug: slug, bodyPeriod: bodyPeriod, dailyPeriod: dailyPeriod, intraDate: intraDate));
final failure = error;
if (failure != null) {
throw failure;
}
return payload;
}
@override
Future<IntraChartModel> fetchIntra({String? slug, String? intraDate}) async {
intraRequests.add((slug: slug, date: intraDate));
final failure = intraError ?? error;
if (failure != null) {
throw failure;
}
return intraByDate[intraDate] ?? payload.intra!;
}
@override
Future<void> addWeight({required double weight}) async {
addedWeights.add(weight);

View File

@@ -0,0 +1,46 @@
{
"data": {
"intra": {
"bars": [
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",
"sleepLabel": "23:00",
"wakeText": "Подъём в 07:30",
"sleepText": "Отход ко сну в 23:00",
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}
}

View File

@@ -0,0 +1,46 @@
{
"data": {
"intra": {
"bars": [
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",
"sleepLabel": "23:00",
"wakeText": "Подъём в 07:30",
"sleepText": "Отход ко сну в 23:00",
"date": "2026-11-08",
"maxDate": "2026-11-09",
"dateLabel": "8 ноября",
"isToday": false
}
}
}

View File

@@ -1,7 +1,15 @@
{
"weight": {
"labels": ["01.11", "05.11", "09.11"],
"values": [74.5, 73.9, 73.2],
"labels": [
"01.11",
"05.11",
"09.11"
],
"values": [
74.5,
73.9,
73.2
],
"last": 73.2,
"delta": -1.3,
"headline": "73.2",
@@ -19,31 +27,87 @@
"hint": ""
},
"measure": {
"labels": ["01.11", "09.11"],
"waist": [82, 80.5],
"chest": [96, 96],
"hips": [101, 100],
"labels": [
"01.11",
"09.11"
],
"waist": [
82,
80.5
],
"chest": [
96,
96
],
"hips": [
101,
100
],
"headline": "81",
"deltaText": "Талия меньше на 1.5 см за период"
},
"daily": {
"labels": ["03.11", "04.11", "05.11"],
"kcal": [1850, 2010, 1930],
"proteins": [92, 101, 96],
"fats": [60, 66, 63],
"carbs": [210, 222, 215],
"labels": [
"03.11",
"04.11",
"05.11"
],
"kcal": [
1850,
2010,
1930
],
"proteins": [
92,
101,
96
],
"fats": [
60,
66,
63
],
"carbs": [
210,
222,
215
],
"average": 1930,
"percent": 98,
"percent": 5,
"headline": "1930",
"deltaText": "98% от нормы"
"deltaText": "Калораж вырос на 5% за период"
},
"intra": {
"bars": [
{"x": 8.5, "p": 120, "f": 90, "c": 240},
{"x": 13, "p": 160, "f": 130, "c": 300}
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"satiety": [{"x": 8.5, "y": 3}, {"x": 13, "y": 4}],
"mood": [{"x": 8.5, "y": 4}],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",

View File

@@ -1,7 +1,38 @@
{
"weight": {"labels": [], "values": [], "last": null, "delta": null, "headline": "—", "unit": "кг", "deltaText": "Недостаточно данных"},
"bmi": {"labels": [], "values": [], "headline": "—", "deltaText": "Укажите рост, чтобы посчитать ИМТ.", "hint": "Укажите рост, чтобы посчитать ИМТ."},
"measure": {"labels": [], "waist": [], "chest": [], "hips": [], "headline": "—", "deltaText": "Недостаточно данных"},
"daily": {"labels": [], "kcal": [], "proteins": [], "fats": [], "carbs": [], "average": null, "percent": null, "headline": "—", "deltaText": ""},
"intra": {"bars": [], "satiety": [], "mood": [], "wake": null, "sleep": null, "date": "2026-11-09", "maxDate": "2026-11-09", "dateLabel": "Сегодня", "isToday": true}
"weight": {
"labels": [],
"values": [],
"last": null,
"delta": null,
"headline": "—",
"unit": "кг",
"deltaText": "Недостаточно данных"
},
"bmi": {
"labels": [],
"values": [],
"headline": "—",
"deltaText": "Укажите рост, чтобы посчитать ИМТ.",
"hint": ""
},
"measure": {
"labels": [],
"waist": [],
"chest": [],
"hips": [],
"headline": "—",
"deltaText": "Недостаточно данных"
},
"daily": null,
"intra": {
"bars": [],
"satiety": [],
"mood": [],
"wake": null,
"sleep": null,
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}

View File

@@ -0,0 +1,124 @@
{
"data": {
"weight": {
"labels": [
"01.11",
"05.11",
"09.11"
],
"values": [
74.5,
73.9,
73.2
],
"last": 73.2,
"delta": -1.3,
"headline": "73.2",
"unit": "кг",
"deltaText": "Снизили на 1.3 кг за период"
},
"bmi": {
"labels": [],
"values": [],
"last": null,
"delta": null,
"headline": "—",
"category": null,
"deltaText": "Укажите рост, чтобы посчитать ИМТ.",
"hint": ""
},
"measure": {
"labels": [
"01.11",
"09.11"
],
"waist": [
82,
80.5
],
"chest": [
96,
96
],
"hips": [
101,
100
],
"headline": "81",
"deltaText": "Талия меньше на 1.5 см за период"
},
"daily": {
"labels": [
"03.11",
"04.11",
"05.11"
],
"kcal": [
1850,
2010,
1930
],
"proteins": [
92,
101,
96
],
"fats": [
60,
66,
63
],
"carbs": [
210,
222,
215
],
"average": 1930,
"percent": 5,
"headline": "1930",
"deltaText": "Калораж вырос на 5% за период"
},
"intra": {
"bars": [
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",
"sleepLabel": "23:00",
"wakeText": "Подъём в 07:30",
"sleepText": "Отход ко сну в 23:00",
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}
}

View File

@@ -0,0 +1,40 @@
{
"data": {
"weight": {
"labels": [],
"values": [],
"last": null,
"delta": null,
"headline": "—",
"unit": "кг",
"deltaText": "Недостаточно данных"
},
"bmi": {
"labels": [],
"values": [],
"headline": "—",
"deltaText": "Укажите рост, чтобы посчитать ИМТ.",
"hint": ""
},
"measure": {
"labels": [],
"waist": [],
"chest": [],
"hips": [],
"headline": "—",
"deltaText": "Недостаточно данных"
},
"daily": null,
"intra": {
"bars": [],
"satiety": [],
"mood": [],
"wake": null,
"sleep": null,
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}
}