Commit baccafba authored by Administrator's avatar Administrator

filter 0 and null values from heart rate and power

parent c8497bca
......@@ -4,7 +4,6 @@ import 'package:encrateia/utils/date_time_utils.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'package:encrateia/models/event.dart';
import 'activity.dart';
import 'dart:math';
class Lap {
DbLap db;
......@@ -94,12 +93,12 @@ class Lap {
static String minHeartRate({List<Event> records}) {
var heartRates = records.map((record) => record.db.heartRate);
return heartRates.reduce(min).toStringAsFixed(1);
return heartRates.min().toStringAsFixed(1);
}
static String maxHeartRate({List<Event> records}) {
var heartRates = records.map((record) => record.db.heartRate);
return heartRates.reduce(max).toStringAsFixed(1);
return heartRates.max().toStringAsFixed(1);
}
static String averagePower({List<Event> records}) {
......@@ -114,11 +113,11 @@ class Lap {
static String minPower({List<Event> records}) {
var powers = records.map((record) => record.db.power);
return powers.reduce(min).toStringAsFixed(1);
return powers.min().toStringAsFixed(1);
}
static String maxPower({List<Event> records}) {
var powers = records.map((record) => record.db.power);
return powers.reduce(max).toStringAsFixed(1);
return powers.max().toStringAsFixed(1);
}
}
import 'dart:math';
import 'dart:math' as math;
extension StatisticFunctions on Iterable {
double mean() {
List<int> records = this.toList();
var sum = records.reduce((a, b) => a + b);
var number = records.length;
var nonZeroValues = this.nonZero();
var sum = nonZeroValues.reduce((a, b) => a + b);
var number = nonZeroValues.length;
return sum / number;
}
double sdev() {
List<int> records = this.toList();
var mean = records.mean();
var nonZeroValues = this.nonZero();
var mean = nonZeroValues.mean();
var sumOfErrorSquares =
records.fold(0.0, (double sum, next) => sum + pow(next - mean, 2));
var variance = sumOfErrorSquares / records.length;
return sqrt(variance);
var sumOfErrorSquares = nonZeroValues.fold(
0.0, (double sum, next) => sum + math.pow(next - mean, 2));
var variance = sumOfErrorSquares / nonZeroValues.length;
return math.sqrt(variance);
}
int min() {
return this.nonZero().reduce(math.min);
}
int max() {
return this.nonZero().reduce(math.max);
}
List<int> nonZero() {
List<int> values = this.toList();
var nonZeroValues = values.where((value) => value != null && value != 0);
return nonZeroValues.toList();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment