Commit aee84ff0 authored by Stefan Haslinger's avatar Stefan Haslinger

hide db from PowerZone

parent a7099b3e
......@@ -581,12 +581,12 @@ class Activity {
Future<void> autoTagger({@required Athlete athlete}) async {
final PowerZone powerZone = await this.powerZone;
if (powerZone.db != null) {
if (powerZone.id != null) {
final Tag powerTag = await Tag.autoPowerTag(
athlete: athlete,
color: powerZone.db.color,
sortOrder: powerZone.db.lowerLimit,
name: powerZone.db.name,
color: powerZone.color,
sortOrder: powerZone.lowerLimit,
name: powerZone.name,
);
await ActivityTagging.createBy(
activity: this,
......
......@@ -10,9 +10,9 @@ class BarZone {
return <BarZone>[
for (final PowerZone powerZone in powerZones)
BarZone(
lower: powerZone.db.lowerLimit.toDouble(),
upper: powerZone.db.upperLimit.toDouble(),
color: powerZone.db.color,
lower: powerZone.lowerLimit.toDouble(),
upper: powerZone.upperLimit.toDouble(),
color: powerZone.color,
)
];
}
......
......@@ -311,12 +311,12 @@ class Lap {
Future<void> autoTagger({@required Athlete athlete}) async {
final PowerZone powerZone = await this.powerZone;
if (powerZone.db != null) {
if (powerZone.id != null) {
final Tag powerTag = await Tag.autoPowerTag(
athlete: athlete,
sortOrder: powerZone.db.lowerLimit,
color: powerZone.db.color,
name: powerZone.db.name,
sortOrder: powerZone.lowerLimit,
color: powerZone.color,
name: powerZone.name,
);
await LapTagging.createBy(
lap: this,
......
......@@ -12,7 +12,7 @@ class PowerZone {
int lowerLimit,
int upperLimit,
int color}) {
db = DbPowerZone()
_db = DbPowerZone()
..powerZoneSchemataId = powerZoneSchema.id
..name = name ?? 'My Zone'
..lowerLimit = lowerLimit ?? 70
......@@ -22,17 +22,39 @@ class PowerZone {
..color = color ?? 0xFFFFc107;
if (lowerPercentage != null)
db.lowerLimit = (lowerPercentage * powerZoneSchema.base / 100).round();
lowerLimit = (lowerPercentage * powerZoneSchema.base / 100).round();
if (upperPercentage != null)
db.upperLimit = (upperPercentage * powerZoneSchema.base / 100).round();
upperLimit = (upperPercentage * powerZoneSchema.base / 100).round();
}
PowerZone.fromDb(this.db);
PowerZone.fromDb(this._db);
DbPowerZone db;
DbPowerZone _db;
int get id => _db.id;
int get color => _db.color;
String get name => _db.name;
int get lowerLimit => _db.lowerLimit;
int get upperLimit => _db.upperLimit;
int get lowerPercentage => _db.lowerPercentage;
int get upperPercentage => _db.upperPercentage;
set color(int value) => _db.color = value;
set name(String value) => _db.name = value;
set lowerLimit(int value) => _db.lowerLimit = value;
set upperLimit(int value) => _db.upperLimit = value;
set lowerPercentage(int value) => _db.lowerPercentage = value;
set upperPercentage(int value) => _db.upperPercentage = value;
set powerZoneSchemataId(int value) => _db.powerZoneSchemataId = value;
set id(int value) => _db.id = value;
@override
String toString() => '< PowerZone | ${db.name} | ${db.lowerLimit} >';
String toString() => '< PowerZone | $name | $lowerLimit >';
Future<BoolResult> delete() async => await _db.delete();
Future<int> save() async => await _db.save();
Future<BoolResult> delete() async => await db.delete();
static Future<BoolCommitResult> upsertAll(List<PowerZone> powerZones) async {
return await DbPowerZone().upsertAll(
powerZones.map((PowerZone powerZone) => powerZone._db).toList());
}
}
......@@ -68,35 +68,35 @@ class PowerZoneSchema {
lowerPercentage: 65,
upperPercentage: 80,
color: Colors.lightGreen.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Moderate',
lowerPercentage: 80,
upperPercentage: 90,
color: Colors.lightBlue.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Threshold',
lowerPercentage: 90,
upperPercentage: 100,
color: Colors.yellow.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Interval',
lowerPercentage: 100,
upperPercentage: 115,
color: Colors.orange.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Repetition',
lowerPercentage: 115,
upperPercentage: 130,
color: Colors.red.value,
).db.save();
).save();
}
Future<void> addJimVanceZones() async {
......@@ -106,49 +106,49 @@ class PowerZoneSchema {
lowerPercentage: 0,
upperPercentage: 81,
color: Colors.grey.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Endurance',
lowerPercentage: 81,
upperPercentage: 88,
color: Colors.lightGreen.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Tempo',
lowerPercentage: 88,
upperPercentage: 95,
color: Colors.lightBlue.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Threshold',
lowerPercentage: 95,
upperPercentage: 105,
color: Colors.yellow.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'High Intensity',
lowerPercentage: 105,
upperPercentage: 115,
color: Colors.orange.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'VO2',
lowerPercentage: 115,
upperPercentage: 128,
color: Colors.red.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Peak',
lowerPercentage: 128,
upperPercentage: 150,
color: Colors.purple.value,
).db.save();
).save();
}
Future<void> addStefanDillingerZones() async {
......@@ -158,42 +158,42 @@ class PowerZoneSchema {
lowerPercentage: 70,
upperPercentage: 80,
color: Colors.lightBlue.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Z2',
lowerPercentage: 80,
upperPercentage: 88,
color: Colors.lightGreen.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Z3',
lowerPercentage: 88,
upperPercentage: 95,
color: Colors.yellow.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Z4',
lowerPercentage: 95,
upperPercentage: 105,
color: Colors.orange.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Z5',
lowerPercentage: 105,
upperPercentage: 115,
color: Colors.red.value,
).db.save();
).save();
await PowerZone(
powerZoneSchema: this,
name: 'Z6',
lowerPercentage: 115,
upperPercentage: 130,
color: Colors.purple.value,
).db.save();
).save();
}
@override
......
......@@ -376,13 +376,13 @@ class RecordList<E> extends DelegatingList<E> {
for (final PowerZone powerZone in powerZones.reversed) {
final int numberInZone = _records
.where((Event event) =>
(event.db.power >= powerZone.db.lowerLimit) &&
(event.db.power <= powerZone.db.upperLimit))
(event.db.power >= powerZone.lowerLimit) &&
(event.db.power <= powerZone.upperLimit))
.length;
distributions.add(BarZone(
lower: counter,
upper: counter + numberInZone,
color: powerZone.db.color,
color: powerZone.color,
));
counter = counter + numberInZone;
}
......
......@@ -7,7 +7,6 @@ import 'package:encrateia/models/power_zone.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
import 'package:encrateia/model/model.dart';
import 'add_power_zone_screen.dart';
class AddPowerZoneSchemaScreen extends StatefulWidget {
......@@ -98,16 +97,16 @@ class _AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
],
rows: powerZones.map((PowerZone powerZone) {
return DataRow(
key: ValueKey<int>(powerZone.db.id),
key: ValueKey<int>(powerZone.id),
cells: <DataCell>[
DataCell(Text(powerZone.db.name)),
DataCell(Text(powerZone.db.lowerLimit.toString() +
DataCell(Text(powerZone.name)),
DataCell(Text(powerZone.lowerLimit.toString() +
' - ' +
powerZone.db.upperLimit.toString())),
powerZone.upperLimit.toString())),
DataCell(CircleColor(
circleSize: 20,
elevation: 0,
color: Color(powerZone.db.color),
color: Color(powerZone.color),
)),
DataCell(
MyIcon.edit,
......@@ -172,8 +171,7 @@ class _AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
Future<void> savePowerZoneSchema(BuildContext context) async {
await widget.powerZoneSchema.save();
await DbPowerZone()
.upsertAll(powerZones.map((PowerZone powerZone) => powerZone.db).toList());
await PowerZone.upsertAll(powerZones);
Navigator.of(context).pop();
}
......@@ -191,10 +189,10 @@ class _AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
setState(() {
widget.powerZoneSchema.base = base;
for (final PowerZone powerZone in powerZones) {
powerZone.db.lowerLimit =
(powerZone.db.lowerPercentage * base / 100).round();
powerZone.db.upperLimit =
(powerZone.db.upperPercentage * base / 100).round();
powerZone.lowerLimit =
(powerZone.lowerPercentage * base / 100).round();
powerZone.upperLimit =
(powerZone.upperPercentage * base / 100).round();
}
});
return null;
......@@ -206,12 +204,11 @@ class _AddPowerZoneSchemaScreenState extends State<AddPowerZoneSchemaScreen> {
..id = null;
final int powerZoneSchemaId = await widget.powerZoneSchema.save();
for (final PowerZone powerZone in powerZones) {
powerZone.db
powerZone
..powerZoneSchemataId = powerZoneSchemaId
..id = null;
}
await DbPowerZone()
.upsertAll(powerZones.map((PowerZone powerZone) => powerZone.db).toList());
await PowerZone.upsertAll(powerZones);
await getData();
showDialog<BuildContext>(
context: context,
......
......@@ -35,8 +35,8 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
Navigator.of(context).pop();
MaterialColorPicker(
onColorChange: (Color color) =>
widget.powerZone.db.color = color.value,
selectedColor: Color(widget.powerZone.db.color));
widget.powerZone.color = color.value,
selectedColor: Color(widget.powerZone.color));
},
),
],
......@@ -48,8 +48,8 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
Future<void> openColorPicker() async {
_openDialog(
MaterialColorPicker(
selectedColor: Color(widget.powerZone.db.color),
onColorChange: (Color color) => setState(() => widget.powerZone.db.color = color.value),
selectedColor: Color(widget.powerZone.color),
onColorChange: (Color color) => setState(() => widget.powerZone.color = color.value),
onBack: () {},
),
);
......@@ -58,13 +58,13 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
@override
Widget build(BuildContext context) {
final TextEditingController lowerLimitController =
TextEditingController(text: widget.powerZone.db.lowerLimit.toString());
TextEditingController(text: widget.powerZone.lowerLimit.toString());
final TextEditingController upperLimitController =
TextEditingController(text: widget.powerZone.db.upperLimit.toString());
TextEditingController(text: widget.powerZone.upperLimit.toString());
final TextEditingController lowerPercentageController = TextEditingController(
text: widget.powerZone.db.lowerPercentage.toString());
text: widget.powerZone.lowerPercentage.toString());
final TextEditingController upperPercentageController = TextEditingController(
text: widget.powerZone.db.upperPercentage.toString());
text: widget.powerZone.upperPercentage.toString());
return Scaffold(
appBar: AppBar(
......@@ -76,16 +76,16 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
children: <Widget>[
TextFormField(
decoration: const InputDecoration(labelText: 'Name'),
initialValue: widget.powerZone.db.name,
onChanged: (String value) => widget.powerZone.db.name = value,
initialValue: widget.powerZone.name,
onChanged: (String value) => widget.powerZone.name = value,
),
TextFormField(
decoration: const InputDecoration(labelText: 'Lower Limit in W'),
controller: lowerLimitController,
keyboardType: TextInputType.number,
onChanged: (String value) {
widget.powerZone.db.lowerLimit = int.parse(value);
widget.powerZone.db.lowerPercentage =
widget.powerZone.lowerLimit = int.parse(value);
widget.powerZone.lowerPercentage =
(int.parse(value) * 100 / widget.base).round();
lowerPercentageController.text =
(int.parse(value) * 100 / widget.base).round().toString();
......@@ -96,8 +96,8 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
controller: upperLimitController,
keyboardType: TextInputType.number,
onChanged: (String value) {
widget.powerZone.db.upperLimit = int.parse(value);
widget.powerZone.db.upperPercentage =
widget.powerZone.upperLimit = int.parse(value);
widget.powerZone.upperPercentage =
(int.parse(value) * 100 / widget.base).round();
upperPercentageController.text =
(int.parse(value) * 100 / widget.base).round().toString();
......@@ -108,8 +108,8 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
controller: lowerPercentageController,
keyboardType: TextInputType.number,
onChanged: (String value) {
widget.powerZone.db.lowerPercentage = int.parse(value);
widget.powerZone.db.lowerLimit =
widget.powerZone.lowerPercentage = int.parse(value);
widget.powerZone.lowerLimit =
(int.parse(value) * widget.base / 100).round();
lowerLimitController.text =
(int.parse(value) * widget.base / 100).round().toString();
......@@ -120,8 +120,8 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
controller: upperPercentageController,
keyboardType: TextInputType.number,
onChanged: (String value) {
widget.powerZone.db.upperPercentage = int.parse(value);
widget.powerZone.db.upperLimit =
widget.powerZone.upperPercentage = int.parse(value);
widget.powerZone.upperLimit =
(int.parse(value) * widget.base / 100).round();
upperLimitController.text =
(int.parse(value) * widget.base / 100).round().toString();
......@@ -132,7 +132,7 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
const Text('Color'),
const Spacer(),
CircleAvatar(
backgroundColor: Color(widget.powerZone.db.color),
backgroundColor: Color(widget.powerZone.color),
radius: 20.0,
),
const Spacer(),
......@@ -158,12 +158,12 @@ class _AddPowerZoneScreenState extends State<AddPowerZoneScreen> {
}
Future<void> savePowerZone(BuildContext context) async {
await widget.powerZone.db.save();
await widget.powerZone.save();
Navigator.of(context).pop();
}
Future<void> deletePowerZone(BuildContext context) async {
await widget.powerZone.db.delete();
await widget.powerZone.delete();
Navigator.of(context).pop();
}
}
......@@ -70,11 +70,11 @@ class GraphUtils {
rangeAnnotationSegmentList = <RangeAnnotationSegment<int>>[
for (PowerZone powerZone in powerZones)
RangeAnnotationSegment<int>(
powerZone.db.lowerLimit,
powerZone.db.upperLimit,
powerZone.lowerLimit,
powerZone.upperLimit,
RangeAnnotationAxisType.measure,
startLabel: powerZone.db.name,
color: convertedColor(dbColor: powerZone.db.color),
startLabel: powerZone.name,
color: convertedColor(dbColor: powerZone.color),
)
];
}
......
......@@ -92,7 +92,7 @@ class MyBarChart extends StatelessWidget {
return maximum.toDouble();
else if (powerZones != null)
return powerZones
.map((PowerZone powerZone) => powerZone.db.upperLimit.toDouble())
.map((PowerZone powerZone) => powerZone.upperLimit.toDouble())
.reduce(math.max);
else if (heartRateZones != null)
return heartRateZones
......@@ -111,7 +111,7 @@ class MyBarChart extends StatelessWidget {
return minimum.toDouble();
else if (powerZones != null)
return powerZones
.map((PowerZone powerZone) => powerZone.db.lowerLimit.toDouble())
.map((PowerZone powerZone) => powerZone.lowerLimit.toDouble())
.reduce(math.min);
else if (heartRateZones != null)
return heartRateZones
......
......@@ -68,11 +68,11 @@ class MyLineChart extends LineChart {
if (powerZones != null)
return NumericExtents(
powerZones
.map((PowerZone powerZone) => powerZone.db.lowerLimit)
.map((PowerZone powerZone) => powerZone.lowerLimit)
.reduce(min) -
5.0,
powerZones
.map((PowerZone powerZone) => powerZone.db.upperLimit)
.map((PowerZone powerZone) => powerZone.upperLimit)
.reduce(max) +
5.0);
else if (heartRateZones != null)
......
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