[chronojump] Encoder: Stream load (50%)



commit 3b3fdf7a3eb7bbe4a20055558e5b3e619136ad1a
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed May 30 15:22:41 2012 +0200

    Encoder: Stream load (50%)

 glade/chronojump.glade   |   18 +++++++++++++-
 src/constants.cs         |    2 +-
 src/encoder.cs           |   61 ++++++++++++++++++++++++++++++++++++++++++++++
 src/gui/encoder.cs       |   44 ++++++++++++++++++++++++++-------
 src/gui/genericWindow.cs |   59 ++++++++++++++++++++++++++++++++++++++++----
 src/sqlite/encoder.cs    |   53 ++++++++++++++++++++++++++++++++++-----
 src/util.cs              |    8 +++---
 7 files changed, 218 insertions(+), 27 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index cc8324a..170c899 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -11289,7 +11289,7 @@ comments</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkScrolledWindow" id="scrolled_window">
+              <widget class="GtkScrolledWindow" id="scrolled_window_textview">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="shadow_type">in</property>
@@ -11306,6 +11306,22 @@ comments</property>
                 <property name="position">4</property>
               </packing>
             </child>
+            <child>
+              <widget class="GtkScrolledWindow" id="scrolled_window_treeview">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <widget class="GtkTreeView" id="treeview">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">5</property>
+              </packing>
+            </child>
           </widget>
           <packing>
             <property name="position">1</property>
diff --git a/src/constants.cs b/src/constants.cs
index 424fb45..434e9ae 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -532,7 +532,7 @@ public class Constants
 
 	//height mentric contains 2 spins
 	public enum GenericWindowShow {
-		ENTRY, SPININT, SPINDOUBLE, HEIGHTMETRIC, TEXTVIEW
+		ENTRY, SPININT, SPINDOUBLE, HEIGHTMETRIC, TEXTVIEW, TREEVIEW
 	}
 	
 	public const string PrefVersionAvailable = "versionAvailable";
diff --git a/src/encoder.cs b/src/encoder.cs
index 49107cc..7ff38a0 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -171,3 +171,64 @@ public class EncoderCurve
 	public string PP_PPT;
 }
 
+public class EncoderSQL
+{
+	public string uniqueID;
+	public int personID;
+	public int sessionID;
+	public string name;
+	public string url;
+	public string type;
+	public string extraWeight;
+	public string eccon;
+	public int time;
+	public int minHeight;
+	public double smooth;
+	public string description;
+	
+	private string ecconLong;
+	
+	public EncoderSQL ()
+	{
+	}
+
+	public EncoderSQL (string uniqueID, int personID, int sessionID, string name, string url, string type, string extraWeight, string eccon, int time, int minHeight, double smooth, string description)
+	{
+		this.uniqueID = uniqueID;
+		this.personID = personID;
+		this.sessionID = sessionID;
+		this.name = name;
+		this.url = url;
+		this.type = type;
+		this.extraWeight = extraWeight;
+		this.eccon = eccon;
+		this.time = time;
+		this.minHeight = minHeight;
+		this.smooth = smooth;
+		this.description = description;
+
+		if(eccon == "c")
+			ecconLong = Catalog.GetString("Concentric");
+		else
+			ecconLong = Catalog.GetString("Eccentric-concentric");
+	}
+	
+	private string getDate() {
+		int pointPos = name.LastIndexOf('.');
+		int dateLength = 19; //YYYY-MM-DD_hh-mm-ss
+		string date = name.Substring(pointPos - dateLength, dateLength);
+		string [] dateParts = date.Split(new char[] {'_'});
+		return dateParts[0] + " " + dateParts[1].Replace('-',':');
+	}
+
+	public string [] ToStringArray () {
+		string [] str = new String [5];
+		str[0] = uniqueID;
+		str[1] = type;
+		str[2] = ecconLong;
+		str[3] = extraWeight;
+		str[4] = getDate();
+		str[5] = description;
+		return str;
+	}
+}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index c515a42..102cf7c 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -79,10 +79,9 @@ public partial class ChronoJumpWindow
 
 	private string encoderAnalysis="powerBars";
 	private string ecconLast;
+	private string encoderTimeStamp;
 	enum encoderModes { CAPTURE, ANALYZE }
 	
-	GenericWindow genericWinForEncoder;
-	
 	//TODO: store encoder data: auto save, and show on a treeview.
 	//TODO: auto close capturing window
 	//TODO: fix date of creation-saving stream and curve
