private void CreateKpi(Collector agent, string value, string name, KpiType kpiType) { var k = new Kpi { Name = name, Value = Convert.ToDouble(value: value), Time = (int)agent.Time, KpiType = kpiType, SimulationConfigurationId = agent.simulationId.Value, SimulationNumber = agent.simulationNumber.Value, IsFinal = false, IsKpi = true, SimulationType = agent.simulationKind.Value }; Kpis.Add(item: k); }
internal void CreateKpi(Collector agent, string value, string name, KpiType kpiType, bool isFinal = false) { var k = new Kpi { Name = name, Value = Math.Round(Convert.ToDouble(value: value), 2), Time = (int)agent.Time, KpiType = kpiType, SimulationConfigurationId = agent.simulationId.Value, SimulationNumber = agent.simulationNumber.Value, IsFinal = isFinal, IsKpi = true, SimulationType = agent.simulationKind.Value, ValueMin = 0, ValueMax = 0 }; Kpis.Add(item: k); }
public override async Task <IEnumerable <Tuple <TimeBucket <TCalendar>, KpiValue> > > GetIfExist(KpiType kpi, IEnumerable <TimeBucket <TCalendar> > timeBuckets, string targetId) { var startPoints = timeBuckets.Where(x => !x.IsPartial).Select(x => x.Start).ToList(); var kpiValues = await Context.KpiValues .Where(x => x.KpiTypeId == kpi.Id && startPoints.Contains(x.DateTimePoint)).ToListAsync(); var keyValuePairs = timeBuckets.Select(x => new Tuple <TimeBucket <TCalendar>, KpiValue>(x, kpiValues.FirstOrDefault(y => y.DateTimePoint == x.Start))) .ToList(); return(keyValuePairs); }
protected override async Task <Tuple <TimeBucket <TCalendar>, KpiValue> > Extract(KpiType kpi, TimeBucket <TCalendar> timeBucket, string targetId) { var parameters = SetParametersValue(kpi.Id, timeBucket, targetId, kpi.Parameters).Cast <object>().ToArray(); var commandText = new SqlCommand(kpi.Query).CommandText; var kpiValue = _targetDbContext.Set <KpiValue>().FromSqlRaw(commandText, parameters).AsNoTracking() .FirstOrDefault() ?? new KpiValue() { Value = 0, DateTimePoint = timeBucket.Start, KpiTypeId = kpi.Id, ExtractedDateTime = DateTime.Now, TargetId = targetId, }; if (!timeBucket.IsPartial) { await Context.KpiValues.AddAsync(kpiValue); await Context.SaveChangesAsync(); } return(new Tuple <TimeBucket <TCalendar>, KpiValue>(timeBucket, kpiValue)); }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="KpiType" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => KpiType.CreateFrom(sourceValue);