protected void writeRunInterval(bool tempTable) { int tracksHere = 0; //different than globakl tracks variable string limitString = ""; //if user clicked in finish earlier if(finish) { if(tracksLimited) { tracksHere = Util.GetNumberOfJumps(intervalTimesString, false); limitString = tracksHere.ToString() + "R"; } else { //when we mark that run should finish by time, chronopic thread is probably capturing data //check if it captured more than date limit, and if it has done, delete last(s) run(s) if(limitAsDouble != -1) { bool eventPassed = Util.EventPassedFromMaxTime(intervalTimesString, limitAsDouble); while(eventPassed) { intervalTimesString = Util.DeleteLastSubEvent(intervalTimesString); //run limited by time that first subRun has arrived later than maximum for the whole run, //and DeleteLastSubEvent returns "-" as a mark if(intervalTimesString[0] == '-') { //this dialog can make crash the software because the non-gui part calls it //new DialogMessage(Constants.MessageTypes.WARNING, // Catalog.GetString("Race will not be recorded, 1st lap is out of time")); feedbackMessage = Catalog.GetString("Race will not be recorded. Out of time."); needShowFeedbackMessage = true; LogB.Information("Race will not be recorded, 1st lap is out of time"); //mark for not having problems with cancelled cancel = true; //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); //end this piece of code return; } else { LogB.Information("Deleted one event out of time"); eventPassed = Util.EventPassedFromMaxTime(intervalTimesString, limitAsDouble); } } } //tracksHere are defined here (and not before) because can change on "while(eventPassed)" before tracksHere = Util.GetNumberOfJumps(intervalTimesString, false); limitString = Util.GetTotalTime(intervalTimesString) + "T"; } } else { if(tracksLimited) { limitString = limitAsDouble.ToString() + "R"; tracksHere = (int) limitAsDouble; } else { limitString = limitAsDouble.ToString() + "T"; string [] myStringFull = intervalTimesString.Split(new char[] {'='}); tracksHere = myStringFull.Length; } } distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracksHere); timeTotal = Util.GetTotalTime(intervalTimesString); string description = ""; if(type == "MTGUG") description = "u u u u u u"; //undefined 6 items of questionnaire if(tempTable) SqliteRunInterval.Insert(false, Constants.TempRunIntervalTable, "NULL", personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracksHere, description, limitString, Util.BoolToNegativeInt(simulated), !startIn //initialSpeed true if not startIn ); else { uniqueID = SqliteRunInterval.Insert(false, Constants.RunIntervalTable, "NULL", personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracksHere, description, limitString, Util.BoolToNegativeInt(simulated), !startIn ); //define the created object eventDone = new RunInterval(uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracksHere, description, limitString, Util.BoolToNegativeInt(simulated), !startIn); /* string tempValuesString; if(tracksLimited) tempValuesString = " (" + distanceIntervalFixed + "x" + tracksHere + "R), " + Catalog.GetString("Time") + ": " + Util.TrimDecimals( timeTotal.ToString(), pDN); else tempValuesString = " (" + distanceIntervalFixed + "x" + Util.TrimDecimals( timeTotal.ToString(), pDN) + "T), " + Catalog.GetString("Tracks") + ": " + tracksHere; string myStringPush = Catalog.GetString("Last run") + ": " + RunnerName + ", " + type + tempValuesString + ", " + Catalog.GetString("AVG Speed") + ": " + Util.TrimDecimals( Util.GetSpeed(distanceTotal.ToString(), timeTotal.ToString(), metersSecondsPreferred ) , pDN ) ; */ if(simulated) feedbackMessage = Catalog.GetString(Constants.SimulatedMessage); else feedbackMessage = ""; needShowFeedbackMessage = true; //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); PrepareEventGraphRunIntervalObject = new PrepareEventGraphRunInterval( distanceIntervalFixed, Util.GetLast(intervalTimesString), intervalTimesString, distanceTotal, distancesString, startIn); needUpdateGraphType = eventType.RUNINTERVAL; needUpdateGraph = true; needEndEvent = true; //used for hiding some buttons on eventWindow, and also for updateTimeProgressBar here } }
protected void writeRunInterval(bool tempTable) { int tracksHere = 0; //different than globakl tracks variable string limitString = ""; //if user clicked in finish earlier if (finish) { if (tracksLimited) { tracksHere = Util.GetNumberOfJumps(intervalTimesString, false); limitString = tracksHere.ToString() + "R"; } else { //when we mark that run should finish by time, chronopic thread is probably capturing data //check if it captured more than date limit, and if it has done, delete last(s) run(s) if (limitAsDouble != -1) { bool eventPassed = Util.EventPassedFromMaxTime(intervalTimesString, limitAsDouble); while (eventPassed) { intervalTimesString = Util.DeleteLastSubEvent(intervalTimesString); //run limited by time that first subRun has arrived later than maximum for the whole run, //and DeleteLastSubEvent returns "-" as a mark if (intervalTimesString[0] == '-') { //this dialog can make crash the software because the non-gui part calls it //new DialogMessage(Constants.MessageTypes.WARNING, // Catalog.GetString("Run will not be recorded, 1st track is out of time")); feedbackMessage = Catalog.GetString("Run will not be recorded. Out of time."); needShowFeedbackMessage = true; LogB.Information("Run will not be recorded, 1st track is out of time"); //mark for not having problems with cancelled cancel = true; //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); //end this piece of code return; } else { LogB.Information("Deleted one event out of time"); eventPassed = Util.EventPassedFromMaxTime(intervalTimesString, limitAsDouble); } } } //tracksHere are defined here (and not before) because can change on "while(eventPassed)" before tracksHere = Util.GetNumberOfJumps(intervalTimesString, false); limitString = Util.GetTotalTime(intervalTimesString) + "T"; } } else { if (tracksLimited) { limitString = limitAsDouble.ToString() + "R"; tracksHere = (int)limitAsDouble; } else { limitString = limitAsDouble.ToString() + "T"; string [] myStringFull = intervalTimesString.Split(new char[] { '=' }); tracksHere = myStringFull.Length; } } distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracksHere); timeTotal = Util.GetTotalTime(intervalTimesString); string description = ""; if (type == "MTGUG") { description = "u u u u u u"; //undefined 6 items of questionnaire } if (tempTable) { SqliteRunInterval.Insert(false, Constants.TempRunIntervalTable, "NULL", personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracksHere, description, limitString, Util.BoolToNegativeInt(simulated), !startIn //initialSpeed true if not startIn ); } else { uniqueID = SqliteRunInterval.Insert(false, Constants.RunIntervalTable, "NULL", personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracksHere, description, limitString, Util.BoolToNegativeInt(simulated), !startIn ); //define the created object eventDone = new RunInterval(uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracksHere, description, limitString, Util.BoolToNegativeInt(simulated), !startIn); string tempValuesString = ""; if (tracksLimited) { tempValuesString = " (" + distanceIntervalFixed + "x" + tracksHere + "R), " + Catalog.GetString("Time") + ": " + Util.TrimDecimals(timeTotal.ToString(), pDN); } else { tempValuesString = " (" + distanceIntervalFixed + "x" + Util.TrimDecimals(timeTotal.ToString(), pDN) + "T), " + Catalog.GetString("Tracks") + ": " + tracksHere; } /* * string myStringPush = Catalog.GetString("Last run") + ": " + RunnerName + ", " + * type + tempValuesString + ", " + * Catalog.GetString("AVG Speed") + ": " + Util.TrimDecimals( * Util.GetSpeed(distanceTotal.ToString(), * timeTotal.ToString(), metersSecondsPreferred ) * , pDN ) ; */ if (simulated) { feedbackMessage = Catalog.GetString(Constants.SimulatedMessage); } else { feedbackMessage = ""; } needShowFeedbackMessage = true; //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); PrepareEventGraphRunIntervalObject = new PrepareEventGraphRunInterval( distanceIntervalFixed, Util.GetLast(intervalTimesString), intervalTimesString, distanceTotal, distancesString); needUpdateGraphType = eventType.RUNINTERVAL; needUpdateGraph = true; needEndEvent = true; //used for hiding some buttons on eventWindow, and also for updateTimeProgressBar here } }
protected override void waitEvent() { double timestamp = 0; bool success = false; string equal = ""; //initialize variables intervalTimesString = ""; tracks = 0; bool ok; timerCount = 0; //bool initialized = false; int countForSavingTempTable = 0; lastTc = 0; distanceIntervalFixed = distanceInterval; double timestampDCFlightTimes = -1; //sum of the flight times that happen in small time double timestampDCContactTimes = -1;//sum of the contact times that happen in small time double timestampDCn = 0; //number of flight times do { if(simulated) ok = true; else ok = cp.Read_event(out timestamp, out platformState); if (ok && !cancel && !finish) { if(distanceInterval == -1) distanceIntervalFixed = Util.GetRunIVariableDistancesStringRow(distancesString, (int) tracks); if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) { //has arrived loggedState = States.ON; //show RSA count down only on air needShowCountDown = false; //if we start out, and we arrive to the platform for the first time, //don't record nothing if(runPhase == runPhases.PRE_RUNNING) { if(speedStartArrival) { runPhase = runPhases.PLATFORM_INI_YES_TIME; //run starts initializeTimer(); //timerCount = 0 } else runPhase = runPhases.PLATFORM_INI_NO_TIME; feedbackMessage = ""; needShowFeedbackMessage = true; } else { runPhase = runPhases.RUNNING; //has arrived and not in the "running previous" //if interval run is "unlimited" not limited by tracks, nor time, //then play with the progress bar until finish button is pressed if(simulated) timestamp = simulatedTimeLast * 1000; //conversion to milliseconds if(checkDoubleContactMode != Constants.DoubleContact.NONE) { if(timestamp <= checkDoubleContactTime) { /* when checking double contact first time that timestamp < checkDoubleContactTime and we arrived (it's a flight time) record this time as timestampDCFlightTimes */ timestampDCn ++; timestampDCFlightTimes += timestamp; continue; } else { if(timestampDCn > 0) { if(checkDoubleContactMode == Constants.DoubleContact.FIRST) { /* user want first flight time, then add all DC times*/ timestamp += timestampDCFlightTimes + timestampDCContactTimes; } else if(checkDoubleContactMode == Constants.DoubleContact.LAST) { //user want last flight time, take that // so we don't need to change timestamp. Or we could do (it triggers a warning): // timestamp = timestamp; } else { /* do the avg of all flights and contacts then add to last timestamp */ timestamp += (timestampDCFlightTimes + timestampDCContactTimes) / timestampDCn; } } } } double myRaceTime = lastTc + timestamp/1000.0; if(intervalTimesString.Length > 0) { equal = "="; } intervalTimesString = intervalTimesString + equal + myRaceTime.ToString(); updateTimerCountWithChronopicData(intervalTimesString); tracks ++; //save temp table if needed countForSavingTempTable ++; if(countForSavingTempTable == timesForSavingRepetitive) { writeRunInterval(true); //tempTable countForSavingTempTable = 0; } if(limitAsDouble == -1) { //has arrived, unlimited updateProgressBar= new UpdateProgressBar ( true, //isEvent true, //unlimited: activity mode tracks ); needUpdateEventProgressBar = true; } else { //has arrived, limited if (tracksLimited) { //has arrived, limited by tracks if(tracks >= limitAsDouble) { runPhase = runPhases.PLATFORM_END; //finished writeRunInterval(false); //tempTable = false success = true; } //progressBarEventOrTimePreExecution( updateProgressBar= new UpdateProgressBar ( true, //isEvent true, //tracksLimited: percentageMode tracks ); needUpdateEventProgressBar = true; } else { //has arrived, limited by time updateProgressBar= new UpdateProgressBar ( true, //isEvent false, //timeLimited: activity mode tracks ); needUpdateEventProgressBar = true; } } distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracks); //update graph PrepareEventGraphRunIntervalObject = new PrepareEventGraphRunInterval( distanceIntervalFixed, myRaceTime, intervalTimesString, distanceTotal, distancesString, startIn); needUpdateGraphType = eventType.RUNINTERVAL; needUpdateGraph = true; //put button_finish as sensitive when first jump is done (there's something recordable) if(tracks == 1) needSensitiveButtonFinish = true; } } else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON) { //it's out, was inside (= has abandoned platform) if(runPhase == runPhases.PLATFORM_INI_NO_TIME) { //run starts initializeTimer(); lastTc = 0; feedbackMessage = ""; needShowFeedbackMessage = true; } else if(runPhase == runPhases.PLATFORM_INI_YES_TIME) { lastTc = timestamp/1000.0; feedbackMessage = ""; needShowFeedbackMessage = true; } else { if(checkDoubleContactMode != Constants.DoubleContact.NONE && timestampDCn > 0) timestampDCContactTimes += timestamp; else lastTc = timestamp/1000.0; //RSA double RSAseconds = Util.GetRunIVariableDistancesThisRowIsRSA( distancesString, Convert.ToInt32(tracks)); if(RSAseconds > 0) { RSABellDone = false; needShowCountDown = true; } else { needShowCountDown = false; feedbackMessage = ""; needShowFeedbackMessage = true; } } runPhase = runPhases.RUNNING; //change the automata state loggedState = States.OFF; } } } while ( ! success && ! cancel && ! finish ); if (finish) { runPhase = runPhases.PLATFORM_END; //write(); //write only if there's a run at minimum if(Util.GetNumberOfJumps(intervalTimesString, false) >= 1) { writeRunInterval(false); //tempTable = false totallyFinished = true; } else { //cancel a run if clicked finish before any events done, or ended by time without events cancel = true; } } if(cancel || finish) { //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); totallyCancelled = true; } }
protected override void waitEvent() { double timestamp = 0; bool success = false; string equal = ""; //initialize variables intervalTimesString = ""; tracks = 0; bool ok; timerCount = 0; //bool initialized = false; int countForSavingTempTable = 0; lastTc = 0; distanceIntervalFixed = distanceInterval; double timestampDCFlightTimes = -1; //sum of the flight times that happen in small time double timestampDCContactTimes = -1; //sum of the contact times that happen in small time double timestampDCn = 0; //number of flight times do { if (simulated) { ok = true; } else { ok = cp.Read_event(out timestamp, out platformState); } if (ok && !cancel && !finish) { if (distanceInterval == -1) { distanceIntervalFixed = Util.GetRunIVariableDistancesStringRow(distancesString, (int)tracks); } if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) { //has arrived loggedState = States.ON; //show RSA count down only on air needShowCountDown = false; //if we start out, and we arrive to the platform for the first time, //don't record nothing if (runPhase == runPhases.PRE_RUNNING) { if (speedStartArrival) { runPhase = runPhases.PLATFORM_INI_YES_TIME; //run starts initializeTimer(); //timerCount = 0 } else { runPhase = runPhases.PLATFORM_INI_NO_TIME; } feedbackMessage = ""; needShowFeedbackMessage = true; } else { runPhase = runPhases.RUNNING; //has arrived and not in the "running previous" //if interval run is "unlimited" not limited by tracks, nor time, //then play with the progress bar until finish button is pressed if (simulated) { timestamp = simulatedTimeLast * 1000; //conversion to milliseconds } if (checkDoubleContactMode != Constants.DoubleContact.NONE) { if (timestamp <= checkDoubleContactTime) { /* * when checking double contact * first time that timestamp < checkDoubleContactTime * and we arrived (it's a flight time) * record this time as timestampDCFlightTimes */ timestampDCn++; timestampDCFlightTimes += timestamp; continue; } else { if (timestampDCn > 0) { if (checkDoubleContactMode == Constants.DoubleContact.FIRST) { /* user want first flight time, * then add all DC times*/ timestamp += timestampDCFlightTimes + timestampDCContactTimes; } else if (checkDoubleContactMode == Constants.DoubleContact.LAST) { //user want last flight time, take that timestamp = timestamp; } else /* do the avg of all flights and contacts * then add to last timestamp */ { timestamp += (timestampDCFlightTimes + timestampDCContactTimes) / timestampDCn; } } } } double myRaceTime = lastTc + timestamp / 1000.0; if (intervalTimesString.Length > 0) { equal = "="; } intervalTimesString = intervalTimesString + equal + myRaceTime.ToString(); updateTimerCountWithChronopicData(intervalTimesString); tracks++; //save temp table if needed countForSavingTempTable++; if (countForSavingTempTable == timesForSavingRepetitive) { writeRunInterval(true); //tempTable countForSavingTempTable = 0; } if (limitAsDouble == -1) { //has arrived, unlimited updateProgressBar = new UpdateProgressBar( true, //isEvent true, //unlimited: activity mode tracks ); needUpdateEventProgressBar = true; } else { //has arrived, limited if (tracksLimited) { //has arrived, limited by tracks if (tracks >= limitAsDouble) { runPhase = runPhases.PLATFORM_END; //finished writeRunInterval(false); //tempTable = false success = true; } //progressBarEventOrTimePreExecution( updateProgressBar = new UpdateProgressBar( true, //isEvent true, //tracksLimited: percentageMode tracks ); needUpdateEventProgressBar = true; } else { //has arrived, limited by time updateProgressBar = new UpdateProgressBar( true, //isEvent false, //timeLimited: activity mode tracks ); needUpdateEventProgressBar = true; } } distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracks); //update graph PrepareEventGraphRunIntervalObject = new PrepareEventGraphRunInterval( distanceIntervalFixed, myRaceTime, intervalTimesString, distanceTotal, distancesString); needUpdateGraphType = eventType.RUNINTERVAL; needUpdateGraph = true; //put button_finish as sensitive when first jump is done (there's something recordable) if (tracks == 1) { needSensitiveButtonFinish = true; } } } else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON) { //it's out, was inside (= has abandoned platform) if (runPhase == runPhases.PLATFORM_INI_NO_TIME) { //run starts initializeTimer(); lastTc = 0; feedbackMessage = ""; needShowFeedbackMessage = true; } else if (runPhase == runPhases.PLATFORM_INI_YES_TIME) { lastTc = timestamp / 1000.0; feedbackMessage = ""; needShowFeedbackMessage = true; } else { if (checkDoubleContactMode != Constants.DoubleContact.NONE && timestampDCn > 0) { timestampDCContactTimes += timestamp; } else { lastTc = timestamp / 1000.0; } //RSA double RSAseconds = Util.GetRunIVariableDistancesThisRowIsRSA( distancesString, Convert.ToInt32(tracks)); if (RSAseconds > 0) { RSABellDone = false; needShowCountDown = true; } else { needShowCountDown = false; feedbackMessage = ""; needShowFeedbackMessage = true; } } runPhase = runPhases.RUNNING; //change the automata state loggedState = States.OFF; } } } while (!success && !cancel && !finish); if (finish) { runPhase = runPhases.PLATFORM_END; //write(); //write only if there's a run at minimum if (Util.GetNumberOfJumps(intervalTimesString, false) >= 1) { writeRunInterval(false); //tempTable = false totallyFinished = true; } else { //cancel a run if clicked finish before any events done, or ended by time without events cancel = true; } } if (cancel || finish) { //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); totallyCancelled = true; } }