[chronojump] Encoder analyze single instant (70%)



commit a259420b93a12264e5e5ce7bb7f896927ce36e5e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Feb 3 18:26:38 2016 +0100

    Encoder analyze single instant (70%)

 encoder/graph.R        |    2 +-
 glade/chronojump.glade |  172 +++++++++++++++++++++++++++++++++++++++---------
 src/constants.cs       |    1 +
 src/encoder.cs         |   13 +++-
 src/gui/encoder.cs     |   89 ++++++++++++++++++++++--
 src/utilEncoder.cs     |    3 +
 src/utilGtk.cs         |   27 +++++++-
 7 files changed, 262 insertions(+), 45 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 8014d4a..5097ba4 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -2721,7 +2721,7 @@ doProcess <- function(options)
                        colnames(df)=c("speed","acceleration","force","power")
 
                        write("going to write it to file", stderr())
-                       write.csv(df, op$SpecialData, append=TRUE, quote=FALSE) #append #TODO: append no va, 
sempre sobreescriu. Val, ho diu l'ajuda q no ho fa perque no seria un csv correcte. Aixi que cal dos arxius 
diferents. Un pel csv i l'altra per aquestes dades de calculatePixelXByTime
+                       write.csv(df, paste(op$EncoderTempPath,"/chronojump-analysis-instant.csv",sep=""), 
append=TRUE, quote=FALSE)
                        #TODO: el millor es enviar el path a tmp i que aqui es generin els arxius, enlloc de 
enviar de C# a R el SpecialData...
 
                        write("done!", stderr())
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 1bc96bb..190888a 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -7978,6 +7978,9 @@ after time</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             <child>
@@ -9449,6 +9452,9 @@ after time</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">2</property>
@@ -10561,6 +10567,9 @@ after time</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">4</property>
@@ -17921,9 +17930,58 @@ on current Chronojump version.</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">2</property>
                                                             <child>
-                                                            <widget class="GtkVBox" id="vbox64">
+                                                            <widget class="GtkScrolledWindow" 
id="scrolledwindow4">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property 
name="hscrollbar_policy">automatic</property>
+                                                            <property 
name="vscrollbar_policy">automatic</property>
+                                                            <child>
+                                                            <widget class="GtkViewport" 
id="viewport_image_encoder_analyze">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="extension_events">all</property>
+                                                            <property name="resize_mode">queue</property>
+                                                            <property name="shadow_type">none</property>
+                                                            <child>
+                                                            <widget class="GtkNotebook" 
id="notebook_encoder_analyze">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="show_tabs">False</property>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_encoder_analyze">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            <property name="icon-size">6</property>
+                                                            </widget>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label147">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">general</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="tab_fill">False</property>
+                                                            <property name="type">tab</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox70">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <widget class="GtkDrawingArea" 
id="drawingarea_encoder_analyze_instant">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
+                                                            <signal name="expose_event" 
handler="on_drawingarea_encoder_analyze_instant_expose_event" swapped="no"/>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
                                                             <child>
                                                             <widget class="GtkVBox" id="vbox68">
                                                             <property name="visible">True</property>
@@ -17933,7 +17991,10 @@ on current Chronojump version.</property>
                                                             <widget class="GtkHScale" 
id="hscale_encoder_analyze_1">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
-                                                            <property name="round_digits">1</property>
+                                                            <property name="adjustment">0 0 300 1 10 
0</property>
+                                                            <property name="round_digits">0</property>
+                                                            <property name="digits">0</property>
+                                                            <signal name="value_changed" 
handler="on_hscale_encoder_analyze_1_value_changed" swapped="no"/>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">True</property>
@@ -17945,7 +18006,8 @@ on current Chronojump version.</property>
                                                             <widget class="GtkHScale" 
id="hscale_encoder_analyze_2">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
-                                                            <property name="round_digits">1</property>
+                                                            <property name="round_digits">0</property>
+                                                            <property name="digits">0</property>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">True</property>
@@ -17980,9 +18042,6 @@ on current Chronojump version.</property>
                                                             <placeholder/>
                                                             </child>
                                                             <child>
