private static IEnumerable <double> GetTimes(ICurve1 curve, double tinc) { if (curve is MultiCurve1) { TimeList times = new TimeList(); MultiCurve1 multi = (MultiCurve1)curve; for (int i = 0; i < multi.NumSegments; i++) { double tmin = multi.GetTMin(i); double tmax = multi.GetTMax(i); double t = tmin; while (t < tmax) { times.Add(t); t += tinc; } times.Add(tmax); } return(times.GetTimes()); } else { TimeList times = new TimeList(); double tmin = curve.TMin; double tmax = curve.TMax; double t = tmin; while (t < tmax) { times.Add(t); t += tinc; } times.Add(tmax); return(times.GetTimes()); } }
public void TimeList_TimeUpdate() { DateTime now = new DateTime(2000, 3, 3, 3, 3, 3); TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(now); list.Add(11, now); Assert.AreEqual(list.SecondsAt(0), 0); list.Add(11, now.AddSeconds(5)); Assert.AreEqual(list.SecondsAt(0), 5); list.Add(11, now.AddSeconds(6)); Assert.AreEqual(list.SecondsAt(0), 6); list.Add(11, now.AddSeconds(9)); Assert.AreEqual(list.SecondsAt(0), 9); list.Add(22, now.AddSeconds(15)); Assert.AreEqual(list.SecondsAt(0), 15); Assert.AreEqual(list.SecondsAt(1), 0); list.Add(22, now.AddSeconds(16)); Assert.AreEqual(list.SecondsAt(0), 15); Assert.AreEqual(list.SecondsAt(1), 1); list.Add(22, now.AddSeconds(20)); Assert.AreEqual(list.SecondsAt(0), 15); Assert.AreEqual(list.SecondsAt(1), 5); list.Add(33, now.AddSeconds(26)); Assert.AreEqual(list.SecondsAt(0), 15); Assert.AreEqual(list.SecondsAt(1), 11); Assert.AreEqual(list.SecondsAt(2), 0); }
public void TimeList_GetSecondsList() { DateTime now = new DateTime(2000, 3, 3, 3, 3, 3); TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(now); list.Add(11, now.AddSeconds(5)); list.Add(22, now.AddSeconds(6)); list.Add(33, now.AddSeconds(11)); List <long> seconds = list.GetSecondsList(now.AddSeconds(17)); Assert.AreEqual(seconds[0], 1); Assert.AreEqual(seconds[1], 5); Assert.AreEqual(seconds[2], 6); }
public void TimeList_AddBoolean() { TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(); Assert.IsTrue(list.Add(11)); Assert.IsFalse(list.Add(11)); Assert.IsTrue(list.Add(22)); Assert.IsFalse(list.Add(22)); Assert.IsFalse(list.Add(22)); Assert.IsTrue(list.Add(33)); Assert.IsTrue(list.Add(44)); Assert.IsTrue(list.Add(55)); Assert.IsFalse(list.Add(55)); }
public void TimeList_CorrectCount() { TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(); Assert.AreEqual(list.Count, 0); list.Add(0); Assert.AreEqual(list.Count, 1); list.Add(0); Assert.AreEqual(list.Count, 1); list.Add(1); Assert.AreEqual(list.Count, 2); list.Add(1); Assert.AreEqual(list.Count, 2); list.Add(2); Assert.AreEqual(list.Count, 3); }
private TimeList<Complex[]> CalcSingle(Ode ode, Complex[] y0, double t_max) { TimeList<Complex[]> solve = new TimeList<Complex[]> (); Complex[] y = y0; for(double t = 0; t < t_max; t += _step.Stepsize) { y = _step.NextStep (ode, t, y); solve.Add (t, y); } return solve; }
public void TimeList_TimeUpdateStart_NotFromZero() { DateTime now = new DateTime(2000, 3, 3, 3, 3, 3); TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(now); list.Add(11, now.AddSeconds(10)); Assert.AreEqual(list.SecondsAt(0), 0); list.Add(22, now.AddSeconds(14)); Assert.AreEqual(list.SecondsAt(0), 4); Assert.AreEqual(list.SecondsAt(1), 0); list.Add(22, now.AddSeconds(15)); Assert.AreEqual(list.SecondsAt(0), 4); Assert.AreEqual(list.SecondsAt(1), 1); list.Add(33, now.AddSeconds(17)); Assert.AreEqual(list.SecondsAt(0), 4); Assert.AreEqual(list.SecondsAt(1), 3); Assert.AreEqual(list.SecondsAt(2), 0); }
private static IEnumerable <double> GetTimes(ICurve2 curve, double tinc) { if (curve is MultiCurve2) { TimeList times = new TimeList(); MultiCurve2 multi = (MultiCurve2)curve; for (int i = 0; i < multi.NumSegments; i++) { double tmin = multi.GetTMin(i); double tmax = multi.GetTMax(i); double t = tmin; while (t < tmax) { times.Add(t); t += tinc; } times.Add(tmax); } return(times.GetTimes()); } else if (curve is DisplacedCurve2) { DisplacedCurve2 displaced = (DisplacedCurve2)curve; return(MathUtils.ConcatSorted(GetTimes(displaced.Curve, tinc), GetTimes(displaced.Displacement, tinc))); } else { TimeList times = new TimeList(); double tmin = curve.TMin; double tmax = curve.TMax; double t = tmin; while (t < tmax) { times.Add(t); t += tinc; } times.Add(tmax); return(times.GetTimes()); } }
public void TimeList_AdjacentDifferent() { TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(); Random r = new Random(); for (int i = 0; i < 10000; i++) { int n = r.Next(1, 10); list.Add(n); } Assert.IsTrue(list.ValidateAdjacentDifferent()); }
/// <summary> /// Eager load data from database /// </summary> private void GetTimeKeepingList() { try { Logger.Info("GetTimeKeepingList Method"); var timeList = DatabaseHelper.GetList <Timekeeping>(); TimeList.Clear(); foreach (var item in timeList) { TimeList.Add(item); } } catch (Exception ex) { Logger.Error(ex, "Exception occured from getting timekeeping list"); } }
private void SplitDataIntoDateAndTime(List <string> receiveDataList) { try { for (var i = 1; i < receiveDataList.Count - 1; i++) { var dateTime = receiveDataList[i].Split(','); DateList.Add(dateTime[0]); TimeList.Add(dateTime[1]); } } catch (Exception e) { Console.WriteLine(e + "Date Cannot be split into Date and Time"); throw; } }
private TimeList GetLevelAwardTimeList(XmlNode levelInfoNode) { TimeList timelist = new TimeList(); var awardList = levelInfoNode.ChildNodes; for (int awardId = 0; awardId < awardList.Count; ++awardId) { if (awardList[awardId].Attributes["id"].Value != awardId.ToString()) { throw new Exception("time level id not correspond necessary order"); } timelist.Add( new MyTime( Convert.ToInt32(awardList[awardId].Attributes["minutes"].Value), Convert.ToInt32(awardList[awardId].Attributes["seconds"].Value) ) ); } return(timelist); }
private async Task GetAvailableHoursForDateAndDirection() { await Task.Run(async() => { if (SelectedDate != null && Direction != null && Direction != "") { CancellationToken token = new CancellationToken(); List <ReservationResponse> reservations = await _reservationService.GetReservationsForDateAndDirections(pathDateAndDirections, Direction, SelectedDate, token); _userReservationDate = _selectedDate.Date.ToString(); List <string> allHoursList = _reservationService.GetAllHours(_direction); DateTime newSelectedDate = new DateTime(); UseTempDateTime(newSelectedDate); //ParseHourArrays(allHoursList); //RemoveReservedHours(allHoursList, reservations); Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { TimeList.Clear(); allHoursList.ForEach(time => TimeList.Add(time)); IsTimeListEnabled = true; }); } }); }
public void TimeList_CorrectTimeSimple() { DateTime now = new DateTime(2000, 3, 3, 3, 3, 3); TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(now); list.Add(11, now); Assert.AreEqual(list.SecondsAt(0), 0); list.Add(22, now.AddSeconds(3)); Assert.AreEqual(list.SecondsAt(0), 3); Assert.AreEqual(list.SecondsAt(1), 0); list.Add(33, now.AddSeconds(7)); Assert.AreEqual(list.SecondsAt(0), 3); Assert.AreEqual(list.SecondsAt(1), 4); Assert.AreEqual(list.SecondsAt(2), 0); list.Add(44, now.AddSeconds(17)); Assert.AreEqual(list.SecondsAt(0), 3); Assert.AreEqual(list.SecondsAt(1), 4); Assert.AreEqual(list.SecondsAt(2), 10); Assert.AreEqual(list.SecondsAt(3), 0); list.Add(55, now.AddSeconds(18)); Assert.AreEqual(list.SecondsAt(0), 3); Assert.AreEqual(list.SecondsAt(1), 4); Assert.AreEqual(list.SecondsAt(2), 10); Assert.AreEqual(list.SecondsAt(3), 1); Assert.AreEqual(list.SecondsAt(4), 0); list.Add(66, now.AddSeconds(21)); Assert.AreEqual(list.SecondsAt(0), 3); Assert.AreEqual(list.SecondsAt(1), 4); Assert.AreEqual(list.SecondsAt(2), 10); Assert.AreEqual(list.SecondsAt(3), 1); Assert.AreEqual(list.SecondsAt(4), 3); Assert.AreEqual(list.SecondsAt(5), 0); Assert.AreEqual(list.Count, 6); }
private static void ExtractNERTags(CoreDocument coredoc, Lucene.Net.Documents.Document document) { //I have no clue as to why NER-tagged messages are stored like that. I guess there is some deep idea behind copying the same info over and over again (or, most likely, this is because some documents have more than one sentence. even tho its stil really stupid) if (coredoc != null) { List nerList = coredoc.entityMentions(); if (nerList.size() > 0) { for (int j = 0; j < nerList.size(); j++) { CoreEntityMention em = (CoreEntityMention)nerList.get(j); //Does this need to be a switch case? if (em.entityType() == "DATE") { var datekey = document.GetField("id").GetInt32Value().Value; if (!DateList.ContainsKey(datekey)) { DateList.Add(datekey, em.text()); } else { DateList.TryUpdate(datekey, DateList[datekey] + ", " + em.text()); } } if (em.entityType() == "TIME") { var timekey = document.GetField("id").GetInt32Value().Value; if (!TimeList.ContainsKey(timekey)) { TimeList.Add(timekey, em.text()); } else { TimeList.TryUpdate(timekey, TimeList[timekey] + ", " + em.text()); } } if (em.entityType() == "LOCATION") { var lockey = document.GetField("id").GetInt32Value().Value; if (!LocList.ContainsKey(lockey)) { LocList.Add(lockey, em.text()); } else { LocList.TryUpdate(lockey, LocList[lockey] + ", " + em.text()); } } if (em.entityType() == "ORGANIZATION") { var orgkey = document.GetField("id").GetInt32Value().Value; if (!OrgList.ContainsKey(orgkey)) { OrgList.Add(orgkey, em.text()); } else { OrgList.TryUpdate(orgkey, OrgList[orgkey] + ", " + em.text()); } } if (em.entityType() == "URL") { var urlkey = document.GetField("id").GetInt32Value().Value; if (!URLList.ContainsKey(urlkey)) { URLList.Add(urlkey, em.text()); } else { URLList.TryUpdate(urlkey, OrgList[urlkey] + ", " + em.text()); } } } } } }
private TimeList<Complex[]> CalcThreaded(Ode ode, Complex[] y0, double t_max) { int ptr = 0; int N = ode.N; double t = 0; TimeList<Complex[]> solve = new TimeList<Complex[]> (); Complex[] y = new Complex[N]; Complex[] lastY = y0; for (int thread = 0; thread < _threadCount; thread++) { ThreadPool.QueueUserWorkItem (new WaitCallback (delegate(object data) { int c; while (t < t_max) { while ((c = Interlocked.Increment(ref ptr)) <= N) { y[c - 1] = _step.NextStepComponent(c - 1, ode, t, lastY); } lock(syncLock) { ((AutoResetEvent)data).Set(); Monitor.Wait(syncLock); } } }), _resets [thread]); } for (t = 0; t < t_max; t += _step.Stepsize) { WaitHandle.WaitAll (_resets); lock(syncLock) { ptr = 0; solve.Add(t, y); lastY = y; y = new Complex[N]; Monitor.PulseAll (syncLock); } } return solve; }
public void TimeList_CorrectValues() { TimeList <Nullable <int> > list = new TimeList <Nullable <int> >(); list.Add(11); list.Add(11); list.Add(22); list.Add(22); list.Add(22); list.Add(33); list.Add(44); list.Add(55); list.Add(55); list.Add(55); list.Add(66); list.Add(66); list.Add(11); Assert.AreEqual(list[0], 11); Assert.AreEqual(list[1], 22); Assert.AreEqual(list[2], 33); Assert.AreEqual(list[3], 44); Assert.AreEqual(list[4], 55); Assert.AreEqual(list[5], 66); Assert.AreEqual(list[6], 11); }