[chronojump] jump simple graph uses List<Jump> instead of string []



commit c383c54bc6d6b1ca7f7b4b3e4a9eb8b32a734430
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jun 12 12:24:03 2020 +0200

    jump simple graph uses List<Jump> instead of string []

 src/gui/app1/jump.cs     |  2 +-
 src/gui/eventExecute.cs  | 63 ++++++++++++++++++++++++------------------------
 src/gui/usefulObjects.cs | 15 +++++-------
 src/jumpsEvolution.cs    |  2 +-
 src/sqlite/jump.cs       | 18 +++++++++++---
 5 files changed, 54 insertions(+), 46 deletions(-)
---
diff --git a/src/gui/app1/jump.cs b/src/gui/app1/jump.cs
index 7d04cd52..0536dd66 100644
--- a/src/gui/app1/jump.cs
+++ b/src/gui/app1/jump.cs
@@ -272,7 +272,7 @@ public partial class ChronoJumpWindow
                PrepareEventGraphJumpSimple eventGraph = new PrepareEventGraphJumpSimple(
                                tv, tc, currentSession.UniqueID, currentPerson.UniqueID, Constants.JumpTable, 
currentEventType.Name, preferences.jumpsDjGraphHeights);
                
-               if(eventGraph.personMAXAtSQLAllSessions > 0 || eventGraph.jumpsAtSQL.Length > 0)
+               if(eventGraph.personMAXAtSQLAllSessions > 0 || eventGraph.jumpsAtSQL.Count > 0)
                        PrepareJumpSimpleGraph(eventGraph, false); //don't animate
        }
        private void updateGraphJumpsReactive ()
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 3d16b7e8..6ad872e1 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -603,15 +603,14 @@ public partial class ChronoJumpWindow
 
                        //fix if there's a max tc or falling height that's higher than max tv
 
-                       foreach(string myStr in eventGraph.jumpsAtSQL) {
-                               string [] jump = myStr.Split(new char[] {':'});
-
-                               string valueToPlot = jump[6]; //tc
+                       foreach(Jump jump in eventGraph.jumpsAtSQL)
+                       {
+                               double valueToPlot = jump.Tc;
                                if(eventGraph.djShowHeights && eventGraph.tc > 0 && eventGraph.tv > 0)
-                                       valueToPlot = jump[7]; //fall
+                                       valueToPlot = jump.Fall;
 
-                               if(Convert.ToDouble(valueToPlot) > maxValue)
-                                       maxValue = Convert.ToDouble(valueToPlot);
+                               if(valueToPlot > maxValue)
+                                       maxValue = valueToPlot;
                        }
                } else {
                        maxValue = eventGraphConfigureWin.Max;
@@ -1055,7 +1054,7 @@ public partial class ChronoJumpWindow
                // if has jumped on another session, magenta line: personMAXAtSQLAllSessions will be displayed
                // if other persons have been jumped on this session, eventGraph.sessionMAXAtSQL and 
eventGraph.sessionAVGAtSQL will be displayed
                // don't need the rest of the method
-               if(eventGraph.jumpsAtSQL.Length == 0)
+               if(eventGraph.jumpsAtSQL.Count == 0)
                        return;
                
                //if person max in all sessions == person max this session, this session max will be only at 
left,
@@ -1074,8 +1073,8 @@ public partial class ChronoJumpWindow
 
                //calculate separation between series and bar width
                int tctfSep = 0; //separation between tc and tf
-               int distanceBetweenCols = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(1+.5)/eventGraph.jumpsAtSQL.Length) -
-                       
Convert.ToInt32((ancho-event_execute_rightMargin)*(0+.5)/eventGraph.jumpsAtSQL.Length);
+               int distanceBetweenCols = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(1+.5)/eventGraph.jumpsAtSQL.Count) -
+                       Convert.ToInt32((ancho-event_execute_rightMargin)*(0+.5)/eventGraph.jumpsAtSQL.Count);
 
                if(eventGraph.tc > 0)
                        tctfSep = Convert.ToInt32(.3*distanceBetweenCols);
@@ -1085,55 +1084,55 @@ public partial class ChronoJumpWindow
                bool animateBar = animate;
                int x = 0;
                int y = 0;