-                                                            <placeholder/>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkLabel" id="label143">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -18082,6 +18141,12 @@ on current Chronojump version.</property>
                                                             <property name="x_options"/>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -18089,42 +18154,36 @@ on current Chronojump version.</property>
                                                             <property name="position">2</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">False</property>
-                                                            <property name="position">0</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="position">1</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkScrolledWindow" 
id="scrolledwindow4">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">True</property>
-                                                            <property 
name="hscrollbar_policy">automatic</property>
-                                                            <property 
name="vscrollbar_policy">automatic</property>
-                                                            <child>
-                                                            <widget class="GtkViewport" 
id="viewport_image_encoder_analyze">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <property name="extension_events">all</property>
-                                                            <property name="resize_mode">queue</property>
-                                                            <property name="shadow_type">none</property>
-                                                            <child>
-                                                            <widget class="GtkImage" 
id="image_encoder_analyze">
+                                                            <widget class="GtkLabel" id="label148">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
-                                                            <property 
name="stock">gtk-missing-image</property>
-                                                            <property name="icon-size">6</property>
+                                                            <property name="label">instant (single 
curve)</property>
                                                             </widget>
+                                                            <packing>
+                                                            <property name="position">1</property>
+                                                            <property name="tab_fill">False</property>
+                                                            <property name="type">tab</property>
+                                                            </packing>
                                                             </child>
                                                             </widget>
                                                             </child>
                                                             </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">1</property>
-                                                            </packing>
                                                             </child>
                                                             </widget>
                                                             <packing>
@@ -22525,6 +22584,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -23536,6 +23598,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -25039,6 +25104,9 @@ by you</property>
               <placeholder/>
             </child>
             <child>
+              <placeholder/>
+            </child>
+            <child>
               <widget class="GtkButton" id="button_video_url">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -25599,6 +25667,9 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -37567,6 +37638,24 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -39574,6 +39663,18 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -40863,9 +40964,6 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                       <placeholder/>
                                     </child>
                                     <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
                                       <widget class="GtkLabel" id="label218">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
@@ -41876,6 +41974,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                     <child>
                                       <placeholder/>
                                     </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </widget>
                                 </child>
                               </widget>
@@ -45659,6 +45760,9 @@ It starts before and arrives there with some speed.</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -46334,6 +46438,9 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -47024,6 +47131,9 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/constants.cs b/src/constants.cs
index 771f092..6882f08 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -723,6 +723,7 @@ public class Constants
        
        public static string EncoderExportTemp = "chronojump-export.csv";
        public static string EncoderSpecialDataTemp = "chronojump-special-data.txt"; //variable;result (eg. 
"1RM;82.78")
+       public static string EncoderInstantDataTemp = "chronojump-analysis-instant.csv";
 
        //note next has 40 chars, and its used also in encoder/graph.R to detect how a file will be treated
        //if this name changes, change it in encoder/graph.R
diff --git a/src/encoder.cs b/src/encoder.cs
index 403d769..931d8c6 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -1459,10 +1459,10 @@ public class EncoderAnalyzeInstant
 
                bool headerLine = true;
                foreach(string l in lines) {
-                       if(headerLine) {
-                               headerLine = false;
-                               continue;
-                       }
+                               if(headerLine) {
+                                       headerLine = false;
+                                       continue;
+                               }
 
                        string [] lsplit = l.Split(new char[] {','});
                        speed.Add(Convert.ToDouble(Util.ChangeDecimalSeparator(lsplit[1])));
@@ -1472,6 +1472,11 @@ public class EncoderAnalyzeInstant
                }
        }
 
