[chronojump] Encoder save best curve done (now need option on preferences)



commit e26d400b74c3d7bb0145af1ca705c4afebbece7d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jul 16 21:06:29 2014 +0200

    Encoder save best curve done (now need option on preferences)

 glade/chronojump.glade      |   73 ++++++++++++++++++++++++++++++++++-
 src/encoder.cs              |   32 +++++++++++++++
 src/gui/encoder.cs          |    7 ++-
 src/gui/encoderTreeviews.cs |   91 ++++++++++++++++++++++++++++++++++++++----
 4 files changed, 191 insertions(+), 12 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 91d8652..948d2e1 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -6194,6 +6194,9 @@ Second Chronopic to platforms.</property>
                                                         <child>
                                                           <placeholder/>
                                                         </child>
+                                                        <child>
+                                                          <placeholder/>
+                                                        </child>
                                                       </widget>
                                                       <packing>
                                                         <property name="expand">True</property>
@@ -6804,6 +6807,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             <child>
@@ -7548,6 +7554,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">2</property>
@@ -8051,6 +8060,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">4</property>
@@ -12938,6 +12950,20 @@ on current Chronojump version.</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkButton" 
id="button_encoder_capture_curves_best">
+                                                            <property name="label" 
translatable="yes">Best</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <signal name="clicked" 
handler="on_button_encoder_capture_curves_best_clicked" swapped="no"/>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkButton" 
id="button_encoder_capture_curves_none">
                                                             <property name="label" 
translatable="yes">None</property>
                                                             <property name="visible">True</property>
@@ -12948,7 +12974,7 @@ on current Chronojump version.</property>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">False</property>
-                                                            <property name="position">2</property>
+                                                            <property name="position">3</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
@@ -17323,6 +17349,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -17734,6 +17763,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -18570,6 +18602,12 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -26095,6 +26133,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>
@@ -27896,6 +27952,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>
@@ -28366,6 +28425,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>
@@ -30631,6 +30693,9 @@ show elevation as:</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -30706,6 +30771,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -30796,6 +30864,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/encoder.cs b/src/encoder.cs
index c8b10f9..9792ca8 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -247,6 +247,7 @@ public class EncoderGraphROptions
 
 
 //used on TreeViews capture and analyze
+//in ec and ecS there are two separated curves, unfortunately, here is not known if it's ecc or con
 public class EncoderCurve
 {
        public bool Record;     //only on capture
@@ -325,8 +326,39 @@ public class EncoderCurve
                        MeanPower + sep + PeakPower + sep + PeakPowerT + sep + 
                        PP_PPT;
        }
+       
+       ~EncoderCurve() {}
+}
+
+
+//to know which is the best curve in a signal...
+public class EncoderSignal
+{
+       private ArrayList curves;
+
+       public EncoderSignal (ArrayList curves) {
+               this.curves = curves;
+       }
+
+       //this can be an eccentric or concentric curve
+       public int FindPosOfBestMeanPower() {
+               double bestMeanPower = 0;
+               int bestMeanPowerPos = 0;
+               int i = 0;
+               foreach(EncoderCurve curve in curves) {
+                       if(Convert.ToDouble(curve.MeanPower) > bestMeanPower) {
+                               bestMeanPower = Convert.ToDouble(curve.MeanPower);
+                               bestMeanPowerPos = i;
+                       }
+                       i++;
+               }
+               return bestMeanPowerPos;
+       }
+       
+       ~EncoderSignal() {}
 }
 
+
 //related to encoderSignalCurve table
 public class EncoderSignalCurve {
        public int uniqueID;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index a9a314b..cf21568 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -2915,10 +2915,13 @@ Log.Write(" AT ANALYZE 2 ");
        }
 
        void on_button_encoder_capture_curves_all_clicked (object o, EventArgs args) {
-               encoderCaptureSaveCurvesAllNone(true);
+               encoderCaptureSaveCurvesAllNoneBest(CurvesSaveOp.ALL);
+       }
+       void on_button_encoder_capture_curves_best_clicked (object o, EventArgs args) {
+               encoderCaptureSaveCurvesAllNoneBest(CurvesSaveOp.BEST);
        }
        void on_button_encoder_capture_curves_none_clicked (object o, EventArgs args) {
-               encoderCaptureSaveCurvesAllNone(false);
+               encoderCaptureSaveCurvesAllNoneBest(CurvesSaveOp.NONE);
        }
 
        void on_combo_encoder_analyze_data_compare_changed (object o, EventArgs args)
diff --git a/src/gui/encoderTreeviews.cs b/src/gui/encoderTreeviews.cs
index bc73b5b..aca91c1 100644
--- a/src/gui/encoderTreeviews.cs
+++ b/src/gui/encoderTreeviews.cs
@@ -258,35 +258,66 @@ public partial class ChronoJumpWindow
                }
        }
 
+       enum CurvesSaveOp { ALL, NONE, BEST }
        
        //allNone: true (save all), false (unsave all)
