[chronojump] Run simple graph can compare between run types and persons



commit 07bebd57d73832ae5bcae1fd869fc1f8f0c33254
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Jun 18 13:22:13 2020 +0200

    Run simple graph can compare between run types and persons

 src/execute/event.cs       |   2 +-
 src/execute/jump.cs        |   6 +--
 src/execute/run.cs         |  15 ++++++-
 src/gui/app1/chronojump.cs |   4 +-
 src/gui/app1/jump.cs       |   4 +-
 src/gui/app1/run.cs        |  11 ++++-
 src/gui/eventExecute.cs    | 109 ++++++++++++++++++++++++++++++---------------
 src/gui/usefulObjects.cs   |  17 +++++--
 8 files changed, 118 insertions(+), 50 deletions(-)
---
diff --git a/src/execute/event.cs b/src/execute/event.cs
index f3699649..3b38f341 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -80,7 +80,7 @@ public class EventExecute
        protected bool volumeOn;
        protected Preferences.GstreamerTypes gstreamer;
        protected int graphLimit;
-       protected bool graphAllJumps;
+       protected bool graphAllTypes;
        protected bool graphAllPersons;
        protected double progressbarLimit;
        protected RepetitiveConditionsWindow repetitiveConditionsWin;
diff --git a/src/execute/jump.cs b/src/execute/jump.cs
index dfa7f0a6..8e3c767c 100644
--- a/src/execute/jump.cs
+++ b/src/execute/jump.cs
@@ -60,7 +60,7 @@ public class JumpExecute : EventExecute
                        bool volumeOn, Preferences.GstreamerTypes gstreamer,
                        double progressbarLimit, ExecutingGraphData egd, string description,
                        bool avoidGraph, //on configChronojump.Exhibition do not show graph because it gets 
