[chronojump] reaction time graph update does not call SQL



commit d3b6aeae24eec29290925b2ba6ae22324a1632d7
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Nov 11 17:34:35 2013 +0100

    reaction time graph update does not call SQL

 src/execute/reactionTime.cs |    6 ++++--
 src/exportSession.cs        |    2 +-
 src/gui/chronojump.cs       |    4 ++--
 src/gui/eventExecute.cs     |   25 ++++++++++---------------
 src/gui/usefulObjects.cs    |   20 +++++++++++++++++++-
 src/report.cs               |    2 +-
 src/server.cs               |    2 +-
 src/sqlite/reactionTime.cs  |   10 +++++++---
 8 files changed, 45 insertions(+), 26 deletions(-)
---
diff --git a/src/execute/reactionTime.cs b/src/execute/reactionTime.cs
index 2dcb8bd..2503a07 100644
--- a/src/execute/reactionTime.cs
+++ b/src/execute/reactionTime.cs
@@ -247,9 +247,11 @@ public class ReactionTimeExecute : EventExecute
                else
                        feedbackMessage = "";
                needShowFeedbackMessage = true; 
+               
+               string table = Constants.ReactionTimeTable;
 
                uniqueID = SqliteReactionTime.Insert(
-                               false, Constants.ReactionTimeTable, 
+                               false, table, 
                                "NULL", personID, sessionID, "", //type
                                time, "", Util.BoolToNegativeInt(simulated)); //time, description, simulated
 
@@ -260,7 +262,7 @@ public class ReactionTimeExecute : EventExecute
                fakeButtonFinished.Click();
                
                //app1.PrepareJumpSimpleGraph(tv, tc);
-               PrepareEventGraphReactionTimeObject = new PrepareEventGraphReactionTime(time);
+               PrepareEventGraphReactionTimeObject = new PrepareEventGraphReactionTime(time, sessionID, 
personID, table, type);
                needUpdateGraphType = eventType.REACTIONTIME;
                needUpdateGraph = true;
                
diff --git a/src/exportSession.cs b/src/exportSession.cs
index 534b2dc..8b34cc8 100644
--- a/src/exportSession.cs
+++ b/src/exportSession.cs
@@ -156,7 +156,7 @@ public class ExportSession
                myJumpsRj = SqliteJumpRj.SelectJumps(mySession.UniqueID, -1, "", "");
                myRuns= SqliteRun.SelectRuns(false, mySession.UniqueID, -1, "");
                myRunsInterval = SqliteRunInterval.SelectRuns(mySession.UniqueID, -1, "");
-               myReactionTimes = SqliteReactionTime.SelectReactionTimes(mySession.UniqueID, -1);
+               myReactionTimes = SqliteReactionTime.SelectReactionTimes(false, mySession.UniqueID, -1);
                myPulses = SqlitePulse.SelectPulses(mySession.UniqueID, -1);
                myMCs = SqliteMultiChronopic.SelectTests(mySession.UniqueID, -1);
        }
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 13e0454..1ed48cd 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -1783,7 +1783,7 @@ public partial class ChronoJumpWindow
 
        //private void fillTreeView_reaction_times (string filter) {
        private void fillTreeView_reaction_times () {
-               string [] myRTs = SqliteReactionTime.SelectReactionTimes(currentSession.UniqueID, -1);
+               string [] myRTs = SqliteReactionTime.SelectReactionTimes(false, currentSession.UniqueID, -1);
                myTreeViewReactionTimes.Fill(myRTs, "");
                expandOrMinimizeTreeView((TreeViewEvent) myTreeViewReactionTimes, treeview_reaction_times);
        }
@@ -4373,7 +4373,7 @@ Console.WriteLine("X");
                                        PreparePulseGraph(Util.GetLast(currentPulse.TimesString), 
currentPulse.TimesString);
                                        break;
                                case EventType.Types.REACTIONTIME:
