Robert,

On 16 June 2015 at 22:46, Robert Helling <[email protected]> wrote:

> No, unfortunately, this is not correct either.
>
> I acknowledge the bug that you describe (the gas change to EAN80 should be
> displayed at 9m depth). But your suggested patch breaks something else
> (which was the original motivation for the ‘postponed’ logic:
>
> Start with air.
>
> Descend to 20m
> Stay there for 5min
> Then switch gas to EAN80 and stay another 10min
> Then switch back to air and stay a further 5min
> ascent [planner ascends to 9m, should switch there back to EAN80 and then
> to the surface].
>
> In my understanding the plan should then look like this:
>
>  depth
> runtime
> duration
> gas
>  20m
> 1min
> 1min
> air
>  20m
> 5min
> 4min
>  20m
> 15min
> 10min
> EAN80
>  20m
> 20min
> 5min
>
>  air
>  9m
> 22min
> 2min
> EAN80
>  0m
> 28min
> 7min
>
>
>
> I agree that this logic currently is completely incomprehensible. Will
> look at this later tonight again.
>

In the attached patch I have tried to simplify the logic and get it to do
the right thing.  Rather than tracking whether a gaschange has been
delayed, it compares the gas used to the last printed gas.  Can you please
have a look?

For your example above, with 45/85 gradient factors

depth

duration

runtime

gas

20m

1min

1min

air

20m

5min

5min



20m

10min

15min

EAN80

20m

5min

20min

air

9m

1min

21min



6m

17min

39min

EAN80

0m

2min

41min



Note that it skips the 9m gas change at 21min because there is no deco stop
and very short legs are skipped (existing logic in the code).

And displaying transitions:

depth

duration

runtime

gas

20m

1min

1min

air

20m

5min

5min



20m

10min

15min

EAN80

20m

5min

20min

air

9m

1min

21min



6m

0min

22min

EAN80

6m

17min

39min



0m

2min

41min



A more serious profile

depth

duration

runtime

gas

70m

2min

2min

(18/20)

70m

23min

25min



40m

5min

30min



40m

20min

50min

EAN28

21m

5min

55min

EAN50

18m

7min

63min



15m

12min

75min



12m

17min

92min



9m

25min

118min



6m

69min

187min

oxygen

0m

2min

189min



Cheers,

Rick
From 0f85b6ad75a50b58a6137733253988341eb5c412 Mon Sep 17 00:00:00 2001
From: Rick Walsh <[email protected]>
Date: Thu, 18 Jun 2015 00:57:31 +1000
Subject: [PATCH 2/2] Improve planner notes gas change logic

This patch improves the logic to choose when to print gas changes in planner notes table.

Signed-off-by: Rick Walsh <[email protected]>
---
 planner.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/planner.c b/planner.c
index 9b2d355..e301d82 100644
--- a/planner.c
+++ b/planner.c
@@ -521,7 +521,8 @@ static unsigned int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops,
 static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
 {
 	char buffer[2000000], temp[100000];
-	int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0;
+	int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1;
+	struct gasmix lastprintgasmix = { -1, -1 };
 	struct divedatapoint *dp = diveplan->dp;
 	bool gaschange = !plan_verbatim, postponed = plan_verbatim;
 	struct divedatapoint *nextdp = NULL;
@@ -648,21 +649,17 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
 					snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time + 30) / 60);
 					len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp);
 				}
-
-				if (gaschange) {
-					if(dp->depth == lastdepth && !postponed) {
-						postponed = true;
+				if (lastprintsetpoint != dp->setpoint || lastprintgasmix.he.permille != gasmix.he.permille ||
+					(lastprintgasmix.o2.permille - gasmix.o2.permille != 0 && abs(lastprintgasmix.o2.permille - gasmix.o2.permille) != O2_IN_AIR)) {
+					if (dp->setpoint) {
+						snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
+						len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&gasmix),
+							temp);
 					} else {
-						if (dp->setpoint) {
-							snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
-							len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix),
-									temp);
-						} else {
-							len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&newgasmix));
-						}
-						gaschange = false;
-						postponed = false;
+						len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&gasmix));
 					}
+					lastprintsetpoint = dp->setpoint;
+					lastprintgasmix = gasmix;
 				} else {
 					len += snprintf(buffer + len, sizeof(buffer) - len, "<td>&nbsp;</td>");
 				}
-- 
2.4.3

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to