Пример #1
0
        /// <summary>
        /// Gets the trends one by one and merges them.
        /// </summary>
        protected TrendBundle MergeTrends(int[] cnlNums, TimeRange timeRange)
        {
            int cnlCnt = cnlNums.Length;

            Trend[] trends = new Trend[cnlCnt];

            for (int i = 0; i < cnlCnt; i++)
            {
                trends[i] = GetTrend(cnlNums[i], timeRange);
            }

            return(TrendHelper.MergeTrends(trends));
        }
Пример #2
0
        public async Task Run()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .AddEnvironmentVariables()
                         .Build();

            _ConfigWrapper             = new ConfigurationWrapper(config);
            _ListenToOnlyTheseChannels = _ConfigWrapper.Get <List <ulong> >("ListenToOnlyTheseChannels");
            _FunctionWrapper           = new FunctionWrapper(_ConfigWrapper);
            _DiscordClient             = new DiscordSocketClient();
            var trendHelper = new TrendHelper(_ConfigWrapper);

            trendHelper.PrefixUpdated += TrendHelper_PrefixUpdated;
            _Services = new ServiceCollection()
                        .AddSingleton(_DiscordClient)
                        .AddSingleton <ITrendHelper>(trendHelper)
                        .AddSingleton(_FunctionWrapper)
                        .AddSingleton(_ConfigWrapper)
                        .AddLogging(s => s.AddConsole())
                        .BuildServiceProvider();
            _Logger             = _Services.GetService <ILogger <Bot> >();
            _DiscordClient.Log += Log;
            await LogInAsync();
            await StartAsync();

            _Commands = new CommandService();
            await _Commands.AddModulesAsync(Assembly.GetEntryAssembly(), _Services);

            DetermineModuleNames();
            _DiscordClient.MessageReceived += MessageReceived;
            _DiscordClient.JoinedGuild     += JoinedGuild;
            _DiscordClient.LeftGuild       += LeftGuild;
            await _DiscordClient.SetGameAsync(_ConfigWrapper["PlayingGame"]);

            _PrefixDictionary = await _FunctionWrapper.GetPrefixDictionaryAsync();
        }
Пример #3
0
        /// <summary>
        /// Spreads the last measure on the application (database, UI, alerts)
        /// </summary>
        /// <param name="lastMeasure"></param>
        private void SpreadLastMeasure(float lastMeasure)
        {
            var  currentUser          = this.userRepository.GetCurrentUser();
            var  userSettings         = this.userSettingsRepository.GetCurrentUserSettings();
            long countExistingMesures = this.glucoseMeasureRepository.CountByUser(currentUser.Id);
            bool isFirstReading       = countExistingMesures == 0;

            // 1 - Driving mode
            // NOTE : We only handle MGDL Measure for the H&D MVP
            this.userRepository.ChangeCurrentMeasure(currentUser, lastMeasure);

            // 2 The notification channel
            var notification = new NotificationMeasure();

            notification.NotificationMessage    = string.Format(Utils.GetTranslation("NotificationMessageCurrentMeasure"), HiLowValueHelper.NewMeasureToString(lastMeasure));
            notification.NewMeasure             = lastMeasure;
            notification.MinimumGlucoseTreshold = userSettings.MinimumGlucoseTreshold;
            notification.MaximumGlucoseTreshold = userSettings.MaximumGlucoseTreshold;
            notification.IsAlert = userRepository.GetCurrentUser().IsAlert;

            //Current Trend management //
            GlucoseMeasure pastFifteenMinMeasure      = glucoseMeasureRepository.GetPastFifteenMinutesMeasureByUser(currentUser.Id);
            float?         pastFifteenMinMeasureValue = null;

            if (pastFifteenMinMeasure != null)
            {
                pastFifteenMinMeasureValue = pastFifteenMinMeasure.GlucoseLevelMGDL;
            }

            //Trend management : Builder //
            switch (TrendHelper.ValuesToTypeTrend(lastMeasure, pastFifteenMinMeasureValue))
            {
            case MeasureTrend.IncreasingHeavy:
                notification.MeasureTrend = MeasureTrend.IncreasingHeavy;
                break;

            case MeasureTrend.Increasing:
                notification.MeasureTrend = MeasureTrend.Increasing;
                break;

            case MeasureTrend.Constant:
                notification.MeasureTrend = MeasureTrend.Constant;
                break;

            case MeasureTrend.Decreasing:
                notification.MeasureTrend = MeasureTrend.Decreasing;
                break;

            case MeasureTrend.DecreasingHeavy:
                notification.MeasureTrend = MeasureTrend.DecreasingHeavy;
                break;

            default:
                notification.MeasureTrend = MeasureTrend.None;
                break;
            }

            //Trend management : Notifications //
            //Save the measure trend in the user data
            this.userRepository.UpdateMeasureTrend(currentUser, notification.MeasureTrend);
            //Send the measure trend event to the drive page
            this.eventAggregator.GetEvent <TrendEvent>().Publish(notification.MeasureTrend);
            //Send the measure trend event to the notification
            this.eventAggregator.GetEvent <NotificationMeasureEvent>().Publish(notification);

            // 3 - Alerts raised to the user ?
            if (userRepository.GetCurrentUser().IsAlert)
            {
                if (lastMeasure > userSettings.MaximumGlucoseTreshold || lastMeasure < userSettings.MinimumGlucoseTreshold)
                {
                    notification.NotificationMessage = string.Format(Utils.GetTranslation("NotificationMessageAlertGlycemia"), HiLowValueHelper.NewMeasureToString(lastMeasure));
                    this.eventAggregator.GetEvent <PushNotificationAlertEvent>().Publish(notification);
                }
            }

            this.precedingMeasure = lastMeasure;
        }
Пример #4
0
 public void SetUp()
 {
     _Config      = new Mock <IConfigurationWrapper>();
     _TrendHelper = new TrendHelper(_Config.Object);
 }