public void Pause(DataSet set) { ActiveForecast forecast; if (_runningForecasts.TryGetValue(set.Token, out forecast)) { forecast.State = FORECAST_STATE.PAUSED; } }
public void ModifyParameters(DataSet set, object parameters) { ActiveForecast forecast; if (_runningForecasts.TryGetValue(set.Token, out forecast)) { forecast.Parameters = parameters; } }
public void Init(DataSet set, IRepository repository, dynamic parameters) { _repository = repository; _runningForecasts.TryAdd(set.Token, new ActiveForecast { Parameters = parameters, Set = set, State = FORECAST_STATE.INITIALIZED }); }
public void AddEntry(DataSet set, DataEntry entry) { var setToAddTo = _repository.Get<DataSet>().FirstOrDefault(s => s.Token == set.Token); if (setToAddTo == null) return; //commit new entry entry.DataSetId = setToAddTo.Id; setToAddTo.Entries.Add(entry); setToAddTo.CurrentPeriod = entry.Period; _repository.Update(setToAddTo); _broadcaster.SendForecast(set); }
public DataSet Init(dynamic parameters) { var set = new DataSet { CurrentPeriod = 1, Entries = new Collection<DataEntry>(), Token = Guid.NewGuid().ToString() }; _repository.Create(set); Groups.Add(Context.ConnectionId, set.Token); _broadcaster.Init(set, _repository, parameters); return set; }
private static void Main(string[] args) { _set = new DataSet(); _parameters = new ExpandoObject(); _parameters.Strategy = FORECAST_STRATEGY.Naive; //Setup initial dataset InitializeClients(); //pause so everything gets init. while (!_initialized){} SendHistoricalData(); _proxySender.Invoke("Start", _set).Wait(); //begin feeding live data constantly Console.WriteLine("Begin sending live data."); while(true) SendLiveData(); }
public void SendForecast(DataSet set) { ActiveForecast forecast; if (_runningForecasts.TryGetValue(set.Token, out forecast)) { if (forecast.State == FORECAST_STATE.STARTED) { FORECAST_STRATEGY strategyType = forecast.Parameters.Strategy; IForecastStrategy strategy; switch (strategyType) { case FORECAST_STRATEGY.Naive: strategy = new NaieveStrategy(); break; case FORECAST_STRATEGY.MovingAverage: strategy = new MovingAverageStrategy(); break; case FORECAST_STRATEGY.SingleExp: strategy = new SingleExponentialSmoothingStrategy(); break; case FORECAST_STRATEGY.DoubleExp: strategy = new DoubleExponentialSmoothingStrategy(); break; case FORECAST_STRATEGY.TripleExp: strategy = new TripleExponentialSmoothingStrategy(); break; default: strategy = new NaieveStrategy(); break; } var model = new Model(strategy, forecast.Set.Entries, forecast.Parameters); var value = model.Forecast(forecast.Set.CurrentPeriod); Clients.Group(set.Token).sendValue(value); forecast.Set.CurrentPeriod++; _repository.Update(forecast.Set); } } }
public void Unregister(DataSet set) { Groups.Remove(Context.ConnectionId, set.Token); }
public void Stop(DataSet set) { _broadcaster.Stop(set); }
public void Start(DataSet set) { _broadcaster.Start(set); }
public void Register(DataSet set) { Groups.Add(Context.ConnectionId, set.Token); }
public void Pause(DataSet set) { _broadcaster.Pause(set); }
public void ModifyParameters(DataSet set, dynamic parameters) { _broadcaster.ModifyParameters(set, parameters); }
private static async void InitializeClients() { _senderConnection = new HubConnection("http://localhost:8080/"); _proxySender = _senderConnection.CreateHubProxy("ForecastingDataHub"); _senderConnection.Start().Wait(); var set = await _proxySender.Invoke("Init", _parameters); _set = new DataSet {CurrentPeriod = set.CurrentPeriod, Token = set.Token }; _retrieverConnection = new HubConnection("http://localhost:8080/"); _proxyRetriever = _retrieverConnection.CreateHubProxy("ForecastingDataHub"); _retrieverConnection.Start().Wait(); _proxyRetriever.Invoke("Register", _set).Wait(); _proxyRetriever.On<ForecastEntry>("sendValue", forecast => Console.WriteLine("The amount of hits for the period {0} will be {1}", forecast.Period, forecast.ForecastValue)); _initialized = true; Console.WriteLine("Finished the initialization of the clients. \nYour token is: " + set.Token); }