public static async Task <Aggregates> ProcessTripDataFile([ActivityTrigger] string url, ILogger log) { Aggregates results = new Aggregates(); log.LogWarning("Processing " + url + "..."); using (WebResponse response = await WebRequest.CreateHttp(url).GetResponseAsync()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8, true, 65536)) { reader.ReadLine(); reader.ReadLine(); while (!reader.EndOfStream) { string text = await reader.ReadLineAsync(); if (!string.IsNullOrEmpty(text)) { double num = double.Parse(text.Substring(text.LastIndexOf(',') + 1)); results.Sum += num; results.Count++; } } results.Average = results.Sum / (double)Math.Max(results.Count, 1); string text2 = url.Substring(url.LastIndexOf('/') + 1); log.LogWarning($"Finished processing {text2}. Ride count: {results.Count:N0}. Total fees: ${results.Sum:N2}, Average fee: ${results.Average:N2}."); return(results); } } } }
/// <summary> /// Initializes a new instance of the <see cref="Select"/> class. /// </summary> /// <param name="aggregates">The aggregates.</param> public Select(params Aggregate[] aggregates) { foreach (Aggregate agg in aggregates) { Aggregates.Add(agg); } }
public void Setup() { _eventStore = new InMemoryEventStore(); _aggregates = Aggregates.CreateWith(_eventStore); _eventHandler = new TestEventHandler(); }
protected void InitializeAggregates(INodeSchema schema, IDictionary <string, Type> parameterTypes) { foreach (var aggregate in Aggregates.Where(agg => agg.Value.SqlExpression != null)) { var sourceExpression = aggregate.Value.SqlExpression; // Sum and Average need to have Decimal values as input for their calculations to work correctly if (aggregate.Value.AggregateType == AggregateType.Average || aggregate.Value.AggregateType == AggregateType.Sum) { sourceExpression = new ConvertCall { Parameter = sourceExpression, DataType = new SqlDataTypeReference { SqlDataTypeOption = SqlDataTypeOption.Decimal } } } ; aggregate.Value.Expression = sourceExpression.Compile(schema, parameterTypes); aggregate.Value.ReturnType = aggregate.Value.SqlExpression.GetType(schema, null, parameterTypes); if (aggregate.Value.AggregateType == AggregateType.Average) { if (aggregate.Value.ReturnType == typeof(SqlByte) || aggregate.Value.ReturnType == typeof(SqlInt16)) { aggregate.Value.ReturnType = typeof(SqlInt32); } } } }
public GameDatabase(ref Action onUpdate, GameObject ui, ICoreMessager coreMessager, Dictionary <KeyPositionType, KeyPosition> keyPositions) { this.KeyPositions = keyPositions; UserManager = new UserManager(); Aggregates = new Aggregates(ref onUpdate, coreMessager); Commands = new Commands(Aggregates, UserManager); GameViewController = new GameViewController(ui); }
public WeatherApi() { _cities = new Cities(); _dailyAverageTemperatures = new DailyAverageTemperatures(); _aggregates = Aggregates.CreateWith(new AzureEventStore()); _aggregates.PublishNewStateTo(new WeatherStationEventHandler()); }
public GameLogic(IEventProcessor eventProsessor, ref Action OnTick, CoreMessager coreMessager, Aggregates aggregates) { this.eventProsessor = eventProsessor; this.coreMessager = coreMessager; this.aggregates = aggregates; coreMessager.AddMessageCallback(HandleMessageReceived); OnTick += Tick; }
private void NewValues(Aggregates aggregates) { _viewModel.Battery = aggregates.Battery?.InstantPower; _viewModel.Grid = aggregates.Site?.InstantPower; _viewModel.Home = aggregates.Load?.InstantPower; _viewModel.Solar = aggregates.Solar?.InstantPower; _viewModel.Errors = aggregates?.ErrorMessage; }
public CatalogSchema() : base("Catalog", "Telesophy.Alexandria.Model") { Entities.Add(mediaSetEntity); Entities.Add(mediaItemEntity); Entities.Add(artistEntity); Aggregates.Add(mediaSetWithAllChildren); Aggregates.Add(mediaItemSingleton); }
/// <summary> /// Initializes a new instance of the <see cref="Select"/> class. /// </summary> /// <param name="aggregates">The aggregates.</param> public Select(params Aggregate[] aggregates) { _provider = ProviderFactory.GetProvider(); SQLCommand = SqlFragment.SELECT; foreach (Aggregate agg in aggregates) { Aggregates.Add(agg); } }
/// <summary> /// Deserializa os dados agregados. /// </summary> /// <param name="aggregate"></param> private void DeserializeAggregate(string aggregate) { Func <AggregateFunction> func; if (_aggregateFactories.TryGetValue(aggregate, out func)) { Aggregates.Add(func()); } }
public double GetCount() { if (!Aggregates.Any(agg => agg.Type == AggregatorType.COUNT)) { throw new ApplicationException("Cannot get Count for Group"); } return(Aggregates.FirstOrDefault(agg => agg.Type == AggregatorType.COUNT).Value); }
/// <summary> /// Retrieves the metric aggregates for the latest complete bucket /// </summary> /// <param name="bucketStartTime">The start time of the bucket with completed aggregates (assumed by newer values arriving)</param> /// <param name="count">The number of metrics the aggregates are based on</param> /// <param name="maximum">The maximum value</param> /// <param name="minimum">The minimum value</param> /// <param name="mean">The average (mean) value</param> /// <param name="standardDeviation">The standard deviation of the values</param> /// <param name="p50">The 50th percentile of the values</param> /// <param name="p90">The 90th percentile of the values</param> /// <param name="p95">The 95th percentile of the values</param> /// <param name="p98">The 98th percentile of the values</param> /// <param name="p99">The 99th percentile of the values</param> public void GetAggregates(out DateTimeOffset?bucketStartTime, out int?count, out double?maximum, out double?minimum, out double?mean, out double?standardDeviation, out double?p50, out double?p90, out double?p95, out double?p98, out double?p99) { var targetKey = -1L; // _bucketValues.Count > 0 ? _bucketValues.Max(item => item.Key) - 1 : -1; if (_bucketValues.Count > 0) { var maxValue = -1L; var previousValue = -1L; var keyEnumerator = _bucketValues.Keys.GetEnumerator(); while (keyEnumerator.MoveNext()) { var currentKey = keyEnumerator.Current; if (currentKey > maxValue) { previousValue = maxValue; maxValue = currentKey; } else if (currentKey > previousValue) { previousValue = currentKey; } } targetKey = previousValue; } if (targetKey >= 0 && _bucketValues.TryGetValue(targetKey, out var values)) { bucketStartTime = GetBucketTime(targetKey, Duration); count = values.Count; var dataValues = new double[count.Value]; for (var index = 0; index < dataValues.Length; index++) { dataValues[index] = values[index]; } Aggregates.GetPerformanceAggregates(dataValues, out maximum, out minimum, out mean, out _, out standardDeviation, out p50, out p90, out p95, out p98, out p99); } else { maximum = null; minimum = null; mean = null; standardDeviation = null; p50 = null; p90 = null; p95 = null; p98 = null; p99 = null; count = null; bucketStartTime = null; } }
private void DeserializeAggregate(string aggregate) { Func <AggregateFunction> factory; if (aggregateFactories.TryGetValue(aggregate, out factory)) { Aggregates.Add(factory()); } }
/// <summary> /// Initializes a new instance of the <see cref="Select"/> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="aggregates">The aggregates.</param> public Select(DataProvider provider, params Aggregate[] aggregates) { Provider = provider; ProviderName = provider.Name; foreach (Aggregate agg in aggregates) { Aggregates.Add(agg); } }
/// <summary> /// Initializes a new instance of the <see cref="Select"/> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="aggregates">The aggregates.</param> public Select(IDataProvider provider, params Aggregate[] aggregates) { SQLCommand = SqlFragment.SELECT; _provider = provider; foreach (Aggregate agg in aggregates) { Aggregates.Add(agg); } }
/// <summary> /// Initializes a new instance of the <see cref="Select"/> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="aggregates">The aggregates.</param> public Select(IDataProvider provider, params Aggregate[] aggregates) { _provider = provider; this.sqlFragment = _provider.SqlFragment; SQLCommand = this.sqlFragment.SELECT; foreach (Aggregate agg in aggregates) { Aggregates.Add(agg); } }
private void EnsureAggregateExists <TAggregate>(Guid AggregateRootId) where TAggregate : IAggregateRoot { var aggregate = Aggregates.Where(x => x.Id == AggregateRootId).FirstOrDefault(); if (aggregate == null) { var aggregateDocument = new AggregateDocument(id: AggregateRootId, type: typeof(TAggregate).AssemblyQualifiedName); Aggregates.Add(aggregateDocument); } }
/// <summary> /// Finds and deserializes an aggregate the specified id, if any. If none exists, returns null. /// </summary> /// <param name="aggregateId">The id of the aggregate. If null, and there's only a single aggregate of the specified type, it returns that; otherwise, it throws.</param> /// <returns>The deserialized aggregate, or null if none exists with the specified id.</returns> public TAggregate GetLatest <TAggregate>(Guid?aggregateId = null) where TAggregate : class, IEventSourced { if (!aggregateId.HasValue) { aggregateId = Aggregates.OfType <TAggregate>().Single().Id; } return(builder.GetRepository(typeof(TAggregate)).GetLatest(aggregateId.Value)); }
/// <summary> /// Finds and deserializes an aggregate the specified id, if any. If none exists, returns null. /// </summary> /// <param name="aggregateId">The id of the aggregate. If null, and there's only a single aggregate of the specified type, it returns that; otherwise, it throws.</param> /// <returns>The deserialized aggregate, or null if none exists with the specified id.</returns> public async Task <TAggregate> GetLatestAsync <TAggregate>(Guid?aggregateId = null) where TAggregate : class, IEventSourced { if (!aggregateId.HasValue) { aggregateId = Aggregates.OfType <TAggregate>().Single().Id; } return(await builder.GetRepository <TAggregate>() .GetLatest(aggregateId.Value)); }
public DataContext RemoveAggregates(IEnumerable <AggregateSymbol> aggregates) { if (aggregates == null) { throw new ArgumentNullException(nameof(aggregates)); } var newAggregates = Aggregates.RemoveRange(aggregates); return(WithAggregates(newAggregates)); }
public PowerwallStatus Map(Aggregates aggregates, Soe soe) { return(new PowerwallStatus { Battery = WattsToKiloWatts(StringToInt(aggregates?.Battery?.InstantPower)), Grid = WattsToKiloWatts(StringToInt(aggregates?.Site?.InstantPower)), Home = WattsToKiloWatts(StringToInt(aggregates?.Load?.InstantPower)), Solar = WattsToKiloWatts(StringToInt(aggregates?.Solar?.InstantPower)), BatteryCharge = StringToInt(soe.Percentage), }); }
public void TestMeanAccuracy(double[] values) { var mathnetValue = values.Sum() / values.Length; var aggregatesValue = Aggregates.Mean(values).Value; mathnetValue = Math.Round(mathnetValue, 6); aggregatesValue = Math.Round(aggregatesValue, 6); Assert.IsNotNull(aggregatesValue, "Aggregates value was not expected to be null"); Assert.IsTrue(mathnetValue == aggregatesValue, $"The mathnet mean does not equal the aggregates sum { mathnetValue } != { aggregatesValue }"); }
/// <summary> /// 构造nvl /// </summary> /// <param name="defaultValue"></param> /// <returns></returns> public Property nvl(object defaultValue) { if (defaultValue.GetType().IsValueType) { Aggregates.Add("nvl({0}, " + defaultValue + ")"); } else { Aggregates.Add("nvl({0}, '" + defaultValue + "')"); } return(this); }
protected override string VisitFunctionCall(CallExpression exp, out object resultObj) { Depth++; var function = exp.Name; var paramBuilder = new StringBuilder(); var iParam = 0; var donutFn = _functionDict.GetFunction(function); donutFn.Parameters = exp.Parameters; string result; var aggStage = _aggTree.AddFunction(donutFn); if (donutFn is IDonutTemplateFunction <string> fnTemplate) { FeatureFunctions.Enqueue(donutFn); var codeContext = new DonutCodeContext(_script); result = fnTemplate.GetTemplate(exp, codeContext); donutFn.Content = new DonutFeatureDefinition(result); resultObj = donutFn; } else if (donutFn.IsAggregate) { string aggregateResult = donutFn.GetValue(); if (aggregateResult == null) { resultObj = null; return(""); } donutFn.Content = new DonutFeatureDefinition(aggregateResult = aggStage.GetValue());//FillCallParameters(donutFn, exp.Parameters); resultObj = donutFn; Aggregates.Enqueue(donutFn); result = aggregateResult; } else { FeatureFunctions.Enqueue(donutFn); foreach (var parameter in exp.Parameters) { var paramStr = Visit(parameter as IExpression); paramBuilder.Append(paramStr); if (iParam < exp.Parameters.Count - 1) { paramBuilder.Append(", "); } iParam++; } result = $"{donutFn}({paramBuilder})"; resultObj = donutFn; } Depth--; return(result); }
/** * Prints all the metric names and values of the aggregate data. The * aggregate metrics represent the sum of the requested metrics across all * of the entries selected by the query and not just the rows returned. */ public void printFeedAggregates() { Console.WriteLine("\n-------- Aggregate Metric Values --------"); Aggregates aggregates = feed.Aggregates; foreach (Metric metric in aggregates.Metrics) { Console.WriteLine( "\nMetric Name = " + metric.Name + "\nMetric Value = " + metric.Value + "\nMetric Type = " + metric.Type + "\nMetric CI = " + metric.ConfidenceInterval); } }
public string Serialize() { var result = new StringBuilder(Member); var aggregates = Aggregates.Select(aggregate => aggregate.FunctionName.Split('_')[0].ToLowerInvariant()); foreach (var aggregate in aggregates) { result.Append("-"); result.Append(aggregate); } return(result.ToString()); }
public SelectColumn(Join @join, ColumnDef columnDef, string alias, ColumnType columnType, string[] dependentOnAliases, bool isVisible, int orderByIndex, Aggregates aggregate, ColumnDef aggregateColumnDef, string isNull, string statement = null, SelectStatement optionsSelectStatement = null) { Join = @join; ColumnDef = columnDef; ColumnType = columnType; Alias = alias; DependentOnAliases = dependentOnAliases; IsVisible = isVisible; OrderByIndex = orderByIndex; Aggregate = aggregate; AggregateColumnDef = aggregateColumnDef; IsNull = isNull; Statement = statement; OptionsSelectStatement = optionsSelectStatement; }
public override void AddRequiredColumns(IDictionary <string, DataSource> dataSources, IDictionary <string, Type> parameterTypes, IList <string> requiredColumns) { // Columns required by previous nodes must be derived from this node, so no need to pass them through. // Just calculate the columns that are required to calculate the groups & aggregates var scalarRequiredColumns = new List <string>(); if (GroupBy != null) { scalarRequiredColumns.AddRange(GroupBy.Select(g => g.GetColumnName())); } scalarRequiredColumns.AddRange(Aggregates.Where(agg => agg.Value.SqlExpression != null).SelectMany(agg => agg.Value.SqlExpression.GetColumns()).Distinct()); Source.AddRequiredColumns(dataSources, parameterTypes, scalarRequiredColumns); }
public AggregateEventInfo GetAggregateEvent(Type aggregateEventType) { if (aggregateEventType == null) { throw new ArgumentNullException(nameof(aggregateEventType)); } if (!aggregateEventType.GetTypeInfo().IsSubclassOf(typeof(AggregateEvent))) { throw new ArgumentOutOfRangeException(nameof(aggregateEventType)); } var info = Aggregates.SelectMany(x => x.Events).SingleOrDefault(t => aggregateEventType == t.Type); return(info ?? throw new LogicSchemaException($"No aggregate event with type '{aggregateEventType.Name}' in logic schema")); }
public void RaiseAggregate <TAggRequest, TAggResponse>(TAggRequest dto, params string[] queues) where TAggRequest : IApiRequestDto { var request = new ApiControllerRequestDto() { Request = dto, ResponseType = typeof(TAggResponse).FullName, Destination = queues.ToList() }; var eventRequestDto = ApplicationContext.Container.Resolve <IEventRequestDto <ApiControllerRequestDto> >(); eventRequestDto.Queues = queues.ToList(); eventRequestDto.MetaData = request; Events.Add(eventRequestDto); Aggregates.Add(eventRequestDto); }
public EventMutator(Aggregates.IUnitOfWork uow) { _uow = uow; }
public TelemetryLapComplete(Aggregates.Telemetry tel, TelemetryDriver driver, Lap lap) { Telemetry = tel; Driver = driver; Lap = lap; }
public TelemetryRefresh(Aggregates.Telemetry instance) { Telemetry = instance; }
public SectionStats(double confidenceMean, Aggregates duration, int count) { ConfidenceMean = confidenceMean; Duration = duration; Count = count; }
public SectionStats() { Duration = new Aggregates(); }
public CommandMutator(Aggregates.IUnitOfWork uow) { _uow = uow; }
public DriversAdded(Aggregates.Telemetry telemetry, IEnumerable<TelemetryDriver> drivers) { Telemetry = telemetry; Drivers = drivers; }
public SampleCommandHandler(Aggregates aggregates) { _aggregates = aggregates; }