[chronojump] RaceAnalyzer can save table
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] RaceAnalyzer can save table
- Date: Mon, 26 Oct 2020 13:43:26 +0000 (UTC)
commit 75a2a77c4035494e5f5ea9c9fa2d9455b7e88ed5
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Oct 26 14:42:55 2020 +0100
RaceAnalyzer can save table
glade/app1.glade | 1 +
src/constants.cs | 2 +-
src/gui/app1/encoder.cs | 13 ++++++--
src/gui/app1/runEncoder.cs | 70 +++++++++++++++++++++++----------------
src/gui/app1/runEncoderAnalyze.cs | 48 +++++++++++++++++++++++++++
src/runEncoder.cs | 19 +++++++++++
6 files changed, 121 insertions(+), 32 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 871dc741..cdcf898a 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -25728,6 +25728,7 @@ Concentric</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Save
table</property>
+ <signal name="clicked"
handler="on_button_raceAnalyzer_table_save_clicked" swapped="no"/>
<child>
<widget class="GtkVBox" id="vbox237">
<property name="visible">True</property>
diff --git a/src/constants.cs b/src/constants.cs
index f147a6e5..8c64bd8a 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -1108,7 +1108,7 @@ public class Constants
ENCODER_ANALYZE_SAVE_AB, ENCODER_ANALYZE_SAVE_TABLE,
FORCESENSOR_SAVE_IMAGE_SIGNAL, FORCESENSOR_SAVE_IMAGE_RFD_AUTO,
FORCESENSOR_SAVE_IMAGE_RFD_MANUAL, FORCESENSOR_ANALYZE_SAVE_AB,
- RUNENCODER_SAVE_IMAGE
+ RUNENCODER_SAVE_IMAGE, RUNENCODER_SAVE_TABLE
}
public static double EncoderErrorCode = -1;
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index ed311153..7646f174 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -2085,7 +2085,8 @@ public partial class ChronoJumpWindow
exportString = Catalog.GetString ("Export repetition in CSV format");
else if(checkFileOp == Constants.CheckFileOp.FORCESENSOR_ANALYZE_SAVE_AB)
exportString = Catalog.GetString ("Export data in CSV format");
- else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
+ else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE ||
+ checkFileOp == Constants.CheckFileOp.RUNENCODER_SAVE_TABLE)
exportString = Catalog.GetString ("Save table");
string nameString = currentPerson.Name + "_" + currentSession.DateShortAsSQL;
@@ -2153,6 +2154,8 @@ public partial class ChronoJumpWindow
nameString += "_forcesensor_analyze_AB_export.csv";
else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
nameString += "_encoder_curves_table.csv";
+ else if(checkFileOp == Constants.CheckFileOp.RUNENCODER_SAVE_TABLE)
+ nameString += "_raceAnalyzer_table.csv";
Gtk.FileChooserDialog fc=
new Gtk.FileChooserDialog(exportString,
@@ -2170,7 +2173,8 @@ public partial class ChronoJumpWindow
if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL ||
checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB ||
checkFileOp == Constants.CheckFileOp.FORCESENSOR_ANALYZE_SAVE_AB ||
- checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
+ checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE ||
+ checkFileOp == Constants.CheckFileOp.RUNENCODER_SAVE_TABLE)
exportFileName = Util.AddCsvIfNeeded(exportFileName);
else //ENCODER_ANALYZE_SAVE_IMAGE, FORCESENSOR_SAVE_IMAGE_SIGNAL,
//FORCESENSOR_SAVE_IMAGE_RFD_AUTO, FORCESENSOR_SAVE_IMAGE_RFD_MANUAL
@@ -2232,6 +2236,9 @@ public partial class ChronoJumpWindow
else if(checkFileOp == Constants.CheckFileOp.RUNENCODER_SAVE_IMAGE)
confirmWin.Button_accept.Clicked +=
new
EventHandler(on_overwrite_file_runencoder_image_save_accepted);
+ else if(checkFileOp == Constants.CheckFileOp.RUNENCODER_SAVE_TABLE)
+ confirmWin.Button_accept.Clicked +=
+ new
EventHandler(on_overwrite_file_raceAnalyzer_save_table_accepted);
} else {
if(checkFileOp == Constants.CheckFileOp.JUMPS_PROFILE_SAVE_IMAGE)
@@ -2264,6 +2271,8 @@ public partial class ChronoJumpWindow
on_button_force_sensor_save_AB_file_selected (exportFileName);
else if(checkFileOp == Constants.CheckFileOp.RUNENCODER_SAVE_IMAGE)
on_button_run_encoder_image_save_selected (exportFileName);
+ else if(checkFileOp == Constants.CheckFileOp.RUNENCODER_SAVE_TABLE)
+ on_button_raceAnalyzer_save_table_file_selected
(exportFileName);
string myString = string.Format(Catalog.GetString("Saved to {0}"),
exportFileName);
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 9e26bda7..4972ce16 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -1058,40 +1058,14 @@ public partial class ChronoJumpWindow
typeof (string)
);
- string line;
- using (StringReader reader = new StringReader (contents))
- {
- line = reader.ReadLine (); //headers
- //LogB.Information(line);
- do {
- line = reader.ReadLine ();
- LogB.Information(line);
- if (line == null)
- break;
-
- string [] cells = line.Split(new char[] {';'});
-
- RunEncoderCSV recsv = new RunEncoderCSV(
- Convert.ToDouble(cells[0]),
Convert.ToDouble(cells[1]), Convert.ToInt32(cells[2]),
- Convert.ToDouble(cells[3]),
Convert.ToDouble(cells[4]), Convert.ToDouble(cells[5]),
- Convert.ToDouble(cells[6]),
Convert.ToDouble(cells[7]), Convert.ToDouble(cells[8]),
- Convert.ToDouble(cells[9]),
Convert.ToDouble(cells[10]), Convert.ToDouble(cells[11]),
- Convert.ToDouble(cells[12]),
Convert.ToDouble(cells[13]), Convert.ToDouble(cells[14]),
- Convert.ToDouble(cells[15]),
Convert.ToDouble(cells[16]), Convert.ToDouble(cells[17]),
- Convert.ToDouble(cells[18]),
Convert.ToDouble(cells[19]), Convert.ToDouble(cells[20]),
- Convert.ToDouble(cells[21])
- );
-
- store.AppendValues (recsv.ToTreeView());
-
- } while(true);
- }
+ RunEncoderCSV recsv = readRunEncoderCSVContents (contents);
+ store.AppendValues (recsv.ToTreeView());
treeview_raceAnalyzer.Model = store;
treeview_raceAnalyzer.Selection.Mode = SelectionMode.None;
treeview_raceAnalyzer.HeadersVisible=true;
-
}
+
private string [] getTreeviewRaceAnalyzerHeaders ()
{
string [] headers = {
@@ -1107,6 +1081,44 @@ public partial class ChronoJumpWindow
return headers;
}
+ //right now it only returns one line
+ private RunEncoderCSV readRunEncoderCSVContents (string contents)
+ {
+ RunEncoderCSV recsv = new RunEncoderCSV();
+ string line;
+ using (StringReader reader = new StringReader (contents))
+ {
+ line = reader.ReadLine (); //headers
+ //LogB.Information(line);
+ do {
+ line = reader.ReadLine ();
+ LogB.Information(line);
+ if (line == null)
+ break;
+
+ string [] cells = line.Split(new char[] {';'});
+
+ recsv = new RunEncoderCSV(
+ Convert.ToDouble(cells[0]), Convert.ToDouble(cells[1]),
Convert.ToInt32(cells[2]),
+ Convert.ToDouble(cells[3]), Convert.ToDouble(cells[4]),
Convert.ToDouble(cells[5]),
+ Convert.ToDouble(cells[6]), Convert.ToDouble(cells[7]),
Convert.ToDouble(cells[8]),
+ Convert.ToDouble(cells[9]), Convert.ToDouble(cells[10]),
Convert.ToDouble(cells[11]),
+ Convert.ToDouble(cells[12]), Convert.ToDouble(cells[13]),
Convert.ToDouble(cells[14]),
+ Convert.ToDouble(cells[15]), Convert.ToDouble(cells[16]),
Convert.ToDouble(cells[17]),
+ Convert.ToDouble(cells[18]), Convert.ToDouble(cells[19]),
Convert.ToDouble(cells[20]),
+ Convert.ToDouble(cells[21])
+ );
+ } while(true);
+ }
+
+ return recsv;
+ }
+
+ private void on_button_raceAnalyzer_table_save_clicked (object o, EventArgs args)
+ {
+ checkFile(Constants.CheckFileOp.RUNENCODER_SAVE_TABLE);
+ }
+
private string readFromRunEncoderIfDataArrived()
{
string str = "";
diff --git a/src/gui/app1/runEncoderAnalyze.cs b/src/gui/app1/runEncoderAnalyze.cs
index 6e665d0c..aa0022c3 100644
--- a/src/gui/app1/runEncoderAnalyze.cs
+++ b/src/gui/app1/runEncoderAnalyze.cs
@@ -187,4 +187,52 @@ public partial class ChronoJumpWindow
new DialogMessage(Constants.MessageTypes.INFO, myString);
}
+ private void on_button_raceAnalyzer_save_table_file_selected (string destination)
+ {
+ try {
+ //this overwrites if needed
+ TextWriter writer = File.CreateText(destination);
+
+ string sep = " ";
+ if (preferences.CSVExportDecimalSeparator == "COMMA")
+ sep = ";";
+ else
+ sep = ",";
+
+ //write header
+ writer.WriteLine(Util.RemoveNewLine(Util.StringArrayToString(
+ getTreeviewRaceAnalyzerHeaders(), sep), false));
+
+ string contents = Util.ReadFile(RunEncoder.GetCSVResultsFileName(), false);
+ RunEncoderCSV recsv = readRunEncoderCSVContents(contents);
+
+ writer.WriteLine(recsv.ToCSV(preferences.CSVExportDecimalSeparator));
+/*
+
+ //write curves rows
+ ArrayList array = getTreeViewCurves(encoderAnalyzeListStore);
+
+ foreach (EncoderCurve ec in array)
+ {
+ writer.WriteLine(ec.ToCSV(false, preferences.CSVExportDecimalSeparator,
preferences.encoderWorkKcal, phase));
+ }
+ */
+
+ writer.Flush();
+ writer.Close();
+ ((IDisposable)writer).Dispose();
+ } catch {
+ string myString = string.Format(
+ Catalog.GetString("Cannot save file {0} "), destination);
+ new DialogMessage(Constants.MessageTypes.WARNING, myString);
+ }
+ }
+
+ private void on_overwrite_file_raceAnalyzer_save_table_accepted(object o, EventArgs args)
+ {
+ on_button_raceAnalyzer_save_table_file_selected (exportFileName);
+
+ string myString = string.Format(Catalog.GetString("Saved to {0}"), exportFileName);
+ new DialogMessage(Constants.MessageTypes.INFO, myString);
+ }
}
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index d61a6abf..d2921cbc 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -380,6 +380,25 @@ public class RunEncoderCSV
Util.TrimDecimals(Pmax_rel_lm, 3)
};
}
+
+ public string ToCSV(string decimalSeparator)
+ {
+ //latin: 2,3 ; 2,5
+ //non-latin: 2.3 , 2.5
+
+ string sep = ":::";
+ string str = Util.StringArrayToString(ToTreeView(), sep);
+
+ if(decimalSeparator == "COMMA")
+ str = Util.ConvertToComma(str);
+ else
+ str = Util.ConvertToPoint(str);
+
+ if(decimalSeparator == "COMMA")
+ return Util.ChangeChars(str, ":::", ";");
+ else
+ return Util.ChangeChars(str, ":::", ",");
+ }
}
public class RunEncoderGraph
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]