On 10 June, 2014 - Anton Lundin wrote:

> On 10 June, 2014 - Dirk Hohndel wrote:
> 
> > 
> > As discussed, part of this was implemented.
> > The part that's missing seems a tiny bit too user specific.
> > Breaking this down as "volume of air" + "volume of O₂" + "volume of He" is
> > of course possible, but I'm not sure a lot of people would have any use
> > for that data.
> > I could see maybe adding this as a tooltip... still not sure.
> >
> 
> I would actually like such a feature. We usually by 50L bottles of He
> and O2 and mix our gases ourself and when its time to split the bill its
> kinda good to verify that what got written into the gas fill log is
> somewhat close to what i actually logged i used.
> 
> I'm currently trying to produce a poc of how this could look.
> 

Quite ugly thing but it kinda works. You hopefully get the idea.

//Anton

-- 
Anton Lundin    +46702-161604
diff --git i/helpers.h w/helpers.h
index 392dcb5..36ceb1e 100644
--- i/helpers.h
+++ w/helpers.h
@@ -33,7 +33,7 @@ QString get_dive_date_string(timestamp_t when);
 QString get_short_dive_date_string(timestamp_t when);
 QString get_trip_date_string(timestamp_t when, int nr);
 QString uiLanguage(QLocale *callerLoc);
-void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsed);
+void selectedDivesGasUsed(QVector<QPair<struct gasmix*, int> > &gasUsed);
 
 #define M_OR_FT(_m, _f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) 
: (feet_to_mm(_f)))
 
diff --git i/qt-ui/maintab.cpp w/qt-ui/maintab.cpp
index ae2876b..770fcb4 100644
--- i/qt-ui/maintab.cpp
+++ w/qt-ui/maintab.cpp
@@ -531,18 +531,37 @@ void MainTab::updateDiveInfo(int dive)
                
ui.timeLimits->setMaximum(get_time_string(stats_selection.longest_time.seconds, 
0));
                
ui.timeLimits->setMinimum(get_time_string(stats_selection.shortest_time.seconds,
 0));
                // now let's get some gas use statistics
-               QVector<QPair<QString, int> > gasUsed;
+               QVector<QPair<struct gasmix*, int> > gasUsed;
                QString gasUsedString;
-               QPair<QString, int> topGases[20] = { };
-               volume_t vol;
+               QPair<struct gasmix*, int> topGases[20] = { };
                selectedDivesGasUsed(gasUsed);
+               volume_t vol;
+               volume_t he = {}, o2 = {};
+               struct gasmix *mix;
+               QPair<struct gasmix*, int> gasPair;
+               foreach (gasPair, gasUsed) {
+                       mix = gasPair.first;
+                       vol.mliter = gasPair.second;
+                       //Really naive gas computations here, but it gives the 
picture
+                       if (gasmix_is_air(mix))
+                               continue;
+                       if (get_he(mix) != 0) {
+                               o2.mliter += (get_he(mix) * get_o2(mix) * 
vol.mliter) / 1000000;
+                               he.mliter += (get_he(mix) * vol.mliter) / 1000;
+                       } else if (get_o2(mix) == 1000) {
+                               o2.mliter += vol.mliter;
+                       } else
+                               o2.mliter += ((get_o2(mix) - O2_IN_AIR) * 
vol.mliter) / 1000;
+               }
+               gasUsedString.append(QString("He: %1, O2: 
%2\n").arg(get_volume_string(he, true)).arg(get_volume_string(o2, true)));
                for (int j = 0; j < 20; j++) {
                        if (gasUsed.isEmpty())
                                break;
-                       QPair<QString, int> gasPair = gasUsed.last();
+                       gasPair = gasUsed.last();
                        gasUsed.pop_back();
+                       mix = gasPair.first;
                        vol.mliter = gasPair.second;
-                       gasUsedString.append(gasPair.first).append(": 
").append(get_volume_string(vol, true)).append("\n");
+                       gasUsedString.append(gasname(mix)).append(": 
").append(get_volume_string(vol, true)).append("\n");
                }
                if (!gasUsed.isEmpty())
                        gasUsedString.append("...");
diff --git i/qthelper.cpp w/qthelper.cpp
index 8b7b396..0150df2 100644
--- i/qthelper.cpp
+++ w/qthelper.cpp
@@ -282,17 +282,18 @@ extern "C" void picture_load_exif_data(struct picture *p, 
timestamp_t *timestamp
                return;
 }
 
-static bool lessThan(const QPair<QString, int> &a, const QPair<QString, int> 
&b)
+static bool lessThan(const QPair<struct gasmix*, int> &a, const QPair<struct 
gasmix*, int> &b)
 {
        return a.second < b.second;
 }
 
-void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsedOrdered)
+void selectedDivesGasUsed(QVector<QPair<struct gasmix*, int> > &gasUsedOrdered)
 {
        int i, j;
        struct dive *d;
-       QString gas;
-       QMap<QString, int> gasUsed;
+       struct gasmix *gas;
+       QMap<struct gasmix*, int> gasUsed;
+       QMap<QString, struct gasmix*> gasFolder;
        for_each_dive (i, d) {
                if (!d->selected)
                        continue;
@@ -301,11 +302,14 @@ void selectedDivesGasUsed(QVector<QPair<QString, int> > 
&gasUsedOrdered)
                for (j = 0; j < MAX_CYLINDERS; j++)
                        if (diveGases[j].mliter) {
                                QString gasName = 
gasname(&d->cylinder[j].gasmix);
-                               gasUsed[gasName] += diveGases[j].mliter;
+                               if (!gasFolder.contains(gasName))
+                                       gasFolder[gasName] = 
&d->cylinder[j].gasmix;
+                               gas = gasFolder[gasName];
+                               gasUsed[gas] += diveGases[j].mliter;
                        }
        }
        Q_FOREACH(gas, gasUsed.keys()) {
-               gasUsedOrdered.append(QPair<QString, int>(gas, gasUsed[gas]));
+               gasUsedOrdered.append(QPair<struct gasmix*, int>(gas, 
gasUsed[gas]));
        }
        qSort(gasUsedOrdered.begin(), gasUsedOrdered.end(), lessThan);
 }
_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to