Esempio n. 1
0
        public ResultsPage(ExpertSystemAlgorithm expertSystem)
        {
            InitializeComponent();
            _expertSystem = expertSystem;
            _finalResults = _expertSystem.GetFinalResults();

            var stats = _finalResults
                        .GroupBy(s => s)
                        .Select(x => new
            {
                Id    = x.Key,
                Count = x.Count()
            })
                        .OrderByDescending(x => x.Count);

            int overallCount = stats.Sum(x => x.Count);

            stats.ToList().ForEach(a =>
            {
                string text;

                if (a.Id == "")
                {
                    text = "No mental disorders diagnosed";
                }
                else
                {
                    text = QuestionDataLoader.Instance.QuestionData
                           .Where(x => x.Id == 9).First().Answers
                           .Where(y => y.Id == int.Parse(a.Id)).First().String;
                }

                Label label = new Label
                {
                    Content = $"{text}: {Decimal.Round((decimal)100.0 * a.Count / overallCount, 2)}% ({a.Count} of {overallCount})"
                };

                resultPanel.Children.Add(label);
            });
        }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();

            Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

            _loggerWindow.Show();

            _stackId = new Stack <int>();

            Logger.Info($"Initializing QuestionDataLoader ({_jsonPath}).");
            _loader = QuestionDataLoader.Instance;
            _loader.Initialize(new object[] { _jsonPath });

            Logger.Info($"Initializing DbHandler ({_dbPath}).");
            _handler = DbHandler.Instance;
            _handler.Initialize(new object[] { _dbPath });

            _loader.QuestionIds.ToList().ForEach((x) => { _stackId.Push(x); });

            Logger.Info("Adding questions.");
            List <Question> questions = new List <Question>();

            _loader.QuestionIds.ToList().ForEach(i => questions.Add(new Question(i)));
            Logger.Info($"{questions.Count} questions added.");

            Logger.Info("Initializing ExpertSystemAlgorithm.");
            _system = new ExpertSystemAlgorithm(questions);


            _mainPage         = new MainPage(_system.AvailableQuestionsCount);
            _mainPage.OnNext += MainPage_Started;
            _mainPage.OnNext += Page_OnNext;

            Navigate(_mainPage);
        }