+       public double GetSpeed(int ms) { return(speed[ms]); }
+       public double GetAccel(int ms) { return(accel[ms]); }
+       public double GetForce(int ms) { return(force[ms]); }
+       public double GetPower(int ms) { return(power[ms]); }
+
        public void PrintDebug() {
                LogB.Information("Printing speed");
                foreach(double s in speed)
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index ed7532e..f8a9f35 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -135,6 +135,12 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.ComboBox combo_encoder_analyze_data_compare;
        [Widget] Gtk.Button button_encoder_analyze_data_compare;
        
+       [Widget] Gtk.HScale hscale_encoder_analyze_1;
+       [Widget] Gtk.Label label_encoder_analyze_speed_1;
+       [Widget] Gtk.Label label_encoder_analyze_accel_1;
+       [Widget] Gtk.Label label_encoder_analyze_force_1;
+       [Widget] Gtk.Label label_encoder_analyze_power_1;
+
        [Widget] Gtk.Button button_encoder_analyze_image_save;
        [Widget] Gtk.Button button_encoder_analyze_table_save;
        [Widget] Gtk.Button button_encoder_analyze_1RM_save;
@@ -184,6 +190,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.CheckButton check_encoder_analyze_mean_or_max;
        
        [Widget] Gtk.Viewport viewport_image_encoder_analyze;
+       [Widget] Gtk.Notebook notebook_encoder_analyze;
        [Widget] Gtk.Image image_encoder_analyze;
        [Widget] Gtk.ProgressBar encoder_pulsebar_analyze;
        
@@ -212,6 +219,8 @@ public partial class ChronoJumpWindow
        private string encoderTimeStamp;
        private string encoderSignalUniqueID;
 
+       private EncoderAnalyzeInstant eai;
+
        private ArrayList array1RM;
 
        private ArrayList encoderCompareInterperson;    //personID:personName
@@ -4877,8 +4886,14 @@ public partial class ChronoJumpWindow
                        }
                } else { //encoderActions.ANALYZE
                        //the -3 is because image is inside (is smaller than) viewport
-                       image_encoder_width = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-5; 
-                       image_encoder_height = UtilGtk.WidgetHeight(viewport_image_encoder_analyze)-5;
+                       if(encoderAnalysis == "single") {
+                               image_encoder_width = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-5; 
+                               image_encoder_height = 
UtilGtk.WidgetHeight(viewport_image_encoder_analyze)/2; //to allow hslides and table
+                               //TODO: improve this
+                       } else {
+                               image_encoder_width = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-5; 
+                               image_encoder_height = UtilGtk.WidgetHeight(viewport_image_encoder_analyze)-5;
+                       }
 
                        encoder_pulsebar_analyze.Text = Catalog.GetString("Please, wait.");
                        encoderRProcAnalyze.status = EncoderRProc.Status.WAITING;
@@ -5345,6 +5360,52 @@ public partial class ChronoJumpWindow
                }
        }
        
