[chronojump] sprint communication 75% done



commit bcf0aa76b38d0443c26f10195b2d5ca3dc14f5d4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Mar 22 23:55:02 2017 +0100

    sprint communication 75% done

 glade/app1.glade  |    6 ++-
 src/gui/sprint.cs |   91 +++++++++++++++++++++++++++++++++++++++++++++++-----
 src/sprint.cs     |   40 ++++++++++++++++++++++-
 3 files changed, 125 insertions(+), 12 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 275e63a..faff3f8 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -13686,7 +13686,6 @@ Concentric</property>
                                                     <property name="spacing">12</property>
                                                     <child>
                                                       <widget class="GtkScrolledWindow" id="scrolledwindow3">
-                                                        <property name="width_request">250</property>
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">True</property>
                                                         <property 
name="hscrollbar_policy">automatic</property>
@@ -13701,7 +13700,7 @@ Concentric</property>
                                                         </child>
                                                       </widget>
                                                       <packing>
-                                                        <property name="expand">False</property>
+                                                        <property name="expand">True</property>
                                                         <property name="fill">True</property>
                                                         <property name="position">0</property>
                                                       </packing>
@@ -19607,6 +19606,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/gui/sprint.cs b/src/gui/sprint.cs
index c0f4d51..ae54a4c 100644
--- a/src/gui/sprint.cs
+++ b/src/gui/sprint.cs
@@ -23,11 +23,13 @@ using Gtk;
 using Glade;
 using System.Text; //StringBuilder
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 
 
 public partial class ChronoJumpWindow
 {
        [Widget] Gtk.Button button_sprint;
+       static Sprint sprint;
 
        private void createTreeView_runs_interval_sprint (Gtk.TreeView tv)
        {
@@ -37,14 +39,15 @@ public partial class ChronoJumpWindow
                tv.HeadersVisible=true;
 
                int count = 0;
-               //tv.AppendColumn (Catalog.GetString ("Type"), new CellRendererText(), "text", count++);
-               //tv.AppendColumn (Catalog.GetString ("ID"), new CellRendererText(), "text", count++);
-               //tv.AppendColumn (Catalog.GetString ("Total time"), new CellRendererText(), "text", count++);
                tv.AppendColumn ("Type", new CellRendererText(), "text", count++);
                tv.AppendColumn ("ID", new CellRendererText(), "text", count++);
+               tv.AppendColumn ("Distances", new CellRendererText(), "text", count++);
+               tv.AppendColumn ("Split times", new CellRendererText(), "text", count++);
                tv.AppendColumn ("Total time", new CellRendererText(), "text", count++);
 
-               TreeStore store = new TreeStore(typeof (string), typeof (string), typeof (string));
+               TreeStore store = new TreeStore(
+                               typeof (string), typeof (string), typeof (string),
+                               typeof (string), typeof (string));
                tv.Model = store;
 
                if (currentSession == null || currentPerson == null)
@@ -53,19 +56,54 @@ public partial class ChronoJumpWindow
                tv.Selection.Changed -= onTreeviewSprintSelectionEntry;
                tv.Selection.Changed += onTreeviewSprintSelectionEntry;
 
-               string [] array = SqliteRunInterval.SelectRuns(false, currentSession.UniqueID, 
currentPerson.UniqueID, "");
-               foreach (string line in array)
+               List<object> runITypes = SqliteRunIntervalType.SelectRunIntervalTypesNew("", false);
+               string [] runsArray = SqliteRunInterval.SelectRuns(
+                               false, currentSession.UniqueID, currentPerson.UniqueID, "");
+
+               foreach (string line in runsArray)
                {
                        string [] lineSplit = line.Split(new char[] {':'});
+                       string positions = runIntervalDistances(lineSplit[4], runITypes);
+                       if(positions == "")
+                               continue;
+
+                       positions = Util.ChangeChars(positions, "-", ";");
+
+                       string intervalTimes = lineSplit[8];
+                       string [] intervalTimesSplit = intervalTimes.Split(new char[] {'='});
+
+                       //accumulated
+                       double timeAccumulated = 0;
+                       string splitTimes = "";
+                       string sep = "";
+                       foreach(string time in intervalTimesSplit)
+                       {
+                               double timeD = Convert.ToDouble(time);
+                               timeAccumulated += timeD;
+                               splitTimes += sep + Util.TrimDecimals(timeAccumulated, 
preferences.digitsNumber);
+                               sep = ";";
+                       }
+
                        string [] lineParams = { 
                                lineSplit[4],
-                               lineSplit[1], 
+                               lineSplit[1],
+                               positions,
+                               splitTimes,
                                Util.TrimDecimals(lineSplit[6], preferences.digitsNumber)
                        };
                        store.AppendValues (lineParams);
                }
        }
 
+       private string runIntervalDistances(string runTypeEnglishName, List<object> runITypes)
+       {
+               foreach(SelectRunITypes type in runITypes)
+                       if(type.NameEnglish == runTypeEnglishName)
+                               return(type.DistancesString);
+
+               return "";
+       }
+
        private void onTreeviewSprintSelectionEntry (object o, EventArgs args)
        {
                TreeModel model;
@@ -77,9 +115,44 @@ public partial class ChronoJumpWindow
                }
        }
 
