aboutsummaryrefslogtreecommitdiffstats
path: root/statistics.c
AgeCommit message (Collapse)Author
2015-10-30Move all core-functionality to subsurface-coreGravatar Tomaz Canabrava
And adapt a new CMakeLists.txt file for it. On the way I've also found out that we where double-compilling a few files. I've also set the subsurface-core as a include_path but that was just to reduce the noise on this commit, since I plan to remove it from the include path to make it obligatory to specify something like include "subsurface-core/dive.h" for the header files. Since the app is growing quite a bit we ended up having a few different files with almost same name that did similar things, I want to kill that (for instance Dive.h, dive.h, PrintDive.h and such). Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-18Display divetime according to dive mode and translationGravatar Giorgio Marzano
Many time stats in maintab display also seconds in short freediving Signed-off-by: Giorgio Marzano <marzano.giorgio@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-11Better testing if the first gas is explicitGravatar Dirk Hohndel
Given that we might be adding a gas change event at t = 0 we need to check for both that and t = time_or_first_sample. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-29Cylinders which have lesser pressure in the end are usedGravatar Robert C. Helling
Make cylinders that have at least 5bar less pressure in the end than in the beginning considered "used". Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Refactor dctype -> divemodeGravatar Robert C. Helling
... and repair a failed rebase (sorry). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17In a CCR dive the diluent and oxygen cylinders are both usedGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07Convert volume calculations into floating pointGravatar Anton Lundin
The basic problem was that for gases containing more than 2147483648 ml of nitrogen the calculations overflowed. This changes the code into using floating point math for that calculation which will be more accurate to. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-03Fix two more potential crashes for dives without samplesGravatar Dirk Hohndel
This should be all of them (famous last words). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-28Explicit first gas only on first sampleGravatar Dirk Hohndel
Instead of the 30 second heuristic we only assume that this is an explicit first gas if the event coincides the first sample. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-28Improve tank handling for CobaltGravatar Dirk Hohndel
This isn't Cobalt specific, this is specific to dive computers that indicate the first tank that's in use with a gaschange event that coincides with the first sample. We need to make sure that we suppress showing that gas change event (regardless which cylinder it goes to) and instead set the correct cylinder index from the very start of the dive. This works with the test data I have and doesn't seem to break thing with any of the files that I tried... but I'm worried that this is not the right way to do things. Fixes #742 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-06Make gas use statistics be coherent and more completeGravatar Linus Torvalds
The gas use logic in the dive statistics page is confused. The SAC case had a special case for "unknown", but only for the first gas. Other gases had the normal empty case. Also, the logic was really odd - if you had gases that weren't used (or pressures not known) intermixed with gases you *did* have pressure for, the statistics got really confused. The list of gases showed all gases that we know about during the dive, but then the gas use and SAC-rate lists wouldn't necessarily match, because the loops that computed those stopped after the first gas that didn't have any pressure change. To make things worse, the first cylinder was special-cased again, so it all lined up for the single-cylinder case. This makes all the cylinders act the same way, leaving unknown gas use (and thus SAC) just empty for that gas. It also fixes the SAC calculation case where we don't have real samples, and the profile is a fake profile - possibly with gas changes in between the fake points. We now make the SAC calculations match what we show - which is admittedly not at all necessarily what the dive was, but at least we're consistent. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17Replace cylinder_is_used with is_cylinder_usedGravatar Anton Lundin
is_cylinder_used uses get_cylinder_index as underlaying function that does the right thing with with respect on how to find the closest matching cylinder, and handles both types of gaschange events correctly. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17Rename is_gas_used to is_gas_usedGravatar Anton Lundin
This function operates on cylinder ids, so its actually about cylinders not gases. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17Statistics: change our notion of "bogus SAC rate"Gravatar Dirk Hohndel
With a pSCR it is entirely possible to have a SAC rate below 2.8l/min. Since we still don't want to include SAC rates of 0 let's change the cutoff to 0.1l/min. Fixes #624 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-29Calculate approx gas bill on divesGravatar Anton Lundin
This uses a bit of naive gas computations to figure out how much of different base gases you used up on the dives the statistics is done for. It's quite useful to get a minimum line about how big your gas bill is going to be after a dive trip. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01Remove is_air() and convert its users to gasmixGravatar Dirk Hohndel
Also make gasname() and get_gas_string() global functions (which allows us to delete code elsewhere). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20Migrate code to for_each_dive and for_each_dcGravatar Anton Lundin
[Dirk Hohndel: this overlapped with my commit 09e7c61feeea ("Consistently use for_each_dive (and use it correctly)") so I took the pieces that I had missed] Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20Consistently use for_each_dive (and use it correctly)Gravatar Dirk Hohndel
The way the macro is written there is no need to test the dive against NULL before dereferencing. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-13Do not check for null before free.Gravatar Tomaz Canabrava
C specs says that we can safelly free a NULL pointer, so there's no reason to check if it's null before freeing it. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-26Don't calculate SAC-rates for negative pressure changesGravatar Linus Torvalds
They happen - maybe the cylinder actually warmed up, or maybe the user entered just a ending pressure without a starting pressure. Regardless, just ignore cylinder pressure changes that go up. Also ignore cylinders with a zero ending pressure: that's really a *missing* pressure rather than an actual zero pressure. As Dirk says, the scuba regulators don't even work without a healthy positive pressure differential, so even when you breathe down a tank to "empty", it won't be at zero pressure (this is true even with gauge pressure, where zero means "atmospheric pressure"). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27Massive automated whitespace cleanupGravatar Dirk Hohndel
I know everyone will hate it. Go ahead. Complain. Call me names. At least now things are consistent and reproducible. If you want changes, have your complaint come with a patch to scripts/whitespace.pl so that we can automate it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16Convert the C code to using stdbool and true/falseGravatar Anton Lundin
Earlier we converted the C++ code to using true/false, and this converts the C code to using the same style. We already depended on stdbool.h in subsurfacestartup.[ch], and we build with -std=gnu99 so nobody could build subsurface without a c99 compiler. [Dirk Hohndel: small change suggested by Thiago Macieira: don't include stdbool.h for C++] Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-11Ensure gaslist is NULL terminatedGravatar Miika Turkia
If buffer copying is restricted by the buffer size in strncpy or snprintf, the copied string is not NULL terminated. Add one to the end just to make sure. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11Close warning first might be garbageGravatar Anton Lundin
First might be garbage if get_ranges would be called when dive_table.nr == 0. This would rather signal that something else is broken, but at least we shouldn't make it worse. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-08Make local helpers staticGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-30Fix a crash when no trip existsGravatar Miika Turkia
When there are no trips at all, we have to skip the Yearly statistics alltogether, including the header line (that should display all the dives added together). Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-29Rewrite is_gas_used to use get_cylinder_indexGravatar Anton Lundin
get_cylinder_index implements a algorithm to map gaschange events to gas idx. This is a bit clumsy to use it to map if a gas idx have bin used, but its consistent with other parts. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27Only return gas volumes for gases usedGravatar Anton Lundin
We check in get_gaslist is_gas_used, so if were going to be consistent about what we return from get_gaslist and in get_gas_used, only return gas volumes that we actually consumed during the dive. The problem now this fixes can be seen in dives/test10.xml Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-24Bugfix crash in trip statistics for non trip divesGravatar Anton Lundin
This fixes a crash when you have non-trip dives in your logbook. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-23Adding trip based statisticsGravatar Miika Turkia
This adds trip based statistics to the Yearly Statistics view. Signed-off-by: Miika Turkia <miika.turkia@nixu.fi> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-21Fix a couple of warningsGravatar Dirk Hohndel
Removing unused variables. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19Do per cylinder statisticsGravatar Anton Lundin
This shows how much gas form each cylinder was used. I would like to add SAC to that list too but it became a mess trying to calculate average depth per cylinder. Design based on idea in #284 Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-02Replaced the tag implementationGravatar Maximilian Güntner
The new implementation supports custom tags which are provided by the user as well as default tags which are provided by subsurface. Default tags can be translated and will be written to XML in their non-localized form. Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
2013-10-20Get rid of compiler warning on format stringsGravatar Miika Turkia
This gets rid of compiler warnings "format not a string literal and no format arguments [-Wformat-security]". E.g. when building distribution packages these warnings are often treated as errors preventing the build (with good reason). Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2013-10-09Next step towards working translationsGravatar Dirk Hohndel
This may seem like a really odd change - but with this change the Qt tools can correctly parse the C files (and qt-gui.cpp) and get the context for the translatable strings right. It's not super-pretty (I'll admit that _("string literal") is much easier on the eye than translate("gettextFromC", "string literal") ) but I think this will be the price of success. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06Make is_gas_used work with SAMPLE_EVENT_GASCHANGEGravatar Anton Lundin
SAMPLE_EVENT_GASCHANGE only contains o2 part, and not the he part so when looking at ex the gaslist for dives/test20.xml it got it realy wrong. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06Trying to switch to Qt translationGravatar Dirk Hohndel
This compiles and looks about right, but it doesn't appear to work, yet. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06First steps towards removing glib dependenciesGravatar Dirk Hohndel
- remove the build flags and libraries from the Makefile / Configure.mk - remove the glib types (gboolean, gchar, gint64, gint) - comment out / hack around gettext - replace the glib file helper functions - replace g_ascii_strtod - replace g_build_filename - use environment variables instead of g_get_home_dir() & g_get_user_name() - comment out GPS string parsing (uses glib utf8 macros) This needs massive cleanup, but it's a snapshot of what I have right now, in case people want to look at it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-03Bugfix typo in get_gas_usedGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19Improve readability of yearly statisticsGravatar Dirk Hohndel
Make the entries for years bold, keep the months non-bold. It's still a sea of data, but this is an improvement. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-12Show EANxx for Nitrox in info tabGravatar Dirk Hohndel
Showing all gases (except air) as (o2/he) feels a bit odd, most people would only use the two gas notation if they are actually diving trimix. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-31List only the gases used in the Info tabGravatar Dirk Hohndel
The equipment tab will still show all defined gases, but the info for the dive should only list the ones used. Also change the name of the two gas related boxes to better reflect the data that is shown. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-19Continue populating the DiveInfo tabGravatar Dirk Hohndel
Pulled one more helper from statistics-gtk.c (but didn't modify the code there to use it as that code is no longer being compiled). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-17Merge branch 'Qt'Gravatar Dirk Hohndel
After the 3.1 release it is time to shift the focus on the Qt effort - and the best way to do this is to merge the changes in the Qt branch into master. Linus was extremely nice and did a merge for me. I decided to do my own merge instead (which by accident actually based on a different version of the Qt branch) and then used his merge to double check what I was doing. I resolved a few things differently but overall what we did was very much the same (and I say this with pride since Linus is a professional git merger) Here's his merge commit message: This is a rough and tumble merge of the Qt branch into 'master', trying to sort out the conflicts as best as I could. There were two major kinds of conflicts: - the Makefile changes, in particular the split of the single Makefile into Rules.mk and Configure.mk, along with the obvious Qt build changes themselves. Those changes conflicted with some of the updates done in mainline wrt "release" targets and some helper macros ($(NAME) etc). Resolved by largely taking the Qt branch versions, and then editing in the most obvious parts of the Makefile updates from mainline. NOTE! The script/get_version shell script was made to just fail silently on not finding a git repository, which avoided having to take some particularly ugly Makefile changes. - Various random updates in mainline to support things like dive tags. The conflicts were mainly to the gtk GUI parts, which obviously looked different afterwards. I fixed things up to look like the newer code, but since the gtk files themselves are actually dead in the Qt branch, this is largely irrelevant. NOTE! This does *NOT* introduce the equivalent Qt functionality. The fields are there in the code now, but there's no Qt UI for the whole dive tag stuff etc. This seems to compile for me (although I have to force "QMAKE=qmake-qt4" on f19), and results in a Linux binary that seems to work, but it is otherwise largely untested. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-14Add tag for deco divesGravatar Dirk Hohndel
Fixes #85 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-06Start populating the maintab Dive Info widgetGravatar Dirk Hohndel
Establish some useful helpers and use them when updating the values. One of the helpers (from statistics.c) puzzlingly doesn't link - so that's ifdefed out. Also had to re-arrange the settings reading code (it came too late) and to extract the expanding code of the top dive from the settings reading code (as it had no business being there to begin with). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-15Separate Gtk related code from core logic: statisticsGravatar Dirk Hohndel
Fairly straight forward, so far just one tiny bit of code restructuring, everything else separated cleanly. Added statistics-gtk.c and statistics.h This should make no difference to functionality. Cherry-picked from Qt branch; fixed merge issues mostly caused by dive_tags and Makefile changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-14Separate Gtk related code from core logic: statisticsGravatar Dirk Hohndel
Fairly straight forward, so far just one tiny bit of code restructuring, everything else separated cleanly. Added statistics-gtk.c and statistics.h This should make no difference to functionality. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-10Add four more tagsGravatar Dirk Hohndel
Student (training), Instructor (teaching), Photo and Video Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09Automatically show Freshwater tag (but don't set it)Gravatar Dirk Hohndel
If the salinity is 10000 we show (but do not set) the Freshwater tag. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>