public IActionResult GetUserOperationResult([FromRoute] string userOperationId) { UserAnalyticsOperation userAnalyticsOperation = _analyticsService.GetUserAnalyticsOperation(userOperationId); if (userAnalyticsOperation == null || userAnalyticsOperation.Status != OperationStatus.Complete) { return(NotFound()); } return(Ok()); // todo: return result of operation }
/// <summary> /// Execute operation. Publishes event, that contains AnalyticsOperation for analytical modules. /// </summary> /// <param name="operation"></param> public void ExecuteOperation(UserAnalyticsOperation operation) { _operationRequestRepository.Add(operation); _operationRequestRepository.SaveChanges(); TimeSeriesAnalysisRequestEvent @event = new TimeSeriesAnalysisRequestEvent(operation); string routingKey = _analyticsRegistry.GetQueue(operation.OperationName); if (routingKey != null) { _eventBus.PublishToTopic(@event, routingKey); } else { throw new InvalidRequestException("no such operation"); // not sure if it is right exception } }
public async Task Handle(TimeSeriesAnalysisRequestEvent @event, string operationName) { UserAnalyticsOperation operation = @event.Operation; try { InfluxResult <DynamicInfluxRow> influxResult = await _timeSeriesService.ReadMeasurementById(operation.TimeSeriesId); List <DynamicInfluxRow> rowsList = influxResult.Series[0].Rows; Series <DateTime?, double> series = rowsList .Select(x => KeyValue.Create( x.Timestamp, (double)x.Fields[operation.Arguments["column"].ToString()])). ToSeries(); // apply operation switch (operationName) { case "Mean": System.Console.WriteLine(series.Mean()); break; case "Min": System.Console.WriteLine(series.Min()); break; case "Max": System.Console.WriteLine(series.Max()); break; default: throw new NotSupportedException(); } operation.Status = OperationStatus.Complete; } catch (Exception e) { operation.Status = OperationStatus.Error; } finally { _eventBus.Publish(new DiagnosticsResponseEvent(operation)); } }
public IActionResult GetUserOperation([FromRoute] string userOperationId) { UserAnalyticsOperation userAnalyticsOperation = _analyticsService.GetUserAnalyticsOperation(userOperationId); if (userAnalyticsOperation == null) { return(NotFound()); } UserAnalyticsOperationModel model = new UserAnalyticsOperationModel { Id = userAnalyticsOperation.Id.ToString(), OperationName = userAnalyticsOperation.OperationName, Status = userAnalyticsOperation.Status.ToString(), TimeSeriesId = userAnalyticsOperation.TimeSeriesId }; return(Ok(model)); }
public async Task <IActionResult> Calculation([FromBody] AnalyticsRequestModel analyticsRequestModel) //([FromBody] AnalyticsOperation analyticsOperation) { UserAnalyticsOperation analyticsOperation = new UserAnalyticsOperation { Id = Guid.NewGuid(), OperationName = analyticsRequestModel.OperationName, TimeSeriesId = analyticsRequestModel.TimeSeriesId, Arguments = analyticsRequestModel.Arguments }; _analyticsService.ExecuteOperation(analyticsOperation); UserAnalyticsOperationModel userAnalyticsOperationModel = new UserAnalyticsOperationModel { Id = analyticsOperation.Id.ToString(), OperationName = analyticsOperation.OperationName, TimeSeriesId = analyticsOperation.TimeSeriesId, Status = analyticsOperation.Status.ToString() }; Response.Headers.Add("Location", $"api/v1/analytics/operations/{analyticsOperation.Id}"); return(Accepted(userAnalyticsOperationModel)); }
public DiagnosticsResponseEvent(UserAnalyticsOperation operation) : base() { Operation = operation; }
public TimeSeriesAnalysisRequestEvent(UserAnalyticsOperation operation) : base() { Operation = operation; }
/// <summary> /// Fetch results of operation. /// </summary> /// <param name="operation"></param> public void FetchResults(UserAnalyticsOperation operation) { throw new NotImplementedException(); }
/// <summary> /// Check status of operation. /// </summary> /// <param name="operation"></param> /// <returns></returns> public OperationStatus CheckResults(UserAnalyticsOperation operation) { return(_operationRequestRepository.GetStatus(operation.Id)); }