addDummyData method

Future<void> addDummyData({
  1. int numberOfDay = 365,
  2. Function? onSuccess,
  3. Function? onError,
  4. List<SymptomsData>? symptomsData,
})

Implementation

Future<void> addDummyData(
    {int numberOfDay = 365,
    Function? onSuccess,
    Function? onError,
    List<SymptomsData>? symptomsData}) async {
  if (numberOfDay < 1) {
    throw "Required valid day";
  }

  // clear data
  final dbHelper = MenstrualCycleDbHelper.instance;
  String encryptedUserid = getCustomerId();
  // Clear period data
  await dbHelper.clearPeriodLog(encryptedUserid);
  // Clear symptoms data
  await dbHelper.clearSymptomsLog(encryptedUserid);

  final random = Random();
  int randomPeriodLength = 4 + random.nextInt(1);
  int randomCycleLength = 25 + random.nextInt(5);
  //printMenstrualCycleLogs("-------- Start Process --------");
  try {
    // Start period data

    for (int i = numberOfDay; i > 0; i--) {
      DateTime periodStartDate = DateTime.now().add(Duration(days: -i));
      /*printMenstrualCycleLogs(
          "-------- Period Day (${CalenderDateUtils.dateDayFormat(periodStartDate)}) -------- $i");
      printMenstrualCycleLogs(
          "-------- randomCycleLength $randomCycleLength --------");*/
      List<DateTime> selectedPeriodsDate = [];
      selectedPeriodsDate.add(periodStartDate);
      for (int index = 1; index <= randomPeriodLength; index++) {
        DateTime nextPeriodDate = periodStartDate.add(Duration(days: index));
        /* printMenstrualCycleLogs(
            "-------- Next Period Day (${CalenderDateUtils.dateDayFormat(nextPeriodDate)}) --------");*/
        selectedPeriodsDate.add(nextPeriodDate);
      }

      await dbHelper.insertPeriodLog(selectedPeriodsDate);
      // Start Symptoms data
      for (int cycleIndex = 0; cycleIndex < randomCycleLength; cycleIndex++) {
        await saveSymptomsLogs(
          userSymptomsData: getRandomSymptomsData(symptomsData),
          onError: () {},
          waterValue: "${random.nextInt(20)}",
          weight: "${20 + random.nextInt(60)}.0",
          bodyTemperature: "${35 + random.nextInt(40)}.${random.nextInt(99)}",
          meditationTime: "${random.nextInt(120)}",
          sleepBedTime: TimeOfDay(
              minute: 0 + random.nextInt(55), hour: 19 + random.nextInt(3)),
          sleepWakeUpTime: TimeOfDay(
              minute: 0 + random.nextInt(55), hour: 4 + random.nextInt(3)),
          cycleDay: cycleIndex + 1,
          symptomsLogDate: periodStartDate.add(Duration(days: cycleIndex)),
          onSuccess: (id) {},
        );
      }

      i = i - randomCycleLength + 1; // length of cycle
      randomPeriodLength = 4 + random.nextInt(2);
      randomCycleLength = 25 + random.nextInt(5);
    }
  } catch (e) {
    onError!.call();
  }
  calculateLastPeriodDate();
  onSuccess!.call();
  //printMenstrualCycleLogs("-------- End Process --------");
}