too slow with big database
-                       bool jumpsDjGraphHeights, int graphLimit, bool graphAllJumps, bool graphAllPersons
+                       bool jumpsDjGraphHeights, int graphLimit, bool graphAllTypes, bool graphAllPersons
                        )
        {
                this.personID = personID;
@@ -82,7 +82,7 @@ public class JumpExecute : EventExecute
                this.avoidGraph = avoidGraph;
                this.jumpsDjGraphHeights = jumpsDjGraphHeights;
                this.graphLimit = graphLimit;
-               this.graphAllJumps = graphAllJumps;
+               this.graphAllTypes = graphAllTypes;
                this.graphAllPersons = graphAllPersons;
        
                if(TypeHasFall) {
@@ -483,7 +483,7 @@ public class JumpExecute : EventExecute
 
                if(! avoidGraph)
                {
-                       if(graphAllJumps)
+                       if(graphAllTypes)
                                type = "";
 
                        PrepareEventGraphJumpSimpleObject = new PrepareEventGraphJumpSimple(
diff --git a/src/execute/run.cs b/src/execute/run.cs
index a80d44f0..aae6df70 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -83,7 +83,8 @@ public class RunExecute : EventExecute
                        double progressbarLimit, ExecutingGraphData egd,
                        Constants.DoubleContact checkDoubleContactMode, int checkDoubleContactTime, 
                        bool speedStartArrival, bool measureReactionTime,
-                       Gtk.Image image_run_execute_running, Gtk.Image image_run_execute_photocell
+                       Gtk.Image image_run_execute_running, Gtk.Image image_run_execute_photocell,
+                       int graphLimit, bool graphAllTypes, bool graphAllPersons
                        )
        {
                this.personID = personID;
@@ -106,6 +107,9 @@ public class RunExecute : EventExecute
                this.measureReactionTime = measureReactionTime;
                this.image_run_execute_running = image_run_execute_running;
                this.image_run_execute_photocell = image_run_execute_photocell;
+               this.graphLimit = graphLimit;
+               this.graphAllTypes = graphAllTypes;
+               this.graphAllPersons = graphAllPersons;
 
                reactionTimeMS = 0;
 
@@ -702,8 +706,15 @@ public class RunExecute : EventExecute
                //define the created object
                eventDone = new Run(uniqueID, personID, sessionID, type, distance, trackTime, description, 
Util.BoolToNegativeInt(simulated), !startIn);
 
+               if(graphAllTypes)
+                       type = "";
+
                //app1.PrepareRunSimpleGraph(time, distance/time);
-               PrepareEventGraphRunSimpleObject = new PrepareEventGraphRunSimple(trackTime, 
distance/trackTime, sessionID, personID, table, type);
+               PrepareEventGraphRunSimpleObject = new PrepareEventGraphRunSimple(
+                               trackTime, distance/trackTime, sessionID,
+                               personID, graphAllPersons, graphLimit,
+                               table, type);
+
                needUpdateGraphType = eventType.RUN;
                needUpdateGraph = true;
                
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 69a6b59d..5f5ba9ac 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -4468,7 +4468,9 @@ public partial class ChronoJumpWindow
                                preferences.runSpeedStartArrival,
                                check_run_simple_with_reaction_time.Active,
                                image_run_execute_running,
-                               image_run_execute_photocell
+                               image_run_execute_photocell,
+                               Convert.ToInt32(spin_contacts_graph_last_limit.Value),
+                               radio_contacts_graph_allTests.Active, radio_contacts_graph_allPersons.Active
                                );
 
                if (! canCaptureC)
diff --git a/src/gui/app1/jump.cs b/src/gui/app1/jump.cs
index 35cbf370..718c5f43 100644
--- a/src/gui/app1/jump.cs
+++ b/src/gui/app1/jump.cs
@@ -273,10 +273,10 @@ public partial class ChronoJumpWindow
                if(radio_contacts_graph_allTests.Active)
                        typeTemp = "";
 
-
                PrepareEventGraphJumpSimple eventGraph = new PrepareEventGraphJumpSimple(
                                tv, tc, currentSession.UniqueID,
-                               currentPerson.UniqueID, radio_contacts_graph_allPersons.Active, 
Convert.ToInt32(spin_contacts_graph_last_limit.Value),
+                               currentPerson.UniqueID, radio_contacts_graph_allPersons.Active,
+                               Convert.ToInt32(spin_contacts_graph_last_limit.Value),
                                Constants.JumpTable, typeTemp, preferences.jumpsDjGraphHeights);
                
                if(eventGraph.personMAXAtSQLAllSessions > 0 || eventGraph.jumpsAtSQL.Count > 0)
diff --git a/src/gui/app1/run.cs b/src/gui/app1/run.cs
index 849ba6c9..d6001fd7 100644
--- a/src/gui/app1/run.cs
+++ b/src/gui/app1/run.cs
@@ -153,11 +153,18 @@ public partial class ChronoJumpWindow
                        currentRunType.Name 
                        );
 
+               string typeTemp = currentEventType.Name;
+               if(radio_contacts_graph_allTests.Active)
+                       typeTemp = "";
+
                PrepareEventGraphRunSimple eventGraph = new PrepareEventGraphRunSimple(
                                1, 1, //both unused
-                               currentSession.UniqueID, currentPerson.UniqueID, Constants.RunTable, 
currentEventType.Name);
+                               currentSession.UniqueID,
+                               currentPerson.UniqueID, radio_contacts_graph_allPersons.Active,
+                               Convert.ToInt32(spin_contacts_graph_last_limit.Value),
+                               Constants.RunTable, typeTemp);
                
-               if(eventGraph.personMAXAtSQLAllSessions > 0 || eventGraph.runsAtSQL.Length > 0)
+               if(eventGraph.personMAXAtSQLAllSessions > 0 || eventGraph.runsAtSQL.Count > 0)
                        PrepareRunSimpleGraph(eventGraph, false); //don't animate
        }
        private void updateGraphRunsInterval ()
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index b40309d9..90c565f1 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -1122,9 +1122,10 @@ public partial class ChronoJumpWindow
                int longestWordSize = 0;
                if (showTextOnBar)
                {
-                       longestWordSize = findLongestWordSize (eventGraph.jumpsAtSQL, eventGraph.type == ""); 
// condition for "all jumps"
-                       layoutText = calculateLayoutFontForText (eventGraph.jumpsAtSQL, longestWordSize, 
layoutText, ancho);
-                       maxRowsForText = calculateMaxRowsForText (eventGraph.jumpsAtSQL, longestWordSize, 
eventGraph.type == ""); //also adds +1 if simulated
+                       List<Event> events = Jump.JumpListToEventList(eventGraph.jumpsAtSQL);
+                       longestWordSize = findLongestWordSize (events, eventGraph.type == ""); // condition 
for "all jumps"
+                       layoutText = calculateLayoutFontForText (events, longestWordSize, layoutText, ancho);
+                       maxRowsForText = calculateMaxRowsForText (events, longestWordSize, eventGraph.type == 
""); //also adds +1 if simulated
                        bottomMargin = calculateBottomMarginForText (maxRowsForText, layoutText);
                }
 
