health_kit_raw_data_api.dart 3.11 KB
import 'package:pigeon/pigeon.dart';

class HealthKitRawDataPoint {
  int dataType;
  int startTime;
  int endTime;
  double? value;
  bool? isMotionLike;

  HealthKitRawDataPoint({
    required this.dataType,
    required this.startTime,
    required this.endTime,
    this.value,
    this.isMotionLike,
  });
}

class HealthKitRawSleepDataPoint {
  int dataType;
  List<HealthKitRawDataPoint> sleepDataPoints;
  HealthKitRawSleepDataPoint({
    required this.dataType,
    required this.sleepDataPoints,
  });
}

class HealthKitRawWorkoutDataPoint {
  int workoutType;
  int startTime;
  int endTime;

  HealthKitRawWorkoutDataPoint({
    required this.workoutType,
    required this.startTime,
    required this.endTime,
  });
}

class HealthKitRawMotionDataPoint {
  int motionType;
  int startTime;
  int endTime;

  HealthKitRawMotionDataPoint({
    required this.motionType,
    required this.startTime,
    required this.endTime,
  });
}

class HealthKitRawActivityDataPoint {
  int endTime;
  // 千卡
  double? activeEnergyBurned;
  double? activeEnergyBurnedGoal;
  // 公里
  double? appleMoveTime;
  double? appleMoveTimeGoal;
  // 分钟
  double? appleExerciseTime;
  double? exerciseTimeGoal;
//小时
  double? appleStandHours;
  double? standHoursGoal;

  HealthKitRawActivityDataPoint({
    required this.endTime,
    this.activeEnergyBurned,
    this.activeEnergyBurnedGoal,
    this.appleMoveTime,
    this.appleMoveTimeGoal,
    this.appleExerciseTime,
    this.exerciseTimeGoal,
    this.appleStandHours,
    this.standHoursGoal,
  });
}

@ConfigurePigeon(
  PigeonOptions(
    dartOut: 'lib/pigeon/health_kit_raw_data_api.g.dart',
    dartPackageName: 'doublefeel_flutter',
    dartOptions: DartOptions(),
    swiftOut: 'ios/Runner/Pigeon/HealthKitRawDataApi.swift',
    swiftOptions: SwiftOptions(),
    copyrightHeader: 'pigeon/copyright.txt',
  ),
)
@HostApi()
abstract class HealthKitRawDataHostApi {
  /// 是否有AppleHealth数据
  @async
  bool hasHealthData();

  /// 从AppleHealth 中读取原始数据
  @async
  List<HealthKitRawDataPoint> getHealthKitRawData(
      int dataType, int startTime, int endTime);

  /// 原生数据上传
  @async
  bool performHealthDataUpload();

  /// 上传心率 - 实时压力数据, 返回上传截止的时间戳, 方便flutter修改数据库
  @async
  int performHRDataUpload({required String sqliteFilePath});

  /// 上传HRV - HRV压力数据, 返回上传截止的时间戳,方便flutter 修改数据库
  @async
  int performHRVDataUpload({required String sqliteFilePath});

  /// 上传当前实时压力(统计维度是当天)
  @async
  bool performAvgRealtimeStressDataUpload({required String sqliteFilePath});

  /// 从从AppleHealth中读取睡眠数据
  @async
  List<HealthKitRawSleepDataPoint> getHealthKitRawSleepData(
      int startTime, int endTime);

  /// 从从AppleHealth中读取活动统计数据
  @async
  List<HealthKitRawActivityDataPoint> getHealthKitRawActivityData(
      int startTime, int endTime);

  /// 从从AppleHealth中读取锻炼数据
  @async
  List<HealthKitRawWorkoutDataPoint> getHealthKitRawWorkoutData(
      int startTime, int endTime);
}