@@ -181,6 +180,8 @@ public partial class ChronoJumpWindow
 
 		Util.RunPythonEncoder(Constants.EncoderScriptCapture, es, true);
 
+		encoderTimeStamp = UtilDate.ToFile(DateTime.Now);
+
 		encoderThreadStart(encoderModes.CAPTURE);
 	}
 		
@@ -243,7 +244,27 @@ public partial class ChronoJumpWindow
 		
 	void on_button_encoder_load_stream_clicked (object o, EventArgs args) 
 	{
-		Log.WriteLine("TODO: Load stream");
+		ArrayList data = SqliteEncoder.SelectStreams(false, currentPerson.UniqueID, currentSession.UniqueID);
+
+		ArrayList dataPrint = new ArrayList();
+		foreach(EncoderSQL es in data) {
+			dataPrint.Add(es.ToStringArray());
+		}
+		
+		string [] columnsString = {
+			Catalog.GetString("ID"),
+			Catalog.GetString("Type"),
+			Catalog.GetString("Contraction"),
+			Catalog.GetString("Extra weight"),
+			Catalog.GetString("Date"),
+			Catalog.GetString("Comment")
+		};
+
+		genericWin = GenericWindow.Show(
+				string.Format(Catalog.GetString("Select stream of athlete {0} on this session."), 
+					currentPerson.Name), Constants.GenericWindowShow.TREEVIEW);
+
+		genericWin.SetTreeview(columnsString, dataPrint);
 	}
 
 	private EncoderCurve getCurve(int selectedID) 
@@ -304,7 +325,7 @@ public partial class ChronoJumpWindow
 			feedback = Catalog.GetString("Stream saved");
 		}
 		
-		string desc = entry_encoder_capture_comment.Text.ToString();
+		string desc = Util.RemoveTildeAndColonAndDot(entry_encoder_capture_comment.Text.ToString());
 		//Log.WriteLine(desc);
 
 		if(type == "curve") {
@@ -322,10 +343,12 @@ public partial class ChronoJumpWindow
 
 			//Log.WriteLine(curveStart + "->" + duration);
 			fileSaved = Util.EncoderSaveCurve(Util.GetEncoderDataTempFileName(), curveStart, duration,
-					currentSession.UniqueID, currentPerson.UniqueID, currentPerson.Name);
+					currentSession.UniqueID, currentPerson.UniqueID, 
+					currentPerson.Name, encoderTimeStamp);
 			path = Util.GetEncoderSessionDataCurveDir(currentSession.UniqueID);
 		} else { //stream
-			fileSaved = Util.CopyTempEncoderData (currentSession.UniqueID, currentPerson.UniqueID, currentPerson.Name);
+			fileSaved = Util.CopyTempEncoderData (currentSession.UniqueID, currentPerson.UniqueID, 
+					currentPerson.Name, encoderTimeStamp);
 			path = Util.GetEncoderSessionDataStreamDir(currentSession.UniqueID);
 		}
 
@@ -334,10 +357,10 @@ public partial class ChronoJumpWindow
 		else
 			type += "JUMP";
 
-		//Adding on SQL
-		SqliteEncoder.Insert(false, "-1", 
+		EncoderSQL eSQL = new EncoderSQL(
+				"-1", 
 				currentPerson.UniqueID, currentSession.UniqueID, 
-				fileSaved,
+				fileSaved,		//to know date do: select substr(name,-23,19) from encoder;
 				path,			//url
 				type,
 				findMass(false),	//when save on sql, do not include person weight
@@ -347,6 +370,9 @@ public partial class ChronoJumpWindow
 				(double) spin_encoder_smooth.Value,
 				desc);
 		
+				//Adding on SQL
+		SqliteEncoder.Insert(false, eSQL);
+		
 		encoder_pulsebar_capture.Text = feedback;
 	}
 
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index 4e2404a..b3c1933 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2009   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2012   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -24,6 +24,7 @@ using Glade;
 //using Gnome;
 using GLib; //for Value
 //using System.Text; //StringBuilder
+using System.Collections; //ArrayList
 
 
 public class GenericWindow
@@ -34,15 +35,19 @@ public class GenericWindow
 	[Widget] Gtk.Entry entry;
 	[Widget] Gtk.SpinButton spin_int;
 	[Widget] Gtk.SpinButton spin_double;
