Exemple #1
0
        public override void Update(IEnumerable <PersistedCityStatisticsWithFinancialData> statistics, PersistedCityStatisticsWithFinancialData current)
        {
            var cityStatistics = new CityStatisticsView(current);

            groupBox1.BeginInvoke(new MethodInvoker(() =>
            {
                AddLabelValue("Population", cityStatistics.Population.ToString("N0"), dataGridView1);
                AddLabelValue("Assessed value", cityStatistics.AssessedValue.ToString("C"), dataGridView1);
                AddLabelValue("Category", cityStatistics.CityCategory, dataGridView1);
                AddLabelValue("Current funds", cityStatistics.CurrentAmountOfFunds.ToString("C"), dataGridView2);
                AddLabelValue("Projected income", cityStatistics.CurrentProjectedAmountOfFunds.ToString("C"), dataGridView2);

                listBox1.DataSource = cityStatistics.GetIssueDataMeterResults()
                                      .Select(x => $"{x.Name} - {x.ValueCategory} ({x.PercentageScoreString}%)")
                                      .ToList();

                listBox2.DataSource =
                    new[]
                {
                    new
                    {
                        Percentage = cityStatistics.GetNegativeOpinion().ToString("P"),
                        Name       = "Negative"
                    },
                    new
                    {
                        Percentage = cityStatistics.GetPositiveOpinion().ToString("P"),
                        Name       = "Positive"
                    }
                }
                .OrderByDescending(x => x.Percentage)
                .Select(x => x.Name + ' ' + x.Percentage)
                .ToList();
            }));
        }
        private void SimulationSession_OnYearAndOrMonthChanged(object sender, EventArgsWithData <IYearAndMonth> e)
        {
            SimulationSession.GetRecentStatistics().WithResultIfHasMatch(cityStatistics =>
            {
                var cityStatisticsView = new CityStatisticsView(cityStatistics);

                GlobalHost
                .ConnectionManager
                .GetHubContext <SimulationHub>()
                .Clients
                .All
                .onYearAndMonthChanged(new YearAndMonthChangedState
                {
                    yearAndMonthDescription = e.EventData.GetCurrentDescription(),
                    overallLabelsAndValues  = new[]
                    {
                        new LabelAndValue {
                            label = "Population", value = cityStatisticsView.Population.ToString("N0")
                        },
                        new LabelAndValue {
                            label = "Assessed value", value = cityStatisticsView.AssessedValue.ToString("C0")
                        },
                        new LabelAndValue {
                            label = "Category", value = cityStatisticsView.CityCategory
                        }
                    },
                    generalOpinion = new[]
                    {
                        new { Opinion = cityStatisticsView.GetPositiveOpinion(), Label = "Positive" },
                        new { Opinion = cityStatisticsView.GetNegativeOpinion(), Label = "Negative" }
                    }
                    .OrderByDescending(y => y.Opinion)
                    .Select(y => new LabelAndValue {
                        label = $"{y.Label}", value = $"{y.Opinion.ToString("P1")}"
                    })
                    .ToArray(),
                    cityBudgetLabelsAndValues = new[]
                    {
                        new LabelAndValue {
                            label = "Current funds", value = cityStatisticsView.CurrentAmountOfFunds.ToString()
                        },
                        new LabelAndValue {
                            label = "Projected income", value = cityStatisticsView.CurrentProjectedAmountOfFunds.ToString()
                        },
                    },
                    issueLabelAndValues = cityStatisticsView
                                          .GetIssueDataMeterResults()
                                          .Select(x => new LabelAndValue()
                    {
                        label = x.Name,
                        value = $"{x.ValueCategory} ({x.PercentageScoreString}%)"
                    })
                                          .ToArray()
                });
            });
        }
Exemple #3
0
        private async void SimulationSession_OnYearAndOrMonthChanged(object sender, EventArgsWithData <IYearAndMonth> e)
        {
            try
            {
                await Startup.WithSimulationHub(async simulationHub =>
                {
                    await SimulationSession.GetRecentStatistics().WithResultIfHasMatch(cityStatistics =>
                    {
                        var cityStatisticsView = new CityStatisticsView(cityStatistics);

                        return(simulationHub
                               .Clients
                               .All
                               .SendAsync("onYearAndMonthChanged", new YearAndMonthChangedState
                        {
                            yearAndMonthDescription = e.EventData.GetCurrentDescription(),
                            overallLabelsAndValues = new[]
                            {
                                new LabelAndValue {
                                    label = "Population", value = cityStatisticsView.Population.ToString("N0")
                                },
                                new LabelAndValue {
                                    label = "Assessed value", value = cityStatisticsView.AssessedValue.ToString("C0")
                                },
                                new LabelAndValue {
                                    label = "Category", value = cityStatisticsView.CityCategory
                                }
                            },
                            generalOpinion = new[]
                            {
                                new { Opinion = cityStatisticsView.GetPositiveOpinion(), Label = "Positive" },
                                new { Opinion = cityStatisticsView.GetNegativeOpinion(), Label = "Negative" }
                            }
                            .OrderByDescending(y => y.Opinion)
                            .Select(y => new LabelAndValue {
                                label = $"{y.Label}", value = $"{y.Opinion:P1}"
                            })
                            .ToArray(),
                            cityBudgetLabelsAndValues = new[]
                            {
                                new LabelAndValue {
                                    label = "Current funds", value = cityStatisticsView.CurrentAmountOfFunds.ToString()
                                },
                                new LabelAndValue {
                                    label = "Projected income", value = cityStatisticsView.CurrentProjectedAmountOfFunds.ToString()
                                },
                            },
                            issueLabelAndValues = cityStatisticsView
                                                  .GetIssueDataMeterResults()
                                                  .Select(x => new LabelAndValue()
                            {
                                label = x.Name,
                                value = $"{x.ValueCategory} ({x.PercentageScoreString}%)"
                            })
                                                  .ToArray()
                        }));
                    });
                });
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteLine(ex);
            }
        }