[chronojump] jumpsProfile graph (2)



commit e3394a9e6b9ce76bbb62d53a957336dafd761781
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jun 28 10:49:23 2016 +0200

    jumpsProfile graph (2)

 src/gui/chronojump.cs   |   25 +++++++++++++
 src/gui/jumpsProfile.cs |   87 ++++++++++++++++++++++++++++++-----------------
 src/sqlite/jump.cs      |    2 +-
 src/sqlite/stat.cs      |   72 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 154 insertions(+), 32 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index ffc82b2..4817684 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -192,6 +192,9 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Button button_jumps_rj_result_help_power;
        [Widget] Gtk.Button button_jumps_rj_result_help_stiffness;
        
+       [Widget] Gtk.DrawingArea drawingarea_jumps_profile;
+       
+       
        //runs
        [Widget] Gtk.MenuItem menu_execute_simple_runs1;
        [Widget] Gtk.MenuItem menu_execute_intervallic_runs1;
@@ -6503,6 +6506,28 @@ LogB.Debug("X");
                                UtilGtk.ErasePaint(encoder_capture_curves_bars_drawingarea, 
encoder_capture_curves_bars_pixmap);
                }
        }
+       
+       JumpsProfileGraph jumpsProfileGraph;
+       private void jumpsProfileDo (bool calculateData, DrawingArea area) 
+       {
+               if(currentPerson == null || currentSession == null)
+                       return;
+               
+               if(jumpsProfileGraph == null)
+                       jumpsProfileGraph = new JumpsProfileGraph();
+
+
+               if(calculateData)
+                       jumpsProfileGraph.Calculate(currentPerson.UniqueID, currentSession.UniqueID);
+
+               jumpsProfileGraph.Graph(area);
+       }
+       private void on_drawingarea_jumps_profile_expose_event (object o, ExposeEventArgs args) 
+       {
+               DrawingArea area = (DrawingArea) o;
+               //jumpsProfileDo(false); //do not calculate data
+               jumpsProfileDo(true, area); //do not calculate data
+       }
 
 
        /* ---------------------------------------------------------
diff --git a/src/gui/jumpsProfile.cs b/src/gui/jumpsProfile.cs
index d20fb9e..7e9b3a2 100644
--- a/src/gui/jumpsProfile.cs
+++ b/src/gui/jumpsProfile.cs
@@ -20,54 +20,79 @@
 
 using System;
 using Gtk;
-using Glade;
 using Cairo;
+using System.Collections.Generic; //List
 
-partial class ChronoJumpWindow
+public class JumpsProfileGraph
 {
-       [Widget] Gtk.DrawingArea drawingarea_jumps_profile;
-       
-       private void on_drawingarea_jumps_profile_expose_event (object o, ExposeEventArgs args) 
+       private double index1;
+       private double index2;
+       private double index3;
+       private double index4;
+       private double index5;
+
+       public JumpsProfileGraph() {
+       }
+
+       public void Calculate (int personID, int sessionID)
+       {
+               List<Double> l = SqliteStat.SelectChronojumpProfile(personID, sessionID);
+
+               index1 = l[0];
+               index2 = l[1];
+               index3 = l[2];
+               index4 = l[3];
+               index5 = l[4];
+       }
+
+       public void Graph (DrawingArea area) 
        {
-               DrawingArea area = (DrawingArea) o;
                Cairo.Context g = Gdk.CairoHelper.Create (area.GdkWindow);
-               
-               jp_plotArc(100, 100, 50, 0, 0.25, g, new Cairo.Color(1,0,0));
-               jp_plotArc(100, 100, 50, .25, .75, g, new Cairo.Color(0,1,0));
-               jp_plotArc(100, 100, 50, .75, 2, g, new Cairo.Color(0,0,1));
+
+               //TODO: delete this             
+               plotArc(100, 100, 50, 0, 0.25, g, new Cairo.Color(1,0,0));
+               plotArc(100, 100, 50, .25, .75, g, new Cairo.Color(0,1,0));
+               plotArc(100, 100, 50, .75, 2, g, new Cairo.Color(0,0,1));
        
                //palette: http://www.colourlovers.com/palette/7991/%28not_so%29_still_life     
-               jp_plotArc(300, 200, 150, 0, 0.25, g, jp_colorFromRGB(90,68,102));
-               jp_plotArc(300, 200, 150, .25, .75, g, jp_colorFromRGB(240,57,43));
-               jp_plotArc(300, 200, 150, .75, 1.25, g, jp_colorFromRGB(254,176,20));
-               jp_plotArc(300, 200, 150, 1.25, 1.5, g, jp_colorFromRGB(250,209,7));
-               jp_plotArc(300, 200, 150, 1.5, 2, g, jp_colorFromRGB(235,235,207));
+               Cairo.Color color1 = colorFromRGB(90,68,102);
+               Cairo.Color color2 = colorFromRGB(240,57,43);
+               Cairo.Color color3 = colorFromRGB(254,176,20);
+               Cairo.Color color4 = colorFromRGB(250,209,7);
+               Cairo.Color color5 = colorFromRGB(235,235,207);
+               
+               //TODO: use indexes
+               plotArc(300, 200, 150, 0, 0.25, g, color1);
+               plotArc(300, 200, 150, .25, .75, g, color2);
+               plotArc(300, 200, 150, .75, 1.25, g, color3);
+               plotArc(300, 200, 150, 1.25, 1.5, g, color4);
+               plotArc(300, 200, 150, 1.5, 2, g, color5);
 
                int width = 40;
                int height = 24;
                //R seq(from=50,to=(350-24),length.out=5)
                //[1] 50 119 188 257 326 
-               jp_drawRoundedRectangle (500,  50, width, height, 3, g, jp_colorFromRGB(90,68,102));
-               jp_drawRoundedRectangle (500, 119, width, height, 4, g, jp_colorFromRGB(240,57,43));
-               jp_drawRoundedRectangle (500, 188, width, height, 5, g, jp_colorFromRGB(254,176,20));
-               jp_drawRoundedRectangle (500, 257, width, height, 6, g, jp_colorFromRGB(250,209,7));
-               jp_drawRoundedRectangle (500, 326, width, height, 7, g, jp_colorFromRGB(235,235,207));
+               drawRoundedRectangle (500,  50, width, height, 3, g, color1);
+               drawRoundedRectangle (500, 119, width, height, 4, g, color2);
+               drawRoundedRectangle (500, 188, width, height, 5, g, color3);
+               drawRoundedRectangle (500, 257, width, height, 6, g, color4);
+               drawRoundedRectangle (500, 326, width, height, 7, g, color5);
        
                g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
                int textHeight = 12;
                g.SetFontSize(textHeight);
                
-               jp_printText(560,  50, height, textHeight, "Index 1", g);
-               jp_printText(560, 119, height, textHeight, "Index 2", g);
-               jp_printText(560, 188, height, textHeight, "Index 3", g);
-               jp_printText(560, 257, height, textHeight, "Index 4", g);
-               jp_printText(560, 326, height, textHeight, "Index 5", g);
+               printText(560,  50, height, textHeight, "Index 1", g);
+               printText(560, 119, height, textHeight, "Index 2", g);
+               printText(560, 188, height, textHeight, "Index 3", g);
+               printText(560, 257, height, textHeight, "Index 4", g);
+               printText(560, 326, height, textHeight, "Index 5", g);
 
                g.GetTarget().Dispose ();
                g.Dispose ();
        }
        
-       private void jp_plotArc(int centerx, int centery, int radius, double start, double end, 
+       private void plotArc(int centerx, int centery, int radius, double start, double end, 
                        Cairo.Context g, Cairo.Color color) 
        {
                //pie chart
@@ -82,19 +107,19 @@ partial class ChronoJumpWindow
                g.Stroke ();
        }
        
-       private void jp_printText(int x, int y, int height, int textHeight, string text, Cairo.Context g) {
+       private void printText(int x, int y, int height, int textHeight, string text, Cairo.Context g) {
                g.MoveTo(x, ((y+y+height)/2) + textHeight/2.0);
                g.ShowText(text);
        }
 
        //http://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cairo/cookbook/       
-       private void jp_drawRoundedRectangle (double x, double y, double width, double height, 
+       private void drawRoundedRectangle (double x, double y, double width, double height, 
                        double radius, Cairo.Context g, Cairo.Color color)
        {
                g.Save ();
 
                if ((radius > height / 2) || (radius > width / 2))
-                       radius = jp_min (height / 2, width / 2);
+                       radius = min (height / 2, width / 2);
 
                g.MoveTo (x, y + radius);
                g.Arc (x + radius, y + radius, radius, Math.PI, -Math.PI / 2);
@@ -114,7 +139,7 @@ partial class ChronoJumpWindow
                g.Stroke ();    
        }
 
-       private double jp_min (params double[] arr)
+       private double min (params double[] arr)
        {
                int minp = 0;
                for (int i = 1; i < arr.Length; i++)
@@ -124,7 +149,7 @@ partial class ChronoJumpWindow
                return arr[minp];
        }
 
-       private Cairo.Color jp_colorFromRGB(int red, int green, int blue) {
+       private Cairo.Color colorFromRGB(int red, int green, int blue) {
                return new Cairo.Color(red/255.0, green/255.0, blue/255.0);
        }
 }
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index dd61f92..f19da60 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.cs
@@ -252,7 +252,7 @@ class SqliteJump : Sqlite
 
                return str;
        }
-               
+       
 
        public static void Update(int jumpID, string type, string tv, string tc, string fall, int personID, 
double weight, string description, double angle)
        {
diff --git a/src/sqlite/stat.cs b/src/sqlite/stat.cs
index 9504b73..99cf11f 100644
--- a/src/sqlite/stat.cs
+++ b/src/sqlite/stat.cs
@@ -1388,6 +1388,78 @@ LogB.SQL(intervalSpeeds);
        ABK-CMJ         Cap. Braços (hability)
        DJa             F Reactiu-reflexa
        */
