[chronojump] Created UtilEncoder.cs
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Created UtilEncoder.cs
- Date: Sat, 2 Nov 2013 00:01:49 +0000 (UTC)
commit 0e628d629b1aafcbf668a6b6252f94431da12cbc
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Nov 1 19:01:11 2013 +0100
Created UtilEncoder.cs
src/Makefile.am | 1 +
src/chronojump.cs | 2 +-
src/gui/encoder.cs | 82 +++++-----
src/util.cs | 454 +-------------------------------------------------
src/utilEncoder.cs | 473 ++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 523 insertions(+), 489 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4dbd4d5..f5b2ff9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -136,6 +136,7 @@ SOURCES = \
util.cs\
utilAll.cs\
utilDate.cs\
+ utilEncoder.cs\
utilGtk.cs\
utilVideo.cs\
constants.cs\
diff --git a/src/chronojump.cs b/src/chronojump.cs
index c650c64..d027d6e 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -161,7 +161,7 @@ public class ChronoJump
//to store user videos and photos
Util.CreateMultimediaDirsIfNeeded();
//to store encoder data and graphs
- Util.CreateEncoderDirIfNeeded();
+ UtilEncoder.CreateEncoderDirIfNeeded();
//TODO: create encoder session dirs when load or create a session, or when use encoder with button
capture_from_encoder
//TODO: when a session is deleted, encoder data has to be deleted, also multimedia videos, I suppose. Show
message to user warning about it
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 048c625..a4ff6b6 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -308,7 +308,7 @@ public partial class ChronoJumpWindow
EncoderStruct es = new EncoderStruct(
"", //no data input
"", //no graph ouptut
- Util.GetEncoderDataTempFileName(), //OutputData1
+ UtilEncoder.GetEncoderDataTempFileName(), //OutputData1
"", //OutputData2
"", //SpecialData
ep);
@@ -327,7 +327,7 @@ public partial class ChronoJumpWindow
//Does not work. Basically it records, but Rec message is not shown because we would
need to open a new thread here
//title to sen to python software has to be without spaces
- Util.RunEncoderCapturePython(
+ UtilEncoder.RunEncoderCapturePython(
Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "----" +
Util.ChangeSpaceAndMinusForUnderscore(exerciseNameShown) + "----(" +
Util.ConvertToPoint(findMassFromCombo(true)) + "Kg)",
@@ -513,11 +513,11 @@ public partial class ChronoJumpWindow
void encoder_recalculate(bool save)
{
- if (File.Exists(Util.GetEncoderDataTempFileName())) {
+ if (File.Exists(UtilEncoder.GetEncoderDataTempFileName())) {
//change sign on signal file if checkbutton_encoder_capture_inverted.Active changed
if(lastRecalculateWasInverted != checkbutton_encoder_capture_inverted.Active) {
- Util.ChangeSign(Util.GetEncoderDataTempFileName());
+ UtilEncoder.ChangeSign(UtilEncoder.GetEncoderDataTempFileName());
lastRecalculateWasInverted = checkbutton_encoder_capture_inverted.Active;
}
@@ -534,7 +534,7 @@ public partial class ChronoJumpWindow
private void encoderUpdateTreeViewCapture()
{
- string contents = Util.ReadFile(Util.GetEncoderCurvesTempFileName(), false);
+ string contents = Util.ReadFile(UtilEncoder.GetEncoderCurvesTempFileName(), false);
if (contents == null || contents == "") {
encoderButtonsSensitive(encoderSensEnum.DONENOSIGNAL);
} else {
@@ -719,14 +719,14 @@ public partial class ChronoJumpWindow
//capturingRotaryInertial = false;
EncoderStruct es = new EncoderStruct(
- Util.GetEncoderDataTempFileName(),
- Util.GetEncoderGraphTempFileName(),
- Util.GetEncoderCurvesTempFileName(),
- Util.GetEncoderStatusTempFileName(),
+ UtilEncoder.GetEncoderDataTempFileName(),
+ UtilEncoder.GetEncoderGraphTempFileName(),
+ UtilEncoder.GetEncoderCurvesTempFileName(),
+ UtilEncoder.GetEncoderStatusTempFileName(),
"", //SpecialData
ep);
- bool result = Util.RunEncoderGraph(
+ bool result = UtilEncoder.RunEncoderGraph(
Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "-" +
Util.ChangeSpaceAndMinusForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)) +
"-(" + Util.ConvertToPoint(findMassFromCombo(true)) + "Kg)",
@@ -1179,7 +1179,7 @@ public partial class ChronoJumpWindow
bool success = false;
foreach(EncoderSQL es in data) { //it will run only one time
- success = Util.CopyEncoderDataToTemp(es.url, es.filename);
+ success = UtilEncoder.CopyEncoderDataToTemp(es.url, es.filename);
if(success) {
combo_encoder_exercise.Active =
UtilGtk.ComboMakeActive(combo_encoder_exercise, es.exerciseName);
combo_encoder_eccon.Active = UtilGtk.ComboMakeActive(combo_encoder_eccon,
es.ecconLong);
@@ -1280,24 +1280,24 @@ public partial class ChronoJumpWindow
Util.GetDecimalSeparator()
);
- string dataFileName = Util.GetEncoderDataTempFileName();
+ string dataFileName = UtilEncoder.GetEncoderDataTempFileName();
EncoderStruct encoderStruct = new EncoderStruct(
dataFileName,
- Util.GetEncoderGraphTempFileName(),
+ UtilEncoder.GetEncoderGraphTempFileName(),
selectedFileName,
- Util.GetEncoderStatusTempFileName(),
+ UtilEncoder.GetEncoderStatusTempFileName(),
"", //SpecialData
ep);
- Util.RunEncoderGraph(
+ UtilEncoder.RunEncoderGraph(
Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "-" +
Util.ChangeSpaceAndMinusForUnderscore(lastEncoderSQL.exerciseName) +
"-(" + displacedMass + "Kg)",
encoderStruct);
//encoder_pulsebar_capture.Text = string.Format(Catalog.GetString(
- // "Exported to {0}."), Util.GetEncoderExportTempFileName());
+ // "Exported to {0}."), UtilEncoder.GetEncoderExportTempFileName());
}
string exportFileName;
@@ -1463,7 +1463,7 @@ public partial class ChronoJumpWindow
if(curve.Start != null) {
//Log.WriteLine(curveStart + "->" + duration);
- Util.EncoderDeleteCurveFromSignal(Util.GetEncoderDataTempFileName(), curveStart,
duration);
+ UtilEncoder.EncoderDeleteCurveFromSignal(UtilEncoder.GetEncoderDataTempFileName(),
curveStart, duration);
}
//force a recalculate
encoder_recalculate(true); //save the curve
@@ -1586,17 +1586,17 @@ public partial class ChronoJumpWindow
Log.WriteLine(curveStart + "->" + duration);
int curveIDMax = Sqlite.Max(Constants.EncoderTable, "uniqueID", false);
- fileSaved = Util.EncoderSaveCurve(Util.GetEncoderDataTempFileName(), curveStart,
duration,
+ fileSaved = UtilEncoder.EncoderSaveCurve(UtilEncoder.GetEncoderDataTempFileName(),
curveStart, duration,
currentSession.UniqueID, currentPerson.UniqueID,
currentPerson.Name, encoderTimeStamp, curveIDMax);
- path = Util.GetEncoderSessionDataCurveDir(currentSession.UniqueID);
+ path = UtilEncoder.GetEncoderSessionDataCurveDir(currentSession.UniqueID);
} else { //signal
//desc = Util.RemoveTildeAndColonAndDot(entry_encoder_signal_comment.Text.ToString());
desc = "";
- fileSaved = Util.CopyTempToEncoderData (currentSession.UniqueID,
currentPerson.UniqueID,
+ fileSaved = UtilEncoder.CopyTempToEncoderData (currentSession.UniqueID,
currentPerson.UniqueID,
currentPerson.Name, encoderTimeStamp);
- path = Util.GetEncoderSessionDataSignalDir(currentSession.UniqueID);
+ path = UtilEncoder.GetEncoderSessionDataSignalDir(currentSession.UniqueID);
}
string myID = "-1";
@@ -1710,7 +1710,7 @@ public partial class ChronoJumpWindow
Util.ConvertToPoint(findMassFromCombo(true)) + "Kg)",
//es,
(int) encoderCaptureOptionsWin.spin_encoder_capture_time.Value,
- Util.GetEncoderDataTempFileName(),
+ UtilEncoder.GetEncoderDataTempFileName(),
chronopicWin.GetEncoderPort());
//wait to ensure capture thread has ended
@@ -1993,7 +1993,7 @@ public partial class ChronoJumpWindow
combo_encoder_analyze_curve_num_combo));
- dataFileName = Util.GetEncoderGraphInputMulti();
+ dataFileName = UtilEncoder.GetEncoderGraphInputMulti();
double bodyMass = Convert.ToDouble(currentPersonSession.Weight);
@@ -2182,15 +2182,15 @@ Log.WriteLine(str);
Util.GetDecimalSeparator()
);
- dataFileName = Util.GetEncoderDataTempFileName();
+ dataFileName = UtilEncoder.GetEncoderDataTempFileName();
}
EncoderStruct encoderStruct = new EncoderStruct(
dataFileName,
- Util.GetEncoderGraphTempFileName(),
- Util.GetEncoderAnalyzeTableTempFileName(),
- Util.GetEncoderStatusTempFileName(),
- Util.GetEncoderSpecialDataTempFileName(),
+ UtilEncoder.GetEncoderGraphTempFileName(),
+ UtilEncoder.GetEncoderAnalyzeTableTempFileName(),
+ UtilEncoder.GetEncoderStatusTempFileName(),
+ UtilEncoder.GetEncoderSpecialDataTempFileName(),
ep);
//show mass in title except if it's curves because then can be different mass
@@ -2203,7 +2203,7 @@ Log.WriteLine(str);
if( ! radiobutton_encoder_analyze_data_user_curves.Active)
titleStr += "-" +
Util.ChangeSpaceAndMinusForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise));
- Util.RunEncoderGraph(titleStr, encoderStruct);
+ UtilEncoder.RunEncoderGraph(titleStr, encoderStruct);
}
private void on_radiobutton_encoder_analyze_data_current_signal_toggled (object obj, EventArgs args) {
@@ -2599,7 +2599,7 @@ Log.WriteLine(str);
void on_button_encoder_save_image_file_selected (string destination)
{
try {
- File.Copy(Util.GetEncoderGraphTempFileName(), destination, true);
+ File.Copy(UtilEncoder.GetEncoderGraphTempFileName(), destination, true);
} catch {
string myString = string.Format(
Catalog.GetString("Cannot save file {0} "), destination);
@@ -2644,7 +2644,7 @@ Log.WriteLine(str);
void on_button_encoder_analyze_1RM_save_clicked (object o, EventArgs args)
{
- string contents = Util.ReadFile(Util.GetEncoderSpecialDataTempFileName(), true);
+ string contents = Util.ReadFile(UtilEncoder.GetEncoderSpecialDataTempFileName(), true);
string [] load1RMStr = contents.Split(new char[] {';'});
double load1RM = Convert.ToDouble(Util.ChangeDecimalSeparator(load1RMStr[1]));
@@ -4065,7 +4065,7 @@ Log.WriteLine(str);
{
if(! encoderThreadR.IsAlive || encoderProcessCancel) {
if(encoderProcessCancel){
- Util.CancelRScript = true;
+ UtilEncoder.CancelRScript = true;
}
finishPulsebar(encoderModes.CALC_RECALC_CURVES);
@@ -4082,7 +4082,7 @@ Log.WriteLine(str);
{
if(! encoderThreadR.IsAlive || encoderProcessCancel) {
if(encoderProcessCancel){
- Util.CancelRScript = true;
+ UtilEncoder.CancelRScript = true;
}
finishPulsebar(encoderModes.LOAD);
@@ -4099,7 +4099,7 @@ Log.WriteLine(str);
{
if(! encoderThreadR.IsAlive || encoderProcessCancel) {
if(encoderProcessCancel){
- Util.CancelRScript = true;
+ UtilEncoder.CancelRScript = true;
}
finishPulsebar(encoderModes.ANALYZE);
@@ -4124,8 +4124,8 @@ Log.WriteLine(str);
try {
string contents = Catalog.GetString("Please, wait.");
double fraction = -1;
- if(Util.FileExists(Util.GetEncoderStatusTempFileName())) {
- contents = Util.ReadFile(Util.GetEncoderStatusTempFileName(), true);
+ if(Util.FileExists(UtilEncoder.GetEncoderStatusTempFileName())) {
+ contents = Util.ReadFile(UtilEncoder.GetEncoderStatusTempFileName(), true);
//contents is:
//(1/5) Starting R
//(5/5) R tasks done
@@ -4155,7 +4155,7 @@ Log.WriteLine(str);
}
} catch {
- //Util.GetEncoderStatusTempFileName() is deleted at the end of the process
+ //UtilEncoder.GetEncoderStatusTempFileName() is deleted at the end of the process
//this can make crash updatePulsebar sometimes
}
}
@@ -4199,7 +4199,7 @@ Log.WriteLine(str);
if(notebook_encoder_capture.CurrentPage == 0)
notebook_encoder_capture.NextPage();
- Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
+ Pixbuf pixbuf = new Pixbuf (UtilEncoder.GetEncoderGraphTempFileName());
//from a file
image_encoder_capture.Pixbuf = pixbuf;
encoderUpdateTreeViewCapture();
image_encoder_capture.Sensitive = true;
@@ -4225,11 +4225,11 @@ Log.WriteLine(str);
} else {
//TODO pensar en si s'ha de fer 1er amb mida petita i despres amb gran (en el
zoom),
//o si es una sola i fa alguna edicio
- Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
+ Pixbuf pixbuf = new Pixbuf (UtilEncoder.GetEncoderGraphTempFileName());
//from a file
image_encoder_analyze.Pixbuf = pixbuf;
encoder_pulsebar_analyze.Text = "";
- string contents = Util.ReadFile(Util.GetEncoderAnalyzeTableTempFileName(),
false);
+ string contents =
Util.ReadFile(UtilEncoder.GetEncoderAnalyzeTableTempFileName(), false);
if (contents != null && contents != "") {
treeviewEncoderAnalyzeRemoveColumns();
createTreeViewEncoderAnalyze(contents);
@@ -4251,7 +4251,7 @@ Log.WriteLine(str);
}
treeview_encoder_capture_curves.Sensitive = true;
- Util.FileDelete(Util.GetEncoderStatusTempFileName());
+ Util.FileDelete(UtilEncoder.GetEncoderStatusTempFileName());
}
/* end of thread stuff */
diff --git a/src/util.cs b/src/util.cs
index b0e75c4..1aba68b 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -28,8 +28,6 @@ using System.IO; //for detect OS
//this class tries to be a space for methods that are used in different classes
public class Util
{
- public static bool CancelRScript;
-
//all numbers are saved in database with '.' as decimal separator (method for numbers)
public static string ConvertToPoint (double myDouble)
{
@@ -340,13 +338,6 @@ public class Util
return myStringBuilder.ToString();
}
- private static string changeSpaceToSpaceMark(string myString)
- {
- StringBuilder myStringBuilder = new StringBuilder(myString);
- myStringBuilder.Replace(" ", "WINDOWSSPACEMARK");
- return myStringBuilder.ToString();
- }
-
public static string GetHeightInCentimeters (string time) {
// s = 4.9 * (tv/2)^2
double timeAsDouble = Convert.ToDouble(time);
@@ -831,138 +822,6 @@ public class Util
/********** end of multimedia paths ************/
- /********** start of encoder paths ************/
-
- /*
- * encoder data and graphs are organized by sessions
- * chronojump / encoder / sessionID / data
- * chronojump / encoder / sessionID / graphs
- */
-
- public static string GetEncoderDir() {
- return Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
- "Chronojump" + Path.DirectorySeparatorChar + "encoder");
- }
-
- //to store encoder data and graphs
- public static void CreateEncoderDirIfNeeded () {
- string [] dirs = { GetEncoderDir() };
- foreach (string d in dirs) {
- if( ! Directory.Exists(d)) {
- Directory.CreateDirectory (d);
- Log.WriteLine (string.Format("created dir: {0}", d));
- }
- }
- }
-
- public static string GetEncoderSessionDir (int sessionID) {
- return GetEncoderDir() + Path.DirectorySeparatorChar + sessionID.ToString();
- }
-
- public static string GetEncoderSessionDataDir (int sessionID) {
- return GetEncoderSessionDir(sessionID) + Path.DirectorySeparatorChar + "data";
- }
-
- public static string GetEncoderSessionDataCurveDir (int sessionID) {
- return GetEncoderSessionDataDir(sessionID) + Path.DirectorySeparatorChar + "curve";
- }
-
- public static string GetEncoderSessionDataSignalDir (int sessionID) {
- return GetEncoderSessionDataDir(sessionID) + Path.DirectorySeparatorChar + "signal";
- }
-
- public static string GetEncoderSessionGraphsDir (int sessionID) {
- return GetEncoderSessionDir(sessionID) + Path.DirectorySeparatorChar + "graphs";
- }
-
- public static void CreateEncoderSessionDirsIfNeeded (int sessionID) {
- string [] dirs = {
- GetEncoderSessionDir(sessionID), GetEncoderSessionDataDir(sessionID),
- GetEncoderSessionDataCurveDir(sessionID), GetEncoderSessionDataSignalDir(sessionID),
- GetEncoderSessionGraphsDir(sessionID) };
- foreach (string d in dirs) {
- if( ! Directory.Exists(d)) {
- Directory.CreateDirectory (d);
- Log.WriteLine (string.Format("created dir: {0}", d));
- }
- }
- }
-
- public static string GetEncoderDataTempFileName() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderDataTemp);
- }
- public static string GetEncoderCurvesTempFileName() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderCurvesTemp);
- }
- public static string GetEncoderAnalyzeTableTempFileName() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderAnalyzeTableTemp);
- }
- public static string GetEncoderGraphTempFileName() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderGraphTemp);
- }
- public static string GetEncoderGraphInputMulti() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderGraphInputMulti);
- }
- public static string GetEncoderStatusTempFileName() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderStatusTemp);
- }
- public static string GetEncoderExportTempFileName() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderExportTemp);
- }
- public static string GetEncoderSpecialDataTempFileName() {
- return Path.Combine(Path.GetTempPath(), Constants.EncoderSpecialDataTemp);
- }
-
-
-// public static void MoveTempToEncoderData(int sessionID, int uniqueID) {
- public static string CopyTempToEncoderData(int sessionID, int uniqueID, string personName, string
timeStamp)
- {
- string fileName="";
- if(File.Exists(GetEncoderDataTempFileName())) {
- CreateEncoderSessionDirsIfNeeded(sessionID);
-// try {
-// File.Move(GetEncoderDataTempFileName(), GetEncoderSessionDataDir(sessionID));
-// } catch {
- fileName = uniqueID.ToString() + "-" + personName + "-" +
- timeStamp + ".txt";
-
- File.Copy(GetEncoderDataTempFileName(),
- GetEncoderSessionDataSignalDir(sessionID) +
- Path.DirectorySeparatorChar + fileName, true);
-// }
- }
- return fileName;
- }
-
- public static bool CopyEncoderDataToTemp(string url, string fileName)
- {
- string origin = url + Path.DirectorySeparatorChar + fileName;
- string dest = GetEncoderDataTempFileName();
- if(File.Exists(origin)) {
- File.Copy(origin, dest, true);
- return true;
- }
- return false;
- }
-
-
- private static string getEncoderScriptCapture() {
- if(UtilAll.IsWindows())
- return System.IO.Path.Combine(GetPrefixDir(),
- "bin" + Path.DirectorySeparatorChar + "encoder",
Constants.EncoderScriptCaptureWindows);
- else
- return System.IO.Path.Combine(
- getDataDir(), "encoder", Constants.EncoderScriptCaptureLinux);
- }
-
- private static string getEncoderScriptGraph() {
- return System.IO.Path.Combine(
- getDataDir(), "encoder", Constants.EncoderScriptGraph);
- }
-
-
- /********** end of encoder paths ************/
public static string GetManualDir() {
//we are on:
@@ -982,17 +841,17 @@ public class Util
".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar);
}
- private static string getDataDir(){
+ public static string GetDataDir(){
return System.IO.Path.Combine(GetPrefixDir(),
"share" + Path.DirectorySeparatorChar + "chronojump");
}
public static string GetImagesDir(){
- return System.IO.Path.Combine(getDataDir(),"images");
+ return System.IO.Path.Combine(GetDataDir(),"images");
}
public static string GetCssDir(){
- return getDataDir();
+ return GetDataDir();
}
public static void BackupDirCreateIfNeeded () {
@@ -1059,9 +918,9 @@ public class Util
}
}
-
+
public static void RunRScript(string rScript){
- CancelRScript = false;
+ //CancelRScript = false;
ProcessStartInfo pinfo;
Process r;
@@ -1087,312 +946,13 @@ public class Util
r.StartInfo = pinfo;
r.Start();
r.WaitForExit();
- while ( ! ( File.Exists(outputFile) || CancelRScript) );
+ //while ( ! ( File.Exists(outputFile) || CancelRScript) );
+ while ( ! ( File.Exists(outputFile) ) );
} catch {
//maybe R is not installed
}
}
- public static void RunEncoderCapturePython(string title, EncoderStruct es, string port)
- {
- CancelRScript = false;
-
- ProcessStartInfo pinfo;
- Process p;
- //Old comment:
- //If output file is not given, R will try to write in the running folder
- //in which we may haven't got permissions
-
- string pBin="";
- pinfo = new ProcessStartInfo();
-
- string outputFileCheck = "";
-
-
- /*
- on Windows (py2exe) we execute a exe with the py file that contains python
- on linux we execute python and call to the py file
- also on windows we need the full path to find R
- */
- if (UtilAll.IsWindows()) {
- pBin=getEncoderScriptCapture();
- pinfo.Arguments = title + " " + es.OutputData1 + " " + es.Ep.ToString1() + " " + port
- + " " + changeSpaceToSpaceMark(
- System.IO.Path.Combine(GetPrefixDir(), "bin" +
Path.DirectorySeparatorChar + "R.exe"));
- }
- else {
- pBin="python";
- pinfo.Arguments = getEncoderScriptCapture() + " " + title + " " +
- es.OutputData1 + " " + es.Ep.ToString1() + " " + port;
- }
-
- outputFileCheck = es.OutputData1;
-
- pinfo.FileName=pBin;
-
- pinfo.CreateNoWindow = true;
- pinfo.UseShellExecute = false;
-
- Console.WriteLine(outputFileCheck);
- if (File.Exists(outputFileCheck))
- File.Delete(outputFileCheck);
-
- p = new Process();
- p.StartInfo = pinfo;
- p.Start();
- Log.WriteLine(p.Id.ToString());
-
- p.WaitForExit();
- while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
- }
-
- public static bool RunEncoderGraph(string title, EncoderStruct es)
- {
- CancelRScript = false;
-
- ProcessStartInfo pinfo;
- Process p;
- //If output file is not given, R will try to write in the running folder
- //in which we may haven't got permissions
-
- string pBin="";
- pinfo = new ProcessStartInfo();
-
- string operatingSystem = "Linux";
-
- pBin="Rscript";
- //pBin="R";
- if (UtilAll.IsWindows()) {
- //on Windows we need the \"str\" to call without problems in path with spaces
- pBin = "\"" + System.IO.Path.Combine(GetPrefixDir(), "bin" +
Path.DirectorySeparatorChar + "Rscript.exe") + "\"";
- Log.WriteLine("pBin:" + pBin);
-
- //On win32 R understands backlash as an escape character and
- //a file path uses Unix-like path separator '/'
- es.InputData = es.InputData.Replace("\\","/");
- es.OutputGraph = es.OutputGraph.Replace("\\","/");
- es.OutputData1 = es.OutputData1.Replace("\\","/");
- es.OutputData2 = es.OutputData2.Replace("\\","/");
- es.SpecialData = es.SpecialData.Replace("\\","/");
- operatingSystem = "Windows";
- }
-
- //--- way A. passing options to a file
- string scriptOptions = es.InputData + "\n" +
- es.OutputGraph + "\n" + es.OutputData1 + "\n" +
- es.OutputData2 + "\n" + es.SpecialData + "\n" +
- es.Ep.ToString2("\n") + "\n" + title + "\n" + operatingSystem + "\n";
-
- string optionsFile = Path.GetTempPath() + "Roptions.txt";
- TextWriter writer = File.CreateText(optionsFile);
- writer.Write(scriptOptions);
- writer.Flush();
- ((IDisposable)writer).Dispose();
-
- if (UtilAll.IsWindows()) {
- //On win32 R understands backlash as an escape character and
- //a file path uses Unix-like path separator '/'
- optionsFile = optionsFile.Replace("\\","/");
- }
-
- //on Windows we need the \"str\" to call without problems in path with spaces
- pinfo.Arguments = "\"" + getEncoderScriptGraph() + "\" " + optionsFile;
-
- Log.WriteLine("Arguments:" + pinfo.Arguments);
-
- /*
- pinfo.Arguments = "CMD BATCH --no-save '--args optionsFile=\"" + optionsFile + "\"' \"" +
- getEncoderScriptGraph() + "\" \"" +
- Path.GetTempPath() + "error.txt\"";
- */
-
- //--- way B. put options as arguments
- /*
- string argumentOptions = es.InputData + " " +
- es.OutputGraph + " " + es.OutputData1 + " " + es.OutputData2 + " " +
- es.Ep.ToString2(" ") + " " + title;
-
- pinfo.Arguments = getEncoderScriptGraph() + " " + argumentOptions;
- */
-
- Log.WriteLine("------------- 1 ---");
- Log.WriteLine(optionsFile.ToString());
- Log.WriteLine("------------- 2 ---");
- Log.WriteLine(scriptOptions.ToString());
- Log.WriteLine("------------- 3 ---");
- Log.WriteLine(pinfo.Arguments.ToString());
- Log.WriteLine("------------- 4 ---");
-
- string outputFileCheck = "";
- string outputFileCheck2 = "";
-
- //Wait until this to update encoder gui (if don't wait then treeview will be outdated)
- //exportCSV is the only one that doesn't have graph. all the rest Analysis have graph and data
- if(es.Ep.Analysis == "exportCSV")
- outputFileCheck = es.OutputData1;
- else {
- //outputFileCheck = es.OutputGraph;
- //
- //OutputData1 because since Chronojump 1.3.6,
- //encoder analyze has a treeview that can show the curves
- //when a graph analysis is done, curves file has to be written
- outputFileCheck = es.OutputData1;
- //check also the otuput graph
- outputFileCheck2 = es.OutputGraph;
- }
-
- pinfo.FileName=pBin;
-
- pinfo.CreateNoWindow = true;
- pinfo.UseShellExecute = false;
-
- //delete output file check(s)
- Console.WriteLine("Deleting... " + outputFileCheck);
- if (File.Exists(outputFileCheck))
- File.Delete(outputFileCheck);
-
- if(outputFileCheck2 != "") {
- Console.WriteLine("Deleting... " + outputFileCheck2);
- if (File.Exists(outputFileCheck2))
- File.Delete(outputFileCheck2);
- }
-
- //delete 1RM data if exists
- if (File.Exists(es.SpecialData))
- File.Delete(es.SpecialData);
-
- try {
- p = new Process();
- p.StartInfo = pinfo;
- p.Start();
- p.WaitForExit();
-
- if(outputFileCheck2 == "")
- while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
- else
- while ( ! ( (File.Exists(outputFileCheck) && File.Exists(outputFileCheck2))
|| CancelRScript ) );
- } catch {
- return false;
- }
-
- return true;
- }
-
- private static string [] encoderFindPos(string contents, int start, int duration) {
- int startPos = 0;
- int durationPos = 0;
- int i,digits;
- for(i=0, digits=0; i < contents.Length; i++) {
- if(Char.IsDigit(contents[i])) {
- digits ++;
- if(digits==start) {
- startPos = i;
- //but digit can be negative, check previous char if it was a '-'
- if(contents[i-1] == '-')
- startPos = i-1;
- //duration == -1 means: until the end
- if(duration == -1) {
- //when removing from startPos until the end,
- //the ',' before startPos will be in the end of the file
- //and then chronojump will try to read after that comma
- //because it reads in a Split (',')
- //for this reason we need to start removing that comma if
exists
- if(contents[startPos-1] == ',')
- startPos --;
-
- durationPos = contents.Length - startPos;
- break;
- }
- }
- if(startPos > 0 && digits == start + duration)
- durationPos = i-startPos;
- }
- }
- //Log.WriteLine("s "+ startPos.ToString());
- //Log.WriteLine("d "+ durationPos.ToString());
- //Log.WriteLine("i " + i.ToString());
-
- string [] returnStr = new string[2];
- returnStr [0] = startPos.ToString();
- returnStr [1] = durationPos.ToString();
- return returnStr;
- }
-
- public static void EncoderDeleteCurveFromSignal(string fileName, int start, int duration) {
- string contents = ReadFile(fileName, false);
- string [] startAndDuration = encoderFindPos(contents, start, duration);
-
- StringBuilder myStringBuilder = new StringBuilder(contents);
- myStringBuilder.Remove(
- Convert.ToInt32(startAndDuration[0]),
- Convert.ToInt32(startAndDuration[1]));
- contents = myStringBuilder.ToString();
-
- TextWriter writer = File.CreateText(fileName);
- writer.Write(contents);
- writer.Flush();
- ((IDisposable)writer).Dispose();
- }
-
- public static string EncoderSaveCurve(string fileNameSignal, int start, int duration,
- int sessionID, int uniqueID, string personName, string timeStamp, int curveIDMax)
- {
- string contents = ReadFile(fileNameSignal, false);
- string [] startAndDuration = encoderFindPos(contents, start, duration);
-
- contents = contents.Substring(
- Convert.ToInt32(startAndDuration[0]),
- Convert.ToInt32(startAndDuration[1])-1); //-1 is for not ending file with a
comma
- //don't know why but some curves are stored with a "," as last character
- //this curves also are in the form: "1, 2, 3, 4," instead of "1,2,3,4"
- //this produces an NA in reading of curves on graph.R
- //in the meantime this NA in reading in graph.R has been deleted
- //dataTempFile = dataTempFile[!is.na(dataTempFile)]
-
-
- string fileCurve = uniqueID.ToString() + "-" + personName + "-" +
- (++ curveIDMax).ToString() + "-" + timeStamp + ".txt";
- string fileCurveFull = GetEncoderSessionDataCurveDir(sessionID) + Path.DirectorySeparatorChar
+ fileCurve;
-
- TextWriter writer = File.CreateText(fileCurveFull);
- writer.Write(contents);
- writer.Flush();
- ((IDisposable)writer).Dispose();
-
- return fileCurve;
- }
-
- //used on encoder inverted-noninverted
- public static void ChangeSign(string fileName)
- {
- string data = ReadFile(fileName, true);
- if(data != null) {
- TextWriter writer;
- try {
- writer = File.CreateText(fileName);
- } catch {return;}
-
- using (StringReader reader = new StringReader (data)) {
- do {
- string line = reader.ReadLine ();
- if (line == null)
- break;
- string [] ints = line.Split(new char[] {','});
- string sep = "";
- foreach(string istr in ints) {
- int i = Convert.ToInt32(istr);
- i *= -1;
- writer.Write(sep + i.ToString());
- sep = ", ";
- }
- } while(true);
- }
- writer.Flush();
- ((IDisposable)writer).Dispose();
- }
- }
-
-
/*
* currently not used, we copy the assemblies now
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
new file mode 100644
index 0000000..dd881c1
--- /dev/null
+++ b/src/utilEncoder.cs
@@ -0,0 +1,473 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * 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-2012 Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+//using System.Data;
+using System.Text; //StringBuilder
+using System.Collections; //ArrayList
+using System.Diagnostics; //for detect OS
+using System.IO; //for detect OS
+
+//this class tries to be a space for methods that are used in different classes
+public class UtilEncoder
+{
+ public static bool CancelRScript;
+
+
+ /********** start of encoder paths ************/
+
+ /*
+ * encoder data and graphs are organized by sessions
+ * chronojump / encoder / sessionID / data
+ * chronojump / encoder / sessionID / graphs
+ */
+
+ public static string GetEncoderDir() {
+ return Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+ "Chronojump" + Path.DirectorySeparatorChar + "encoder");
+ }
+
+ //to store encoder data and graphs
+ public static void CreateEncoderDirIfNeeded () {
+ string [] dirs = { GetEncoderDir() };
+ foreach (string d in dirs) {
+ if( ! Directory.Exists(d)) {
+ Directory.CreateDirectory (d);
+ Log.WriteLine (string.Format("created dir: {0}", d));
+ }
+ }
+ }
+
+ public static string GetEncoderSessionDir (int sessionID) {
+ return GetEncoderDir() + Path.DirectorySeparatorChar + sessionID.ToString();
+ }
+
+ public static string GetEncoderSessionDataDir (int sessionID) {
+ return GetEncoderSessionDir(sessionID) + Path.DirectorySeparatorChar + "data";
+ }
+
+ public static string GetEncoderSessionDataCurveDir (int sessionID) {
+ return GetEncoderSessionDataDir(sessionID) + Path.DirectorySeparatorChar + "curve";
+ }
+
+ public static string GetEncoderSessionDataSignalDir (int sessionID) {
+ return GetEncoderSessionDataDir(sessionID) + Path.DirectorySeparatorChar + "signal";
+ }
+
+ public static string GetEncoderSessionGraphsDir (int sessionID) {
+ return GetEncoderSessionDir(sessionID) + Path.DirectorySeparatorChar + "graphs";
+ }
+
+ public static void CreateEncoderSessionDirsIfNeeded (int sessionID) {
+ string [] dirs = {
+ GetEncoderSessionDir(sessionID), GetEncoderSessionDataDir(sessionID),
+ GetEncoderSessionDataCurveDir(sessionID), GetEncoderSessionDataSignalDir(sessionID),
+ GetEncoderSessionGraphsDir(sessionID) };
+ foreach (string d in dirs) {
+ if( ! Directory.Exists(d)) {
+ Directory.CreateDirectory (d);
+ Log.WriteLine (string.Format("created dir: {0}", d));
+ }
+ }
+ }
+
+ public static string GetEncoderDataTempFileName() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderDataTemp);
+ }
+ public static string GetEncoderCurvesTempFileName() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderCurvesTemp);
+ }
+ public static string GetEncoderAnalyzeTableTempFileName() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderAnalyzeTableTemp);
+ }
+ public static string GetEncoderGraphTempFileName() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderGraphTemp);
+ }
+ public static string GetEncoderGraphInputMulti() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderGraphInputMulti);
+ }
+ public static string GetEncoderStatusTempFileName() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderStatusTemp);
+ }
+ public static string GetEncoderExportTempFileName() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderExportTemp);
+ }
+ public static string GetEncoderSpecialDataTempFileName() {
+ return Path.Combine(Path.GetTempPath(), Constants.EncoderSpecialDataTemp);
+ }
+
+
+// public static void MoveTempToEncoderData(int sessionID, int uniqueID) {
+ public static string CopyTempToEncoderData(int sessionID, int uniqueID, string personName, string
timeStamp)
+ {
+ string fileName="";
+ if(File.Exists(GetEncoderDataTempFileName())) {
+ CreateEncoderSessionDirsIfNeeded(sessionID);
+// try {
+// File.Move(GetEncoderDataTempFileName(), GetEncoderSessionDataDir(sessionID));
+// } catch {
+ fileName = uniqueID.ToString() + "-" + personName + "-" +
+ timeStamp + ".txt";
+
+ File.Copy(GetEncoderDataTempFileName(),
+ GetEncoderSessionDataSignalDir(sessionID) +
+ Path.DirectorySeparatorChar + fileName, true);
+// }
+ }
+ return fileName;
+ }
+
+ public static bool CopyEncoderDataToTemp(string url, string fileName)
+ {
+ string origin = url + Path.DirectorySeparatorChar + fileName;
+ string dest = GetEncoderDataTempFileName();
+ if(File.Exists(origin)) {
+ File.Copy(origin, dest, true);
+ return true;
+ }
+ return false;
+ }
+
+
+ private static string getEncoderScriptCapture() {
+ if(UtilAll.IsWindows())
+ return System.IO.Path.Combine(Util.GetPrefixDir(),
+ "bin" + Path.DirectorySeparatorChar + "encoder",
Constants.EncoderScriptCaptureWindows);
+ else
+ return System.IO.Path.Combine(
+ Util.GetDataDir(), "encoder", Constants.EncoderScriptCaptureLinux);
+ }
+
+ private static string getEncoderScriptGraph() {
+ return System.IO.Path.Combine(
+ Util.GetDataDir(), "encoder", Constants.EncoderScriptGraph);
+ }
+
+
+ /********** end of encoder paths ************/
+
+ private static string changeSpaceToSpaceMark(string myString)
+ {
+ StringBuilder myStringBuilder = new StringBuilder(myString);
+ myStringBuilder.Replace(" ", "WINDOWSSPACEMARK");
+ return myStringBuilder.ToString();
+ }
+
+
+ public static void RunEncoderCapturePython(string title, EncoderStruct es, string port)
+ {
+ CancelRScript = false;
+
+ ProcessStartInfo pinfo;
+ Process p;
+ //Old comment:
+ //If output file is not given, R will try to write in the running folder
+ //in which we may haven't got permissions
+
+ string pBin="";
+ pinfo = new ProcessStartInfo();
+
+ string outputFileCheck = "";
+
+
+ /*
+ on Windows (py2exe) we execute a exe with the py file that contains python
+ on linux we execute python and call to the py file
+ also on windows we need the full path to find R
+ */
+ if (UtilAll.IsWindows()) {
+ pBin=getEncoderScriptCapture();
+ pinfo.Arguments = title + " " + es.OutputData1 + " " + es.Ep.ToString1() + " " + port
+ + " " + changeSpaceToSpaceMark(
+ System.IO.Path.Combine(Util.GetPrefixDir(), "bin" +
Path.DirectorySeparatorChar + "R.exe"));
+ }
+ else {
+ pBin="python";
+ pinfo.Arguments = getEncoderScriptCapture() + " " + title + " " +
+ es.OutputData1 + " " + es.Ep.ToString1() + " " + port;
+ }
+
+ outputFileCheck = es.OutputData1;
+
+ pinfo.FileName=pBin;
+
+ pinfo.CreateNoWindow = true;
+ pinfo.UseShellExecute = false;
+
+ Console.WriteLine(outputFileCheck);
+ if (File.Exists(outputFileCheck))
+ File.Delete(outputFileCheck);
+
+ p = new Process();
+ p.StartInfo = pinfo;
+ p.Start();
+ Log.WriteLine(p.Id.ToString());
+
+ p.WaitForExit();
+ while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
+ }
+
+ public static bool RunEncoderGraph(string title, EncoderStruct es)
+ {
+ CancelRScript = false;
+
+ ProcessStartInfo pinfo;
+ Process p;
+ //If output file is not given, R will try to write in the running folder
+ //in which we may haven't got permissions
+
+ string pBin="";
+ pinfo = new ProcessStartInfo();
+
+ string operatingSystem = "Linux";
+
+ pBin="Rscript";
+ //pBin="R";
+ if (UtilAll.IsWindows()) {
+ //on Windows we need the \"str\" to call without problems in path with spaces
+ pBin = "\"" + System.IO.Path.Combine(Util.GetPrefixDir(), "bin" +
Path.DirectorySeparatorChar + "Rscript.exe") + "\"";
+ Log.WriteLine("pBin:" + pBin);
+
+ //On win32 R understands backlash as an escape character and
+ //a file path uses Unix-like path separator '/'
+ es.InputData = es.InputData.Replace("\\","/");
+ es.OutputGraph = es.OutputGraph.Replace("\\","/");
+ es.OutputData1 = es.OutputData1.Replace("\\","/");
+ es.OutputData2 = es.OutputData2.Replace("\\","/");
+ es.SpecialData = es.SpecialData.Replace("\\","/");
+ operatingSystem = "Windows";
+ }
+
+ //--- way A. passing options to a file
+ string scriptOptions = es.InputData + "\n" +
+ es.OutputGraph + "\n" + es.OutputData1 + "\n" +
+ es.OutputData2 + "\n" + es.SpecialData + "\n" +
+ es.Ep.ToString2("\n") + "\n" + title + "\n" + operatingSystem + "\n";
+
+ string optionsFile = Path.GetTempPath() + "Roptions.txt";
+ TextWriter writer = File.CreateText(optionsFile);
+ writer.Write(scriptOptions);
+ writer.Flush();
+ ((IDisposable)writer).Dispose();
+
+ if (UtilAll.IsWindows()) {
+ //On win32 R understands backlash as an escape character and
+ //a file path uses Unix-like path separator '/'
+ optionsFile = optionsFile.Replace("\\","/");
+ }
+
+ //on Windows we need the \"str\" to call without problems in path with spaces
+ pinfo.Arguments = "\"" + getEncoderScriptGraph() + "\" " + optionsFile;
+
+ Log.WriteLine("Arguments:" + pinfo.Arguments);
+
+ /*
+ pinfo.Arguments = "CMD BATCH --no-save '--args optionsFile=\"" + optionsFile + "\"' \"" +
+ getEncoderScriptGraph() + "\" \"" +
+ Path.GetTempPath() + "error.txt\"";
+ */
+
+ //--- way B. put options as arguments
+ /*
+ string argumentOptions = es.InputData + " " +
+ es.OutputGraph + " " + es.OutputData1 + " " + es.OutputData2 + " " +
+ es.Ep.ToString2(" ") + " " + title;
+
+ pinfo.Arguments = getEncoderScriptGraph() + " " + argumentOptions;
+ */
+
+ Log.WriteLine("------------- 1 ---");
+ Log.WriteLine(optionsFile.ToString());
+ Log.WriteLine("------------- 2 ---");
+ Log.WriteLine(scriptOptions.ToString());
+ Log.WriteLine("------------- 3 ---");
+ Log.WriteLine(pinfo.Arguments.ToString());
+ Log.WriteLine("------------- 4 ---");
+
+ string outputFileCheck = "";
+ string outputFileCheck2 = "";
+
+ //Wait until this to update encoder gui (if don't wait then treeview will be outdated)
+ //exportCSV is the only one that doesn't have graph. all the rest Analysis have graph and data
+ if(es.Ep.Analysis == "exportCSV")
+ outputFileCheck = es.OutputData1;
+ else {
+ //outputFileCheck = es.OutputGraph;
+ //
+ //OutputData1 because since Chronojump 1.3.6,
+ //encoder analyze has a treeview that can show the curves
+ //when a graph analysis is done, curves file has to be written
+ outputFileCheck = es.OutputData1;
+ //check also the otuput graph
+ outputFileCheck2 = es.OutputGraph;
+ }
+
+ pinfo.FileName=pBin;
+
+ pinfo.CreateNoWindow = true;
+ pinfo.UseShellExecute = false;
+
+ //delete output file check(s)
+ Console.WriteLine("Deleting... " + outputFileCheck);
+ if (File.Exists(outputFileCheck))
+ File.Delete(outputFileCheck);
+
+ if(outputFileCheck2 != "") {
+ Console.WriteLine("Deleting... " + outputFileCheck2);
+ if (File.Exists(outputFileCheck2))
+ File.Delete(outputFileCheck2);
+ }
+
+ //delete 1RM data if exists
+ if (File.Exists(es.SpecialData))
+ File.Delete(es.SpecialData);
+
+ try {
+ p = new Process();
+ p.StartInfo = pinfo;
+ p.Start();
+ p.WaitForExit();
+
+ if(outputFileCheck2 == "")
+ while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
+ else
+ while ( ! ( (File.Exists(outputFileCheck) && File.Exists(outputFileCheck2))
|| CancelRScript ) );
+ } catch {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static string [] encoderFindPos(string contents, int start, int duration) {
+ int startPos = 0;
+ int durationPos = 0;
+ int i,digits;
+ for(i=0, digits=0; i < contents.Length; i++) {
+ if(Char.IsDigit(contents[i])) {
+ digits ++;
+ if(digits==start) {
+ startPos = i;
+ //but digit can be negative, check previous char if it was a '-'
+ if(contents[i-1] == '-')
+ startPos = i-1;
+ //duration == -1 means: until the end
+ if(duration == -1) {
+ //when removing from startPos until the end,
+ //the ',' before startPos will be in the end of the file
+ //and then chronojump will try to read after that comma
+ //because it reads in a Split (',')
+ //for this reason we need to start removing that comma if
exists
+ if(contents[startPos-1] == ',')
+ startPos --;
+
+ durationPos = contents.Length - startPos;
+ break;
+ }
+ }
+ if(startPos > 0 && digits == start + duration)
+ durationPos = i-startPos;
+ }
+ }
+ //Log.WriteLine("s "+ startPos.ToString());
+ //Log.WriteLine("d "+ durationPos.ToString());
+ //Log.WriteLine("i " + i.ToString());
+
+ string [] returnStr = new string[2];
+ returnStr [0] = startPos.ToString();
+ returnStr [1] = durationPos.ToString();
+ return returnStr;
+ }
+
+ public static void EncoderDeleteCurveFromSignal(string fileName, int start, int duration) {
+ string contents = Util.ReadFile(fileName, false);
+ string [] startAndDuration = encoderFindPos(contents, start, duration);
+
+ StringBuilder myStringBuilder = new StringBuilder(contents);
+ myStringBuilder.Remove(
+ Convert.ToInt32(startAndDuration[0]),
+ Convert.ToInt32(startAndDuration[1]));
+ contents = myStringBuilder.ToString();
+
+ TextWriter writer = File.CreateText(fileName);
+ writer.Write(contents);
+ writer.Flush();
+ ((IDisposable)writer).Dispose();
+ }
+
+ public static string EncoderSaveCurve(string fileNameSignal, int start, int duration,
+ int sessionID, int uniqueID, string personName, string timeStamp, int curveIDMax)
+ {
+ string contents = Util.ReadFile(fileNameSignal, false);
+ string [] startAndDuration = encoderFindPos(contents, start, duration);
+
+ contents = contents.Substring(
+ Convert.ToInt32(startAndDuration[0]),
+ Convert.ToInt32(startAndDuration[1])-1); //-1 is for not ending file with a
comma
+ //don't know why but some curves are stored with a "," as last character
+ //this curves also are in the form: "1, 2, 3, 4," instead of "1,2,3,4"
+ //this produces an NA in reading of curves on graph.R
+ //in the meantime this NA in reading in graph.R has been deleted
+ //dataTempFile = dataTempFile[!is.na(dataTempFile)]
+
+
+ string fileCurve = uniqueID.ToString() + "-" + personName + "-" +
+ (++ curveIDMax).ToString() + "-" + timeStamp + ".txt";
+ string fileCurveFull = GetEncoderSessionDataCurveDir(sessionID) + Path.DirectorySeparatorChar
+ fileCurve;
+
+ TextWriter writer = File.CreateText(fileCurveFull);
+ writer.Write(contents);
+ writer.Flush();
+ ((IDisposable)writer).Dispose();
+
+ return fileCurve;
+ }
+
+ //used on encoder inverted-noninverted
+ public static void ChangeSign(string fileName)
+ {
+ string data = Util.ReadFile(fileName, true);
+ if(data != null) {
+ TextWriter writer;
+ try {
+ writer = File.CreateText(fileName);
+ } catch {return;}
+
+ using (StringReader reader = new StringReader (data)) {
+ do {
+ string line = reader.ReadLine ();
+ if (line == null)
+ break;
+ string [] ints = line.Split(new char[] {','});
+ string sep = "";
+ foreach(string istr in ints) {
+ int i = Convert.ToInt32(istr);
+ i *= -1;
+ writer.Write(sep + i.ToString());
+ sep = ", ";
+ }
+ } while(true);
+ }
+ writer.Flush();
+ ((IDisposable)writer).Dispose();
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]