+       public static bool GetSelectedSprint (Gtk.TreeView tv)
+       {
+               TreeModel model;
+               TreeIter iter;
+
+               if (tv.Selection.GetSelected (out model, out iter))
+               {
+                        string positions = (string) model.GetValue(iter, 2);
+                        positions = Util.ChangeChars(positions, ",", ".");
+                        //add start TODO: check if needed
+                        positions = "0;" + positions;
+
+                        string splitTimes = (string) model.GetValue(iter, 3);
+                        splitTimes = Util.ChangeChars(splitTimes, ",", ".");
+                        //add start TODO: check if needed
+                        splitTimes = "0;" + splitTimes;
+
+                        sprint = new Sprint(
+                                        positions,
+                                        splitTimes,
+                                        currentPersonSession.Weight, //TODO: can be more if extra weight
+                                        currentPersonSession.Height,
+                                        25);
+                       return true;
+               }
+               return false;
+       }
+
+
        private void on_button_sprint_clicked (object o, EventArgs args)
        {
-               //test calling sprint.R file
-               new Sprint();
+               if(! GetSelectedSprint(treeview_runs_interval_sprint))
+               {
+                       new DialogMessage(Constants.MessageTypes.WARNING, "Error");
+                       return;
+               }
+
+               sprint.CallR();
+               new DialogMessage(Constants.MessageTypes.WARNING, "Ok");
        }
 }
diff --git a/src/sprint.cs b/src/sprint.cs
index 939fe06..789ac9b 100644
--- a/src/sprint.cs
+++ b/src/sprint.cs
@@ -26,7 +26,37 @@ public class Sprint
 {
        string optionsFile;
 
-       public Sprint()
+       //private List<double> positions;
+       //private List<double> splitTimes;
+       private string positions;
+       private string splitTimes;
+       private double mass;
+       private double personHeight;
+       private double tempC;
+
+       public Sprint(string positions, string splitTimes,
+                       double mass, double personHeight, double tempC)
+       {
+               this.positions = positions;
+               this.splitTimes = splitTimes;
+               this.mass = mass;
+               this.personHeight = personHeight;
+               this.tempC = tempC;
+       }
+
+       /*
+       public Sprint(List<double> positions, List<double> splitTimes,
+                       double mass, double personHeight, double tempC)
+       {
+               this.positions = positions;
+               this.splitTimes = splitTimes;
+               this.mass = mass;
+               this.personHeight = personHeight;
+               this.tempC = tempC;
+       }
+       */
+
+       public void CallR()
        {
                optionsFile = Path.GetTempPath() + "Roptions.txt";
 
@@ -48,12 +78,20 @@ public class Sprint
 
        private void writeOptionsFile()
        {
+               /*
                string scriptOptions =
                        "#positions\n" +        "0;20;40;70" + "\n" +
                        "#splitTimes\n" +       "0;2.73;4.49;6.95" + "\n" +
                        "#mass\n" +             "75" + "\n" +
                        "#personHeight\n" +     "1.65" + "\n" +
                        "#tempC\n" +            "25" + "\n";
+                       */
+               string scriptOptions =
+                       "#positions\n" +        positions + "\n" +
+                       "#splitTimes\n" +       splitTimes + "\n" +
+                       "#mass\n" +             mass + "\n" +
+                       "#personHeight\n" +     personHeight + "\n" +
+                       "#tempC\n" +            tempC + "\n";
 
                TextWriter writer = File.CreateText(optionsFile);
                writer.Write(scriptOptions);


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