+
+       private static double selectDouble (string sqlSelect) 
+       {
+               dbcmd.CommandText = sqlSelect;
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+               
+               double result = 0;
+               if(reader.Read())
+                       result = Convert.ToDouble(Util.ChangeDecimalSeparator(reader[0].ToString()));
+
+               reader.Close();
+               
+               return result;
+       }
+
+       //Current person
+       public static List<Double> SelectChronojumpProfile (int pID, int sID)
+       {
+               string personID = pID.ToString();
+               string sessionID = sID.ToString();
+
+               Sqlite.Open();
+               
+               //select personID and each index (using IDDoubleLists)
+               double fMax = selectDouble( 
+                               "SELECT MAX(jump.tv * jump.tv * 1.226) " +
+                               " FROM jump " +
+                               " WHERE type = \"SJl\" AND jump.weight = 100 " +
+                               " AND personID = " + personID + " AND sessionID = " + sessionID);
+               
+               double fExpl = selectDouble( 
+                               "SELECT MAX(j1.tv * j1.tv * 1.226) - MAX(j2.tv * j2.tv * 1.226) AS myIndex " +
+                               " FROM jump AS j1, jump AS j2 " +
+                               " WHERE j1.type = \"SJ\" AND j2.type = \"SJl\" AND j2.weight=100 " +
+                               " AND j1.personID = " + personID + " AND j2.personID = " + personID + 
+                               " AND j1.sessionID = " + sessionID + " AND j2.sessionID = " + sessionID);
+
+               double cElast = selectDouble( 
+                               "SELECT MAX(j1.tv * j1.tv * 1.226) - MAX(j2.tv * j2.tv * 1.226) AS myIndex " +
+                               " FROM jump AS j1, jump AS j2 " +
+                               " WHERE j1.type = \"CMJ\" AND j2.type = \"SJ\" " +
+                               " AND j1.personID = " + personID + " AND j2.personID = " + personID + 
+                               " AND j1.sessionID = " + sessionID + " AND j2.sessionID = " + sessionID);
+       
+               double cArms = selectDouble( 
+                               "SELECT MAX(j1.tv * j1.tv * 1.226) - MAX(j2.tv * j2.tv * 1.226) AS myIndex " +
+                               " FROM jump AS j1, jump AS j2 " +
+                               " WHERE j1.type = \"ABK\" AND j2.type = \"CMJ\" " +
+                               " AND j1.personID = " + personID + " AND j2.personID = " + personID + 
+                               " AND j1.sessionID = " + sessionID + " AND j2.sessionID = " + sessionID);
+
+               double fReact = selectDouble( 
+                               "SELECT MAX(jump.tv * jump.tv * 1.226) " +
+                               " FROM jump WHERE type = \"DJa\" " +
+                               " AND personID = " + personID + " AND sessionID = " + sessionID);
+       
+               Sqlite.Close();
+
+               List<Double> l = new List<Double>();            
+               l.Add(fMax);
+               l.Add(fExpl);
+               l.Add(cElast);
+               l.Add(cArms);
+               l.Add(fReact);
+               return l;
+       }
+
+       //all persons in session (unused)
        public static ArrayList SelectChronojumpProfile (string sessionID)
        {
                Sqlite.Open();


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