-       void encoderCaptureSaveCurvesAllNone(bool allNone)
+       void encoderCaptureSaveCurvesAllNoneBest(CurvesSaveOp saveOption)
        {
-               int i = 0; //on "c": i is every row; on other eccons: i is every two rows
+               int bestRow = 0;
+               if(saveOption == CurvesSaveOp.BEST) {
+                       //get the concentric curves
+                       EncoderSignal encoderSignal = new 
EncoderSignal(treeviewEncoderCaptureCurvesGetCurves(AllEccCon.CON));
+                       bestRow = encoderSignal.FindPosOfBestMeanPower();
+                       
+                       //convert from c to ec. eg.
+                       //three concentric curves: c[0], c[1], c[2]
+                       //coming from three ecc-con: e[0], c[1], e[2], c[3], e[4], c[5]
+                       //if from first list, c[2] is the best, then on second list it will be the ec curve: 
e[4],c[5]
+                       //always multiply *2
+                       if(ecconLast != "c")
+                               bestRow *= 2;
+               }
+
+
+               int i = 0; //on "c" and ! "c": i is every row
                string sep = "";
                string messageRows = "";
+               
                TreeIter iter;
                bool iterOk = encoderCaptureListStore.GetIterFirst(out iter);
+               if(! iterOk)
+                       return;
+
+               bool changeTo;
                while(iterOk) {
                        TreePath path = encoderCaptureListStore.GetPath(iter);
                        
                        EncoderCurve curve = (EncoderCurve) encoderCaptureListStore.GetValue (iter, 0);
-                       if(curve.Record != allNone) { 
+                       if(
+                                       (! curve.Record && saveOption == CurvesSaveOp.ALL) ||
+                                       (! curve.Record && saveOption == CurvesSaveOp.BEST && i == bestRow) ||
+                                       (curve.Record && saveOption == CurvesSaveOp.BEST && i != bestRow) ||
+                                       (curve.Record && saveOption == CurvesSaveOp.NONE) ) 
+                       { 
+                               changeTo = ! curve.Record;
+                               
+                               Log.WriteLine(i.ToString() + " was: " + curve.Record.ToString() + "; will be: 
" + (! curve.Record).ToString());
+
                                //change value
-                               ((EncoderCurve) encoderCaptureListStore.GetValue (iter, 0)).Record = allNone;
+                               ((EncoderCurve) encoderCaptureListStore.GetValue (iter, 0)).Record = changeTo;
 
                                //this makes RenderRecord work on changed row without having to put mouse 
there
                                encoderCaptureListStore.EmitRowChanged(path,iter);
 
                                //on "ecS" don't pass the 2nd row, pass always the first
-                               saveOrDeleteCurveFromCaptureTreeView(i, curve, allNone);
+                               saveOrDeleteCurveFromCaptureTreeView(i, curve, changeTo);
                                
                                if(ecconLast != "c") {
                                        path.Next();
                                        encoderCaptureListStore.IterNext (ref iter);
                                
                                        //change value
-                                       ((EncoderCurve) encoderCaptureListStore.GetValue (iter, 0)).Record = 
allNone;
+                                       ((EncoderCurve) encoderCaptureListStore.GetValue (iter, 0)).Record = 
changeTo;
 
                                        //this makes RenderRecord work on changed row without having to put 
mouse there
                                        encoderCaptureListStore.EmitRowChanged(path,iter);
@@ -294,7 +325,16 @@ public partial class ChronoJumpWindow
                                        
                                messageRows += sep + (i+1).ToString();
                                sep = ", ";
+                       } else {
+                               //if we don't change rows
+                               //but is ec
+                               //the advance now one row (the 'e')
+                               //and later it will advance the 'c'
+                               if(ecconLast != "c") {
+                                       encoderCaptureListStore.IterNext (ref iter);
+                               }
                        }
+
                        i ++;
                        if(ecconLast != "c")
                                i ++;
@@ -304,10 +344,10 @@ public partial class ChronoJumpWindow
                //combo_encoder_capture_show_save_curve_button();
                        
                string message = "";
-               if(allNone)
-                       message = Catalog.GetString("Saved");
-               else
+               if(saveOption == CurvesSaveOp.NONE)
                        message = Catalog.GetString("Removed");
+               else
+                       message = Catalog.GetString("Saved");
                label_encoder_curve_action.Text = message + " " + messageRows;
 
                        
@@ -1110,6 +1150,39 @@ public partial class ChronoJumpWindow
                return curve;
        }
 
+       private enum AllEccCon { ALL, ECC, CON }
+
+       private ArrayList treeviewEncoderCaptureCurvesGetCurves(AllEccCon option) 
+       {
+               TreeIter iter;
+               ArrayList curves = new ArrayList();
+                       
+               bool iterOk = encoderCaptureListStore.GetIterFirst(out iter);
+               if(! iterOk)
+                       return curves;
+
+               bool oddRow = true;
+               while(iterOk) {
+                       if(ecconLast != "c" && option == AllEccCon.CON && oddRow) {
+                               oddRow = ! oddRow;
+                               iterOk = encoderCaptureListStore.IterNext (ref iter);
+                               continue;
+                       }
+                       if(ecconLast != "c" && option == AllEccCon.ECC && ! oddRow) {
+                               oddRow = ! oddRow;
+                               iterOk = encoderCaptureListStore.IterNext (ref iter);
+                               continue;
+                       }
+                               
+                       EncoderCurve curve = (EncoderCurve) encoderCaptureListStore.GetValue (iter, 0);
+                       curves.Add(curve);
+
+                       oddRow = ! oddRow;
+                       iterOk = encoderCaptureListStore.IterNext (ref iter);
+               }
+
+               return curves;
+       }
        
        // ---------helpful methods -----------
        


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