-               int count = eventGraph.jumpsAtSQL.Length;
-               foreach(string myStr in eventGraph.jumpsAtSQL) 
+               int countToDraw = eventGraph.jumpsAtSQL.Count;
+               int countJumps = eventGraph.jumpsAtSQL.Count;
+
+               foreach(Jump jump in eventGraph.jumpsAtSQL)
                {
-                       string [] jump = myStr.Split(new char[] {':'});
-       
                        //if tc, maybe also tv  
                        if(eventGraph.tc > 0) {
                                //small layout when tc and tv and there are more than 4 jumps
                                Pango.Layout layout = layoutMid;
-                               if(eventGraph.tv > 0 && eventGraph.jumpsAtSQL.Length > 4)
+                               if(eventGraph.tv > 0 && countJumps > 4)
                                        layout = layoutSmall;
                                
                                //do not animate last tc, if tv is animated because then tc is not shown
                                if(eventGraph.tv >0)
                                        animateBar = false;
 
-                               string valueToPlot = jump[6]; //tc
+                               double valueToPlot = jump.Tc;
                                if(eventGraph.djShowHeights && eventGraph.tc > 0 && eventGraph.tv > 0)
-                                       valueToPlot = jump[7]; //fall
+                                       valueToPlot = jump.Fall;
 
-                               x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(count-.5)/eventGraph.jumpsAtSQL.Length)-barDesplLeft;
-                               y = calculatePaintHeight(Convert.ToDouble(valueToPlot), alto, maxValue, 
minValue, topMargin, bottomMargin);
+                               x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(countToDraw-.5)/countJumps)-barDesplLeft;
+                               y = calculatePaintHeight(valueToPlot, alto, maxValue, minValue, topMargin, 
bottomMargin);
                                
-                               drawBar(x, y, barWidth, alto, pen_rojo, count == eventGraph.jumpsAtSQL.Length,
-                                               jump[11] == "-1", Convert.ToDouble(valueToPlot), layout, 
animateBar);
+                               drawBar(x, y, barWidth, alto, pen_rojo, countToDraw == countJumps,
+                                               jump.Simulated == -1, valueToPlot, layout, animateBar);
 
                                //tv
                                if(eventGraph.tv > 0)
                                {
-                                       valueToPlot = jump[5]; //tv
+                                       valueToPlot = jump.Tv;
                                        if(eventGraph.djShowHeights && eventGraph.tc > 0 && eventGraph.tv > 0)
-                                               valueToPlot = Util.GetHeightInCentimeters(jump[5]); //jump 
height
+                                               valueToPlot = Util.GetHeightInCentimeters(jump.Tv); //jump 
height
 
-                                       x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(count-.5)/eventGraph.jumpsAtSQL.Length)-barDesplLeft 
+tctfSep;
-                                       y = calculatePaintHeight(Convert.ToDouble(valueToPlot), alto, 
maxValue, minValue, topMargin, bottomMargin);
+                                       x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(countToDraw-.5)/countJumps)-barDesplLeft +tctfSep;
+                                       y = calculatePaintHeight(valueToPlot, alto, maxValue, minValue, 
topMargin, bottomMargin);
                                        
-                                       drawBar(x, y, barWidth, alto, pen_azul_claro, count == 
eventGraph.jumpsAtSQL.Length,
-                                                       jump[11] == "-1", Convert.ToDouble(valueToPlot), 
layout, animateBar);
+                                       drawBar(x, y, barWidth, alto, pen_azul_claro, countToDraw == 
countJumps,
+                                                       jump.Simulated == -1, valueToPlot, layout, 
animateBar);
                                }
 
                        } else { //has not tc. Show only height
-                               x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(count-.5)/eventGraph.jumpsAtSQL.Length)-barDesplLeft 
+tctfSep;
-                               y = 
calculatePaintHeight(Convert.ToDouble(Util.GetHeightInCentimeters(jump[5])), 
+                               x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(countToDraw-.5)/countJumps)-barDesplLeft +tctfSep;
+                               y = calculatePaintHeight(Util.GetHeightInCentimeters(jump.Tv),
                                                alto, maxValue, minValue, topMargin, bottomMargin);
 
