[chronojump] runsSimple capture graph button maxAllSessions implemented



commit 582411c22fa737fe769f94a0d25450266bc2143c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jul 8 10:07:38 2016 +0200

    runsSimple capture graph button maxAllSessions implemented

 src/gui/eventExecute.cs  |   64 ++++++++++++++++++++++++++++++----------------
 src/gui/run.cs           |    2 +-
 src/gui/usefulObjects.cs |    2 +
 src/sqlite/run.cs        |   23 ++++++++++++++++
 4 files changed, 68 insertions(+), 23 deletions(-)
---
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 9a8036b..5373073 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -559,21 +559,29 @@ public partial class ChronoJumpWindow
        
        private void on_button_person_max_all_sessions_info_clicked(object o, EventArgs args) 
        {
+               string [] str;
+               string testName;
                if(radio_mode_jumps_small.Active) {
-                       string [] str = SqliteJump.SelectTestMaxStuff(currentPerson.UniqueID, 
currentJumpType); 
-                                       
-                       if(str[2] == "" || str[2] == "0")
-                               new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Missing 
data."));
-                       else {
-                               string message = string.Format(Catalog.GetString("Best {0} jump of person {1} 
is {2}\nDone at session {3} ({4})"),
-                                               currentJumpType.Name, currentPerson.Name, 
-                                               Util.TrimDecimals(Util.ChangeDecimalSeparator(str[2]), 3), 
-                                               str[1], str[0]);
-                               if(str[3] == "-1")
-                                       message += "\n" + Catalog.GetString("Simulated");
-
-                               new DialogMessage(Constants.MessageTypes.INFO, message);
-                       }
+                       str = SqliteJump.SelectTestMaxStuff(currentPerson.UniqueID, currentJumpType); 
+                       testName = currentJumpType.Name;
+               }
+               else if(radio_mode_runs_small.Active) {
+                       str = SqliteRun.SelectTestMaxStuff(currentPerson.UniqueID, currentRunType); 
+                       testName = currentRunType.Name;
+               } else
+                       return;
+
+               if(str[2] == "" || str[2] == "0")
+                       new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Missing data."));
+               else {
+                       string message = string.Format(Catalog.GetString("Best {0} test of person {1} is 
{2}\nDone at session {3} ({4})"),
+                                       testName, currentPerson.Name, 
+                                       Util.TrimDecimals(Util.ChangeDecimalSeparator(str[2]), 3), 
+                                       str[1], str[0]);
+                       if(str[3] == "-1")
+                               message += "\n" + Catalog.GetString("Simulated");
+
+                       new DialogMessage(Constants.MessageTypes.INFO, message);
                }
        }
        
@@ -671,9 +679,11 @@ public partial class ChronoJumpWindow
                int bottomMargin = 0; 
 
                //if max value of graph is automatic
-               if(eventGraphConfigureWin.Max == -1)
+               if(eventGraphConfigureWin.Max == -1) {
                        maxValue = eventGraph.sessionMAXAtSQL;
-               else {
+                       if(eventGraph.personMAXAtSQLAllSessions > maxValue)
+                               maxValue = eventGraph.personMAXAtSQLAllSessions;
+               } else {
                        maxValue = eventGraphConfigureWin.Max;
                        topMargin = 0;
                }
@@ -1114,12 +1124,6 @@ public partial class ChronoJumpWindow
                if(maxValue - minValue <= 0)
                        return;
                
-               //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 barWidth = Convert.ToInt32(.3*distanceBetweenCols);
-               int barDesplLeft = Convert.ToInt32(.5*barWidth);
-
                /*
                //paint reference guide black and green if needed
                drawGuideOrAVG(pen_black_discont, eventGraphConfigureWin.BlackGuide, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue);
@@ -1130,9 +1134,25 @@ public partial class ChronoJumpWindow
                        
                drawGuideOrAVG(pen_black_90, eventGraph.sessionMAXAtSQL, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue);
                drawGuideOrAVG(pen_black_discont, eventGraph.sessionAVGAtSQL, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue);
+               drawGuideOrAVG(pen_magenta, eventGraph.personMAXAtSQLAllSessions, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue);
+               
+               //if currentPerson has not run on this session, 
+               // 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)
+                       return;
+               
                drawGuideOrAVG(pen_yellow, eventGraph.personMAXAtSQL, alto, ancho, topMargin, bottomMargin, 
maxValue, minValue);
                drawGuideOrAVG(pen_yellow_discont, eventGraph.personAVGAtSQL, alto, ancho, topMargin, 
bottomMargin, maxValue, minValue);
 
+               //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 barWidth = Convert.ToInt32(.3*distanceBetweenCols);
+               int barDesplLeft = Convert.ToInt32(.5*barWidth);
+
+
                int x = 0;
                int y = 0;
                int count = eventGraph.runsAtSQL.Length;
diff --git a/src/gui/run.cs b/src/gui/run.cs
index ff10ab0..85ab20f 100644
--- a/src/gui/run.cs
+++ b/src/gui/run.cs
@@ -1007,7 +1007,7 @@ partial class ChronoJumpWindow
                                1, 1, //both unused
                                currentSession.UniqueID, currentPerson.UniqueID, Constants.RunTable, 
currentEventType.Name);
                
-               if(eventGraph.runsAtSQL.Length > 0)
+               if(eventGraph.personMAXAtSQLAllSessions > 0 || eventGraph.runsAtSQL.Length > 0)
                        PrepareRunSimpleGraph(eventGraph, false); //don't animate
        }
        
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index 4afb26d..4d1e828 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -131,6 +131,7 @@ public class PrepareEventGraphRunSimple {
        //sql data of previous runs to plot graph and show stats at bottom
        public string [] runsAtSQL;
        
+       public double personMAXAtSQLAllSessions;
        public double personMAXAtSQL;
        public double sessionMAXAtSQL;
 
@@ -154,6 +155,7 @@ public class PrepareEventGraphRunSimple {
                
                string sqlSelect = "distance/time";
                
+               personMAXAtSQLAllSessions = SqliteSession.SelectMAXEventsOfAType(true, -1, personID, table, 
type, sqlSelect);
                personMAXAtSQL = SqliteSession.SelectMAXEventsOfAType(true, sessionID, personID, table, type, 
sqlSelect);
                sessionMAXAtSQL = SqliteSession.SelectMAXEventsOfAType(true, sessionID, -1, table, type, 
sqlSelect);
                
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index b99f047..fa704cc 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -191,6 +191,29 @@ class SqliteRun : Sqlite
                return myRun;
        }
                
+       public static string [] SelectTestMaxStuff(int personID, RunType runType) 
+       {
+               Sqlite.Open();
+               
+               dbcmd.CommandText = "SELECT session.date, session.name, MAX(distance/time), run.simulated " + 
+                       " FROM run, session WHERE type = \"" + runType.Name + "\" AND personID = " + personID 
+ 
+                       " AND run.sessionID = session.uniqueID";
+               
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+               reader.Read();
+               
+               string [] str = DataReaderToStringArray(reader, 4);
+               
+               reader.Close();
+               Sqlite.Close();
+
+               return str;
+       }
+       
        public static void Update(int runID, string type, string distance, string time, int personID, string 
description)
        {
                Sqlite.Open();


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