-	[Widget] Gtk.ScrolledWindow scrolled_window;
 	[Widget] Gtk.Box hbox_height_metric;
 	[Widget] Gtk.SpinButton spin_feet;
 	[Widget] Gtk.SpinButton spin_inches;
+	[Widget] Gtk.ScrolledWindow scrolled_window_textview;
 	[Widget] Gtk.TextView textview;
+	[Widget] Gtk.ScrolledWindow scrolled_window_treeview;
+	[Widget] Gtk.TreeView treeview;
 	[Widget] Gtk.Button button_accept;
 
 	static GenericWindow GenericWindowBox;
 	
+	private TreeStore store;
+	
 	public GenericWindow ()
 	{
 		Glade.XML gladeXML;
@@ -71,7 +76,8 @@ public class GenericWindow
 		spin_int.Hide();
 		spin_double.Hide();
 		hbox_height_metric.Hide();
-		scrolled_window.Hide();
+		scrolled_window_textview.Hide();
+		scrolled_window_treeview.Hide();
 
 		if(stuff == Constants.GenericWindowShow.ENTRY)
 			entry.Show();
@@ -81,8 +87,10 @@ public class GenericWindow
 			spin_double.Show();
 		else if(stuff == Constants.GenericWindowShow.HEIGHTMETRIC)
 			hbox_height_metric.Show();
-		else //if(stuff == Constants.GenericWindowShow.TEXTVIEW)
-			scrolled_window.Show();
+		else if(stuff == Constants.GenericWindowShow.TEXTVIEW)
+			scrolled_window_textview.Show();
+		else //if(stuff == Constants.GenericWindowShow.TREEVIEW)
+			scrolled_window_treeview.Show();
 	}
 	
 	public void SetSpinRange(double min, double max) {
@@ -95,6 +103,47 @@ public class GenericWindow
 		textview.Buffer = tb;
 	}
 	
+	//data is an ArrayList of strings[], each string [] is a row, each of its strings is a column
+	public void SetTreeview(string [] columnsString, ArrayList data) 
+	{
+		//adjust window to be bigger
+		generic_window.Resizable = true;
+		scrolled_window_treeview.WidthRequest = 500;
+		scrolled_window_treeview.HeightRequest = 250;
+
+		store = getStore(columnsString.Length); 
+		treeview.Model = store;
+		prepareHeaders(columnsString);
+		
+		foreach (string [] line in data) 
+			store.AppendValues (line);
+	}
+	
+	private TreeStore getStore (int columns)
+	{
+		//prepares the TreeStore for required columns
+		Type [] types = new Type [columns];
+		for (int i=0; i < columns; i++) {
+			types[i] = typeof (string);
+		}
+		TreeStore myStore = new TreeStore(types);
+		return myStore;
+	}
+	
+	private void prepareHeaders(string [] columnsString) 
+	{
+		treeview.HeadersVisible=true;
+		int i=0;
+		bool visible = false;
+		foreach(string myCol in columnsString) {
+			UtilGtk.CreateCols(treeview, store, myCol, i++, visible);
+			if(i == 1)
+				store.SetSortFunc (0, UtilGtk.IdColumnCompare);
+			visible = true;
+		}
+	}
+	
+	
 	public void SetButtonAcceptLabel(string str) {
 		button_accept.Label=str;
 	}
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index c8c1686..8d073aa 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -60,20 +60,21 @@ class SqliteEncoder : Sqlite
 	 * Encoder class methods
 	 */
 	
-	public static int Insert(bool dbconOpened, string uniqueID, int personID, int sessionID, string name, string url, string type, string extraWeight, string eccon, int time, int minHeight, double smooth, string description)
+	public static int Insert(bool dbconOpened, EncoderSQL es)
+//			string uniqueID, int personID, int sessionID, string name, string url, string type, string extraWeight, string eccon, int time, int minHeight, double smooth, string description)
 	{
 		if(! dbconOpened)
 			dbcon.Open();
 
-		if(uniqueID == "-1")
-			uniqueID = "NULL";
+		if(es.uniqueID == "-1")
+			es.uniqueID = "NULL";
 
 		dbcmd.CommandText = "INSERT INTO " + Constants.EncoderTable +  
 				" (uniqueID, personID, sessionID, name, url, type, extraWeight, eccon, time, minHeight, smooth, description)" +
-				" VALUES (" + uniqueID + ", "
-				+ personID + ", " + sessionID + ", '" + name + "', '" + url + "', '" + type + "', '" 
-				+ extraWeight + "', '" + eccon + "', " + time + ", " + minHeight + ", " 
-				+ Util.ConvertToPoint(smooth) + ", '" + description + "')" ;
+				" VALUES (" + es.uniqueID + ", "
+				+ es.personID + ", " + es.sessionID + ", '" + es.name + "', '" + es.url + "', '" + es.type + "', '" 
+				+ es.extraWeight + "', '" + es.eccon + "', " + es.time + ", " + es.minHeight + ", " 
+				+ Util.ConvertToPoint(es.smooth) + ", '" + es.description + "')" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
 
@@ -89,5 +90,43 @@ class SqliteEncoder : Sqlite
 		return myLast;
 	}
 	
