mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Do not count gas used in planned dives for statistics
This is important if in one dive we have the real dive and
a planned version of the dive as different computers using
different sets of cylinders.
[Dirk Hohndel: an early version of this was mistakenly pushed out
               by me; I reverted that and added this commit since
               fixing things up as I had done for the other two
               patches made things nearly unreadable]
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
			
			
This commit is contained in:
		
							parent
							
								
									67de8f3a49
								
							
						
					
					
						commit
						5aa9c6fa1b
					
				
					 1 changed files with 29 additions and 14 deletions
				
			
		| 
						 | 
					@ -326,41 +326,56 @@ void get_selected_dives_text(char *buffer, size_t size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used
 | 
					#define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool has_gaschange_event(struct dive *dive, struct divecomputer *dc, int idx) {
 | 
				
			||||||
 | 
						bool first_gas_explicit = false;
 | 
				
			||||||
 | 
						struct event *event = get_next_event(dc->events, "gaschange");
 | 
				
			||||||
 | 
						while (event) {
 | 
				
			||||||
 | 
							if (dc->sample && (event->time.seconds == 0 ||
 | 
				
			||||||
 | 
									   (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))
 | 
				
			||||||
 | 
								first_gas_explicit = true;
 | 
				
			||||||
 | 
							if (get_cylinder_index(dive, event) == idx)
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							event = get_next_event(event->next, "gaschange");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (dc->divemode == CCR && (idx == dive->diluent_cylinder_index || idx == dive->oxygen_cylinder_index))
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						return !first_gas_explicit && idx == 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool is_cylinder_used(struct dive *dive, int idx)
 | 
					bool is_cylinder_used(struct dive *dive, int idx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct divecomputer *dc;
 | 
						struct divecomputer *dc;
 | 
				
			||||||
	bool firstGasExplicit = false;
 | 
					 | 
				
			||||||
	if (cylinder_none(&dive->cylinder[idx]))
 | 
						if (cylinder_none(&dive->cylinder[idx]))
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((dive->cylinder[idx].start.mbar - dive->cylinder[idx].end.mbar) > SOME_GAS)
 | 
						if ((dive->cylinder[idx].start.mbar - dive->cylinder[idx].end.mbar) > SOME_GAS)
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	for_each_dc(dive, dc) {
 | 
						for_each_dc(dive, dc) {
 | 
				
			||||||
		struct event *event = get_next_event(dc->events, "gaschange");
 | 
							if (has_gaschange_event(dive, dc, idx))
 | 
				
			||||||
		while (event) {
 | 
					 | 
				
			||||||
			if (dc->sample && (event->time.seconds == 0 ||
 | 
					 | 
				
			||||||
					   (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))
 | 
					 | 
				
			||||||
				firstGasExplicit = true;
 | 
					 | 
				
			||||||
			if (get_cylinder_index(dive, event) == idx)
 | 
					 | 
				
			||||||
				return true;
 | 
					 | 
				
			||||||
			event = get_next_event(event->next, "gaschange");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (dc->divemode == CCR && (idx == dive->diluent_cylinder_index || idx == dive->oxygen_cylinder_index))
 | 
					 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (idx == 0 && !firstGasExplicit)
 | 
					 | 
				
			||||||
		return true;
 | 
					 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])
 | 
					void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int idx;
 | 
						int idx;
 | 
				
			||||||
 | 
						struct divecomputer *dc;
 | 
				
			||||||
 | 
						bool used;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (idx = 0; idx < MAX_CYLINDERS; idx++) {
 | 
						for (idx = 0; idx < MAX_CYLINDERS; idx++) {
 | 
				
			||||||
 | 
							used = false;
 | 
				
			||||||
		cylinder_t *cyl = &dive->cylinder[idx];
 | 
							cylinder_t *cyl = &dive->cylinder[idx];
 | 
				
			||||||
		pressure_t start, end;
 | 
							pressure_t start, end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!is_cylinder_used(dive, idx))
 | 
							for_each_dc(dive, dc) {
 | 
				
			||||||
 | 
								if (!strcmp(dc->model, "planned dive"))
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								if (has_gaschange_event(dive, dc, idx))
 | 
				
			||||||
 | 
									used = true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!used)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		start = cyl->start.mbar ? cyl->start : cyl->sample_start;
 | 
							start = cyl->start.mbar ? cyl->start : cyl->sample_start;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue