public TestModule(TestTwin defaultTwin = null) { Twin.SetDefault(defaultTwin ?? _defaultTwin); Twin.Subscribe(async twin => { Logger.LogInformation("Twin update"); await Twin.ReportAsync(twin); return(TwinResult.Ok); }); }
public TemperatureSensor() { _startTimeStamp = DateTime.Now; Twin.Subscribe(async twin => { Logger.LogInformation("Twin update"); ConfigureGenerator(twin); await Twin.ReportAsync(twin); return(TwinResult.Ok); }); }
public ModelTraining(IOrchestrator proxy) { var sample = new Queue <Temperature>(); Twin.Subscribe(async twin => { Logger.LogInformation("Twin update"); lock (_sync) { _aggregationSize = twin.AggregationSize; _tumblingWindowPercentage = twin.TumblingWindowPercentage; } await Twin.ReportAsync(twin); return(TwinResult.Ok); }); proxy.Training.Subscribe(this, async signal => { Model model = null; lock (sample) { sample.Enqueue(signal); if (sample.Count >= _aggregationSize) { var kMeansTraining = new KMeansTraining(_numClusters); kMeansTraining.TrainModel(sample.Select(e => new[] { e.TimeStamp, e.Value }).ToArray()); model = new Model { Algorithm = Algorithm.kMeans, DataJson = kMeansTraining.SerializeModel() }; for (var i = 0; i < _tumblingWindowPercentage * _aggregationSize / 100; i++) { sample.Dequeue(); } } } if (model != null) { await Model.PublishAsync(model).ConfigureAwait(false); } return(MessageResult.Ok); }); }
//this is a temp depedency, until we get the feature extraction module public Orchestrator(ITemperatureSensor temperatureProxy, IModelTraining trainerProxy) { temperatureProxy.Temperature.Subscribe(this, async signal => { OrchestratorTwin twin; lock (_twinLock) { twin = _lastTwin; } if (twin == null) { return(MessageResult.Ok); } if (twin.Scale == TemperatureScale.Celsius) { signal.Value = signal.Value * 9 / 5 + 32; } await BroadcastMessage(signal, twin); return(MessageResult.Ok); }); trainerProxy.Model.Subscribe(this, async model => { Logger.LogInformation( $"New Trained Model for {model.Algorithm}. Updating the model in {model.Algorithm}"); await Model.PublishAsync(model); return(MessageResult.Ok); }); Twin.Subscribe(async twin => { lock (_twinLock) { _lastTwin = twin; } Logger.LogInformation($"Twin update. Routing = {twin.RoutingMode.ToString()}"); await Twin.ReportAsync(twin); return(TwinResult.Ok); }); }
public Visualization(IOrchestrator proxy, IConfigurationRoot configuration) { _configuration = configuration; _chartDataDictionary = new Dictionary <string, Chart>(); proxy.Visualization.Subscribe(this, async e => { await RenderAsync(e); return(MessageResult.Ok); }); Twin.Subscribe(twin => { Logger.LogInformation("Twin update"); ConfigureCharts(twin); return(Task.FromResult(TwinResult.Ok)); }); }