/// <summary> /// Gets the min and max values of a storage site environemental factor. /// </summary> /// <param name="id">ID of the storage site.</param> /// <param name="factor">The factor to get data for.</param> /// <param name="startTime">The period start time.</param> /// <param name="endTime">The period end time.</param> /// <returns>Returns the maxima.</returns> private IActionResult GetStorageSiteEnvironementalFactorExtrema(Guid id, EnvironmentalFactor factor, DateTime startTime, DateTime endTime) { // Validate times if (startTime == null || startTime == default) { return(HandleBadRequest("No start time provided.")); } startTime = startTime.ToUniversalTime(); if (endTime == null || endTime == default) { endTime = DateTime.UtcNow; } if (startTime > DateTime.UtcNow || startTime > endTime) { return(HandleBadRequest("Invalid start time provided.")); } // Get extrema try { Extrema extrema = EnvironmentService.GetExtrema(id, factor, startTime, endTime); return(Ok(extrema)); } catch (StorageSiteNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
public LevelRun(BidiLink firstLink, BidiLink lastLink, CharType sor, CharType eor) { this.FirstLink = firstLink; this.LastLink = lastLink; switch (sor) { case CharType.L: _extrema |= Extrema.SOR_L; break; case CharType.R: _extrema |= Extrema.SOR_R; break; #if DEBUG default: throw (new ArgumentException("The type of SOR should be either L or R.")); #endif } switch (eor) { case CharType.L: _extrema |= Extrema.EOR_L; break; case CharType.R: _extrema |= Extrema.EOR_R; break; #if DEBUG default: throw (new ArgumentException("The type of EOR should be either L or R.")); #endif } // An isolating run ends at an isolating initiator. switch (lastLink.type) { case CharType.LRI: case CharType.RLI: case CharType.FSI: _kind |= Kind.Isolate | Kind.Partial; break; } // A terminating run starts with a PDI. if (firstLink.type == CharType.PDI) { _kind |= Kind.Terminating; } this.SubsequentLink = lastLink.Next; }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Extrema extrema = Bezier.Extrema(); for (int i = 0; i < extrema.X.Length; i++) { DrawPoint(e.Graphics, Bezier.Position(extrema.Values[i]), Color.Blue, 10); } }
/// <summary> /// Gets the min and max values for a specific storage site and environmental factor. /// </summary> /// <param name="site">The storage site to get the history for.</param> /// <param name="factor">The factor to get the history for.</param> /// <param name="startTime">Start time of the period to get value for.</param> /// <param name="endTime">End time of the period to get value for.</param> /// <returns> /// Returns the extrema. /// </returns> public Extrema GetExtrema(StorageSite site, EnvironmentalFactor factor, DateTime startTime, DateTime endTime) { string column = GetColumnName(factor); Extrema extrema = null; using (IDbConnection connection = GetNewConnection()) { extrema = connection.QuerySingleOrDefault <Extrema>($"SELECT min({column}) AS min_value, max({column}) AS max_value FROM environment WHERE site=@Id AND timestamp>@StartTime AND timestamp<@EndTime", new { site.Id, startTime, endTime }); } return(extrema); }
/// <summary> /// Calculates all the extrema on a curve.<br/> /// Extrema are calculated for each dimension, rather than for the full curve, <br/> /// so that the result is not the number of convex/concave transitions, but the number of those transitions for each separate dimension. /// </summary> /// <param name="curve">Curve where the extrema are calculated.</param> /// <returns>The extrema.</returns> internal static Extrema ComputeExtrema(NurbsBase curve) { var derivPts = DerivativeCoordinates(curve.ControlPointLocations); Extrema extrema = new Extrema(); int dim = derivPts[0][0].Size; for (int j = 0; j < dim; j++) { List <double> p0 = new List <double>(); for (int i = 0; i < derivPts[0].Count; i++) { p0.Add(derivPts[0][i][j]); } List <double> result = new List <double>(DerivativesRoots(p0)); if (curve.Degree == 3) { IList <double> p1 = new List <double>(); for (int i = 0; i < derivPts[1].Count; i++) { p1.Add(derivPts[1][i][j]); } result = result.Concat(DerivativesRoots(p1).ToList()).ToList(); } result = result.Where((t) => t >= 0 && t <= 1).ToList(); result.Sort(); extrema[j] = result; } extrema.Values = extrema[0].Union(extrema[1]).Union(extrema[2]).OrderBy(x => x).ToList(); return(extrema); }
/// <summary> /// Retrieves all related material data from a transaction. /// </summary> /// <typeparam name="Guid">ID of the transaction to use as a starting point.</typeparam> /// <returns>Returns a trace result on success.</returns> /// <exception cref="Exceptions.TransactionNotFoundException" /> /// <exception cref="Exceptions.MaterialBatchNotFoundException" /> /// <exception cref="Exceptions.MaterialNotFoundException" /> public TraceResult Trace(Guid transactionId) { // Get checkout transaction Transaction checkOutTransaction = TransactionLogService.GetTransaction(transactionId); // Get checkin transaction Transaction checkInTransaction = TransactionLogService.GetTransactionLog(checkOutTransaction.MaterialBatchId).Last(); // Get batch MaterialBatch batch = InventoryService.GetMaterialBatch(checkOutTransaction.MaterialBatchId); // Get and replace material data in extra step, since the InventoryService currently doesn't return custom material prop values Material material = MaterialsService.GetMaterial(batch.Material.Id); batch.Material = material; // Get temperature extrema Extrema temperature = EnvironmentService.GetExtrema(batch.StorageLocation.StorageSiteId, EnvironmentalFactor.Temperature, checkInTransaction.Timestamp, checkOutTransaction.Timestamp); // Get humidity extrema Extrema humidity = EnvironmentService.GetExtrema(batch.StorageLocation.StorageSiteId, EnvironmentalFactor.Humidity, checkInTransaction.Timestamp, checkOutTransaction.Timestamp); // Return trace result object return(new TraceResult() { Batch = batch, CheckInTransaction = checkInTransaction, CheckOutTransaction = checkOutTransaction, Temperature = temperature, Humidity = humidity }); }
public Extrema GetExtrema(StorageSite site, EnvironmentalFactor factor, DateTime startTime, DateTime endTime) { Extrema extrema = null; switch (factor) { case EnvironmentalFactor.Temperature: if (Temperature.TryGetValue(site.Id, out List <DataPoint> temperatures)) { if (temperatures.Count > 0) { extrema = new Extrema() { MaxValue = temperatures.Where(t => t.Timestamp >= startTime && t.Timestamp <= endTime).Max(t => t.Value), MinValue = temperatures.Where(t => t.Timestamp >= startTime && t.Timestamp <= endTime).Min(t => t.Value) }; } } break; case EnvironmentalFactor.Humidity: if (Humidity.TryGetValue(site.Id, out List <DataPoint> humidities)) { if (humidities.Count > 0) { extrema = new Extrema() { MaxValue = humidities.Where(t => t.Timestamp >= startTime && t.Timestamp <= endTime).Max(t => t.Value), MinValue = humidities.Where(t => t.Timestamp >= startTime && t.Timestamp <= endTime).Min(t => t.Value) }; } } break; default: throw new NotImplementedException(); } return(extrema); }
public virtual BoundingBox GetBoundingBox() { NurbsBase curve = this; if (IsPeriodic) { curve = ClampEnds(); } List <Point3> pts = new List <Point3> { curve.ControlPointLocations[0] }; List <NurbsBase> beziers = Modify.Curve.DecomposeIntoBeziers(curve, true); foreach (NurbsBase crv in beziers) { Extrema e = Evaluate.Curve.ComputeExtrema(crv); pts.AddRange(e.Values.Select(eValue => crv.PointAt(eValue))); } pts.Add(curve.ControlPointLocations[curve.ControlPointLocations.Count - 1]); Point3[] removedDuplicate = Point3.CullDuplicates(pts, GSharkMath.MinTolerance); return(new BoundingBox(removedDuplicate)); }
public IReadOnlyList <double> Extrema() { Extrema extremaResult = Evaluate.Curve.ComputeExtrema(this); return(extremaResult.Values.ToList()); }
private static bool IsIncluded(LinkedList <DateTime> childrenOfB, Extrema extrema) { var extremaPrices = extrema.Prices.Select(c => c.StartTime).ToList(); return(childrenOfB.All(dateTime => extremaPrices.Contains(dateTime))); }