Commit f293be6b authored by Administrator's avatar Administrator

a bit of code cleanup

parent 85277900
......@@ -63,7 +63,7 @@ class Activity extends ChangeNotifier {
String toString() => '< Activity | ${db.name} | ${db.startTime} >';
Duration movingDuration() => Duration(seconds: db.movingTime ?? 0);
get({ActivityAttr activityAttr}) {
getAttribute(ActivityAttr activityAttr) {
switch (activityAttr) {
case ActivityAttr.avgPower:
return db.avgPower;
......@@ -496,7 +496,7 @@ class Activity extends ChangeNotifier {
return activities;
}
getPowerZoneSchema() async {
get powerZoneSchema async {
if (_powerZoneSchema == null) {
_powerZoneSchema = await PowerZoneSchema.getBy(
athletesId: db.athletesId,
......@@ -506,7 +506,7 @@ class Activity extends ChangeNotifier {
return _powerZoneSchema;
}
getHeartRateZoneSchema() async {
get heartRateZoneSchema async {
if (_heartRateZoneSchema == null) {
_heartRateZoneSchema = await HeartRateZoneSchema.getBy(
athletesId: db.athletesId,
......@@ -516,13 +516,12 @@ class Activity extends ChangeNotifier {
return _heartRateZoneSchema;
}
getPowerZone() async {
get powerZone async {
if (_powerZone == null) {
var powerZoneSchema = await getPowerZoneSchema();
var dbPowerZone = await DbPowerZone()
.select()
.powerZoneSchemataId
.equals(powerZoneSchema.db.id)
.equals((await powerZoneSchema).db.id)
.and
.lowerLimit
.lessThanOrEquals(db.avgPower)
......@@ -535,13 +534,12 @@ class Activity extends ChangeNotifier {
return _powerZone;
}
getHeartRateZone() async {
get heartRateZone async {
if (_heartRateZone == null) {
var heartRateZoneSchema = await getHeartRateZoneSchema();
var dbHeartRateZone = await DbHeartRateZone()
.select()
.heartRateZoneSchemataId
.equals(heartRateZoneSchema.db.id)
.equals((await heartRateZoneSchema).db.id)
.and
.lowerLimit
.lessThanOrEquals(db.avgHeartRate)
......@@ -556,7 +554,7 @@ class Activity extends ChangeNotifier {
}
autoTagger({@required Athlete athlete}) async {
PowerZone powerZone = await getPowerZone();
var powerZone = await this.powerZone;
if (powerZone.db != null) {
Tag powerTag = await Tag.autoPowerTag(
athlete: athlete,
......@@ -571,7 +569,7 @@ class Activity extends ChangeNotifier {
);
}
HeartRateZone heartRateZone = await getHeartRateZone();
var heartRateZone = await this.heartRateZone;
if (heartRateZone.db != null) {
Tag heartRateTag = await Tag.autoHeartRateTag(
athlete: athlete,
......
......@@ -15,7 +15,7 @@ class ActivityList<E> extends DelegatingList<E> {
@required ActivityAttr activityAttr,
}) {
_activities.asMap().forEach((index, activity) {
double sumOfAvg = activity.get(activityAttr: activityAttr) * fullDecay;
double sumOfAvg = activity.getAttribute(activityAttr) * fullDecay;
double sumOfWeightings = fullDecay * 1.0;
for (var olderIndex = index + 1;
olderIndex < _activities.length;
......@@ -26,7 +26,7 @@ class ActivityList<E> extends DelegatingList<E> {
24;
if (daysAgo > fullDecay) break;
sumOfAvg += (fullDecay - daysAgo) *
_activities[olderIndex].get(activityAttr: activityAttr);
_activities[olderIndex].getAttribute(activityAttr);
sumOfWeightings += (fullDecay - daysAgo);
}
......
......@@ -121,7 +121,6 @@ class Event {
event.index = counter;
counter = counter + 1;
}
return eventList;
}
......@@ -137,7 +136,6 @@ class Event {
event.index = counter;
counter = counter + 1;
}
return eventList;
}
}
......@@ -74,14 +74,14 @@ class Lap {
return lap;
}
Future<List<Event>> get records async {
get records async {
if (_records == null) {
_records = await Event.recordsByLap(lap: this);
}
return _records;
}
Future<double> get avgPower async {
get avgPower async {
if (db.avgPower == null) {
db.avgPower = RecordList(await this.records).calculateAveragePower();
await db.save();
......@@ -89,7 +89,7 @@ class Lap {
return db.avgPower;
}
Future<double> get sdevPower async {
get sdevPower async {
if (db.sdevPower == null) {
db.sdevPower = RecordList(await this.records).calculateSdevPower();
await db.save();
......@@ -97,7 +97,7 @@ class Lap {
return db.sdevPower;
}
Future<int> get minPower async {
get minPower async {
if (db.minPower == null) {
db.minPower = RecordList(await this.records).calculateMinPower();
await db.save();
......@@ -105,7 +105,7 @@ class Lap {
return db.minPower;
}
Future<int> get maxPower async {
get maxPower async {
if (db.maxPower == null) {
db.maxPower = RecordList(await this.records).calculateMaxPower();
await db.save();
......@@ -113,7 +113,7 @@ class Lap {
return db.maxPower;
}
Future<double> get avgGroundTime async {
get avgGroundTime async {
if (db.avgGroundTime == null) {
db.avgGroundTime =
RecordList(await this.records).calculateAverageGroundTime();
......@@ -122,7 +122,7 @@ class Lap {
return db.avgGroundTime;
}
Future<double> get sdevGroundTime async {
get sdevGroundTime async {
if (db.sdevGroundTime == null) {
db.sdevGroundTime =
RecordList(await this.records).calculateSdevGroundTime();
......@@ -131,7 +131,7 @@ class Lap {
return db.sdevGroundTime;
}
Future<double> get avgVerticalOscillation async {
get avgVerticalOscillation async {
if (db.avgVerticalOscillation == null ||
db.avgVerticalOscillation == 6553.5) {
db.avgVerticalOscillation =
......@@ -141,7 +141,7 @@ class Lap {
return db.avgVerticalOscillation;
}
Future<double> get sdevVerticalOscillation async {
get sdevVerticalOscillation async {
if (db.sdevVerticalOscillation == null) {
db.sdevVerticalOscillation =
RecordList(await this.records).calculateSdevVerticalOscillation();
......@@ -150,7 +150,7 @@ class Lap {
return db.sdevVerticalOscillation;
}
Future<double> get avgStrydCadence async {
get avgStrydCadence async {
if (db.avgStrydCadence == null) {
db.avgStrydCadence =
RecordList(await this.records).calculateAverageStrydCadence();
......@@ -159,7 +159,7 @@ class Lap {
return db.avgStrydCadence;
}
Future<double> get sdevStrydCadence async {
get sdevStrydCadence async {
if (db.sdevStrydCadence == null) {
db.sdevStrydCadence =
RecordList(await this.records).calculateSdevStrydCadence();
......@@ -168,7 +168,7 @@ class Lap {
return db.sdevStrydCadence;
}
Future<double> get avgLegSpringStiffness async {
get avgLegSpringStiffness async {
if (db.avgLegSpringStiffness == null) {
db.avgLegSpringStiffness =
RecordList(await this.records).calculateAverageLegSpringStiffness();
......@@ -177,7 +177,7 @@ class Lap {
return db.avgLegSpringStiffness;
}
Future<double> get sdevLegSpringStiffness async {
get sdevLegSpringStiffness async {
if (db.sdevLegSpringStiffness == null) {
db.sdevLegSpringStiffness =
RecordList(await this.records).calculateSdevLegSpringStiffness();
......@@ -186,7 +186,7 @@ class Lap {
return db.sdevLegSpringStiffness;
}
Future<double> get avgFormPower async {
get avgFormPower async {
if (db.avgFormPower == null) {
db.avgFormPower =
RecordList(await this.records).calculateAverageFormPower();
......@@ -195,7 +195,7 @@ class Lap {
return db.avgFormPower;
}
Future<double> get sdevFormPower async {
get sdevFormPower async {
if (db.sdevFormPower == null) {
db.sdevFormPower =
RecordList(await this.records).calculateSdevFormPower();
......@@ -219,7 +219,7 @@ class Lap {
return lapList;
}
getPowerZoneSchema() async {
get powerZoneSchema async {
if (_powerZoneSchema == null) {
var dbActivity = await DbActivity().getById(db.activitiesId);
......@@ -231,7 +231,7 @@ class Lap {
return _powerZoneSchema;
}
getHeartRateZoneSchema() async {
get heartRateZoneSchema async {
if (_heartRateZoneSchema == null) {
var dbActivity = await DbActivity().getById(db.activitiesId);
......@@ -260,13 +260,12 @@ class Lap {
await db.save();
}
getPowerZone() async {
get powerZone async {
if (_powerZone == null) {
var powerZoneSchema = await getPowerZoneSchema();
var dbPowerZone = await DbPowerZone()
.select()
.powerZoneSchemataId
.equals(powerZoneSchema.db.id)
.equals((await powerZoneSchema).db.id)
.and
.lowerLimit
.lessThanOrEquals(db.avgPower)
......@@ -279,13 +278,12 @@ class Lap {
return _powerZone;
}
getHeartRateZone() async {
get heartRateZone async {
if (_heartRateZone == null) {
var heartRateZoneSchema = await getHeartRateZoneSchema();
var dbHeartRateZone = await DbHeartRateZone()
.select()
.heartRateZoneSchemataId
.equals(heartRateZoneSchema.db.id)
.equals((await heartRateZoneSchema).db.id)
.and
.lowerLimit
.lessThanOrEquals(db.avgHeartRate)
......@@ -300,7 +298,7 @@ class Lap {
}
autoTagger({@required Athlete athlete}) async {
PowerZone powerZone = await getPowerZone();
var powerZone = await this.powerZone;
if (powerZone.db != null) {
Tag powerTag = await Tag.autoPowerTag(
athlete: athlete,
......@@ -315,7 +313,7 @@ class Lap {
);
}
HeartRateZone heartRateZone = await getHeartRateZone();
var heartRateZone = await this.heartRateZone;
if (heartRateZone.db != null) {
Tag heartRateTag = await Tag.autoHeartRateTag(
athlete: athlete,
......
......@@ -4,7 +4,7 @@ class IntPlotPoint {
IntPlotPoint({this.domain, this.measure});
String toString() => '< IntPlotPoint | $domain | $measure >';
toString() => '< IntPlotPoint | $domain | $measure >';
}
class DoublePlotPoint {
......@@ -13,5 +13,5 @@ class DoublePlotPoint {
DoublePlotPoint({this.domain, this.measure});
String toString() => '< DoublePlotPoint | $domain | $measure >';
toString() => '< DoublePlotPoint | $domain | $measure >';
}
......@@ -35,7 +35,7 @@ class PowerDuration {
}
}
List<IntPlotPoint> asList() {
asList() {
List<IntPlotPoint> plotPoints = [];
powerMap.forEach((duration, power) {
......@@ -49,5 +49,5 @@ class PowerDuration {
return plotPoints;
}
static int scaled({int seconds}) => (200 * log(seconds)).round();
static scaled({int seconds}) => (200 * log(seconds)).round();
}
......@@ -27,16 +27,14 @@ class PowerZone extends ChangeNotifier {
if (upperPercentage != null)
db.upperLimit = (upperPercentage * powerZoneSchema.db.base / 100).round();
}
PowerZone.fromDb(this.db);
String toString() => '< PowerZone | ${db.name} | ${db.lowerLimit} >';
delete() async {
await this.db.delete();
}
delete() async => await this.db.delete();
static Future<List<PowerZone>> all(
{@required PowerZoneSchema powerZoneSchema}) async {
static all({@required PowerZoneSchema powerZoneSchema}) async {
var dbPowerZoneList = await powerZoneSchema.db
.getDbPowerZones()
.orderByDesc('lowerlimit')
......
......@@ -179,11 +179,9 @@ class PowerZoneSchema extends ChangeNotifier {
String toString() => '< PowerZoneSchema | ${db.name} | ${db.date} >';
delete() async {
await this.db.delete();
}
delete() async => await this.db.delete();
static Future<List<PowerZoneSchema>> all({@required Athlete athlete}) async {
static all({@required Athlete athlete}) async {
var dbPowerZoneSchemaList =
await athlete.db.getDbPowerZoneSchemas().orderByDesc('date').toList();
var powerZoneSchemas = dbPowerZoneSchemaList
......@@ -192,10 +190,7 @@ class PowerZoneSchema extends ChangeNotifier {
return powerZoneSchemas;
}
static getBy({
int athletesId,
DateTime date,
}) async {
static getBy({int athletesId, DateTime date}) async {
var dbPowerZoneSchemas = await DbPowerZoneSchema()
.select()
.athletesId
......
......@@ -13,31 +13,31 @@ class RecordList<E> extends DelegatingList<E> {
: _records = records,
super(records);
String sdevHeartRate() => _records
get sdevHeartRateString => _records
.map((record) => record.db.heartRate)
.nonZeroInts()
.sdev()
.toStringAsFixed(2);
String minHeartRate() => _records
get minHeartRateString => _records
.map((record) => record.db.heartRate)
.nonZeroInts()
.min()
.toString();
String avgHeartRate() => _records
get avgHeartRateString => _records
.map((record) => record.db.heartRate)
.nonZeroInts()
.mean()
.toStringOrDashes(1);
String maxHeartRate() => _records
get maxHeartRateString => _records
.map((record) => record.db.heartRate)
.nonZeroInts()
.max()
.toString();
double calculateAveragePower() {
calculateAveragePower() {
var powers = _records
.where((record) =>
record.db.power != null &&
......@@ -51,7 +51,7 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevPower() => _records
calculateSdevPower() => _records
.where((record) =>
record.db.power != null &&
record.db.power > 0 &&
......@@ -59,7 +59,7 @@ class RecordList<E> extends DelegatingList<E> {
.map((record) => record.db.power)
.sdev();
int calculateMinPower() {
calculateMinPower() {
var powers = _records.map((record) => record.db.power).nonZeroInts();
if (powers.length > 0)
return powers.min();
......@@ -67,7 +67,7 @@ class RecordList<E> extends DelegatingList<E> {
return 0;
}
int calculateMaxPower() {
calculateMaxPower() {
var powers = _records.map((record) => record.db.power).nonZeroInts();
if (powers.length > 0)
return powers.max();
......@@ -75,7 +75,7 @@ class RecordList<E> extends DelegatingList<E> {
return 0;
}
int calculateAverageHeartRate() {
calculateAverageHeartRate() {
var heartRates = _records
.where((record) =>
record.db.heartRate != null &&
......@@ -89,7 +89,7 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevHeartRate() => _records
calculateSdevHeartRate() => _records
.where((record) =>
record.db.heartRate != null &&
record.db.heartRate > 0 &&
......@@ -97,7 +97,7 @@ class RecordList<E> extends DelegatingList<E> {
.map((record) => record.db.heartRate)
.sdev();
int calculateMinHeartRate() {
calculateMinHeartRate() {
var heartRates =
_records.map((record) => record.db.heartRate).nonZeroInts();
......@@ -107,7 +107,7 @@ class RecordList<E> extends DelegatingList<E> {
return 0;
}
int calculateMaxHeartRate() {
calculateMaxHeartRate() {
var heartRates =
_records.map((record) => record.db.heartRate).nonZeroInts();
......@@ -117,7 +117,7 @@ class RecordList<E> extends DelegatingList<E> {
return 0;
}
double calculateAverageSpeed() {
calculateAverageSpeed() {
var speeds = _records.map((record) => record.db.speed).nonZeroDoubles();
if (speeds.length > 0) {
......@@ -126,7 +126,7 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateAverageGroundTime() {
calculateAverageGroundTime() {
var groundTimes =
_records.map((record) => record.db.groundTime).nonZeroDoubles();
......@@ -136,10 +136,10 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevGroundTime() =>
calculateSdevGroundTime() =>
_records.map((record) => record.db.groundTime).nonZeroDoubles().sdev();
double calculateAverageStrydCadence() {
calculateAverageStrydCadence() {
var strydCadences = _records
.map((record) => record.db.strydCadence ?? 0.0 * 2)
.nonZeroDoubles();
......@@ -150,15 +150,14 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevStrydCadence() => _records
calculateSdevStrydCadence() => _records
.map((record) => record.db.strydCadence ?? 0.0 * 2)
.nonZeroDoubles()
.sdev();
double calculateAverageLegSpringStiffness() {
var legSpringStiffnesses = _records
.map((record) => record.db.legSpringStiffness)
.nonZeroDoubles();
calculateAverageLegSpringStiffness() {
var legSpringStiffnesses =
_records.map((record) => record.db.legSpringStiffness).nonZeroDoubles();
if (legSpringStiffnesses.length > 0) {
return legSpringStiffnesses.mean();
......@@ -166,12 +165,12 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevLegSpringStiffness() => _records
calculateSdevLegSpringStiffness() => _records
.map((record) => record.db.legSpringStiffness)
.nonZeroDoubles()
.sdev();
double calculateAverageVerticalOscillation() {
calculateAverageVerticalOscillation() {
var verticalOscillation = _records
.map((record) => record.db.verticalOscillation)
.nonZeroDoubles();
......@@ -182,12 +181,12 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevVerticalOscillation() => _records
calculateSdevVerticalOscillation() => _records
.map((record) => record.db.verticalOscillation)
.nonZeroDoubles()
.sdev();
double calculateAverageFormPower() {
calculateAverageFormPower() {
var formPowers = _records
.where((record) =>
record.db.formPower != null && record.db.formPower < 200)
......@@ -199,13 +198,13 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevFormPower() => _records
calculateSdevFormPower() => _records
.where(
(record) => record.db.formPower != null && record.db.formPower < 200)
.map((record) => record.db.formPower)
.sdev();
double calculateAveragePowerRatio() {
calculateAveragePowerRatio() {
var powerRatios = _records
.where((record) =>
record.db.power != null &&
......@@ -221,7 +220,7 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevPowerRatio() => _records
calculateSdevPowerRatio() => _records
.where((record) =>
record.db.power != null &&
record.db.power != 0 &&
......@@ -231,7 +230,7 @@ class RecordList<E> extends DelegatingList<E> {
(record.db.power - record.db.formPower) / record.db.power * 100)
.sdev();
double calculateAverageStrideRatio() {
calculateAverageStrideRatio() {
var powerRatios = _records
.where((record) =>
record.db.speed != null &&
......@@ -252,7 +251,7 @@ class RecordList<E> extends DelegatingList<E> {
return -1;
}
double calculateSdevStrideRatio() => _records
calculateSdevStrideRatio() => _records
.where((record) =>
record.db.speed != null &&
record.db.strydCadence != null &&
......@@ -302,7 +301,7 @@ class RecordList<E> extends DelegatingList<E> {
List<DoublePlotPoint> toDoubleDataPoints({
int amount,
@required LapDoubleAttr attribute,
double weight
double weight,
}) {
int index = 0;
List<DoublePlotPoint> plotPoints = [];
......
......@@ -16,7 +16,7 @@ abstract class StravaFitDownload {
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
};
static Future<int> byId({String id, Athlete athlete}) async {
static byId({String id, Athlete athlete}) async {
String exportUri = baseUri + 'activities/$id/export_original';
Directory appDocDir = await getApplicationDocumentsDirectory();
......@@ -38,7 +38,7 @@ abstract class StravaFitDownload {
}
}
static Future<bool> logInIfNecessary({Dio dio, Athlete athlete}) async {
static logInIfNecessary({Dio dio, Athlete athlete}) async {
var dashboardResponse = await getDashboard(dio: dio);
if (dashboardResponse.data.toString().contains("logged-in")) {
print("Already logged in to Strava");
......@@ -57,7 +57,7 @@ abstract class StravaFitDownload {
}
}
static Future<Response> getDashboard({Dio dio}) async {
static getDashboard({Dio dio}) async {
return await dio.get(
dashboardUri,
options: Options(headers: headers, validateStatus: (_) => true),
......
......@@ -24,12 +24,14 @@ class Tag extends ChangeNotifier {
String toString() => '< Tag | ${db.name} >';
delete() async {
await this.db.delete();
}
delete() async => await this.db.delete();
static Future<List<Tag>> all({@required TagGroup tagGroup}) async {
var dbTagList = await tagGroup.db.getDbTags().orderBy('sortOrder').orderBy('name').toList();
static all({@required TagGroup tagGroup}) async {
var dbTagList = await tagGroup.db