+	public static ArrayList SelectStreams (bool dbconOpened, int personID, int sessionID)
+	{
+		if(! dbconOpened)
+			dbcon.Open();
+
+		dbcmd.CommandText = "SELECT * FROM " + Constants.EncoderTable + 
+			" WHERE personID = " + personID + " AND sessionID = " + sessionID +
+			" AND SUBSTR(type,1,6)='stream'";
+		
+		SqliteDataReader reader;
+		reader = dbcmd.ExecuteReader();
+
+		ArrayList array = new ArrayList(1);
+
+		EncoderSQL es = new EncoderSQL();
+		while(reader.Read()) {
+			es = new EncoderSQL (
+					reader[0].ToString(),			//uniqueID
+					Convert.ToInt32(reader[1].ToString()),	//personID	
+					Convert.ToInt32(reader[2].ToString()),	//sessionID
+					reader[3].ToString(),			//name
+					reader[4].ToString(),			//url
+					reader[5].ToString(),			//type
+					reader[6].ToString(),			//extraWeight
+					reader[7].ToString(),			//eccon
+					Convert.ToInt32(reader[8].ToString()),	//time
+					Convert.ToInt32(reader[9].ToString()),	//minHeight
+					Convert.ToDouble(Util.ChangeDecimalSeparator(reader[10].ToString())), //smooth
+					reader[11].ToString()			//description
+					);
+			array.Add (es);
+		}
+		reader.Close();
+		if(! dbconOpened)
+			dbcon.Close();
+
+		return array;
+	}
 
 }
diff --git a/src/util.cs b/src/util.cs
index 9922a83..90f1e77 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -855,7 +855,7 @@ public class Util
 	}
 
 //	public static void MoveTempEncoderData(int sessionID, int uniqueID) {
-	public static string CopyTempEncoderData(int sessionID, int uniqueID, string personName) 
+	public static string CopyTempEncoderData(int sessionID, int uniqueID, string personName, string timeStamp) 
 	{
 		string fileName="";
 		if(File.Exists(GetEncoderDataTempFileName())) {
@@ -864,7 +864,7 @@ public class Util
 //				File.Move(GetEncoderDataTempFileName(), GetEncoderSessionDataDir(sessionID));
 //			} catch {
 				fileName = uniqueID.ToString() + "-" + personName + "-" +
-						UtilDate.ToFile(DateTime.Now) + ".txt";
+						timeStamp + ".txt";
 				
 				File.Copy(GetEncoderDataTempFileName(), 
 						GetEncoderSessionDataStreamDir(sessionID) + 
@@ -1074,7 +1074,7 @@ public class Util
 	}
 
 	public static string EncoderSaveCurve(string fileNameStream, int start, int duration, 
-			int sessionID, int uniqueID, string personName) 
+			int sessionID, int uniqueID, string personName, string timeStamp) 
 	{
 		string contents = ReadFile(fileNameStream);
 		string [] startAndDuration = encoderFindPos(contents, start, duration);
@@ -1083,7 +1083,7 @@ public class Util
 				Convert.ToInt32(startAndDuration[0]), 
 				Convert.ToInt32(startAndDuration[1])-1); //-1 is for not ending file with a comma
 			
-		string fileCurve = uniqueID.ToString() + "-" + personName + "-" + UtilDate.ToFile(DateTime.Now) + ".txt";
+		string fileCurve = uniqueID.ToString() + "-" + personName + "-" + timeStamp + ".txt";
 		string fileCurveFull = GetEncoderSessionDataCurveDir(sessionID) + Path.DirectorySeparatorChar + fileCurve;
 		
 		TextWriter writer = File.CreateText(fileCurveFull);



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