@@ -1146,8 +1147,8 @@ public partial class ChronoJumpWindow
                paintSimpleAxis(ancho, alto, topMargin, bottomMargin, layout, "cm");
 
                //calculate separation between series and bar width
-               int distanceBetweenCols = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(1+.5)/eventGraph.jumpsAtSQL.Count) -
-                       Convert.ToInt32((ancho-event_execute_rightMargin)*(0+.5)/eventGraph.jumpsAtSQL.Count);
+               int distanceBetweenCols = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(1+.5)/countJumps) -
+                       Convert.ToInt32((ancho-event_execute_rightMargin)*(0+.5)/countJumps);
 
                /*
                 * check if one bar has to be shown or two
@@ -1366,11 +1367,11 @@ public partial class ChronoJumpWindow
                                layout);
        }
 
-       private int calculateMaxRowsForText (List<Jump> jumps, int longestWordSize, bool allJumps)
+       private int calculateMaxRowsForText (List<Event> events, int longestWordSize, bool allJumps)
        {
                int maxRows = 0;
 
-               foreach(Jump jump in jumps)
+               foreach(Event ev in events)
                {
                        int rows = 0;
                        if(allJumps)                    //to write the jump type (1st the jump type because 
it's only one row)
@@ -1378,7 +1379,7 @@ public partial class ChronoJumpWindow
 
                        //try to pack small words if they fit in a row using wordsAccu (accumulated)
                        string wordsAccu = "";
-                       string [] words = jump.Description.Split(new char[] {' '});
+                       string [] words = ev.Description.Split(new char[] {' '});
 
                        foreach(string word in words)
                        {
@@ -1394,7 +1395,7 @@ public partial class ChronoJumpWindow
                        if(wordsAccu != "")
                                rows ++;
 
-                       if(jump.Simulated == -1) //to write simulated at bottom
+                       if(ev.Simulated == -1) //to write simulated at bottom
                                rows ++;
 
                        if(rows > maxRows)
@@ -1415,13 +1416,13 @@ public partial class ChronoJumpWindow
                return lHeight * maxRows;
        }
 
-       private int findLongestWordSize (List<Jump> jumps, bool allJumps)
+       private int findLongestWordSize (List<Event> events, bool allTypes)
        {
                int longestWordSize = 0;
 
-               foreach(Jump jump in jumps)
+               foreach(Event ev in events)
                {
-                       string [] textArray = jump.Description.Split(new char[] {' '});
+                       string [] textArray = ev.Description.Split(new char[] {' '});
                        foreach(string text in textArray)
                        {
                                if(text.Length > longestWordSize)
@@ -1430,17 +1431,17 @@ public partial class ChronoJumpWindow
 
                        //note jump type will be in one line
                        //TODO: check it in local user language (Catalog)
-                       if(allJumps && jump.Type.Length > longestWordSize)
-                               longestWordSize = jump.Type.Length;
+                       if(allTypes && ev.Type.Length > longestWordSize)
+                               longestWordSize = ev.Type.Length;
 
-                       if(jump.Simulated == -1 && event_execute_label_simulated.Length > longestWordSize)
+                       if(ev.Simulated == -1 && event_execute_label_simulated.Length > longestWordSize)
                                longestWordSize = event_execute_label_simulated.Length;
                }
 
                return longestWordSize;
        }
 
-       private Pango.Layout calculateLayoutFontForText (List<Jump> jumps, int longestWordSize, Pango.Layout 
layout, int ancho)
+       private Pango.Layout calculateLayoutFontForText (List<Event> events, int longestWordSize, 
Pango.Layout layout, int ancho)
        {
                // 1) set marginBetweenTexts to 1.1 character
                layout.SetMarkup("a");
@@ -1457,7 +1458,7 @@ public partial class ChronoJumpWindow
                layout.GetPixelSize(out lWidth, out lHeight);
 
                // 3) if longestWord * jumps.Count does not fit, iterate to find correct font size
-               if(jumps.Count * (lWidth + marginBetweenTexts) > ancho)
+               if(events.Count * (lWidth + marginBetweenTexts) > ancho)
                {
                        int i = 1;
                        do {
@@ -1469,7 +1470,7 @@ public partial class ChronoJumpWindow
                                layout.GetPixelSize(out lWidth, out lHeight);
 
                                i ++;
-                       } while (jumps.Count * (lWidth + marginBetweenTexts) > ancho);
+                       } while (events.Count * (lWidth + marginBetweenTexts) > ancho);
                }
 
                return layout;
@@ -1669,6 +1670,10 @@ public partial class ChronoJumpWindow
                int ancho=drawingarea.Allocation.Width;
                int alto=drawingarea.Allocation.Height;
 
+               //person name or test type
+               //note that this could be a problem if there is a run with Description of several lines and 
current person, current test is used
+               bool showTextOnBar = true;
+
                //fix problem on show graph at Chronojump start
                if(event_execute_drawingarea == null ||
                                event_execute_pixmap == null ||
@@ -1709,7 +1714,20 @@ public partial class ChronoJumpWindow
                drawGuideOrAVG(pen_green_discont, eventGraphConfigureWin.GreenGuide, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue);
                */
 
