[chronojump] Encoder: export CSV lot better



commit 3e549f3fe6257a3860ef4a88b9c041454d3093d5
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Jan 13 03:16:59 2013 +0100

    Encoder: export CSV lot better

 encoder/graph.R        |   96 +++++++++++++++++++++++++++++++++++++----------
 glade/chronojump.glade |   39 +++++++------------
 src/gui/encoder.cs     |    2 +-
 3 files changed, 91 insertions(+), 46 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 68802d2..24f90cc 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -962,34 +962,88 @@ print("----------------------------")
 	if(analysis=="exportCSV") {
 		print("Starting export...")
 		file=outputData1;
-		col1=rawdata
-		col2=rawdata.cumsum
-		#kn = kinematicsF (rawdata, mass, smoothingOne, g) #filter smoothingOne not good for all signal
-		knC1 = kinematicsF (rawdata[(curves[1,1]-500):curves[1,2]], mass, smoothingOne, g) #here filtering is good
-
-		#TODO: fer les altres curves
-		df=data.frame(cbind(
-				    col1[(curves[1,1]-500):curves[1,2]],col2[(curves[1,1]-500):curves[1,2]],
-				    #kn$speedy,kn$accely,kn$force,kn$power,
-				    knC1$speedy,knC1$accely,knC1$force,knC1$power))
-
-
-#TODO: bug, last 4 columns are shorter
-#TODO: tenir en compte el startH
-
-#		colnames(df)=c("Dist.", "Dist. +", 
-#			       "Speed", "Accel.", "Force", "Power",
-#			       "SpeedC1", "Accel.C1", "ForceC1", "PowerC1")
+		curvesNum = length(curves[,1])
+		
+		maxLength = 0
+		for(i in 1:curvesNum) { 
+			myLength = curves[i,2]-curves[i,1]
+			if(myLength > maxLength)
+				maxLength=myLength
+		}
 
-#		print(head(df))
+		curveCols = 6	#change this value if there are more colums
+		names=c("Dist.", "Dist. +", "Speed", "Accel.", "Force", "Power")
+		nums=1:curvesNum
+		nums=rep(nums,each=curveCols)		
+		namesNums=paste(names, nums)
+		
+		for(i in 1:curvesNum) { 
+			kn = kinematicsF (rawdata[curves[i,1]:curves[i,2]], mass, smoothingOne, g)
+			
+			#fill with NAs in order to have the same length
+			col1 = rawdata[curves[i,1]:curves[i,2]]
+			col2 = rawdata.cumsum[curves[i,1]:curves[i,2]]
+			
+			#add mean and max
+			col1=append(col1,
+				    c(NA,NA,NA,namesNums[((i-1)*curveCols)+1]),
+				    after=0)
+			col2=append(col2,
+				    c(NA,"mean (ABS):","max:",namesNums[((i-1)*curveCols)+2]),
+				    after=0)
+			kn$speedy=append(kn$speedy,
+					 c(
+					   namesNums[((i-1)*curveCols)+3],
+					   mean(abs(kn$speedy)),max(kn$speedy),
+					   namesNums[((i-1)*curveCols)+3]),
+					 after=0)
+			kn$accely=append(kn$accely,
+					 c(
+					   namesNums[((i-1)*curveCols)+4],
+					   mean(abs(kn$accely)),max(kn$accely),
+					   namesNums[((i-1)*curveCols)+4]),
+					 after=0)
+			kn$force=append(kn$force,
+					c(
+					  namesNums[((i-1)*curveCols)+5],
+					  mean(abs(kn$force)),max(kn$force),
+					  namesNums[((i-1)*curveCols)+5]),
+					after=0)
+			kn$power=append(kn$power,
+					c(
+					  namesNums[((i-1)*curveCols)+6],
+					  mean(abs(kn$power)),max(kn$power),
+					  namesNums[((i-1)*curveCols)+6]),
+					after=0)
+			
+			extraRows=4
+			length(col1)=maxLength+extraRows
+			length(col2)=maxLength+extraRows
+			length(kn$speedy)=maxLength+extraRows
+			length(kn$accely)=maxLength+extraRows
+			length(kn$force)=maxLength+extraRows
+			length(kn$power)=maxLength+extraRows
+
+			if(i==1)
+				df=data.frame(cbind(col1, col2,
+						    kn$speedy, kn$accely, kn$force, kn$power))
+			else
+				df=data.frame(cbind(df, col1, col2,
+						    kn$speedy, kn$accely, kn$force, kn$power))
+		}
+	
+		#TODO: time
+		#TODO: tenir en compte el startH
+		
+		colnames(df)=c("Person's name",rep(" ",(curvesNum*curveCols-1)))
 
-		write.csv2(df, file=file, row.names=F)
+		write.csv2(df, file=file, row.names=F, na="")
 		#write.csv2(df, file=file, quotes=F)
 		print("Export done.")
 	}
 	dev.off()
 }
 
-#warnings()
+warnings()
 
 
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index e93b3db..3c27413 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -12538,33 +12538,9 @@ on current Chronojump version.</property>
                                                             <packing>
                                                             <property name="expand">True</property>
                                                             <property name="fill">True</property>
-                                                            <property name="pack_type">end</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
-                                                            <child>
-                                                            <widget class="GtkButton" id="button_encoder_export_signal">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">True</property>
-                                                            <property name="receives_default">True</property>
-                                                            <property name="has_tooltip">True</property>
-                                                            <property name="tooltip" translatable="yes">Export session to _CSV (Spreadsheet)</property>
-                                                            <property name="use_action_appearance">False</property>
-                                                            <signal name="clicked" handler="on_button_encoder_export_signal_clicked" swapped="no"/>
-                                                            <child>
-                                                            <widget class="GtkImage" id="image29">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <property name="stock">gtk-convert</property>
-                                                            </widget>
-                                                            </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">2</property>
-                                                            </packing>
-                                                            </child>
                                                           </widget>
                                                           <packing>
                                                             <property name="expand">False</property>
@@ -12748,6 +12724,21 @@ on current Chronojump version.</property>
                                                     <property name="position">2</property>
                                                   </packing>
                                                 </child>
+                                                <child>
+                                                  <widget class="GtkButton" id="button_encoder_export_all_curves">
+                                                    <property name="label">Export all curves</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">True</property>
+                                                    <property name="use_action_appearance">False</property>
+                                                    <signal name="clicked" handler="on_button_encoder_export_all_curves_clicked" swapped="no"/>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">3</property>
+                                                  </packing>
+                                                </child>
                                               </widget>
                                               <packing>
                                                 <property name="expand">False</property>
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 331b67b..9bcf1d8 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -469,7 +469,7 @@ public partial class ChronoJumpWindow
 		on_button_encoder_recalculate_clicked (o, args); 
 	}
 	
-	void on_button_encoder_export_signal_clicked (object o, EventArgs args) 
+	void on_button_encoder_export_all_curves_clicked (object o, EventArgs args) 
 	{
 		string analysisOptions = "-";
 		if(checkbutton_encoder_propulsive.Active)



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