2023-05-30 09:38:54 +02:00
|
|
|
import 'dart:math';
|
|
|
|
import 'package:ernaehrung/android/components/meal_page_text/days_component.dart';
|
|
|
|
import 'package:ernaehrung/android/config/cast_helper.dart';
|
2023-06-01 12:14:23 +02:00
|
|
|
import 'package:fl_chart/fl_chart.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
2023-05-30 09:38:54 +02:00
|
|
|
import 'package:hive/hive.dart';
|
2023-05-29 12:08:46 +02:00
|
|
|
import '../models/food.dart';
|
2023-06-02 00:38:19 +02:00
|
|
|
import '../models/user.dart';
|
2023-05-30 22:09:16 +02:00
|
|
|
import 'format_helper.dart';
|
2023-05-29 12:08:46 +02:00
|
|
|
|
|
|
|
class StatisticsService {
|
|
|
|
|
2023-05-30 21:03:46 +02:00
|
|
|
static final StatisticsService _instance = StatisticsService._internal();
|
|
|
|
factory StatisticsService() => _instance;
|
|
|
|
|
|
|
|
static StatisticsService get instance => _instance;
|
|
|
|
|
|
|
|
StatisticsService._internal() {
|
2023-06-16 11:44:42 +02:00
|
|
|
//initBoxes();
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
2023-06-16 11:44:42 +02:00
|
|
|
String todayStatisticsBoxName = dotenv.env['STATISTICS_TODAY_BOX'] ?? 'STATISTICS_TODAY_BOX';
|
|
|
|
String mainStatisticsBoxName = dotenv.env['STATISTICS_MAIN_BOX'] ?? 'STATISTICS_MAIN_BOX';
|
|
|
|
String progressStatisticsBoxName = dotenv.env['STATISTICS_PROGRESS_BOX'] ?? 'STATISTICS_PROGRESS_BOX';
|
2023-05-30 09:38:54 +02:00
|
|
|
|
2023-05-30 21:03:46 +02:00
|
|
|
ValueNotifier<int> eatenCalories = ValueNotifier<int>(0);
|
2023-06-02 00:38:19 +02:00
|
|
|
/*
|
|
|
|
* fat 0
|
|
|
|
* protein 1
|
|
|
|
* carbon 2
|
|
|
|
* fat for one day, week, month, 3
|
|
|
|
* protein for one day, week, month 4
|
|
|
|
* carbon for one day, week, month 5
|
|
|
|
* calories for one day, week, month 6
|
|
|
|
* */
|
|
|
|
ValueNotifier<List<double>> ingredients = ValueNotifier<List<double>>([0,0,0,0,0,0,0]);
|
2023-05-30 22:09:16 +02:00
|
|
|
ValueNotifier<int> dailyAverageForCurrentWeek = ValueNotifier<int>(0);
|
|
|
|
ValueNotifier<List<Food>> weeklyCaloryRanking = ValueNotifier<List<Food>>([]);
|
2023-06-01 12:14:23 +02:00
|
|
|
ValueNotifier<List<BarChartGroupData>> barChartData = ValueNotifier<List<BarChartGroupData>>([]);
|
2023-05-30 21:03:46 +02:00
|
|
|
|
2023-05-30 09:38:54 +02:00
|
|
|
initBoxes()async{
|
2023-06-01 12:14:23 +02:00
|
|
|
Box reducedBox = Hive.box(todayStatisticsBoxName);
|
2023-05-30 22:09:16 +02:00
|
|
|
Box progressBox = Hive.box(progressStatisticsBoxName);
|
|
|
|
|
|
|
|
putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []);
|
|
|
|
putIfKeyNotExists([reducedBox,progressBox], 'MITTAGESSEN', []);
|
|
|
|
putIfKeyNotExists([reducedBox,progressBox], 'ABENDESSEN', []);
|
2023-06-01 13:59:12 +02:00
|
|
|
updateStatisticsTodayBoxByTimespan(TimeSpan.day);
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
void putIfKeyNotExists(List<Box> boxes, String key, dynamic value) {
|
|
|
|
for(int i = 0; i < boxes.length;i++){
|
|
|
|
if (!boxes[i].containsKey(key)) {
|
|
|
|
boxes[i].put(key, value);
|
|
|
|
}
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-01 13:59:12 +02:00
|
|
|
updateStatisticsTodayBoxByTimespan(TimeSpan timespan){
|
|
|
|
clearBoxByBox(Hive.box(todayStatisticsBoxName));
|
2023-05-30 22:09:16 +02:00
|
|
|
int timestamp = getTimestampFromNow();
|
2023-06-02 00:38:19 +02:00
|
|
|
int dayLen = 1;
|
2023-06-01 13:59:12 +02:00
|
|
|
switch(timespan){
|
2023-05-30 09:38:54 +02:00
|
|
|
case TimeSpan.day:
|
2023-06-01 12:14:23 +02:00
|
|
|
getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(todayStatisticsBoxName));
|
2023-05-30 09:38:54 +02:00
|
|
|
break;
|
|
|
|
case TimeSpan.week:
|
|
|
|
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp);
|
|
|
|
for(int i = 0;i < currentWeek.length;i++){
|
2023-06-01 12:14:23 +02:00
|
|
|
getNewFoodAndUpdateBoxByTimestampAndBox(currentWeek[i],Hive.box(todayStatisticsBoxName));
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
2023-06-02 00:38:19 +02:00
|
|
|
dayLen = currentWeek.length;
|
2023-05-30 09:38:54 +02:00
|
|
|
break;
|
|
|
|
case TimeSpan.month:
|
2023-05-30 14:40:39 +02:00
|
|
|
List<int> currentMonth = getTimestampsByTimestampAndTimespan(TimeSpan.month,timestamp);
|
|
|
|
for(int i = 0;i < currentMonth.length;i++){
|
2023-06-01 12:14:23 +02:00
|
|
|
getNewFoodAndUpdateBoxByTimestampAndBox(currentMonth[i],Hive.box(todayStatisticsBoxName));
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
2023-06-02 00:38:19 +02:00
|
|
|
dayLen = currentMonth.length;
|
2023-05-30 09:38:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-06-02 00:38:19 +02:00
|
|
|
updateCalculationsAndNotfiyListenersForPorgressStatistics(dayLen);
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2023-06-02 00:38:19 +02:00
|
|
|
void updateCalculationsAndNotfiyListenersForPorgressStatistics(int dayLen){
|
2023-06-01 12:14:23 +02:00
|
|
|
eatenCalories.value = getAllEatenCaloriesByBox(Hive.box(todayStatisticsBoxName));
|
2023-06-02 00:38:19 +02:00
|
|
|
ingredients.value = getAllEatenIngredientsForTodayStatistics(dayLen.roundToDouble());
|
2023-05-30 21:03:46 +02:00
|
|
|
}
|
2023-05-30 22:09:16 +02:00
|
|
|
|
|
|
|
void getNewFoodAndUpdateBoxByTimestampAndBox(int timestamp, Box box){
|
2023-05-30 09:38:54 +02:00
|
|
|
Map<String,List<Food>> newFood = getFoodMapForGivenTimestampFromMainBox(timestamp);
|
|
|
|
if(newFood.keys.isNotEmpty){
|
2023-05-30 22:09:16 +02:00
|
|
|
setElementsOfBoxByBox(newFood, box);
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|
|
|
|
|
2023-06-16 11:44:42 +02:00
|
|
|
bool timestampIsValid(int timestamp){
|
|
|
|
try{
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(timestamp*1000);
|
|
|
|
return true;
|
|
|
|
}catch(e){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-30 09:38:54 +02:00
|
|
|
List<int> getTimestampsByTimestampAndTimespan(TimeSpan timespan, int timestamp) {
|
2023-06-16 11:44:42 +02:00
|
|
|
if(!timestampIsValid(timestamp)){
|
|
|
|
return [];
|
|
|
|
}
|
2023-05-30 09:38:54 +02:00
|
|
|
int range = timespan == TimeSpan.week ? 7 : 31;
|
|
|
|
int targetWeekday = DateTime.monday; // Example target weekday (Monday)
|
|
|
|
DateTime currentDateTime = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
|
|
|
|
int currentWeekday = currentDateTime.weekday;
|
|
|
|
int daysToAdd = targetWeekday - currentWeekday;
|
|
|
|
DateTime targetDateTime = currentDateTime.add(Duration(days: daysToAdd));
|
|
|
|
|
|
|
|
List<int> timestampsForWeekdays = [];
|
|
|
|
for (int i = 0; i < range; i++) {
|
|
|
|
timestampsForWeekdays.add(targetDateTime.millisecondsSinceEpoch ~/ 1000);
|
|
|
|
targetDateTime = targetDateTime.add(const Duration(days: 1));
|
|
|
|
}
|
|
|
|
return timestampsForWeekdays;
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 13:59:12 +02:00
|
|
|
clearBoxByBox(Box box){
|
2023-05-30 09:38:54 +02:00
|
|
|
for(int i = 0; i < box.keys.length;i++){
|
|
|
|
box.put(box.keys.elementAt(i), []);
|
|
|
|
}
|
|
|
|
}
|
2023-05-30 21:03:46 +02:00
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
setElementsOfBoxByBox(Map<String,List<Food>> newFood,Box box){
|
2023-05-30 09:38:54 +02:00
|
|
|
Iterable<String> keys = newFood.keys;
|
|
|
|
for(int i = 0; i < keys.length;i++){
|
2023-05-30 18:02:13 +02:00
|
|
|
List<Food> alreadyExisting = castDynamicToListFood(box.get(keys.elementAt(i)));
|
|
|
|
alreadyExisting.addAll(newFood[keys.elementAt(i)] as Iterable<Food>);
|
|
|
|
box.put(keys.elementAt(i), alreadyExisting);
|
2023-05-30 09:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getDayAsIntFromTimestamp(int timestamp){
|
|
|
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
|
|
|
|
return dateTime.day;
|
|
|
|
}
|
2023-05-29 12:08:46 +02:00
|
|
|
|
2023-05-30 09:38:54 +02:00
|
|
|
Map<String,List<Food>> getFoodMapForGivenTimestampFromMainBox(int timestamp){
|
|
|
|
Box box = Hive.box(mainStatisticsBoxName);
|
2023-06-01 12:14:23 +02:00
|
|
|
dynamic matchingTimestamp = getMatchingTimestamp(box, timestamp);
|
2023-05-30 09:38:54 +02:00
|
|
|
if(matchingTimestamp != null){
|
|
|
|
return castDynamicMap(box.get(matchingTimestamp));
|
|
|
|
}
|
|
|
|
return <String,List<Food>>{};
|
|
|
|
}
|
|
|
|
|
2023-06-01 12:14:23 +02:00
|
|
|
getMatchingTimestamp(Box box,int newTimestamp){
|
2023-05-30 09:38:54 +02:00
|
|
|
if(box.keys.isNotEmpty){
|
|
|
|
for(int i = 0; i < box.keys.length;i++){
|
|
|
|
int timestamp = box.keys.elementAt(i);
|
|
|
|
if(isDateEqual(newTimestamp, timestamp)){
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getMonthAsIntFromTimestamp(int timestamp){
|
|
|
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
|
|
|
|
return dateTime.month;
|
|
|
|
}
|
|
|
|
|
|
|
|
getYearAsIntFromTimestamp(int timestamp){
|
|
|
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
|
|
|
|
return dateTime.year;
|
|
|
|
}
|
|
|
|
|
|
|
|
isDateEqual(int timestamp1, int timestamp2){
|
2023-06-16 11:44:42 +02:00
|
|
|
if(!timestampIsValid(timestamp1) || !timestampIsValid(timestamp2)){
|
|
|
|
return false;
|
|
|
|
}
|
2023-05-30 09:38:54 +02:00
|
|
|
return
|
|
|
|
getDayAsIntFromTimestamp(timestamp1) == getDayAsIntFromTimestamp(timestamp2) &&
|
|
|
|
getMonthAsIntFromTimestamp(timestamp1) == getMonthAsIntFromTimestamp(timestamp2) &&
|
|
|
|
getYearAsIntFromTimestamp(timestamp1) == getYearAsIntFromTimestamp(timestamp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
addItemToMainBox(Food value, String mealType){
|
2023-05-29 12:08:46 +02:00
|
|
|
// Hive.deleteFromDisk();
|
2023-05-30 09:38:54 +02:00
|
|
|
Box box = Hive.box(mainStatisticsBoxName);
|
2023-05-29 12:08:46 +02:00
|
|
|
DateTime dateTime = DateTime.now();
|
2023-05-30 09:38:54 +02:00
|
|
|
|
|
|
|
// DEBUG
|
|
|
|
//DateTime dateTime = getRandomTimestampForTesting();
|
|
|
|
|
|
|
|
int newTimestamp = dateTime.millisecondsSinceEpoch.toInt() ~/ 1000;
|
|
|
|
|
2023-06-01 12:14:23 +02:00
|
|
|
dynamic matchingTimestamp = getMatchingTimestamp(box, newTimestamp);
|
2023-05-30 09:38:54 +02:00
|
|
|
if(matchingTimestamp != null){
|
|
|
|
newTimestamp = matchingTimestamp;
|
|
|
|
}
|
2023-05-30 14:50:27 +02:00
|
|
|
Map<String, List<Food>> valueMap = castDynamicMap(box.get(newTimestamp));
|
2023-05-29 12:08:46 +02:00
|
|
|
List<Food> values = [];
|
|
|
|
if(valueMap.containsKey(mealType)){
|
|
|
|
values = valueMap[mealType]!;
|
|
|
|
}
|
|
|
|
values.add(value);
|
|
|
|
valueMap[mealType] = values;
|
2023-05-30 09:38:54 +02:00
|
|
|
box.put(newTimestamp, valueMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
getRandomTimestampForTesting(){
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
DateTime startOfWeek = now.subtract(Duration(days: now.weekday - 1));
|
2023-05-30 14:40:39 +02:00
|
|
|
DateTime endOfWeek = startOfWeek.add(const Duration(days: 6));
|
2023-05-30 09:38:54 +02:00
|
|
|
|
|
|
|
Random random = Random();
|
|
|
|
int randomMilliseconds = random.nextInt(endOfWeek.millisecondsSinceEpoch - startOfWeek.millisecondsSinceEpoch);
|
|
|
|
DateTime randomTimestamp = startOfWeek.add(Duration(milliseconds: randomMilliseconds));
|
|
|
|
|
|
|
|
return randomTimestamp;
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
int getAllEatenCaloriesByBox(Box box){
|
2023-05-30 16:17:51 +02:00
|
|
|
num sum = 0;
|
2023-05-29 22:04:44 +02:00
|
|
|
for(int i = 0; i < box.keys.length;i++){
|
|
|
|
for(Food food in box.get(box.keys.elementAt(i))){
|
2023-05-30 16:17:51 +02:00
|
|
|
sum += food.calories;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sum as int;
|
|
|
|
}
|
|
|
|
|
2023-06-02 20:21:16 +02:00
|
|
|
double getCaloryTargetForOneDay(){
|
|
|
|
final Box userBox = Hive.box<User>("USER_BOX");
|
|
|
|
return userBox.get("USER").kalorien.toDouble();
|
|
|
|
}
|
|
|
|
|
2023-06-02 00:38:19 +02:00
|
|
|
List<double> getAllEatenIngredientsForTodayStatistics(double dayLen){
|
2023-06-01 12:14:23 +02:00
|
|
|
Box box = Hive.box(todayStatisticsBoxName);
|
2023-06-02 00:38:19 +02:00
|
|
|
final Box userBox = Hive.box<User>("USER_BOX");
|
|
|
|
final calorieSummary = userBox.get("USER").kalorien;
|
|
|
|
|
|
|
|
const double fatPercentPerThousandCalorie = 3.7;
|
|
|
|
const double proteinPercentPerThousandCalorie = 4.5;
|
|
|
|
const double carbsPercentPerThousandCalorie = 12.8;
|
|
|
|
|
|
|
|
double fatSummary = (calorieSummary / 100) * fatPercentPerThousandCalorie;
|
|
|
|
double carbSummary = (calorieSummary / 100) * carbsPercentPerThousandCalorie;
|
|
|
|
double proteinSummary = (calorieSummary / 100) * proteinPercentPerThousandCalorie;
|
|
|
|
|
2023-05-30 17:28:16 +02:00
|
|
|
num fat = 0;
|
|
|
|
num protein = 0;
|
|
|
|
num carbs = 0;
|
|
|
|
for(int i = 0; i < box.keys.length;i++){
|
|
|
|
for(Food food in box.get(box.keys.elementAt(i))){
|
|
|
|
fat += food.fatg;
|
2023-05-30 21:03:46 +02:00
|
|
|
protein += food.proteing;
|
|
|
|
carbs += food.carbohydrateg;
|
2023-05-30 17:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-02 00:38:19 +02:00
|
|
|
|
|
|
|
return [
|
|
|
|
fat.roundToDouble(),
|
|
|
|
protein.roundToDouble(),
|
|
|
|
carbs.roundToDouble(),
|
|
|
|
fatSummary * dayLen,
|
|
|
|
proteinSummary * dayLen,
|
|
|
|
carbSummary * dayLen,
|
|
|
|
calorieSummary * dayLen
|
|
|
|
];
|
2023-05-30 17:28:16 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
void updateCalculationsAndNotfiyListenersForTodayStatistics(){
|
|
|
|
dailyAverageForCurrentWeek.value = getAverageCaloriesForCurrentWeekOnDailyBasis();
|
|
|
|
weeklyCaloryRanking.value = getWeeklyCaloryRanking();
|
2023-06-01 12:14:23 +02:00
|
|
|
barChartData.value = getBarChartData();
|
2023-05-30 22:09:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateProgressBoxValues(){
|
|
|
|
Box box = Hive.box(progressStatisticsBoxName);
|
|
|
|
box.clear();
|
|
|
|
int timestamp = getTimestampFromNow();
|
|
|
|
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp);
|
|
|
|
for(int i = 0;i < currentWeek.length;i++){
|
|
|
|
getNewFoodAndUpdateBoxByTimestampAndBox(currentWeek[i],box);
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|
2023-05-30 22:09:16 +02:00
|
|
|
updateCalculationsAndNotfiyListenersForTodayStatistics();
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
int getAverageCaloriesForCurrentWeekOnDailyBasis(){
|
|
|
|
Box box = Hive.box(progressStatisticsBoxName);
|
|
|
|
return getAllEatenCaloriesByBox(box)~/7;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Food> getWeeklyCaloryRanking(){
|
|
|
|
int timestamp = getTimestampFromNow();
|
|
|
|
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp);
|
|
|
|
List<Food> allFoodsOfWeek = [];
|
|
|
|
for(int i = 0;i < currentWeek.length;i++){
|
|
|
|
Map<String,List<Food>> foodFromMainBox = getFoodMapForGivenTimestampFromMainBox(currentWeek[i]);
|
|
|
|
Iterable<String> keys = foodFromMainBox.keys;
|
|
|
|
if(keys.isNotEmpty){
|
|
|
|
for(int i = 0; i < keys.length;i++ ){
|
|
|
|
allFoodsOfWeek.addAll(foodFromMainBox[keys.elementAt(i)] as Iterable<Food>);
|
|
|
|
}
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|
|
|
|
}
|
2023-05-30 22:09:16 +02:00
|
|
|
allFoodsOfWeek.sort((a, b) => b.calories - a.calories);
|
|
|
|
return getListOfDistinctElements(allFoodsOfWeek);
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 12:14:23 +02:00
|
|
|
int getSumOfCaloriesByFoodList(List<Food> foods){
|
|
|
|
int sum = 0;
|
|
|
|
for(int i = 0; i < foods.length;i++){
|
2023-06-16 11:44:42 +02:00
|
|
|
try{
|
|
|
|
sum += foods[i].calories as int;
|
|
|
|
}catch(e){
|
|
|
|
throw const FormatException('please check formats');
|
|
|
|
}
|
2023-06-01 12:14:23 +02:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<BarChartGroupData> getBarChartData(){
|
|
|
|
int timestamp = getTimestampFromNow();
|
|
|
|
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp);
|
|
|
|
int maxValue = 0;
|
|
|
|
List<List<int>> result =
|
|
|
|
[
|
|
|
|
[0,0,0],
|
|
|
|
[0,0,0],
|
|
|
|
[0,0,0],
|
|
|
|
[0,0,0],
|
|
|
|
[0,0,0],
|
|
|
|
[0,0,0],
|
|
|
|
[0,0,0],
|
|
|
|
]; //[[breakfast,lunch,dinner],[breakfast,lunch,dinner] ...]
|
|
|
|
for(int i = 0;i < currentWeek.length;i++){
|
|
|
|
Map<String,List<Food>> foodMapFromMainBoxByTimestamp = getFoodMapForGivenTimestampFromMainBox(currentWeek[i]);
|
|
|
|
Iterable<String> keys = foodMapFromMainBoxByTimestamp.keys;
|
|
|
|
if(keys.isNotEmpty){
|
|
|
|
for(int j = 0; j < keys.length;j++){
|
|
|
|
int value = getSumOfCaloriesByFoodList(foodMapFromMainBoxByTimestamp[keys.elementAt(j)] ?? []);
|
|
|
|
if(value > maxValue){
|
|
|
|
maxValue = value;
|
|
|
|
}
|
2023-06-01 13:19:55 +02:00
|
|
|
result[i][j] = value;
|
2023-06-01 12:14:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [
|
|
|
|
BarChartGroupData(
|
|
|
|
x: 0,
|
|
|
|
barRods: [BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.yellow,
|
|
|
|
toY: result[0][0].toDouble(), // First segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.red,
|
|
|
|
toY: result[0][1].toDouble(), // Second segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.green,
|
|
|
|
toY: result[0][2].toDouble(), // Second segment color
|
|
|
|
),],
|
|
|
|
),
|
|
|
|
BarChartGroupData(
|
|
|
|
x: 1,
|
|
|
|
barRods: [BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.yellow,
|
|
|
|
toY: result[1][0].toDouble(),
|
|
|
|
// First segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.red,
|
|
|
|
toY: result[1][1].toDouble(), // Second segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.green,
|
|
|
|
toY: result[1][2].toDouble(), // Second segment color
|
|
|
|
),],
|
|
|
|
),
|
|
|
|
BarChartGroupData(
|
|
|
|
x: 2,
|
|
|
|
barRods: [BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.yellow,
|
|
|
|
toY: result[2][0].toDouble(), // First segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.red,
|
|
|
|
toY: result[2][1].toDouble(), // Second segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.green,
|
|
|
|
toY: result[2][2].toDouble(), // Second segment color
|
|
|
|
),],
|
|
|
|
),
|
|
|
|
BarChartGroupData(
|
|
|
|
x: 3,
|
|
|
|
barRods: [BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.yellow,
|
|
|
|
toY: result[3][0].toDouble(), // First segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.red,
|
|
|
|
toY: result[3][1].toDouble(), // Second segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.green,
|
|
|
|
toY: result[3][2].toDouble(), // Second segment color
|
|
|
|
),],
|
|
|
|
showingTooltipIndicators: [0],
|
|
|
|
),
|
|
|
|
BarChartGroupData(
|
|
|
|
x: 4,
|
|
|
|
barRods: [BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.yellow,
|
|
|
|
toY: result[4][0].toDouble(), // First segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.red,
|
|
|
|
toY: result[4][1].toDouble(), // Second segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.green,
|
|
|
|
toY: result[4][2].toDouble(), // Second segment color
|
|
|
|
),],
|
|
|
|
),
|
|
|
|
BarChartGroupData(
|
|
|
|
x: 5,
|
|
|
|
barRods: [BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.yellow,
|
|
|
|
toY: result[5][0].toDouble(), // First segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.red,
|
|
|
|
toY: result[5][1].toDouble(), // Second segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.green,
|
|
|
|
toY: result[5][2].toDouble(), // Second segment color
|
2023-06-01 13:19:55 +02:00
|
|
|
),],
|
2023-06-01 12:14:23 +02:00
|
|
|
),
|
|
|
|
BarChartGroupData(
|
|
|
|
x: 6,
|
|
|
|
barRods: [BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.yellow,
|
|
|
|
toY: result[6][0].toDouble(), // First segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.red,
|
|
|
|
toY: result[6][1].toDouble(), // Second segment color
|
|
|
|
), BarChartRodData(
|
|
|
|
width: 7.5, // Adjust the width of the bar if needed
|
|
|
|
color: Colors.green,
|
|
|
|
toY: result[6][2].toDouble(), // Second segment color
|
|
|
|
),], showingTooltipIndicators: [0],
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
getTimestampFromNow(){
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
return now.millisecondsSinceEpoch.toInt() ~/ 1000;
|
|
|
|
}
|
2023-05-31 13:36:44 +02:00
|
|
|
|
2023-06-01 13:59:12 +02:00
|
|
|
List<Food> getMealsOfTodayByMealtype(String mealtype){
|
|
|
|
int timestamp = getTimestampFromNow();
|
|
|
|
return getFoodMapForGivenTimestampFromMainBox(timestamp)[mealtype] ?? [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-29 12:08:46 +02:00
|
|
|
}
|