-               //blue for TF
+               int countToDraw = eventGraph.runsAtSQL.Count;
+               int countRuns = eventGraph.runsAtSQL.Count;
+               int maxRowsForText = 0;
+
+               Pango.Layout layoutText = layoutMid;
+               int longestWordSize = 0;
+               if (showTextOnBar)
+               {
+                       List<Event> events = Run.RunListToEventList(eventGraph.runsAtSQL);
+                       longestWordSize = findLongestWordSize (events, eventGraph.type == ""); // condition 
for "all runs"
+                       layoutText = calculateLayoutFontForText (events, longestWordSize, layoutText, ancho);
+                       maxRowsForText = calculateMaxRowsForText (events, longestWordSize, eventGraph.type == 
""); //also adds +1 if simulated
+                       bottomMargin = calculateBottomMarginForText (maxRowsForText, layoutText);
+               }
                        
                drawGuideOrAVG(pen_black_90, eventGraph.sessionMAXAtSQL, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue, guideWidthEnum.FULL);
                drawGuideOrAVG(pen_black_discont, eventGraph.sessionAVGAtSQL, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue, guideWidthEnum.FULL);
@@ -1721,7 +1739,7 @@ public partial class ChronoJumpWindow
                // if has run on another session, magenta line: personMAXAtSQLAllSessions will be displayed
                // if other persons have run on this session, eventGraph.sessionMAXAtSQL and 
eventGraph.sessionAVGAtSQL will be displayed
                // don't need the rest of the method
-               if(eventGraph.runsAtSQL.Length == 0)
+               if(countRuns == 0)
                        return;
                
                //if person max in all sessions == person max this session, this session max will be only at 
left,
@@ -1736,27 +1754,48 @@ public partial class ChronoJumpWindow
                paintSimpleAxis(ancho, alto, topMargin, bottomMargin, layoutSmallMid, "m/s");
 
                //calculate bar width
-               int distanceBetweenCols = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(1+.5)/eventGraph.runsAtSQL.Length) -
-                       Convert.ToInt32((ancho-event_execute_rightMargin)*(0+.5)/eventGraph.runsAtSQL.Length);
+               int distanceBetweenCols = Convert.ToInt32((ancho-event_execute_rightMargin)*(1+.5)/countRuns) 
-
+                       Convert.ToInt32((ancho-event_execute_rightMargin)*(0+.5)/countRuns);
                int barWidth = Convert.ToInt32(.3*distanceBetweenCols);
                int barDesplLeft = Convert.ToInt32(.5*barWidth);
 
 
                int x = 0;
                int y = 0;
