[chronojump] Guides for CairoPaintBarsPreJumpReactive (much faster: directly using SQL)



commit b1b3526004100c0b8ac458f177ae4c54f4130138
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Sep 9 09:31:27 2021 +0200

    Guides for CairoPaintBarsPreJumpReactive (much faster: directly using SQL)

 src/gui/eventExecute.cs  | 18 +++------
 src/gui/usefulObjects.cs | 96 +++++++++++++-----------------------------------
 2 files changed, 32 insertions(+), 82 deletions(-)
---
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 5ab4c180e..f0725777c 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -543,19 +543,16 @@ public partial class ChronoJumpWindow
        //barplot of tests in session
        public void on_event_execute_drawingarea_cairo_expose_event(object o, ExposeEventArgs args)
        {
-               LogB.Information("on_event_execute_drawingarea_cairo_expose_event A");
                //right now only for jumps/runs simple
                if(current_mode != Constants.Modes.JUMPSSIMPLE &&
                                current_mode != Constants.Modes.JUMPSREACTIVE &&
                                current_mode != Constants.Modes.RUNSSIMPLE)
                        return;
 
-               LogB.Information("on_event_execute_drawingarea_cairo_expose_event B");
                //if object not defined or not defined fo this mode, return
                if(cairoPaintBarsPre == null || ! cairoPaintBarsPre.ModeMatches (current_mode))
                        return;
 
-               LogB.Information("on_event_execute_drawingarea_cairo_expose_event C");
                //cairoPaintBarsPre.Prepare();
                if(current_mode == Constants.Modes.JUMPSSIMPLE)
                        PrepareJumpSimpleGraph (cairoPaintBarsPre.eventGraphJumpsStored, false);
@@ -563,7 +560,6 @@ public partial class ChronoJumpWindow
                        PrepareJumpReactiveGraph (cairoPaintBarsPre.eventGraphJumpsRjStored, false);
                else if (current_mode == Constants.Modes.RUNSSIMPLE)
                        PrepareRunSimpleGraph (cairoPaintBarsPre.eventGraphRunsStored, false);
-               LogB.Information("on_event_execute_drawingarea_cairo_expose_event D");
        }
 
        