+
+       // -------------- drawingarea_encoder_analyze_instant
+       
+       Pixbuf drawingarea_encoder_analyze_cairo_pixbuf;
+       
+       [Widget] Gtk.DrawingArea drawingarea_encoder_analyze_instant;
+       void on_hscale_encoder_analyze_1_value_changed (object o, EventArgs args) {
+               if(eai != null) {
+                       int ms = Convert.ToInt32(hscale_encoder_analyze_1.Value);
+                       label_encoder_analyze_speed_1.Text = Util.TrimDecimals(eai.GetSpeed(ms), 2);
+                       label_encoder_analyze_accel_1.Text = Util.TrimDecimals(eai.GetAccel(ms), 2);
+                       label_encoder_analyze_force_1.Text = Util.TrimDecimals(eai.GetForce(ms), 2);
+                       label_encoder_analyze_power_1.Text = Util.TrimDecimals(eai.GetPower(ms), 2);
+               
+                       drawingarea_encoder_analyze_instant.QueueDraw(); //will fire ExposeEvent
+               }
+       }
+
+       public void on_drawingarea_encoder_analyze_instant_expose_event(object o, ExposeEventArgs args)
+       {
+               if(drawingarea_encoder_analyze_cairo_pixbuf == null)
+                       return;
+
+               DrawingArea area = (DrawingArea) o;
+               using (Cairo.Context g = Gdk.CairoHelper.Create (area.GdkWindow)) 
+               {
+                       //add image
+                       Gdk.CairoHelper.SetSourcePixbuf (g, drawingarea_encoder_analyze_cairo_pixbuf, 0, 0);
+                       g.Paint();
+
+                       //add rectangle
+                       g.SetSourceRGBA(0.906, 0.745, 0.098, 1); //Chronojump yellow
+                       
+                       int xpos = Convert.ToInt32(hscale_encoder_analyze_1.Value);
+                       g.MoveTo(xpos, 0);
+                       g.LineTo(xpos, drawingarea_encoder_analyze_cairo_pixbuf.Height);
+                       
+                       g.Stroke();
+
+                       g.GetTarget ().Dispose ();
+               }
+       }
+       
+       // -------------- end of drawingarea_encoder_analyze_instant
+
+
        private void finishPulsebar(encoderActions action) {
                if(
                                action == encoderActions.CAPTURE || 
@@ -5594,10 +5655,22 @@ public partial class ChronoJumpWindow
                                //TODO pensar en si s'ha de fer 1er amb mida petita i despres amb gran (en el 
zoom),
                                //o si es una sola i fa alguna edicio
                                
-                               //maybe image is still not readable
-                               image_encoder_analyze = UtilGtk.OpenImageSafe(
-                                               UtilEncoder.GetEncoderGraphTempFileName(),
-                                               image_encoder_analyze);
+                               if(encoderAnalysis == "single") {
+                                       drawingarea_encoder_analyze_cairo_pixbuf = UtilGtk.OpenPixbufSafe(
+                                                       UtilEncoder.GetEncoderGraphTempFileName(),
+                                                       drawingarea_encoder_analyze_cairo_pixbuf);
+
+                                       //TODO: define properties ot the hscales
+                                       
+                                       notebook_encoder_analyze.CurrentPage = 1;
+                               } else {
+                                       //maybe image is still not readable
+                                       image_encoder_analyze = UtilGtk.OpenImageSafe(
+                                                       UtilEncoder.GetEncoderGraphTempFileName(),
+                                                       image_encoder_analyze);
+                                       
+                                       notebook_encoder_analyze.CurrentPage = 0;
+                               }
 
                                encoder_pulsebar_analyze.Text = "";
 
@@ -5613,9 +5686,9 @@ public partial class ChronoJumpWindow
                                }
 
                                if(encoderAnalysis == "single") {
-                                       EncoderAnalyzeInstant eai = new EncoderAnalyzeInstant();
+                                       eai = new EncoderAnalyzeInstant();
                                        eai.ReadFile(
-                                                       UtilEncoder.GetEncoderSpecialDataTempFileName());
+                                                       UtilEncoder.GetEncoderInstantDataTempFileName());
                                        //eai.PrintDebug();
                                }
 
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 9260724..d7529e9 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -117,6 +117,9 @@ public class UtilEncoder
        public static string GetEncoderSpecialDataTempFileName() {
                return Path.Combine(Path.GetTempPath(), Constants.EncoderSpecialDataTemp);
        }
+       public static string GetEncoderInstantDataTempFileName() {
+               return Path.Combine(Path.GetTempPath(), Constants.EncoderInstantDataTemp);
+       }
        public static string GetEncoderTempPathWithoutLastSep() {
                string s = Path.GetTempPath(); //is just temp path
 
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 95f2cbd..a88289c 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -549,8 +549,9 @@ public class UtilGtk
        /*
         * OpenImageSafe checks if it's created and if it has size and can be opened
         * this is used when one process takes an image from another process and maybe is not finished
+        * Now we use imageFileWaitUntilCreated()
         */
-       public static Gtk.Image OpenImageSafe(string filename, Gtk.Image image) 
+       private static void imageFileWaitUntilCreated(string filename) 
        {
                while( ! File.Exists(filename) );
 
@@ -562,7 +563,12 @@ public class UtilGtk
                        else
                                System.Threading.Thread.Sleep(50);
                } while( ! hasSize );
+       }
 
+       public static Gtk.Image OpenImageSafe(string filename, Gtk.Image image) 
+       {
+               imageFileWaitUntilCreated(filename);
+               
                bool readedOk;
                do {
                        readedOk = true;
@@ -579,6 +585,25 @@ public class UtilGtk
                return image;
        }
 
+       public static Gdk.Pixbuf OpenPixbufSafe(string filename, Gdk.Pixbuf pixbuf) 
+       {
+               imageFileWaitUntilCreated(filename);
+               
+               bool readedOk;
+               do {
+                       readedOk = true;
+                       try {
+                               pixbuf = new Pixbuf (filename); //from a file
+                       } catch {
+                               LogB.Warning("File is still not ready. Wait a bit");
+                               System.Threading.Thread.Sleep(50);
+                               readedOk = false;
+                       }
+               } while( ! readedOk );
+
+               return pixbuf;
+       }
+
 
 
 }


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