-                                       PrepareReactionTimeGraph(currentReactionTime.Time);
+                                       
PrepareReactionTimeGraph(currentEventExecute.PrepareEventGraphReactionTimeObject);
                                        break;
                                case EventType.Types.MULTICHRONOPIC:
                                        PrepareMultiChronopicGraph(
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index dfdeded..8ad65e6 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -891,21 +891,13 @@ Log.WriteLine("Preparing reactive A");
                event_execute_drawingarea.QueueDraw();
        }
        
-       public void PrepareReactionTimeGraph(double time) 
+       public void PrepareReactionTimeGraph(PrepareEventGraphReactionTime eventGraph) 
        {
                //check graph properties window is not null (propably user has closed it with the DeleteEvent
                //then create it, but not show it
                if(eventGraphConfigureWin == null)
                        eventGraphConfigureWin = EventGraphConfigureWindow.Show(false);
 
-               
-               //obtain data
-               string [] rts = SqliteReactionTime.SelectReactionTimes(currentSession.UniqueID, 
event_execute_personID);
-
-               double timePersonAVG = SqliteSession.SelectAVGEventsOfAType(
-                               false, currentSession.UniqueID, event_execute_personID, 
event_execute_tableName, event_execute_eventType, "time");
-               double timeSessionAVG = SqliteSession.SelectAVGEventsOfAType(
-                               false, currentSession.UniqueID, -1, event_execute_tableName, 
event_execute_eventType, "time");
 
                double maxValue = 0;
                double minValue = 0;
@@ -915,7 +907,8 @@ Log.WriteLine("Preparing reactive A");
                //if max value of graph is automatic
                if(eventGraphConfigureWin.Max == -1) {
                        maxValue = Util.GetMax(
-                                       time.ToString() + "=" + timePersonAVG.ToString() + "=" + 
timeSessionAVG.ToString());
+                                       eventGraph.time.ToString() + "=" + 
+                                       eventGraph.timePersonAVGAtSQL.ToString() + "=" + 
eventGraph.timeSessionAVGAtSQL.ToString());
                } else {
                        maxValue = eventGraphConfigureWin.Max;
                        topMargin = 0;
@@ -924,16 +917,19 @@ Log.WriteLine("Preparing reactive A");
                //if min value of graph is automatic
                if(eventGraphConfigureWin.Min == -1) {
                        minValue = Util.GetMin(
-                                       time.ToString() + "=" + timePersonAVG.ToString() + "=" + 
timeSessionAVG.ToString());
+                                       eventGraph.time.ToString() + "=" + 
+                                       eventGraph.timePersonAVGAtSQL.ToString() + "=" + 
eventGraph.timeSessionAVGAtSQL.ToString());
                } else {
                        minValue = eventGraphConfigureWin.Min;
                        bottomMargin = 0;
                }
                
                //paint graph (use simple jump method)
-               paintJumpSimple (event_execute_drawingarea, rts, time, timePersonAVG, timeSessionAVG, 0, 0, 
0, maxValue, minValue, topMargin, bottomMargin);
+               paintJumpSimple (event_execute_drawingarea, eventGraph.rtsAtSQL, 
+                               eventGraph.time, eventGraph.timePersonAVGAtSQL, 
eventGraph.timeSessionAVGAtSQL, 
+                               0, 0, 0, maxValue, minValue, topMargin, bottomMargin);
 
-               printLabelsReactionTime (time, timePersonAVG, timeSessionAVG);
+               printLabelsReactionTime (eventGraph.time, eventGraph.timePersonAVGAtSQL, 
eventGraph.timeSessionAVGAtSQL);
                
                // -- refresh
                event_execute_drawingarea.QueueDraw();
@@ -1836,8 +1832,7 @@ Log.WriteLine("Preparing reactive A");
                                }
                                break;
                        case EventType.Types.REACTIONTIME:
