예제 #1
0
        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()
                });
            });
        }
예제 #2
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);
            }
        }