getPeriodRegularityScore method
Calculate period regularity score
Implementation
Future<double> getPeriodRegularityScore() async {
List<int> periodLengths = [];
List<PeriodsDateRange> allPeriodRange = await getAllPeriodsDetails();
if (allPeriodRange.length > 1) {
for (int i = 1; i < allPeriodRange.length; i++) {
//printMenstrualCycleLogs("Len: ${allPeriodRange[i].periodDuration!}");
periodLengths.add(allPeriodRange[i].periodDuration!);
}
}
if (periodLengths.isNotEmpty) {
//Calculate Average period duration (APL)
double avgPeriodLength = _average(periodLengths);
// Calculate Standard Deviation (SD)
double standardDeviation = _stdDev(periodLengths, avgPeriodLength);
// Calculate Cycle Regularity Score (CRS)
double crs = 100 - ((standardDeviation / avgPeriodLength) * 100);
// Ensure CRS is in the range of 0 to 100
return crs.clamp(0, 100);
}
return 0.0;
}