@@ -702,7 +698,6 @@ public partial class ChronoJumpWindow
        public void PrepareJumpReactiveRealtimeCaptureGraph (double lastTv, double lastTc, string tvString, 
string tcString, string type,
                        bool volumeOn, Preferences.GstreamerTypes gstreamer, RepetitiveConditionsWindow 
repetitiveConditionsWin)
        {
-               LogB.Information("PrepareJumpReactiveRealtimeCaptureGraph 0");
                cairoPaintBarsPreRealTime = new CairoPaintBarsPreJumpReactiveRealtimeCapture(
                                event_execute_drawingarea_realtime_capture_cairo, 
preferences.fontType.ToString(), current_mode,
                                currentPerson.Name, type, preferences.digitsNumber,// 
preferences.heightPreferred,
@@ -712,7 +707,6 @@ public partial class ChronoJumpWindow
                //cairoPaintBarsPreRealTime.UseHeights = useHeights;
 
                cairoPaintBarsPreRealTime.Paint();
-               LogB.Information("PrepareJumpReactiveRealtimeCaptureGraph 1");
        }
        
        //identify which subjump is the best or the worst in tv/tc index        
@@ -3017,13 +3011,13 @@ public class CairoPaintBarsPreJumpReactive : CairoPaintBarsPre
 
                cb.PassGuidesData (new CairoBarsGuideManage(
                                        ! ShowPersonNames, true, //usePersonGuides, useGroupGuides
-                                       eventGraphJumpsRjStored.SessionMaxTvSum,
-                                       eventGraphJumpsRjStored.SessionAvgTvSum,
-                                       eventGraphJumpsRjStored.SessionMinTvSum,
+                                       eventGraphJumpsRjStored.sessionMAXAtSQL,
+                                       eventGraphJumpsRjStored.sessionAVGAtSQL,
+                                       eventGraphJumpsRjStored.sessionMINAtSQL,
                                        0,
-                                       eventGraphJumpsRjStored.PersonMaxTvSum,
-                                       eventGraphJumpsRjStored.PersonAvgTvSum,
-                                       eventGraphJumpsRjStored.PersonMinTvSum
+                                       eventGraphJumpsRjStored.personMAXAtSQL,
+                                       eventGraphJumpsRjStored.personAVGAtSQL,
+                                       eventGraphJumpsRjStored.personMINAtSQL
                                        ));
 
                cb.GraphDo (pointA_l, pointB_l, names_l,
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index 709512efd..3d6185161 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -153,12 +153,14 @@ public class PrepareEventGraphJumpReactive
        public List<JumpRj> jumpsAtSQL;
        public string type; //jumpType (useful to know if "all jumps" (type == "")
 
-       public double SessionMaxTvSum;
-       public double SessionAvgTvSum;
-       public double SessionMinTvSum;
-       public double PersonMaxTvSum;
-       public double PersonAvgTvSum;
-       public double PersonMinTvSum;
+       public double personMAXAtSQL;
+       public double sessionMAXAtSQL;
+
+       public double personAVGAtSQL;
+       public double sessionAVGAtSQL;
+
+       public double personMINAtSQL;
+       public double sessionMINAtSQL;
 
        public PrepareEventGraphJumpReactive () {
        }
@@ -172,77 +174,31 @@ public class PrepareEventGraphJumpReactive
                // 1) assign variables
                this.type = type;
 
+               Sqlite.Open(); // ----------------->
+
                int personIDTemp = personID;
-               //if(allPersons)
+               if(allPersons)
                        personIDTemp = -1;
 
-               // 2) select (use limit=-1 to calculate MaxTvSum, ...)
-               List<JumpRj> jAll = SqliteJumpRj.SelectJumps (false, sessionID, personIDTemp, type,
-                               Sqlite.Orders_by.ID_DESC, -1, allPersons);      //show names on comments only 
if "all persons"
-
-               // 3) calulate stats
-               SessionMaxTvSum = 0;
-               SessionAvgTvSum = 0;
-               SessionMinTvSum = 100000;
-               PersonMaxTvSum = 0;
-               PersonAvgTvSum = 0;
-               PersonMinTvSum = 100000;
-
-               jumpsAtSQL = new List<JumpRj>();
-
-               if(jAll.Count == 0)
-               {
-                       SessionMinTvSum = 0;
-                       PersonMinTvSum = 0;
-
-                       return;
-               }
-
-               int personCount = 0;
-               foreach(JumpRj j in jAll)
-               {
-                       //session stuff
-                       if(j.TvSum > SessionMaxTvSum)
-                               SessionMaxTvSum = j.TvSum;
+               jumpsAtSQL = SqliteJumpRj.SelectJumps (true, sessionID, personIDTemp, type,
+                               Sqlite.Orders_by.ID_DESC, limit, allPersons);   //show names on comments only 
if "all persons"
 
-                       SessionAvgTvSum += j.TvSum;
+               string sqlSelect = "tvAvg*jumps";
+               string table = Constants.JumpRjTable;
 
-                       if(j.TvSum < SessionMinTvSum)
-                               SessionMinTvSum = j.TvSum;
-
-                       //person stuff
-                       if(j.PersonID == personID)
-                       {
-                               if(j.TvSum > PersonMaxTvSum)
-                                       PersonMaxTvSum = j.TvSum;
-
-                               PersonAvgTvSum += j.TvSum;
-
-                               if(j.TvSum < PersonMinTvSum)
-                                       PersonMinTvSum = j.TvSum;
+               List<double> personStats = SqliteSession.Select_MAX_AVG_MIN_EventsOfAType(
+                               true, sessionID, personID, table, type, sqlSelect);
+               personMAXAtSQL = personStats[0];
+               personAVGAtSQL = personStats[1];
+               personMINAtSQL = personStats[2];
 
-                               personCount ++;
-                       }
+               List<double> sessionStats = SqliteSession.Select_MAX_AVG_MIN_EventsOfAType(
+                               true, sessionID, -1, table, type, sqlSelect);
+               sessionMAXAtSQL = sessionStats[0];
+               sessionAVGAtSQL = sessionStats[1];
+               sessionMINAtSQL = sessionStats[2];
 
-                       //add the jump to the list
-                       if(jumpsAtSQL.Count < limit && (allPersons || j.PersonID == personID))
-                               jumpsAtSQL.Add(j);
-               }
-               //calculate averages
-               SessionAvgTvSum = UtilAll.DivideSafe(SessionAvgTvSum, jAll.Count);
-               PersonAvgTvSum = UtilAll.DivideSafe(PersonAvgTvSum, personCount);
-
-               //if we have to show one person data, and there are no jumps of this person, set all 
variables 0 again
-               if(! allPersons && personCount == 0)
-               {
-                       jumpsAtSQL = new List<JumpRj>();
-                       SessionMaxTvSum = 0;
-                       SessionAvgTvSum = 0;
-                       SessionMinTvSum = 0;
-                       PersonMaxTvSum = 0;
-                       PersonAvgTvSum = 0;
-                       PersonMinTvSum = 0;
-               }
+               Sqlite.Close(); // < -----------------
        }
 
        ~PrepareEventGraphJumpReactive () {}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]