diff --git a/.env b/.env index ef33393..8cb26a6 100644 --- a/.env +++ b/.env @@ -4,10 +4,7 @@ SECOND_NAME_FIELD=SECOND_NAME WEIGHT_FIELD=WEIGHT HEIGHT_FIELD=HEIGHT CALORIES_FIELD=CALORIES -FIRST_NAME_FIELD=FIRST_NAME -FIRST_NAME_FIELD=FIRST_NAME TODAY_BOX=TODAY -MEALPLAN_BOX=MEALPLAN DATE_FIELD=DATE # datum BREAKFAST_FIELD=FRÜHSTÜCK # frühstück LUNCH_FIELD=MITTAGESSEN # mittagessen diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 631dea2..5c89fed 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.6\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-05-13 11:33:23.416757","version":"3.7.11"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\Nutzer\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.6\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-05-14 09:21:07.613440","version":"3.7.11"} \ No newline at end of file diff --git a/lib/android/components/founded_search_component.dart b/lib/android/components/founded_search_component.dart index c0d32e0..7d67ec9 100644 --- a/lib/android/components/founded_search_component.dart +++ b/lib/android/components/founded_search_component.dart @@ -1,4 +1,5 @@ import 'package:assorted_layout_widgets/assorted_layout_widgets.dart'; +import 'package:ernaehrung/android/config/statistics.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:hive/hive.dart'; @@ -15,8 +16,10 @@ class SearchedFoodComponent extends StatefulWidget { } class _SearchFoodComponentState extends State { + StatisticsService statisticsService = StatisticsService(); void storeFood() async { + statisticsService.addItemToStatisticsBox(widget.food, widget.cardName); final todayBox = Hive.box(dotenv.env['TODAY_BOX']!); if (!todayBox.isOpen){ Hive.openBox(dotenv.env['TODAY_BOX']!); diff --git a/lib/android/config/statistics.dart b/lib/android/config/statistics.dart new file mode 100644 index 0000000..a5e0fbf --- /dev/null +++ b/lib/android/config/statistics.dart @@ -0,0 +1,80 @@ +import 'package:hive/hive.dart'; + +import '../models/food.dart'; + +class StatisticsService { + + final String boxName = 'STATISTICS'; + + StatisticsService() { + initBox(); + } + + initBox()async{ + await Hive.openBox(boxName); + } + + + addItemToStatisticsBox(Food value, String mealType){ + // Hive.deleteFromDisk(); + Box box = Hive.box(boxName); + DateTime dateTime = DateTime.now(); + int timestamp = dateTime.millisecondsSinceEpoch.toInt(); + Map>? valueMap = box.get(timestamp); + valueMap ??= { + "FRÜHSTÜCK": [], + "MITTAGESSEN": [], + "ABENDESSEN": [] + }; + List values = []; + if(valueMap.containsKey(mealType)){ + values = valueMap[mealType]!; + } + values.add(value); + valueMap[mealType] = values; + box.put(timestamp, valueMap); + showItems(); + } + + num getAllCaloriesByTimestamp(DateTime date){ + Box box = Hive.box(boxName); + int timestamp = date.millisecondsSinceEpoch.toInt(); + Map>? valueMap = box.get(timestamp); + if(valueMap == null){ + return 0; + } + num sum = 0; + for(var mealType in valueMap.keys){ + if(valueMap.containsKey(mealType)){ + List values = valueMap[mealType]!; + for(var value in values){ + sum += value.calories; + } + } + } + return sum; + } + + num getCaloriesByTimestampAndMealType(DateTime timestamp, String mealType){ + Box box = Hive.box(boxName); + + Map>? valueMap = box.get(timestamp); + if(valueMap == null){ + return 0; + } + num sum = 0; + if(valueMap.containsKey(mealType)){ + List values = valueMap[mealType]!; + for(var value in values){ + sum += value.calories; + } + } + return sum; + } + + showItems(){ + print("ITEMS"); + print(Hive.box(boxName).keys); + } + +} \ No newline at end of file diff --git a/lib/android/pages/nav_pages/meal_plan_page.dart b/lib/android/pages/nav_pages/meal_plan_page.dart index a832500..7b9a696 100644 --- a/lib/android/pages/nav_pages/meal_plan_page.dart +++ b/lib/android/pages/nav_pages/meal_plan_page.dart @@ -1,10 +1,6 @@ -import 'dart:math'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; import 'package:hive_flutter/adapters.dart'; - import '../../components/card_component.dart'; import '../../models/food.dart'; @@ -41,7 +37,6 @@ class _MealPlanState extends State { for (Food element in dynamicList) { foodList.add(element); } - print(foodList.length); return foodList; } diff --git a/lib/main.dart b/lib/main.dart index 49118c6..300297e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,12 +12,12 @@ void main() async { await dotenv.load(fileName: ".env"); await Hive.initFlutter(); - if (! Hive.isAdapterRegistered(1)) { + if (!Hive.isAdapterRegistered(1)) { Hive.registerAdapter(FoodAdapter()); } + await Hive.openBox(dotenv.env['TODAY_BOX']!); - await Hive.openBox(dotenv.env['MEALPLAN_BOX']!); await setupTodayBox(); if(defaultTargetPlatform == TargetPlatform.android){