diff --git a/lib/features/smartwatch_health_data/HealthDataTransformation.dart b/lib/features/smartwatch_health_data/HealthDataTransformation.dart index d389135d..ffda4f4f 100644 --- a/lib/features/smartwatch_health_data/HealthDataTransformation.dart +++ b/lib/features/smartwatch_health_data/HealthDataTransformation.dart @@ -8,7 +8,7 @@ import 'model/Vitals.dart'; enum Durations { daily("daily"), weekly("weekly"), - monthly("weekly"), + monthly("monthly"), halfYearly("halfYearly"), yearly("yearly"); @@ -47,6 +47,7 @@ class HealthDataTransformation { } // Group by day } else if (filterType == Durations.monthly.value) { if(isBetweenInclusive(parseDate, currentDate.subtract(Duration(days: 30)), DateTime.now())) { + print("the value for the monthly filter is ${vital.value} with the timestamp ${vital.timestamp} and the current date is $currentDate and the parse date is $parseDate"); key = DateFormat('yyyy-MM-dd').format(DateTime.parse(vital.timestamp)); groupedData.putIfAbsent(key, () => []).add(vital); @@ -67,8 +68,13 @@ class HealthDataTransformation { groupedData.forEach((key, values) { double sum = values.fold(0, (acc, v) => acc + num.parse(v.value)); double mean = sum / values.length; + if(selectedSection == "bodyOxygen" || selectedSection == "bodyTemperature") { + mean = sum / values.length; + }else { + mean = sum; + } - double finalValue = filterType == 'weekly' ? mean : sum; + double finalValue = mean; print("the final value is $finalValue for the key $key with the original values ${values.map((v) => v.value).toList()} and uom is ${values.first.unitOfMeasure}"); dataPoints.add(DataPoint( value: smartScale(finalValue), diff --git a/lib/features/smartwatch_health_data/health_provider.dart b/lib/features/smartwatch_health_data/health_provider.dart index 4d47ccb8..963c0352 100644 --- a/lib/features/smartwatch_health_data/health_provider.dart +++ b/lib/features/smartwatch_health_data/health_provider.dart @@ -125,12 +125,10 @@ class HealthProvider with ChangeNotifier { if (result.isError) { error = 'Error initializing device: ${result.asError}'; } else { - LoaderBottomSheet.hideLoader(); - LoaderBottomSheet.showLoader(); await getVitals(); - LoaderBottomSheet.hideLoader(); - await Future.delayed(Duration(seconds: 5)); + // LoaderBottomSheet.hideLoader(); + // await Future.delayed(Duration(seconds: 5)); getIt.get().pushPage(page: SmartWatchActivity()); print('Device initialized successfully'); } @@ -162,7 +160,7 @@ class HealthProvider with ChangeNotifier { break; case Durations.weekly: if (weekly.isNotEmpty) { - selectedData = daily; + selectedData = weekly; break; } selectedData = weekly = healthDataTransformation.transformVitalsToDataPoints(vitals!, Durations.weekly.value, selectedSection); diff --git a/lib/features/smartwatch_health_data/health_service.dart b/lib/features/smartwatch_health_data/health_service.dart index 1cc42014..7d42092d 100644 --- a/lib/features/smartwatch_health_data/health_service.dart +++ b/lib/features/smartwatch_health_data/health_service.dart @@ -189,7 +189,6 @@ class HealthService { return null; } try { - await watchHelper!.getActivity(); await watchHelper!.getHeartRate(); await watchHelper!.getSleep(); await watchHelper!.getSteps(); diff --git a/lib/features/smartwatch_health_data/model/Vitals.dart b/lib/features/smartwatch_health_data/model/Vitals.dart index cea1df4f..96386f2d 100644 --- a/lib/features/smartwatch_health_data/model/Vitals.dart +++ b/lib/features/smartwatch_health_data/model/Vitals.dart @@ -16,6 +16,11 @@ class Vitals { unitOfMeasure: map['uom'] ?? "", ); } + + + toString(){ + return "{\"value\": \"$value\", \"timeStamp\": \"$timestamp\", \"uom\": \"$unitOfMeasure\"}"; + } } class VitalsWRTType { @@ -47,7 +52,6 @@ class VitalsWRTType { map["activity"].forEach((element) { element["uom"] = "Kcal"; var data = Vitals.fromMap(element); - // data.value = (double.parse(data.value)/1000).toStringAsFixed(2); activity.add(data); }); map["steps"].forEach((element) { @@ -70,11 +74,6 @@ class VitalsWRTType { bodyOxygen.add(Vitals.fromMap(element)); }); - map["distance"].forEach((element) { - element["uom"] = "m"; - - bodyOxygen.add(Vitals.fromMap(element)); - }); map["bodyTemperature"].forEach((element) { element["uom"] = "C"; bodyTemperature.add(Vitals.fromMap(element)); diff --git a/lib/features/smartwatch_health_data/watch_connectors/health_connect_helper.dart b/lib/features/smartwatch_health_data/watch_connectors/health_connect_helper.dart index e7ec35b7..ac0170c8 100644 --- a/lib/features/smartwatch_health_data/watch_connectors/health_connect_helper.dart +++ b/lib/features/smartwatch_health_data/watch_connectors/health_connect_helper.dart @@ -11,6 +11,7 @@ class HealthConnectHelper extends WatchHelper { final Health health = Health(); final List _healthPermissions = [ + HealthDataType.ACTIVE_ENERGY_BURNED, HealthDataType.HEART_RATE, HealthDataType.STEPS, HealthDataType.BLOOD_OXYGEN, @@ -24,10 +25,11 @@ class HealthConnectHelper extends WatchHelper { @override FutureOr getHeartRate() async { try { - final types = [HealthDataType.HEART_RATE]; + final types = HealthDataType.HEART_RATE; final endDate = DateTime.now(); + // final startDate = endDate.subtract(Duration(days: 365)); final startDate = endDate.subtract(Duration(days: 365)); - final data = await getData(startDate, endDate, types); + final data = await getHeartData(startDate, endDate, types); addDataToMap("heartRate",data ); } catch (e) { print('Error getting heart rate: $e'); @@ -37,7 +39,7 @@ class HealthConnectHelper extends WatchHelper { @override FutureOr getSleep() async { try { - final types = [HealthDataType.SLEEP_IN_BED]; + final types = HealthDataType.SLEEP_IN_BED; final endDate = DateTime.now(); final startDate = endDate.subtract(Duration(days: 365)); final data = await getData(startDate, endDate, types); @@ -50,7 +52,7 @@ class HealthConnectHelper extends WatchHelper { @override FutureOr getSteps() async { try { - final types = [HealthDataType.STEPS]; + final types = HealthDataType.STEPS; final endDate = DateTime.now(); final startDate = endDate.subtract(Duration(days: 365)); final data = await getData(startDate, endDate, types); @@ -64,7 +66,7 @@ class HealthConnectHelper extends WatchHelper { @override Future getActivity() async { try { - final types = [HealthDataType.ACTIVE_ENERGY_BURNED]; + final types = HealthDataType.ACTIVE_ENERGY_BURNED; final endDate = DateTime.now(); final startDate = endDate.subtract(Duration(days: 365)); final data = await getData(startDate, endDate, types); @@ -77,17 +79,17 @@ class HealthConnectHelper extends WatchHelper { @override Future retrieveData() async { - return mappedData; + return Result.value(getMappedData()); } @override Future getBloodOxygen() async { try { - final types = [HealthDataType.BLOOD_OXYGEN]; + final types = HealthDataType.BLOOD_OXYGEN; final endDate = DateTime.now(); final startDate = endDate.subtract(Duration(days: 365)); final data = await getData(startDate, endDate, types); - addDataToMap("bloodOxygen",data ); + addDataToMapBloodOxygen("bloodOxygen", data); } catch (e) { print('Error getting blood oxygen: $e'); } @@ -96,7 +98,7 @@ class HealthConnectHelper extends WatchHelper { @override Future getBodyTemperature() async { try { - final types = [HealthDataType.BODY_TEMPERATURE]; + final types = HealthDataType.BODY_TEMPERATURE; final endDate = DateTime.now(); final startDate = endDate.subtract(Duration(days: 365)); final data = await getData(startDate, endDate, types); @@ -109,7 +111,7 @@ class HealthConnectHelper extends WatchHelper { @override FutureOr getDistance() async { try { - final types = [HealthDataType.DISTANCE_WALKING_RUNNING]; + final types = HealthDataType.DISTANCE_WALKING_RUNNING; final endDate = DateTime.now(); final startDate = endDate.subtract(Duration(days: 365)); final data = await getData(startDate, endDate, types); @@ -141,7 +143,8 @@ class HealthConnectHelper extends WatchHelper { startDate: startTime, endDate: endTime, types: [type], - interval: 86400, + // interval: 86400, + interval: 3600, ); } @@ -150,9 +153,9 @@ class HealthConnectHelper extends WatchHelper { for (var point in data) { if (point.value is NumericHealthValue) { final numericValue = (point.value as NumericHealthValue).numericValue; - point.value = NumericHealthValue( - numericValue: numericValue * 100, - ); + // point.value = NumericHealthValue( + // numericValue: numericValue * 100, + // ); Vitals vitals = Vitals( value: (point.value as NumericHealthValue).numericValue.toStringAsFixed(2), timestamp: point.dateFrom.toString() @@ -161,4 +164,30 @@ class HealthConnectHelper extends WatchHelper { } } } + + void addDataToMapBloodOxygen(String s, data) { + mappedData[s] = []; + for (var point in data) { + if (point.value is NumericHealthValue) { + final numericValue = (point.value as NumericHealthValue).numericValue; + point.value = NumericHealthValue( + numericValue: numericValue * 100, + ); + Vitals vitals = Vitals(value: (point.value as NumericHealthValue).numericValue.toStringAsFixed(2), timestamp: point.dateFrom.toString()); + mappedData[s]?.add(vitals); + } + } + } + + getMappedData() { + return " { \"heartRate\": ${mappedData["heartRate"] ?? []}, \"sleep\": ${mappedData["sleep"] ?? []}, \"steps\": ${mappedData["steps"] ?? []}, \"activity\": ${mappedData["activity"] ?? []}, \"bloodOxygen\": ${mappedData["bloodOxygen"] ?? []}, \"bodyTemperature\": ${mappedData["bodyTemperature"] ?? []}, \"distance\": ${mappedData["distance"] ?? []} }"; + } + + getHeartData(DateTime startDate, DateTime endDate, HealthDataType types) async { + return await health.getHealthDataFromTypes( + startTime: startDate, + endTime: endDate, + types: [types], + ); + } } diff --git a/lib/presentation/smartwatches/activity_detail.dart b/lib/presentation/smartwatches/activity_detail.dart index 21d168ad..78527140 100644 --- a/lib/presentation/smartwatches/activity_detail.dart +++ b/lib/presentation/smartwatches/activity_detail.dart @@ -125,6 +125,7 @@ class _ActivityDetailsState extends State { return Row( crossAxisAlignment: CrossAxisAlignment.baseline, textBaseline: TextBaseline.alphabetic, + spacing: 4.w, children: [ (averageAsDouble?.toStringAsFixed(2) ?? averageAsString ?? "N/A").toText24(color: AppColors.textGreenColor, fontWeight: FontWeight.w600), Visibility( @@ -246,7 +247,7 @@ class _ActivityDetailsState extends State { height: 300.h, maxY: 150, barColor: AppColors.bgGreenColor, - barWidth: context.read().selectedData.values.toList().first.length < 10 ? 26.w : 20.w, + barWidth: getBarWidth(), barRadius: BorderRadius.circular(8), bottomLabelColor: Colors.black, bottomLabelSize: 12, @@ -339,4 +340,20 @@ class _ActivityDetailsState extends State { static String getMonthName(DateTime date) { return DateUtil.getMonthDayAsOfLang(date.month); } + + double getBarWidth() { + var duration = context.read().selectedDuration; + switch(duration){ + case durations.Durations.daily: + return 26.w; + case durations.Durations.weekly: + return 26.w; + case durations.Durations.monthly: + return 6.w; + case durations.Durations.halfYearly: + return 26.w; + case durations.Durations.yearly: + return 18.w; + } + } } diff --git a/lib/presentation/smartwatches/smart_watch_activity.dart b/lib/presentation/smartwatches/smart_watch_activity.dart index cffb802d..678fd715 100644 --- a/lib/presentation/smartwatches/smart_watch_activity.dart +++ b/lib/presentation/smartwatches/smart_watch_activity.dart @@ -31,7 +31,7 @@ class SmartWatchActivity extends StatelessWidget { description: "Activity rings give you a quick visual reference of how active you are each day. ".needTranslation, trailingIcon: AppAssets.watchActivityTrailing, result: context.read().sumOfNonEmptyData(context.read().vitals?.activity??[]), - unitsOfMeasure: "Cal" + unitsOfMeasure: "Kcal" ).onPress((){ // Map> getVitals() { // return { @@ -48,7 +48,7 @@ class SmartWatchActivity extends StatelessWidget { context.read().deleteDataIfSectionIsDifferent("activity"); context.read().saveSelectedSection("activity"); context.read().fetchData(); - context.read().navigateToDetails("activity", sectionName:"Activity Calories", uom: "cal"); + context.read().navigateToDetails("activity", sectionName:"Activity Calories", uom: "Kcal"); }), resultItem( diff --git a/lib/splashPage.dart b/lib/splashPage.dart index dc7a7c98..326665e9 100644 --- a/lib/splashPage.dart +++ b/lib/splashPage.dart @@ -57,7 +57,7 @@ class _SplashScreenState extends State { await notificationService.initialize(onNotificationClick: (payload) { // Handle notification click here }); - ZoomService().initializeZoomSDK(); + // ZoomService().initializeZoomSDK(); if (isAppOpenedFromCall) { navigateToTeleConsult(); } else {