/// <summary> /// Truncates the indicated time section to truncate. Useful when trying to remove the millisecond part of a date time. /// </summary> /// <param name="dateTime">The <see cref="DateTime"/> to truncate.</param> /// <param name="timeSectionToTruncate">A <see cref="TimeSection"/> that defines which component of the DateTime will be truncated.</param> /// <returns>A truncated <see cref="DateTime"/>.</returns> public static System.DateTime Truncate(this System.DateTime dateTime, TimeSection timeSectionToTruncate) { long ticks; switch (timeSectionToTruncate) { case TimeSection.Millisecond: ticks = TimeSpan.TicksPerSecond; break; case TimeSection.Second: ticks = TimeSpan.TicksPerMinute; break; case TimeSection.Minute: ticks = TimeSpan.TicksPerHour; break; case TimeSection.Hour: ticks = TimeSpan.TicksPerDay; break; default: throw new ArgumentOutOfRangeException("timeSectionToTruncate", "Invalid TimeSection value."); } return(dateTime.AddTicks(-(dateTime.Ticks % ticks))); }
/// <summary> /// 填入时间段 /// </summary> /// <param name="week"></param> /// <param name="xmlPath"></param> private static void LoadTimeSections(int week, string xmlPath) { XDocument day = XDocument.Load(xmlPath); foreach (var TimeSection in day.Elements()) { foreach (var Section in TimeSection.Elements()) { TimeSection timeSection = new TimeSection { beginTime = Convert.ToDateTime(Section.Attribute("BeginTime").Value), name = Section.Attribute("Name").Value, }; if (Section.Attribute("Class").Value != "") { timeSection.Class = int.Parse(Section.Attribute("Class").Value); timeSection.name = classSection[week, timeSection.Class].Name; } else { timeSection.Class = -1; } timeSections[week].Add(timeSection); } } }
private void OnStateChangeHandler(GameState prev, GameState current) { if (current == GameState.RepeatLast) { inPause = 1; } else if (current == GameState.RepeatNewVaccine3) { inPause = 2; } else if (current == GameState.None) { return; } else if (current == GameState.Restart) { //Reset (); ResetScene(); //GameController.Instance.CurrentState = GameState.None; //data.Restart (); return; } else if (current == GameState.Init) { inPause = 0; Lock = false; } if (_sectionWaitCoroutine != null) { StopCoroutine(_sectionWaitCoroutine); } TimeSection ts = FindTimeSection(current); _sectionWaitCoroutine = WaitForSectionEnd(ts); StartCoroutine(_sectionWaitCoroutine); if (current == GameState.Approach) { Invoke("Dragon_idle", 1); } }
// private IEnumerator WaitForSectionEnd(TimeSection timeSection) { // Wait for min number of secods given by the timeSection yield return(new WaitForSeconds(timeSection.duration)); // Check if narration controller is playing yield return(new WaitUntil(() => !narrationController.IsPlaying)); // Check if paused if (timeSection.state == timeSection.fallbackState || timeSection.fallbackState == GameState.None) { //yield return new WaitUntil (() => (!Pause && !Lock)); yield return(new WaitUntil(() => (!Pause))); } //print ("END: " + GameController.Instance.CurrentState); if ((GameController.Instance.CurrentState == GameState.TransferSoundsFading) && Repetitions > 1) { //print (GameController.Instance.CurrentState + " : vaccineID " + vaccineID + " Repetitions " + Repetitions); if (vaccineID == 0) { if (Repetitions == 2) { GameController.Instance.CurrentState = GameState.PausaCorta; } else { GameController.Instance.CurrentState = GameState.Repeat; } } else if (vaccineID == 1) { if (Repetitions == 2) { GameController.Instance.CurrentState = GameState.Medal; } else { GameController.Instance.CurrentState = GameState.RepeatLast; } } else if (vaccineID == 2) { if (Repetitions == 2) { GameController.Instance.CurrentState = GameState.Medal; } else { GameController.Instance.CurrentState = GameState.RepeatNewVaccine; } } else if (vaccineID == 3) { if (Repetitions == 3) { GameController.Instance.CurrentState = GameState.Medal; } else { GameController.Instance.CurrentState = GameState.RepeatNewVaccine2; } } else if (vaccineID == 4) { if (Repetitions == 4) { GameController.Instance.CurrentState = GameState.Medal; } else { GameController.Instance.CurrentState = GameState.RepeatNewVaccine3; } } else if (vaccineID == 5) { GameController.Instance.CurrentState = GameState.NewVaccineDone3; } else if (vaccineID == 6) { if (Repetitions == 5) { GameController.Instance.CurrentState = GameState.Medal; } else { GameController.Instance.CurrentState = GameState.NewVaccineDone4; } } else if (vaccineID == 7) { if (Repetitions == 6) { GameController.Instance.CurrentState = GameState.Medal; } } vaccineID++; } else { GameController.Instance.CurrentState = Pause ? timeSection.fallbackState : timeSection.nextState; } }
/// <summary> /// 添加一个时间段限制规则 /// </summary> /// <param name="timesection"></param> public void AddTimeSection(TimeSection timesection) { timeSectionLimit.Add(timesection); }
public async Task <HeartBeatData> GetLasterDataAsync(int recentMinutes, Application application) { int pollSeconds = 20; int length = recentMinutes * 60 / pollSeconds; //确定多少区段 TimeSection[] times = new TimeSection[length]; for (int i = length - 1; i >= 0; i--) { if (i == length - 1) { TimeSection firsSection = new TimeSection { EndTime = DateTime.Now }; firsSection.StartTime = firsSection.EndTime.AddSeconds(-1 * pollSeconds); times[i] = firsSection; } else { TimeSection timeSection = new TimeSection(); timeSection.EndTime = times[i + 1].StartTime; timeSection.StartTime = timeSection.EndTime.AddSeconds(-1 * pollSeconds); times[i] = timeSection; } } StringBuilder sql = new StringBuilder(); sql.Append($" SELECT logged FROM `log` WHERE LEVEL='Info' AND message='心跳检测' AND Application='{application.GetDescription().ToString()}' AND "); List <string> timeList = new List <string>(); for (int i = 0; i < times.Length; i++) { timeList.Add($" (logged >'{times[i].StartTime}' AND logged <= '{times[i].EndTime}') "); } string skipsql = timeList.Join(" OR "); sql.Append(" ( " + skipsql + " ) "); sql.Append(" ORDER BY logged DESC "); var loggedlist = Connection.Query <DateTime>(sql.ToString(), null).ToList(); HeartBeatData data = new HeartBeatData(); data.XData = new string[times.Length + 1]; data.YData = new decimal[times.Length + 1]; for (int i = 0; i < times.Length; i++) { var item = times[i]; var first = loggedlist.FirstOrDefault(m => m > item.StartTime && m <= item.EndTime); data.XData[i] = item.StartTime.ToString("HH:mm:ss"); if (first != null) { if ((i + 1) % 2 == 1) { data.YData[i] = 1; } else { data.YData[i] = -1; } } else { data.YData[i] = 0; } } data.XData[times.Length] = times.Last().EndTime.ToString("HH:mm:ss"); data.YData[times.Length] = data.YData[times.Length - 1] * -1; return(data); }