/* * Encoder class methods */ public static int Insert(bool dbconOpened, EncoderSQL es) { if(! dbconOpened) dbcon.Open(); if(es.uniqueID == "-1") es.uniqueID = "NULL"; dbcmd.CommandText = "INSERT INTO " + Constants.EncoderTable + " (uniqueID, personID, sessionID, exerciseID, eccon, laterality, extraWeight, signalOrCurve, filename, url, time, minHeight, smooth, description, future1, future2, future3)" + " VALUES (" + es.uniqueID + ", " + es.personID + ", " + es.sessionID + ", " + es.exerciseID + ", '" + es.eccon + "', '" + es.laterality + "', '" + es.extraWeight + "', '" + es.signalOrCurve + "', '" + es.filename + "', '" + es.url + "', " + es.time + ", " + es.minHeight + ", " + Util.ConvertToPoint(es.smooth) + ", '" + es.description + "', '', '', '')" ; Log.WriteLine(dbcmd.CommandText.ToString()); dbcmd.ExecuteNonQuery(); //int myLast = dbcon.LastInsertRowId; //http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c string myString = @"select last_insert_rowid()"; dbcmd.CommandText = myString; int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object. if(! dbconOpened) dbcon.Close(); return myLast; }
protected void on_show_repetitions_row_edit_apply(object o, EventArgs args) { int curveID = genericWinESR.TreeviewSelectedUniqueID; EncoderSQL eSQL = (EncoderSQL)SqliteEncoder.Select( false, curveID, 0, 0, encoderGI, -1, "", EncoderSQL.Eccons.ALL, false, true)[0]; //if changed comment, update SQL, and update treeview //first remove conflictive characters string comment = Util.RemoveTildeAndColonAndDot(genericWinESR.EntryEditRow); if (comment != eSQL.description) { eSQL.description = comment; SqliteEncoder.Update(false, eSQL); //update treeview genericWinESR.on_edit_selected_done_update_treeview(); } //if changed person, proceed LogB.Information("new person: " + genericWinESR.GetComboSelected); int newPersonID = Util.FetchID(genericWinESR.GetComboSelected); if (newPersonID != currentPerson.UniqueID) { EncoderSQL eSQLChangedPerson = eSQL.ChangePerson(genericWinESR.GetComboSelected); SqliteEncoder.Update(false, eSQLChangedPerson); genericWinESR.RemoveSelectedRow(); } genericWinESR.ShowEditRow(false); }
/* * Encoder class methods */ public static int Insert(bool dbconOpened, EncoderSQL es) { if (!dbconOpened) { Sqlite.Open(); } if (es.uniqueID == "-1") { es.uniqueID = "NULL"; } dbcmd.CommandText = "INSERT INTO " + Constants.EncoderTable + " (uniqueID, personID, sessionID, exerciseID, eccon, laterality, extraWeight, " + "signalOrCurve, filename, url, time, minHeight, description, status, " + "videoURL, encoderConfiguration, future1, future2, future3)" + " VALUES (" + es.uniqueID + ", " + es.personID + ", " + es.sessionID + ", " + es.exerciseID + ", \"" + es.eccon + "\", \"" + es.LateralityToEnglish() + "\", \"" + es.extraWeight + "\", \"" + es.signalOrCurve + "\", \"" + es.filename + "\", \"" + removeURLpath(es.url) + "\", " + es.time + ", " + es.minHeight + ", \"" + es.description + "\", \"" + es.status + "\", \"" + removeURLpath(es.videoURL) + "\", \"" + es.encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL) + "\", \"" + Util.ConvertToPoint(es.future1) + "\", \"" + es.future2 + "\", \"" + es.future3 + "\")"; LogB.SQL(dbcmd.CommandText.ToString()); dbcmd.ExecuteNonQuery(); //int myLast = dbcon.LastInsertRowId; //http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c string myString = @"select last_insert_rowid()"; dbcmd.CommandText = myString; int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object. if (!dbconOpened) { Sqlite.Close(); } return(myLast); }
private static void update(bool dbconOpened, EncoderSQL es, SqliteCommand mycmd) { if (!dbconOpened) { Sqlite.Open(); } if (es.uniqueID == "-1") { es.uniqueID = "NULL"; } mycmd.CommandText = "UPDATE " + Constants.EncoderTable + " SET " + " personID = " + es.personID + ", sessionID = " + es.sessionID + ", exerciseID = " + es.exerciseID + ", eccon = \"" + es.eccon + "\", laterality = \"" + es.LateralityToEnglish() + "\", extraWeight = \"" + es.extraWeight + "\", signalOrCurve = \"" + es.signalOrCurve + "\", filename = \"" + es.filename + "\", url = \"" + removeURLpath(es.url) + "\", time = " + es.time + ", minHeight = " + es.minHeight + ", description = \"" + es.description + "\", status = \"" + es.status + "\", videoURL = \"" + removeURLpath(es.videoURL) + "\", encoderConfiguration = \"" + es.encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL) + "\", future1 = \"" + Util.ConvertToPoint(es.future1) + "\", future2 = \"" + es.future2 + "\", future3 = \"" + es.future3 + "\" WHERE uniqueID == " + es.uniqueID; LogB.SQL(mycmd.CommandText.ToString()); mycmd.ExecuteNonQuery(); if (!dbconOpened) { Sqlite.Close(); } }
private bool chronojumpWindowTestsEncoderLoadSignal(int count) { LogB.TestStart("chronojumpWindowTestsLoadSignal"); ArrayList data = encoderLoadSignalData(); //selects signals of this person, this session, this encoderGI if (count >= data.Count) { LogB.TestEnd("chronojumpWindowTestsLoadSignal_ended"); return(false); } EncoderSQL es = (EncoderSQL)data[count]; //first is 0 on_encoder_load_signal_clicked(Convert.ToInt32(es.uniqueID)); //opens load window with first selected genericWin.Button_accept.Click(); //this will call accepted LogB.TestEnd("chronojumpWindowTestsLoadSignal_continuing"); return(true); }
/* * Encoder class methods */ public static int Insert(bool dbconOpened, EncoderSQL es) { if(! dbconOpened) Sqlite.Open(); if(es.uniqueID == "-1") es.uniqueID = "NULL"; dbcmd.CommandText = "INSERT INTO " + Constants.EncoderTable + " (uniqueID, personID, sessionID, exerciseID, eccon, laterality, extraWeight, " + "signalOrCurve, filename, url, time, minHeight, description, status, " + "videoURL, encoderConfiguration, future1, future2, future3)" + " VALUES (" + es.uniqueID + ", " + es.personID + ", " + es.sessionID + ", " + es.exerciseID + ", \"" + es.eccon + "\", \"" + es.LateralityToEnglish() + "\", \"" + es.extraWeight + "\", \"" + es.signalOrCurve + "\", \"" + es.filename + "\", \"" + removeURLpath(es.url) + "\", " + es.time + ", " + es.minHeight + ", \"" + es.description + "\", \"" + es.status + "\", \"" + removeURLpath(es.videoURL) + "\", \"" + es.encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL) + "\", \"" + Util.ConvertToPoint(es.future1) + "\", \"" + es.future2 + "\", \"" + es.future3 + "\")"; LogB.SQL(dbcmd.CommandText.ToString()); dbcmd.ExecuteNonQuery(); //int myLast = dbcon.LastInsertRowId; //http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c string myString = @"select last_insert_rowid()"; dbcmd.CommandText = myString; int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object. if(! dbconOpened) Sqlite.Close(); return myLast; }
//Transaction Update call dbcmdTr will be used public static void Update(bool dbconOpened, EncoderSQL es, SqliteCommand dbcmdTr) { update(dbconOpened, es, dbcmdTr); }
//normal Update call dbcmd will be used public static void Update(bool dbconOpened, EncoderSQL es) { update(dbconOpened, es, dbcmd); }
public void SetUp() { eSQL = new EncoderSQL(); }
//this is called by non gtk thread. Don't do gtk stuff here //I suppose reading gtk is ok, changing will be the problem //called on calculatecurves, recalculate and load private void encoderDoCurvesGraphR(string analysisSent) { LogB.Debug("encoderDoCurvesGraphR() start"); string analysis = analysisSent; string analysisOptions = getEncoderAnalysisOptions(); //without this we loose the videoURL on recalculate string videoURL = ""; if(encoderSignalUniqueID != null && encoderSignalUniqueID != "-1") { string file = Util.GetVideoFileName(currentSession.UniqueID, Constants.TestTypes.ENCODER, Convert.ToInt32(encoderSignalUniqueID)); if(file != null && file != "" && File.Exists(file)) videoURL = file; } //see explanation on the top of this file lastEncoderSQLSignal = new EncoderSQL( "-1", currentPerson.UniqueID, currentSession.UniqueID, getExerciseIDFromCombo(exerciseCombos.CAPTURE), findEccon(true), //force ecS (ecc-conc separated) UtilGtk.ComboGetActive(combo_encoder_laterality), Util.ConvertToPoint(findMass(Constants.MassType.EXTRA)), //when save on sql, do not include person weight "", //signalOrCurve, "", //fileSaved, //to know date do: select substr(name,-23,19) from encoder; "", //path, //url preferences.encoderCaptureTime, preferences.EncoderCaptureMinHeight(encoderConfigurationCurrent.has_inertia), Util.RemoveTildeAndColonAndDot(textview_encoder_signal_comment.Buffer.Text), //desc, "", videoURL, //status, videoURL encoderConfigurationCurrent, "","","", //future1, 2, 3 Util.FindOnArray(':', 2, 1, UtilGtk.ComboGetActive(combo_encoder_exercise_capture), encoderExercisesTranslationAndBodyPWeight) //exerciseName (english) ); EncoderParams ep = new EncoderParams( preferences.EncoderCaptureMinHeight(encoderConfigurationCurrent.has_inertia), getExercisePercentBodyWeightFromComboCapture (), Util.ConvertToPoint(findMass(Constants.MassType.BODY)), Util.ConvertToPoint(findMass(Constants.MassType.EXTRA)), findEccon(true), //force ecS (ecc-conc separated) analysis, "none", //analysisVariables (not needed in create curves). Cannot be blank analysisOptions, preferences.encoderCaptureCheckFullyExtended, preferences.encoderCaptureCheckFullyExtendedValue, encoderConfigurationCurrent, Util.ConvertToPoint(preferences.encoderSmoothCon), //R decimal: '.' 0, //curve is not used here image_encoder_width, image_encoder_height, preferences.CSVExportDecimalSeparator ); EncoderStruct es = new EncoderStruct( UtilEncoder.GetEncoderDataTempFileName(), UtilEncoder.GetEncoderGraphTempFileName(), UtilEncoder.GetEncoderCurvesTempFileName(), UtilEncoder.GetEncoderScriptsPathWithoutLastSep(), UtilEncoder.GetEncoderTempPathWithoutLastSep(), ep); string title = Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "-" + Util.ChangeSpaceAndMinusForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise_capture)); if(encoderConfigurationCurrent.has_inertia) title += "-(" + encoderConfigurationCurrent.inertiaTotal.ToString() + " " + Catalog.GetString("Inertia M.") + ")"; else title += "-(" + Util.ConvertToPoint(findMass(Constants.MassType.DISPLACED)) + "Kg)"; encoderRProcAnalyze.SendData( title, false, //do not use neuromuscularProfile script preferences.RGraphsTranslate ); bool result = encoderRProcAnalyze.StartOrContinue(es); if(result) //store this to show 1,2,3,4,... or 1e,1c,2e,2c,... in RenderN //if is not stored, it can change when changed eccon radiobutton on cursor is in treeview ecconLast = findEccon(false); else { encoderProcessProblems = true; } LogB.Debug("encoderDoCurvesGraphR() end"); }
void delete_encoder_curve(bool dbconOpened, int uniqueID) { LogB.Information(uniqueID.ToString()); bool eSQLfound = true; //EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(dbconOpened, uniqueID, 0, 0, -1, "", EncoderSQL.Eccons.ALL, false, true)[0]; //WARNING because SqliteEncoder.Select may not return nothing, and then cannot be assigned to eSQL //do this: EncoderSQL eSQL = new EncoderSQL(); try { eSQL = (EncoderSQL) SqliteEncoder.Select(dbconOpened, uniqueID, 0, 0, Constants.EncoderGI.ALL, -1, "", EncoderSQL.Eccons.ALL, false, true)[0]; } catch { eSQLfound = false; LogB.Warning("Catched! seems it's already deleted"); } //remove the file if(eSQLfound) Util.FileDelete(eSQL.GetFullURL(false)); //don't convertPathToR Sqlite.Delete(dbconOpened, Constants.EncoderTable, Convert.ToInt32(uniqueID)); ArrayList escArray = SqliteEncoder.SelectSignalCurve(dbconOpened, -1, Convert.ToInt32(uniqueID), //signal, curve -1, -1); //msStart, msEnd if(eSQLfound) SqliteEncoder.DeleteSignalCurveWithCurveID(dbconOpened, Convert.ToInt32(eSQL.uniqueID)); //delete by curveID on SignalCurve table //if deleted curve is from current signal, uncheck it in encoderCaptureCurves if(escArray.Count > 0) { EncoderSignalCurve esc = (EncoderSignalCurve) escArray[0]; if(esc.signalID == Convert.ToInt32(encoderSignalUniqueID)) encoderCaptureSelectBySavedCurves(esc.msCentral, false); } //TODO: change encSelReps and this will change labels updateUserCurvesLabelsAndCombo(dbconOpened); }
private static void update(bool dbconOpened, EncoderSQL es, SqliteCommand mycmd) { if(! dbconOpened) Sqlite.Open(); if(es.uniqueID == "-1") es.uniqueID = "NULL"; mycmd.CommandText = "UPDATE " + Constants.EncoderTable + " SET " + " personID = " + es.personID + ", sessionID = " + es.sessionID + ", exerciseID = " + es.exerciseID + ", eccon = \"" + es.eccon + "\", laterality = \"" + es.LateralityToEnglish() + "\", extraWeight = \"" + es.extraWeight + "\", signalOrCurve = \"" + es.signalOrCurve + "\", filename = \"" + es.filename + "\", url = \"" + removeURLpath(es.url) + "\", time = " + es.time + ", minHeight = " + es.minHeight + ", description = \"" + es.description + "\", status = \"" + es.status + "\", videoURL = \"" + removeURLpath(es.videoURL) + "\", encoderConfiguration = \"" + es.encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL) + "\", future1 = \"" + Util.ConvertToPoint(es.future1) + "\", future2 = \"" + es.future2 + "\", future3 = \"" + es.future3 + "\" WHERE uniqueID == " + es.uniqueID ; LogB.SQL(mycmd.CommandText.ToString()); mycmd.ExecuteNonQuery(); if(! dbconOpened) Sqlite.Close(); }
//pass uniqueID value and then will return one record. do like this: //EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, myUniqueID, 0, 0, 0, "", EncoderSQL.Eccons.ALL, false, true)[0]; //WARNING because SqliteEncoder.Select may not return nothing, and then cannot be assigned to eSQL //see: delete_encoder_curve(bool dbconOpened, int uniqueID) //don't care for the 0, 0, 0 because selection will be based on the myUniqueID and only one row will be returned //or //pass uniqueID==-1 and personID, sessionID, signalOrCurve values, and will return some records //personID can be -1 to get all on that session //sessionID can be -1 to get all sessions //exerciseID can be -1 to get all exercises //signalOrCurve can be "all" //orderIDascendent is good for all the situations except when we want to convert from 1.05 to 1.06 //in that conversion, we want first the last ones, and later the previous // (to delete them if they are old copies) public static ArrayList Select( bool dbconOpened, int uniqueID, int personID, int sessionID, Constants.EncoderGI encoderGI, int exerciseID, string signalOrCurve, EncoderSQL.Eccons ecconSelect, bool onlyActive, bool orderIDascendent) { if (!dbconOpened) { Sqlite.Open(); } string personIDStr = ""; if (personID != -1) { personIDStr = " personID = " + personID + " AND "; } string sessionIDStr = ""; if (sessionID != -1) { sessionIDStr = " sessionID = " + sessionID + " AND "; } string exerciseIDStr = ""; if (exerciseID != -1) { exerciseIDStr = " exerciseID = " + exerciseID + " AND "; } string selectStr = ""; if (uniqueID != -1) { selectStr = Constants.EncoderTable + ".uniqueID = " + uniqueID; } else { if (signalOrCurve == "all") { selectStr = personIDStr + sessionIDStr + exerciseIDStr; } else { selectStr = personIDStr + sessionIDStr + exerciseIDStr + " signalOrCurve = \"" + signalOrCurve + "\""; } if (ecconSelect != EncoderSQL.Eccons.ALL) { selectStr += " AND " + Constants.EncoderTable + ".eccon = \"" + EncoderSQL.Eccons.ecS.ToString() + "\""; } } string andString = ""; if (selectStr != "") { andString = " AND "; } string onlyActiveString = ""; if (onlyActive) { onlyActiveString = " AND " + Constants.EncoderTable + ".status = \"active\" "; } string orderIDstr = ""; if (!orderIDascendent) { orderIDstr = " DESC"; } dbcmd.CommandText = "SELECT " + Constants.EncoderTable + ".*, " + Constants.EncoderExerciseTable + ".name FROM " + Constants.EncoderTable + ", " + Constants.EncoderExerciseTable + " WHERE " + selectStr + andString + Constants.EncoderTable + ".exerciseID = " + Constants.EncoderExerciseTable + ".uniqueID " + onlyActiveString + " ORDER BY substr(filename,-23,19), " + //'filename,-23,19' has the date of capture signal "uniqueID " + orderIDstr; LogB.SQL(dbcmd.CommandText.ToString()); SqliteDataReader reader; reader = dbcmd.ExecuteReader(); ArrayList array = new ArrayList(1); EncoderSQL es = new EncoderSQL(); while (reader.Read()) { string [] strFull = reader[15].ToString().Split(new char[] { ':' }); EncoderConfiguration econf = new EncoderConfiguration( (Constants.EncoderConfigurationNames) Enum.Parse(typeof(Constants.EncoderConfigurationNames), strFull[0])); econf.ReadParamsFromSQL(strFull); //if encoderGI != ALL discard non wanted repetitions if (encoderGI == Constants.EncoderGI.GRAVITATORY && econf.has_inertia) { continue; } else if (encoderGI == Constants.EncoderGI.INERTIAL && !econf.has_inertia) { continue; } LogB.Debug("EncoderConfiguration = " + econf.ToStringOutput(EncoderConfiguration.Outputs.SQL)); //if there's no video, will be "". //if there's video, will be with full path string videoURL = ""; if (reader[14].ToString() != "") { videoURL = addURLpath(fixOSpath(reader[14].ToString())); } //LogB.SQL(econf.ToString(":", true)); es = new EncoderSQL( reader[0].ToString(), //uniqueID Convert.ToInt32(reader[1].ToString()), //personID Convert.ToInt32(reader[2].ToString()), //sessionID Convert.ToInt32(reader[3].ToString()), //exerciseID reader[4].ToString(), //eccon Catalog.GetString(reader[5].ToString()), //laterality reader[6].ToString(), //extraWeight reader[7].ToString(), //signalOrCurve reader[8].ToString(), //filename addURLpath(fixOSpath(reader[9].ToString())), //url Convert.ToInt32(reader[10].ToString()), //time Convert.ToInt32(reader[11].ToString()), //minHeight reader[12].ToString(), //description reader[13].ToString(), //status videoURL, //videoURL econf, //encoderConfiguration Util.ChangeDecimalSeparator(reader[16].ToString()), //future1 (meanPower on curves) reader[17].ToString(), //future2 reader[18].ToString(), //future3 reader[19].ToString() //EncoderExercise.name ); array.Add(es); } reader.Close(); if (!dbconOpened) { Sqlite.Close(); } return(array); }
public void TearDown() { eSQL = null; }
public static void Update(bool dbconOpened, EncoderSQL es) { if(! dbconOpened) dbcon.Open(); if(es.uniqueID == "-1") es.uniqueID = "NULL"; dbcmd.CommandText = "UPDATE " + Constants.EncoderTable + " SET " + " personID = " + es.personID + ", sessionID = " + es.sessionID + ", exerciseID = " + es.exerciseID + ", eccon = '" + es.eccon + "', laterality = '" + es.laterality + "', extraWeight = '" + es.extraWeight + "', signalOrCurve = '" + es.signalOrCurve + "', filename = '" + es.filename + "', url = '" + es.url + "', time = " + es.time + ", minHeight = " + es.minHeight + ", smooth = " + Util.ConvertToPoint(es.smooth) + ", description = '" + es.description + "', future1 = '" + es.future1 + "', future2 = '" + es.future2 + "', future3 = '" + es.future3 + "' WHERE uniqueID == " + es.uniqueID ; Log.WriteLine(dbcmd.CommandText.ToString()); dbcmd.ExecuteNonQuery(); if(! dbconOpened) dbcon.Close(); }
//pass uniqueID value and then will return one record. do like this: //EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, myUniqueID, 0, 0, "")[0]; //or //pass uniqueID==-1 and personID, sessionID, signalOrCurve values, and will return some records public static ArrayList Select(bool dbconOpened, int uniqueID, int personID, int sessionID, string signalOrCurve) { if(! dbconOpened) dbcon.Open(); string selectStr = ""; if(uniqueID != -1) selectStr = Constants.EncoderTable + ".uniqueID = " + uniqueID; else selectStr = "personID = " + personID + " AND sessionID = " + sessionID + " AND signalOrCurve = '" + signalOrCurve + "'"; dbcmd.CommandText = "SELECT " + Constants.EncoderTable + ".*, " + Constants.EncoderExerciseTable + ".name FROM " + Constants.EncoderTable + ", " + Constants.EncoderExerciseTable + " WHERE " + selectStr + " AND " + Constants.EncoderTable + ".exerciseID = " + Constants.EncoderExerciseTable + ".uniqueID "; Log.WriteLine(dbcmd.CommandText.ToString()); 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 Convert.ToInt32(reader[3].ToString()), //exerciseID reader[4].ToString(), //eccon reader[5].ToString(), //laterality reader[6].ToString(), //extraWeight reader[7].ToString(), //signalOrCurve reader[8].ToString(), //filename reader[9].ToString(), //url Convert.ToInt32(reader[10].ToString()), //time Convert.ToInt32(reader[11].ToString()), //minHeight Convert.ToDouble(Util.ChangeDecimalSeparator(reader[12].ToString())), //smooth reader[13].ToString(), //description reader[14].ToString(), //future1 reader[15].ToString(), //future2 reader[16].ToString(), //future3 reader[17].ToString() //EncoderExercise.name ); array.Add (es); } reader.Close(); if(! dbconOpened) dbcon.Close(); return array; }
//pass uniqueID value and then will return one record. do like this: //EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, myUniqueID, 0, 0, 0, "", EncoderSQL.Eccons.ALL, false, true)[0]; //WARNING because SqliteEncoder.Select may not return nothing, and then cannot be assigned to eSQL //see: delete_encoder_curve(bool dbconOpened, int uniqueID) //don't care for the 0, 0, 0 because selection will be based on the myUniqueID and only one row will be returned //or //pass uniqueID==-1 and personID, sessionID, signalOrCurve values, and will return some records //personID can be -1 to get all on that session //sessionID can be -1 to get all sessions //exerciseID can be -1 to get all exercises //signalOrCurve can be "all" //orderIDascendent is good for all the situations except when we want to convert from 1.05 to 1.06 //in that conversion, we want first the last ones, and later the previous // (to delete them if they are old copies) public static ArrayList Select( bool dbconOpened, int uniqueID, int personID, int sessionID, Constants.EncoderGI encoderGI, int exerciseID, string signalOrCurve, EncoderSQL.Eccons ecconSelect, bool onlyActive, bool orderIDascendent) { if(! dbconOpened) Sqlite.Open(); string personIDStr = ""; if(personID != -1) personIDStr = " personID = " + personID + " AND "; string sessionIDStr = ""; if(sessionID != -1) sessionIDStr = " sessionID = " + sessionID + " AND "; string exerciseIDStr = ""; if(exerciseID != -1) exerciseIDStr = " exerciseID = " + exerciseID + " AND "; string selectStr = ""; if(uniqueID != -1) selectStr = Constants.EncoderTable + ".uniqueID = " + uniqueID; else { if(signalOrCurve == "all") selectStr = personIDStr + sessionIDStr + exerciseIDStr; else selectStr = personIDStr + sessionIDStr + exerciseIDStr + " signalOrCurve = \"" + signalOrCurve + "\""; if(ecconSelect != EncoderSQL.Eccons.ALL) selectStr += " AND " + Constants.EncoderTable + ".eccon = \"" + EncoderSQL.Eccons.ecS.ToString() + "\""; } string andString = ""; if(selectStr != "") andString = " AND "; string onlyActiveString = ""; if(onlyActive) onlyActiveString = " AND " + Constants.EncoderTable + ".status = \"active\" "; string orderIDstr = ""; if(! orderIDascendent) orderIDstr = " DESC"; dbcmd.CommandText = "SELECT " + Constants.EncoderTable + ".*, " + Constants.EncoderExerciseTable + ".name FROM " + Constants.EncoderTable + ", " + Constants.EncoderExerciseTable + " WHERE " + selectStr + andString + Constants.EncoderTable + ".exerciseID = " + Constants.EncoderExerciseTable + ".uniqueID " + onlyActiveString + " ORDER BY substr(filename,-23,19), " + //'filename,-23,19' has the date of capture signal "uniqueID " + orderIDstr; LogB.SQL(dbcmd.CommandText.ToString()); SqliteDataReader reader; reader = dbcmd.ExecuteReader(); ArrayList array = new ArrayList(1); EncoderSQL es = new EncoderSQL(); while(reader.Read()) { string [] strFull = reader[15].ToString().Split(new char[] {':'}); EncoderConfiguration econf = new EncoderConfiguration( (Constants.EncoderConfigurationNames) Enum.Parse(typeof(Constants.EncoderConfigurationNames), strFull[0]) ); econf.ReadParamsFromSQL(strFull); //if encoderGI != ALL discard non wanted repetitions if(encoderGI == Constants.EncoderGI.GRAVITATORY && econf.has_inertia) continue; else if(encoderGI == Constants.EncoderGI.INERTIAL && ! econf.has_inertia) continue; LogB.Debug("EncoderConfiguration = " + econf.ToStringOutput(EncoderConfiguration.Outputs.SQL)); //if there's no video, will be "". //if there's video, will be with full path string videoURL = ""; if(reader[14].ToString() != "") videoURL = addURLpath(fixOSpath(reader[14].ToString())); //LogB.SQL(econf.ToString(":", true)); es = new EncoderSQL ( reader[0].ToString(), //uniqueID Convert.ToInt32(reader[1].ToString()), //personID Convert.ToInt32(reader[2].ToString()), //sessionID Convert.ToInt32(reader[3].ToString()), //exerciseID reader[4].ToString(), //eccon Catalog.GetString(reader[5].ToString()),//laterality reader[6].ToString(), //extraWeight reader[7].ToString(), //signalOrCurve reader[8].ToString(), //filename addURLpath(fixOSpath(reader[9].ToString())), //url Convert.ToInt32(reader[10].ToString()), //time Convert.ToInt32(reader[11].ToString()), //minHeight reader[12].ToString(), //description reader[13].ToString(), //status videoURL, //videoURL econf, //encoderConfiguration Util.ChangeDecimalSeparator(reader[16].ToString()), //future1 (meanPower on curves) reader[17].ToString(), //future2 reader[18].ToString(), //future3 reader[19].ToString() //EncoderExercise.name ); array.Add (es); } reader.Close(); if(! dbconOpened) Sqlite.Close(); return array; }
string encoderSaveSignalOrCurve(string mode, int selectedID) { //mode is different than type. //mode can be curve, allCurves or signal //type is to print on db at type column: curve or signal + (bar or jump) string signalOrCurve = ""; string feedback = ""; string fileSaved = ""; string path = ""; if(mode == "curve") { signalOrCurve = "curve"; decimal curveNum = (decimal) treeviewEncoderCurvesEventSelectedID(); //on c and ec: 1,2,3,4,... if(ecconLast != "c") curveNum = decimal.Truncate((curveNum +1) /2); //1,1,2,2,... feedback = string.Format(Catalog.GetString("Curve {0} saved"), curveNum); } else if(mode == "allCurves") { signalOrCurve = "curve"; feedback = Catalog.GetString("All curves saved"); } else //mode == "signal" signalOrCurve = "signal"; string desc = ""; if(mode == "curve" || mode == "allCurves") { EncoderCurve curve = treeviewEncoderCurvesGetCurve(selectedID,true); //some start at ,5 because of the spline filtering int curveStart = Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curve.Start))); int duration = Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curve.Duration))); if(ecconLast != "c") { EncoderCurve curveNext = treeviewEncoderCurvesGetCurve(selectedID+1,false); duration += Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curveNext.Duration))); } desc = Util.RemoveTildeAndColonAndDot(entry_encoder_curve_comment.Text.ToString()); Log.WriteLine(curveStart + "->" + duration); int curveIDMax = Sqlite.Max(Constants.EncoderTable, "uniqueID", false); fileSaved = Util.EncoderSaveCurve(Util.GetEncoderDataTempFileName(), curveStart, duration, currentSession.UniqueID, currentPerson.UniqueID, currentPerson.Name, encoderTimeStamp, curveIDMax); path = Util.GetEncoderSessionDataCurveDir(currentSession.UniqueID); } else { //signal desc = Util.RemoveTildeAndColonAndDot(entry_encoder_signal_comment.Text.ToString()); fileSaved = Util.CopyTempToEncoderData (currentSession.UniqueID, currentPerson.UniqueID, currentPerson.Name, encoderTimeStamp); path = Util.GetEncoderSessionDataSignalDir(currentSession.UniqueID); } string myID = "-1"; if(mode == "signal") myID = encoderSignalUniqueID; EncoderSQL eSQL = new EncoderSQL( myID, currentPerson.UniqueID, currentSession.UniqueID, Convert.ToInt32( Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_encoder_exercise), encoderExercisesTranslationAndBodyPWeight) ), //exerciseID findEccon(true), //force ecS (ecc-conc separated) UtilGtk.ComboGetActive(combo_encoder_laterality), findMass(false), //when save on sql, do not include person weight signalOrCurve, fileSaved, //to know date do: select substr(name,-23,19) from encoder; path, //url (int) spin_encoder_capture_time.Value, (int) spin_encoder_capture_min_height.Value, (double) spin_encoder_smooth.Value, desc, "","","", Util.FindOnArray(':', 2, 1, UtilGtk.ComboGetActive(combo_encoder_exercise), encoderExercisesTranslationAndBodyPWeight) //exerciseName (english) ); //if is a signal that we just loaded, then don't insert, do an update //we know it because encoderUniqueID is != than "-1" if we loaded something from database //on curves, always insert, because it can be done with different smoothing, different params if(myID == "-1") { myID = SqliteEncoder.Insert(false, eSQL).ToString(); //Adding on SQL if(mode == "signal") { encoderSignalUniqueID = myID; feedback = Catalog.GetString("Signal saved"); } } else { //only signal is updated SqliteEncoder.Update(false, eSQL); //Adding on SQL feedback = Catalog.GetString("Signal updated"); } return feedback; }