-                                       PrepareReactionTimeGraph(
-                                                       
currentEventExecute.PrepareEventGraphReactionTimeObject.time);
+                                       
PrepareReactionTimeGraph(currentEventExecute.PrepareEventGraphReactionTimeObject);
                                break;
                        case EventType.Types.PULSE:
                                        PreparePulseGraph(
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index 61189d7..530a8d7 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -215,12 +215,30 @@ public class PrepareEventGraphPulse {
 }
 
 public class PrepareEventGraphReactionTime {
+       //sql data of previous rts to plot graph and show stats at bottom
+       public string [] rtsAtSQL;
+       public double timePersonAVGAtSQL;
+       public double timeSessionAVGAtSQL;
+
        public double time;
 
        public PrepareEventGraphReactionTime() {
        }
 
-       public PrepareEventGraphReactionTime(double time) {
+       public PrepareEventGraphReactionTime(double time, int sessionID, int personID, string table, string 
type) 
+       {
+               Sqlite.Open();
+
+               //obtain data
+               rtsAtSQL = SqliteReactionTime.SelectReactionTimes(true, sessionID, personID);
+
+               timePersonAVGAtSQL = SqliteSession.SelectAVGEventsOfAType(
+                               true, sessionID, personID, table, type, "time");
+               timeSessionAVGAtSQL = SqliteSession.SelectAVGEventsOfAType(
+                               true, sessionID, -1, table, type, "time");
+               
+               Sqlite.Close();
+       
                this.time = time;
        }
 
diff --git a/src/report.cs b/src/report.cs
index 1dbb94b..f44598a 100644
--- a/src/report.cs
+++ b/src/report.cs
@@ -132,7 +132,7 @@ public class Report : ExportSession
                        myRunsInterval = SqliteRunInterval.SelectRuns(sessionID, -1, "");
                }
                if(ShowReactionTimes) {
-                       myReactionTimes= SqliteReactionTime.SelectReactionTimes(sessionID, -1);
+                       myReactionTimes= SqliteReactionTime.SelectReactionTimes(false, sessionID, -1);
                }
                if(ShowPulses) {
                        myPulses= SqlitePulse.SelectPulses(sessionID, -1);
diff --git a/src/server.cs b/src/server.cs
index 5af4a01..01a50a7 100644
--- a/src/server.cs
+++ b/src/server.cs
@@ -452,7 +452,7 @@ public class Server
                                countE = 0;                                     
                                countS = 0;                                     
 
-                               string [] rts = 
SqliteReactionTime.SelectReactionTimes(currentSession.UniqueID, person.UniqueID);
+                               string [] rts = SqliteReactionTime.SelectReactionTimes(false, 
currentSession.UniqueID, person.UniqueID);
                                Sqlite.Open();
                                foreach(string myRt in rts) {
                                        string [] js = myRt.Split(new char[] {':'});
diff --git a/src/sqlite/reactionTime.cs b/src/sqlite/reactionTime.cs
index e7528d5..e79d429 100644
--- a/src/sqlite/reactionTime.cs
+++ b/src/sqlite/reactionTime.cs
@@ -84,15 +84,17 @@ class SqliteReactionTime : Sqlite
        }
 
        //if all persons, put -1 in personID
-       public static string[] SelectReactionTimes(int sessionID, int personID) 
+       public static string[] SelectReactionTimes(bool dbconOpened, int sessionID, int personID) 
        {
+               if(!dbconOpened)
+                       dbcon.Open();
+
                string tp = Constants.PersonTable;
 
                string filterPersonString = "";
                if(personID != -1)
                        filterPersonString = " AND " + tp + ".uniqueID == " + personID;
 
-               dbcon.Open();
                dbcmd.CommandText = "SELECT " + tp + ".name, reactionTime.* " +
                        " FROM " + tp + ", reactionTime " +
                        " WHERE " + tp + ".uniqueID == reactionTime.personID" + 
@@ -125,7 +127,9 @@ class SqliteReactionTime : Sqlite
                }
 
                reader.Close();
-               dbcon.Close();
+               
+               if(!dbconOpened)
+                       dbcon.Close();
 
                string [] myEvents = new string[count];
                count =0;


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