small cleanup

welcome
98spag 2023-05-30 14:40:39 +02:00
parent 6ff338ad5e
commit 1f52c7971a
2 changed files with 7 additions and 10 deletions

View File

@ -1,5 +1,4 @@
import 'dart:math';
import 'package:ernaehrung/android/components/meal_page_text/days_component.dart';
import 'package:ernaehrung/android/config/cast_helper.dart';
import 'package:hive/hive.dart';
@ -29,7 +28,6 @@ class StatisticsService {
updateReducedBoxByTimespan(TimeSpan timeSpan){
clearReducedBoxBeforeUpdate();
print(timeSpan);
DateTime now = DateTime.now();
int timestamp = now.millisecondsSinceEpoch.toInt() ~/ 1000;
switch(timeSpan){
@ -43,9 +41,9 @@ class StatisticsService {
}
break;
case TimeSpan.month:
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.month,timestamp);
for(int i = 0;i < currentWeek.length;i++){
getNewFoodAndUpdateReducedBoxByTimestamp(currentWeek[i]);
List<int> currentMonth = getTimestampsByTimestampAndTimespan(TimeSpan.month,timestamp);
for(int i = 0;i < currentMonth.length;i++){
getNewFoodAndUpdateReducedBoxByTimestamp(currentMonth[i]);
}
break;
}
@ -168,7 +166,7 @@ class StatisticsService {
getRandomTimestampForTesting(){
DateTime now = DateTime.now();
DateTime startOfWeek = now.subtract(Duration(days: now.weekday - 1));
DateTime endOfWeek = startOfWeek.add(Duration(days: 6));
DateTime endOfWeek = startOfWeek.add(const Duration(days: 6));
Random random = Random();
int randomMilliseconds = random.nextInt(endOfWeek.millisecondsSinceEpoch - startOfWeek.millisecondsSinceEpoch);
@ -179,7 +177,7 @@ class StatisticsService {
num getAllCaloriesByBoxAndTimestamp(Box box,DateTime date){
int timestamp = date.millisecondsSinceEpoch.toInt() ~/ 1000;
Map<String, List<Food>>? valueMap = castDynamicMap(box.get(timestamp));
Map<String, List<Food>> valueMap = castDynamicMap(box.get(timestamp));
num sum = 0;
for(var mealType in valueMap.keys){
if(valueMap.containsKey(mealType)){
@ -194,7 +192,7 @@ class StatisticsService {
num getCaloriesByTimestampAndMealTypeAndBox(Box box,DateTime date, String mealType){
int timestamp = date.millisecondsSinceEpoch.toInt() ~/ 1000;
Map<String, List<Food>>? valueMap = castDynamicMap(box.get(timestamp));
Map<String, List<Food>> valueMap = castDynamicMap(box.get(timestamp));
num sum = 0;
if(valueMap.containsKey(mealType)){
List<Food> values = valueMap[mealType]!;

View File

@ -1,8 +1,7 @@
import 'package:basic_utils/basic_utils.dart';
import 'package:ernaehrung/android/components/card/card_component.dart';
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import '../../components/diet_chart_component.dart';
import '../../components/food_list_component.dart';
import '../../components/statistics_circular_indicator_component.dart';
class TodayPage extends StatefulWidget {