public static string GetInterval(Interval?interval = null) { switch (interval) { case Interval.OneMinute: return("1m"); case Interval.TwoMinutes: return("2m"); case Interval.FiveMinutes: return("5m"); case Interval.FifteenMinutes: return("15m"); case Interval.ThirtyMinutes: return("30m"); case Interval.SixtyMinutes: return("60m"); case Interval.NinetyMinutes: return("90m"); case Interval.OneHour: return("1h"); case Interval.OneDay: return("1d"); case Interval.FiveDays: return("5d"); case Interval.OneWeek: return("1wk"); case Interval.OneMonth: return("1mo"); case Interval.ThreeMonths: return("3mo"); default: return("1d"); } }
public static SurfacePoint[] _GetDivby2dPoints(this Surface srf, int divby, Interval?uDomain = null, Interval?vDomain = null) { if (!uDomain.HasValue) { uDomain = srf.Domain(0); } if (!vDomain.HasValue) { vDomain = srf.Domain(1); } var udom = uDomain.Value; var vdom = vDomain.Value; if (divby == 0) { return(new[] { new SurfacePoint(udom.Mid, vdom.Mid) }); } var res = new List <SurfacePoint>(); for (int iu = 0; iu <= divby; iu++) { for (int iv = 0; iv <= divby; iv++) { var u = udom.T0 + udom.Length * iu / divby; var v = vdom.T0 + vdom.Length * iv / divby; res.Add(new SurfacePoint(u, v)); } } return(res.ToArray()); }
internal void AddFeature(uint id, Envelope geometry, Interval?zRange, Interval?mRange) { NumRecords++; XRange = XRange.ExpandedByInterval(Interval.Create(geometry.MinX, geometry.MaxX)); YRange = YRange.ExpandedByInterval(Interval.Create(geometry.MinY, geometry.MaxY)); ZRange = ZRange.ExpandedByInterval(zRange ?? Interval.Create()); MRange = MRange.ExpandedByInterval(mRange ?? Interval.Create()); }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="fid">The feature's id</param> /// <param name="geometry">The features geometry</param> /// <param name="zRange">An optional value for the z-Range</param> /// <param name="mRange">An optional value for the m-Range</param> #pragma warning disable 3001 public SbnTreeRebuildRequiredEventArgs(uint fid, Envelope geometry, Interval?zRange, Interval?mRange) #pragma warning restore 3001 { Fid = fid; Geometry = geometry; ZRange = zRange; MRange = mRange; }
private static string SerializeInterval(Interval?value) { if (value == null) { return(null); } return(SerializeInterval(value.Value)); }
// copy on write so we can cache a..Start intervals and sets of that public virtual void AddImpl(Interval addition) { //[email protected]("add "+addition+" to "+intervals.toString()); if (addition.IsEmpty) { return; } // find position in list // Use iterators as we modify list in place //for ( ListIterator iter = intervals.listIterator(); iter.hasNext(); ) for (int i = 0; i < intervals.Count; i++) { Interval r = intervals[i]; if (addition.Equals(r)) { return; } Interval?union = addition.Union(r); if (union != null) { // next to each other, make a single larger interval intervals[i] = union.Value; // make sure we didn't just create an interval that // should be merged with next interval in list if (i < intervals.Count - 1) { i++; Interval next = intervals[i]; Interval?union2 = union.Value.Union(next); if (union2 != null) { // if we bump up against or overlap next, merge intervals.RemoveAt(i); i--; intervals[i] = union2.Value; } } return; } if (addition.Start < r.Start) { // insert before r //iter.previous(); //iter.add( addition ); intervals.Insert(i, addition); return; } // if disjoint and after r, a future iteration will handle it } // ok, must be after last interval (and disjoint from last interval) // just add it intervals.Add(addition); }
public string GetTimeSeriesRaw(string ric, string startDate, string endDate, Interval?interval = Interval.daily, IEnumerable <TimeSeriesField> fields = null, int?count = null, Calendar?calendar = null, Corax?corax = null) { string[] formats = { "yyyy-MM-dd", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm:sszzz" }; DateTime expectedDate; if (!DateTime.TryParseExact(startDate, formats, null, DateTimeStyles.None, out expectedDate)) { EikonException error = new EikonException(HttpStatusCode.BadRequest, "Unsupported start Date Format. (yyyy-MM-dd, yyyy-MM-ddTHH:mm:SS, or yyyy-MM-ddTHH:mm:SSzzz"); _logger?.LogError(error.Message); error.Source = "TimeSeries"; throw (error); } if (!DateTime.TryParseExact(endDate, formats, null, DateTimeStyles.None, out expectedDate)) { EikonException error = new EikonException(HttpStatusCode.BadRequest, "Unsupported end Date Format. (yyyy-MM-dd, yyyy-MM-ddTHH:mm:SS, or yyyy-MM-ddTHH:mm:SSzzz"); _logger?.LogError(error.Message); error.Source = "TimeSeries"; throw (error); } if (fields != null) { if (fields.Contains(TimeSeriesField.TIMESTAMP) == false) { List <TimeSeriesField> temp = fields.ToList(); temp.Insert(0, TimeSeriesField.TIMESTAMP); fields = temp; } } TimeSeriesRequest request = new TimeSeriesRequest { rics = new List <string> { ric }, fields = fields?.ToList(), startdate = startDate, enddate = endDate, interval = interval, calendar = calendar, corax = corax, count = count }; var response = SerializeAndSendRequest <TimeSeriesRequest>(request); return(response); }
public Frame <int, string> GetTimeSeries(IEnumerable <string> rics, string startDate, string endDate, Interval?interval = Interval.daily, IEnumerable <TimeSeriesField> fields = null, int?count = null, Calendar?calendar = null, Corax?corax = null) { return(TimeSeries.GetTimeSeries(rics, startDate, endDate, interval, fields, count, calendar, corax)); }
public Interval?Overlap(Interval other) { Interval?intersection = Intersection(other); if (intersection == null || intersection.Value.IsEmpty) { return(null); } return(intersection); }
private void LookForTheSixth() { if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.MajorSixth))) { fSixthInterval = Interval.MajorSixth; } else { fSixthInterval = null; } }
private void ExtendCurrentItem(Interval?timeRange) { if (!timeRange.HasValue || !CurrentItem.TimeRange.HasValue) { return; } CurrentItem.TimeRange = new Interval( Instant.Min(CurrentItem.TimeRange.Value.Start, timeRange.Value.Start), Instant.Max(CurrentItem.TimeRange.Value.End, timeRange.Value.End)); }
private void LookForTheFourth() { if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.PerfectFourth))) { fFourthInterval = Interval.PerfectFourth; } else { fFourthInterval = null; } }
private void LookForTheNinth() { if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.MajorSecond))) { fNinthInterval = Interval.MajorSecond; } else if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.MinorSecond))) { fNinthInterval = Interval.MinorSecond; } else { fNinthInterval = null; } }
private void LookForTheThird() { if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.MajorThird))) { fThirdInterval = Interval.MajorThird; } else if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.MinorThird))) { fThirdInterval = Interval.MinorThird; } else { fThirdInterval = null; } }
public async Task <IEnumerable <ConsolidatedSales> > GetSales(Interval?per, int?value) { var sales = new List <Sales>(); if (per.HasValue) { var dateRange = SetDateInterval(per.Value, value.Value); sales = await _salesRepository.GetByInterval(dateRange.start, dateRange.end); } else { sales = await _salesRepository.GetAll(); } return(ConsolidateSales(sales)); }
private static Interval?GoldenRatio(Interval?ab, double e, Func <double, double> function) { Console.WriteLine("Golden Ratio started."); var a = ab !.Left; var b = ab !.Right; var c = b - K * (b - a); var d = a + K * (b - a); var fc = function(c); var fd = function(d); var i = 0; Console.WriteLine("\ta\tc\td\tb"); //\tf(a)\tf(c)\tf(d)\tf(b) while (b - a > e) { Console.WriteLine($"i: {i}\t{a:0.000}\t{c:0.000}\t{d:0.000}\t{b:0.000}"); //\t{function(a):0.000}\t{fc:0.000}\t{fd:0.000}\t{function(b):0.000} if (fc < fd) { b = d; d = c; c = b - K * (b - a); fd = fc; fc = function(c); } else { a = c; c = d; d = a + K * (b - a); fc = fd; fd = function(d); } i++; } var interval = new Interval { Left = a, Right = b }; Console.WriteLine($"Golden Ratio concluded after {i} iterations."); Console.WriteLine($"Resulting interval: {interval}"); Console.WriteLine(); return(interval); }
/// <summary> /// Method to insert a new feature to the tree /// </summary> /// <param name="fid">The feature's id</param> /// <param name="envelope">The feature's geometry</param> /// <param name="zRange">The z-ordinate extent</param> /// <param name="mRange">The m-ordinate extent</param> #pragma warning disable 3001 public void Insert(uint fid, Envelope envelope, Interval?zRange = null, Interval?mRange = null) #pragma warning restore 3001 { // lock the tree Monitor.Enter(_syncRoot); // Convert to an sbnfeature var sbnFeature = ToSbnFeature(fid, envelope); var inserted = false; // Has the tree already been built? if (Built) { // Does the feature fit into the current tree, signal that // the tree needs to be recreated in order to function properly. if (!_header.Extent.Contains(envelope)) { OnRebuildRequired(new SbnTreeRebuildRequiredEventArgs(fid, envelope, zRange, mRange)); Monitor.Exit(_syncRoot); return; } // Compute number of features in tree var featureCount = FeatureCount + 1; // Does the new number of features require more levels? if (GetNumberOfLevels(featureCount) != NumLevels) { // This can be done inplace. RebuildTree(featureCount, sbnFeature); inserted = true; } } //Insert the feature if (!inserted) { Insert(sbnFeature); } // Update the header metrics _header.AddFeature(fid, envelope, zRange ?? Interval.Create(), mRange ?? Interval.Create()); // unlock the tree Monitor.Exit(_syncRoot); }
public IntervalSet(IList <Interval> intervals) { List <Interval> orderedIntervals = intervals.OrderBy(i => i.Start).ToList(); for (int i = 0; i < orderedIntervals.Count - 1; i++) { Interval?union = orderedIntervals[i].Union(orderedIntervals[i + 1]); if (union != null) { orderedIntervals[i] = union.Value; orderedIntervals.RemoveAt(i + 1); i--; // repeat this index } } this.intervals = orderedIntervals; }
public static IReadOnlyList <Interval> Group(IReadOnlyList <Interval> input) { var intervalPool = SharedPools.Default <List <Interval> >(); var sortedIntervals = intervalPool.AllocateAndClear(); sortedIntervals.AddRange(input); sortedIntervals.Sort(); var intervalList = intervalPool.AllocateAndClear(); Interval?accumulator = null; for (var i = 0; i < sortedIntervals.Count; i++) { var interval = sortedIntervals[i]; if (accumulator is null) { accumulator = interval; continue; } var joins = Join(accumulator.Value, interval); switch (joins.Count) { case 2: intervalList.Add(joins[0]); accumulator = joins[1]; break; case 1: accumulator = joins[0]; break; } } if (accumulator != null) { intervalList.Add(accumulator.Value); } intervalPool.ClearAndFree(sortedIntervals); return(intervalList); }
/** Return the interval with elements from this not in other; * other must not be totally enclosed (properly contained) * within this, which would result in two disjoint intervals * instead of the single one returned by this method. */ public Interval?DifferenceNotProperlyContained(Interval other) { Interval?diff = null; // other.a to left of this.a (or same) if (other.StartsBeforeNonDisjoint(this)) { diff = Interval.FromBounds(Math.Max(this.a, other.b + 1), this.b); } // other.a to right of this.a else if (other.StartsAfterNonDisjoint(this)) { diff = Interval.FromBounds(this.a, other.a - 1); } return(diff); }
public string GetTimeSeriesRaw(string ric, DateTime startDate, DateTime endDate, Interval?interval = Interval.daily, IEnumerable <TimeSeriesField> fields = null, int?count = null, Calendar?calendar = null, Corax?corax = null) { if (fields != null) { if (fields.Contains(TimeSeriesField.TIMESTAMP) == false) { List <TimeSeriesField> temp = fields.ToList(); temp.Insert(0, TimeSeriesField.TIMESTAMP); fields = temp; } } TimeSeriesRequest request = new TimeSeriesRequest { rics = new List <string> { ric }, fields = fields?.ToList(), startdate = startDate.Kind == DateTimeKind.Utc ? startDate.ToString("yyyy-MM-ddTHH:mm:ssZ") : startDate.ToString("yyyy-MM-ddTHH:mm:sszzz"), enddate = endDate.Kind == DateTimeKind.Utc ? endDate.ToString("yyyy-MM-ddTHH:mm:ssZ") : endDate.ToString("yyyy-MM-ddTHH:mm:sszzz"), interval = interval, calendar = calendar, corax = corax, count = count }; var response = SerializeAndSendRequest <TimeSeriesRequest>(request); return(response); //if (response == null) return null; //return JsonConvert.DeserializeObject<TimeSeriesResponse>(response, new JsonSerializerSettings //{ // Error = HandleDeserializationError //}); }
private void LookForTheFifth() { if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.PerfectFifth))) { fFifthInterval = Interval.PerfectFifth; } else if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.DiminishedFifth))) { fFifthInterval = Interval.DiminishedFifth; } else if (this.FindNote(((NoteValue)fTonicNote).Shift(Interval.AugmentedFifth))) { fFifthInterval = Interval.AugmentedFifth; } else { fFifthInterval = null; } }
public Frame <int, string> GetTimeSeries(string ric, string startDate, string endDate, Interval?interval = Interval.daily, IEnumerable <TimeSeriesField> fields = null, int?count = null, Calendar?calendar = null, Corax?corax = null) { var response = GetTimeSeriesRaw(ric, startDate, endDate, interval, fields, count, calendar, corax); if (response == null) { return(Frame.CreateEmpty <int, string>()); } return(CreateFrame(JsonConvert.DeserializeObject <TimeSeriesResponse>(response, new JsonSerializerSettings { Error = HandleDeserializationError }))); }
public static async Task <Video> Load(StorageFile source) { var dateEncoded = await source.GetProperty <DateTimeOffset?>(StorageFileProperty.DateEncoded); var encodedDuration = await source.GetProperty <ulong?>(StorageFileProperty.Duration); Interval?recordedInterval = null; if (dateEncoded.HasValue && encodedDuration.HasValue) { var duration = ToTimeSpan(encodedDuration.Value); var end = dateEncoded.Value.Add(duration); recordedInterval = new Interval(dateEncoded.Value.ToInstant(), end.ToInstant()); } return(new Video { RecordedInterval = recordedInterval, Source = source, Thumbnail = await source.GetThumbnail() }); }
public CodeLocation(string fileName, Interval span, Interval seek) { _fileName = fileName; _span = span; _seek = seek; }
public static Antlr4.Runtime.Misc.IntervalSet Subtract(Antlr4.Runtime.Misc.IntervalSet left, Antlr4.Runtime.Misc.IntervalSet right) { if (left == null || left.IsNil) { return(new Antlr4.Runtime.Misc.IntervalSet()); } Antlr4.Runtime.Misc.IntervalSet result = new Antlr4.Runtime.Misc.IntervalSet(left); if (right == null || right.IsNil) { // right set has no elements; just return the copy of the current set return(result); } int resultI = 0; int rightI = 0; while (resultI < result.intervals.Count && rightI < right.intervals.Count) { Interval resultInterval = result.intervals[resultI]; Interval rightInterval = right.intervals[rightI]; // operation: (resultInterval - rightInterval) and update indexes if (rightInterval.b < resultInterval.a) { rightI++; continue; } if (rightInterval.a > resultInterval.b) { resultI++; continue; } Interval?beforeCurrent = null; Interval?afterCurrent = null; if (rightInterval.a > resultInterval.a) { beforeCurrent = new Interval(resultInterval.a, rightInterval.a - 1); } if (rightInterval.b < resultInterval.b) { afterCurrent = new Interval(rightInterval.b + 1, resultInterval.b); } if (beforeCurrent != null) { if (afterCurrent != null) { // split the current interval into two result.intervals[resultI] = beforeCurrent.Value; result.intervals.Insert(resultI + 1, afterCurrent.Value); resultI++; rightI++; continue; } else { // replace the current interval result.intervals[resultI] = beforeCurrent.Value; resultI++; continue; } } else { if (afterCurrent != null) { // replace the current interval result.intervals[resultI] = afterCurrent.Value; rightI++; continue; } else { // remove the current interval (thus no need to increment resultI) result.intervals.RemoveAt(resultI); continue; } } } // If rightI reached right.intervals.size(), no more intervals to subtract from result. // If resultI reached result.intervals.size(), we would be subtracting from an empty set. // Either way, we are done. return(result); }
public void GetOverlapsWith_SingleInterval(string name, Interval firstInterval, Interval secondInterval, Interval?overlap) { // Arrange var first = new[] { firstInterval }; var second = new[] { secondInterval }; // Act var overlaps = first.GetOverlapsWith(second).ToList(); // Assert var singleOrDefault = overlaps.Cast <Interval?>().SingleOrDefault(); singleOrDefault.Should().Be(overlap); }
public static ContainerSpan StyleGrade(this string @string, double performance, Interval?range) { var y = (range ?? Interval.Unit).UnitNormalize(performance); // poor man's color scale, red - yellow - green var hsv = new Hsv(h: (float)(y * 120), s: 1, v: 1); var rgb = (Rgb24)colorConverter.ToRgb(hsv); return(new ContainerSpan( ForegroundColorSpan.Rgb(rgb.R, rgb.G, rgb.B), new ContentSpan(@string), ForegroundColorSpan.Reset())); }
public static Point3d[] _GetDivby3dPoints(this Surface srf, int divby, Interval?uDomain = null, Interval?vDomain = null) { return(srf._GetDivby2dPoints(divby, uDomain, vDomain).Select(o => srf.PointAt(o.u, o.v)).ToArray()); }
/// <summary> /// Method to create an <see cref="SbnTree"/> from a collection of (id, geometry) tuples /// </summary> /// <param name="boxedFeatures">The (id, geometry) tuples</param> /// <param name="zRange">The z-ordinate extent</param> /// <param name="mRange">The m-ordinate extent</param> /// <returns>The newly created tree</returns> public static SbnTree Create(ICollection <Tuple <uint, IGeometry> > boxedFeatures, Interval?zRange = null, Interval?mRange = null) { Interval x, y, z, m; GetIntervals(boxedFeatures, out x, out y, out z, out m); if (zRange.HasValue) { z = z.ExpandedByInterval(zRange.Value); } if (mRange.HasValue) { m = m.ExpandedByInterval(mRange.Value); } var tree = new SbnTree(new SbnHeader(boxedFeatures.Count, x, y, z, m)); foreach (var boxedFeature in boxedFeatures) { tree.Insert(tree.ToSbnFeature(boxedFeature.Item1, boxedFeature.Item2)); } tree.CompactSeamFeatures(); return(tree); }