Skip to content

Commit

Permalink
Better presentation of min gas
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Jul 24, 2023
1 parent 0f1ff87 commit 271c821
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 40 deletions.
70 changes: 37 additions & 33 deletions lib/divecalculation/divecalculation_rockbottom_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flaska/divecalculation/divecalculation_cylinder_view.dart';
import 'package:flaska/proto/proto.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -22,23 +23,24 @@ class RockBottomView extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text("TROUBLE SOLVING AT DEPTH", style: h1),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
Expanded(
child: ValueUnit(title: "TIME", value: state.settings.troubleSolvingDuration.toString(), unit: "min"),
),
Expanded(
child: ValueUnit(title: "SAC", value: dcvm.troubleSolvingSacLabel, unit: dcvm.sacUnit),
),
Expanded(
child: ValueUnit(title: "GAS", value: dcvm.troubleSolvingVolumeLabel, unit: dcvm.volumeUnit),
),
],
if (dcvm.troubleSolvingVolume.l > 0) Text("TROUBLE SOLVING AT DEPTH", style: h1),
if (dcvm.troubleSolvingVolume.l > 0)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
Expanded(
child: ValueUnit(title: "TIME", value: shortNumber(state.settings.troubleSolvingDuration), unit: "min"),
),
Expanded(
child: ValueUnit(title: "SAC", value: dcvm.troubleSolvingSacLabel, unit: dcvm.sacUnit),
),
Expanded(
child: ValueUnit(title: "GAS", value: dcvm.troubleSolvingVolumeLabel, unit: dcvm.volumeUnit),
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Text("ASCENT", style: h1),
Expand Down Expand Up @@ -81,24 +83,26 @@ class RockBottomView extends StatelessWidget {
],
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Text("TOTAL", style: h1),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
Expanded(
child: ValueUnit(title: "TIME", value: dcvm.totalDurationLabel, unit: "min"),
),
Expanded(child: Container()),
Expanded(
child: ValueUnit(title: "GAS", value: dcvm.totalVolumeLabel, unit: dcvm.volumeUnit),
),
],
if (dcvm.troubleSolvingVolume.l > 0 || dcvm.safetyStopVolume.l > 0)
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Text("TOTAL", style: h1),
),
if (dcvm.troubleSolvingVolume.l > 0 || dcvm.safetyStopVolume.l > 0)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
Expanded(
child: ValueUnit(title: "TIME", value: dcvm.totalDurationLabel, unit: "min"),
),
Expanded(child: Container()),
Expanded(
child: ValueUnit(title: "GAS", value: dcvm.totalVolumeLabel, unit: dcvm.volumeUnit),
),
],
),
),
),
],
),
);
Expand Down
7 changes: 4 additions & 3 deletions lib/models/divecalculation_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flaska/divecalculation/divecalculation_cylinder_view.dart';
import 'package:sprintf/sprintf.dart';

import 'units.dart';
Expand Down Expand Up @@ -28,7 +29,7 @@ class DiveCalculationViewModel {
Distance get ascentAverageDepth => DistanceM(state.depth.m / 2);
String get ascentAverageDepthLabel => state.metric ? sprintf("%.0f", [ascentAverageDepth.m]) : sprintf("%.0f", [ascentAverageDepth.ft]);

String get ascentDurationLabel => sprintf("%.1f", [state.rockBottom.ascentDuration]);
String get ascentDurationLabel => shortNumber(state.rockBottom.ascentDuration);

Volume get ascentSac => VolumeL(state.settings.ascentSacMultiplier * state.settings.sacRate.l);
String get ascentSacLabel => state.metric ? sprintf("%.0f", [ascentSac.l]) : sprintf("%.1f", [ascentSac.cuft]);
Expand All @@ -38,7 +39,7 @@ class DiveCalculationViewModel {

String get safetyStopDepthLabel => state.metric ? sprintf("%.0f", [state.settings.safetyStopDepth.m]) : sprintf("%.0f", [state.settings.safetyStopDepth.ft]);

String get safetyStopDurationLabel => sprintf("%.1f", [state.settings.safetyStopDuration]);
String get safetyStopDurationLabel => shortNumber(state.settings.safetyStopDuration);

Volume get safetyStopSac => VolumeL(state.settings.safetyStopSacMultiplier * state.settings.sacRate.l);
String get safetyStopSacLabel => state.metric ? sprintf("%.0f", [safetyStopSac.l]) : sprintf("%.1f", [safetyStopSac.cuft]);
Expand All @@ -48,7 +49,7 @@ class DiveCalculationViewModel {

double get totalDuration =>
state.settings.ascentRate.m == 0 ? 0 : state.settings.troubleSolvingDuration + state.settings.safetyStopDuration + state.rockBottom.ascentDuration;
String get totalDurationLabel => sprintf("%.1f", [totalDuration]);
String get totalDurationLabel => shortNumber(totalDuration);

Volume get totalVolume => state.rockBottom.volume;
String get totalVolumeLabel => state.metric ? sprintf("%.0f", [totalVolume.l]) : sprintf("%.1f", [totalVolume.cuft]);
Expand Down
12 changes: 9 additions & 3 deletions lib/models/rockbottom_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ class RockBottomModel {
double get safetyStopAtm => (10 + settings.safetyStopDepth.m) / 10;

Volume get troubleSolvingVolume {
// Min gas trouble solving is calculated at the average depth for simplicity.
// Min gas trouble solving is calculated at the average depth, so it
// comes in the ascent duration.
if (settings.principles == Principles.MINGAS) {
return VolumeL(settings.troubleSolvingDuration * settings.sacRate.l * settings.troubleSolvingSacMultiplier * avgAtm);
return VolumeL(0);
}
return VolumeL(settings.troubleSolvingDuration * settings.sacRate.l * settings.troubleSolvingSacMultiplier * depthAtm);
}

double get ascentDuration => (depth.m / settings.ascentRate.m).ceilToDouble();
double get ascentDuration {
// Min gas trouble solving is one minute at the average depth, so we add
// it here.
final margin = settings.principles == Principles.MINGAS ? 1 : 0;
return (depth.m / settings.ascentRate.m).ceilToDouble() + margin;
}

Volume get ascentVolume => VolumeL(ascentDuration * settings.sacRate.l * settings.ascentSacMultiplier * avgAtm);

Expand Down
2 changes: 1 addition & 1 deletion lib/settings/settings_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
if (!newSettings.isMetric && newSettings.sacRate.cuft < 0.5) newSettings.sacRate = VolumeL(0.5);
newSettings.troubleSolvingSacMultiplier = 2;
newSettings.ascentSacMultiplier = 2;
newSettings.troubleSolvingDuration = 1;
newSettings.troubleSolvingDuration = 0;
newSettings.safetyStopDuration = 0;
newSettings.safetyStopSacMultiplier = 0;
newSettings.hideNdlNotice = true;
Expand Down

0 comments on commit 271c821

Please sign in to comment.