-               int count = eventGraph.runsAtSQL.Length;
-               foreach(string myStr in eventGraph.runsAtSQL) {
-                       string [] run = myStr.Split(new char[] {':'});
-                       if(Convert.ToDouble(run[5]) > 0 && Convert.ToDouble(run[6]) > 0) {
-                               x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(count-.5)/eventGraph.runsAtSQL.Length)-barDesplLeft;
-                               y = calculatePaintHeight(Convert.ToDouble(run[5])/Convert.ToDouble(run[6]), 
alto, maxValue, minValue, 
+               foreach(Run run in eventGraph.runsAtSQL)
+               {
+                       //string [] run = myStr.Split(new char[] {':'});
+                       if(run.Distance > 0 && run.Time > 0)
+                       {
+                               x = 
Convert.ToInt32((ancho-event_execute_rightMargin)*(countToDraw-.5)/countRuns)-barDesplLeft;
+                               y = calculatePaintHeight(run.Distance/run.Time, alto, maxValue, minValue,
                                                topMargin, bottomMargin);
 
-                               drawBar(x, y, barWidth, alto, bottomMargin, pen_background, count == 
eventGraph.runsAtSQL.Length,
-                                               Convert.ToDouble(run[5])/Convert.ToDouble(run[6]), layoutMid, 
animate);//, "", layoutMid, 0, animate);
+                               drawBar(x, y, barWidth, alto, bottomMargin, pen_background, countToDraw == 
countRuns,
+                                               run.Distance/run.Time, layoutMid, animate);//, "", layoutMid, 
0, animate);
                        }
 
-                       count --;
+                       //these two methods are out of drawBar because (on jumps) can be related to two bars 
TC,TF
+                       if(run.Simulated == -1)
+                               plotSimulatedMessage(
+                                               
Convert.ToInt32((ancho-event_execute_rightMargin)*(countToDraw-.5)/countRuns),
+                                               alto, layoutText);
+
+                       if (showTextOnBar && (eventGraph.type == "" || run.Description != ""))
+                       {
+                               string typeRowString = "";
+                               if (eventGraph.type == "") //if "all runs" show run.Type
+                                       typeRowString = run.Type;
+
+                               plotTextBelowBar(
+                                               
Convert.ToInt32((ancho-event_execute_rightMargin)*(countToDraw-.5)/countRuns),
+                                               y, alto,
+                                               typeRowString,
+                                               run.Description, //is the name of the person
+                                               layoutText, longestWordSize, maxRowsForText);
+                       }
+
+                       countToDraw --;
                }
        }
 
@@ -2701,16 +2740,16 @@ public partial class ChronoJumpWindow
        {
                if(current_menuitem_mode == Constants.Menuitem_modes.JUMPSSIMPLE)
                        updateGraphJumpsSimple ();
-
-               //TODO: run simple, rt
+               else if(current_menuitem_mode == Constants.Menuitem_modes.RUNSSIMPLE)
+                       updateGraphRunsSimple ();
        }
 
        private void on_radio_contacts_graph_person_toggled (object o, EventArgs args)
        {
                if(current_menuitem_mode == Constants.Menuitem_modes.JUMPSSIMPLE)
                        updateGraphJumpsSimple ();
-
-               //TODO: run simple, rt
+               else if(current_menuitem_mode == Constants.Menuitem_modes.RUNSSIMPLE)
+                       updateGraphRunsSimple ();
        }
 
        // <---- end of test simple controls -----
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index 0cb47343..9bfc9ef7 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -157,7 +157,7 @@ public class PrepareEventGraphJumpReactive {
 
 public class PrepareEventGraphRunSimple {
        //sql data of previous runs to plot graph and show stats at bottom
-       public string [] runsAtSQL;
+       public List<Run> runsAtSQL;
        
        public double personMAXAtSQLAllSessions;
        public double personMAXAtSQL;
@@ -168,17 +168,25 @@ public class PrepareEventGraphRunSimple {
        
        public double time;
        public double speed;
+       public string type; //jumpType (useful to know if "all jumps" (type == "")
 
        public PrepareEventGraphRunSimple() {
        }
 
-       public PrepareEventGraphRunSimple(double time, double speed, int sessionID, int personID, string 
table, string type) 
+       public PrepareEventGraphRunSimple(double time, double speed, int sessionID,
+                       int personID, bool allPersons, int limit,
+                       string table, string type)
        {
                Sqlite.Open();
                
+               int personIDTemp = personID;
+               if(allPersons)
+                       personIDTemp = -1;
+
                //obtain data
-               runsAtSQL = SqliteRun.SelectRunsSA (true, sessionID, personID, type,
-                               Sqlite.Orders_by.ID_DESC, 10); //select only last 10
+               runsAtSQL = SqliteRun.SelectRuns (true, sessionID, personIDTemp, type,
+                               Sqlite.Orders_by.ID_DESC, limit,
+                               allPersons); //show names on comments only if "all persons"
 
                
                string sqlSelect = "distance/time";
@@ -199,6 +207,7 @@ public class PrepareEventGraphRunSimple {
                
                this.time = time;
                this.speed = speed;
+               this.type = type;
                
                Sqlite.Close();
        }


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