-                               drawBar(x, y, barWidth, alto, pen_azul_claro, count == 
eventGraph.jumpsAtSQL.Length,
-                                               jump[11] == "-1", 
Convert.ToDouble(Util.GetHeightInCentimeters(jump[5])), layoutMid, animateBar);
+                               drawBar(x, y, barWidth, alto, pen_azul_claro, countToDraw == countJumps,
+                                               jump.Simulated == -1, Util.GetHeightInCentimeters(jump.Tv), 
layoutMid, animateBar);
                        }
-                       count --;
+                       countToDraw --;
                }
 
                //add legend box
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index e01d1232..3850111b 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -57,10 +57,10 @@ public class ExecutingGraphData
        }
 }      
 
-public class PrepareEventGraphJumpSimple {
+public class PrepareEventGraphJumpSimple
+{
        //sql data of previous jumps to plot graph and show stats at bottom
-       public string [] jumpsAtSQL;
-       //public List<Jump> jumpsAtSQL;
+       public List<Jump> jumpsAtSQL;
        
        public double personMAXAtSQLAllSessions;
        public double personMAXAtSQL;
@@ -82,13 +82,10 @@ public class PrepareEventGraphJumpSimple {
 
        public PrepareEventGraphJumpSimple(double tv, double tc, int sessionID, int personID, string table, 
string type, bool djShowHeights)
        {
-               Sqlite.Open();
-
-               //select data from SQL to update graph  
-               jumpsAtSQL = SqliteJump.SelectJumpsSA(true, sessionID, personID, "", type,
+               jumpsAtSQL = SqliteJump.SelectJumps (sessionID, personID, type,
                                Sqlite.Orders_by.ID_DESC, 10); //select only last 10
-               //jumpsAtSQL = SqliteJump.SelectJumps (true, sessionID, personID, "", type,
-               //              Sqlite.Orders_by.ID_DESC, 10); //select only last 10
+
+               Sqlite.Open();
 
 
                string sqlSelect = "";
diff --git a/src/jumpsEvolution.cs b/src/jumpsEvolution.cs
index 6f0e4c46..f00a5005 100644
--- a/src/jumpsEvolution.cs
+++ b/src/jumpsEvolution.cs
@@ -36,7 +36,7 @@ public class JumpsEvolution
        public void Calculate (int personID, string jumpType)
        {
                //1 get data
-                List<Jump> jump_l = SqliteJump.SelectJumps (personID, -1, jumpType);
+                List<Jump> jump_l = SqliteJump.SelectJumps (-1, personID, jumpType, 
Sqlite.Orders_by.DEFAULT, -1);
 
                //2 convert to list of PointF
                point_l = new List<PointF>();
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index 54f82009..785f437b 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.cs
@@ -195,22 +195,34 @@ class SqliteJump : Sqlite
 
        //like SelectJumpsSA above method but much better: return list of jumps
        //sID -1 means all sessions
-       public static List<Jump> SelectJumps (int pID, int sID, string jumpType)
+       //limit -1 means no limit
+       public static List<Jump> SelectJumps (int sID, int pID, string jumpType, Orders_by order, int limit)
        {
          //jumps previous to DB 1.82 have no datetime on jump
          //find session datetime for that jumps
          List<Session> session_l = SqliteSession.SelectAll();
 
-         string personID = pID.ToString();
          string filterSessionString = "";
          if(sID != -1)
                  filterSessionString = " AND sessionID == " + sID.ToString();
 
+         string personID = pID.ToString();
+
+         string orderByString = " ORDER BY jump.uniqueID ";
+         if(order == Orders_by.ID_DESC)
+                 orderByString = " ORDER BY jump.uniqueID DESC ";
+
+         string limitString = "";
+         if(limit != -1)
+                 limitString = " LIMIT " + limit;
+
+
          Sqlite.Open();
 
          // Selecciona les dades de tots els salts
          dbcmd.CommandText = "SELECT * FROM jump WHERE personID = " + personID +
-                 filterSessionString +  " AND jump.type = \"" + jumpType + "\"";
+                 filterSessionString +  " AND jump.type = \"" + jumpType + "\"" +
+                 orderByString + limitString;
 
          LogB.SQL(dbcmd.CommandText.ToString());
          dbcmd.ExecuteNonQuery();


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