Example #1
0
        private void SelectCountry(object sender, MouseEventArgs args)
        {
            int x, y;

            GraphicalUtilities.GraphicsCoordsToMapCoords(m_mapControl1.Size, m_mapControl1.MyWorldModel.Size, args.X,
                                                         args.Y, out x,
                                                         out y);
            DiseaseNode    n  = m_mapControl1.MyWorldModel.NodeAt(x, y);
            SimCountryData cd = m_mapControl1.MyWorldModel.CountryForCode(n.MapCell.CountryCode);

            if (cd != null)
            {
                CountrySelected?.Invoke(cd);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Dictionary <string, string> countryCodeForName = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            using (var reader = new StreamReader(@"../../Data/ISO_3166-1_alpha-3.tdf"))
            {
                using (
                    var csv = new CsvReader(reader)
                {
                    Configuration = { Delimiter = "\t", HasHeaderRecord = false }
                }
                    )
                {
                    foreach (CountryNameAndCode countryNameAndCode in csv.GetRecords <CountryNameAndCode>())
                    {
                        countryCodeForName.Add(countryNameAndCode.Name, countryNameAndCode.Code);
                    }
                }
            }
            string  json = File.ReadAllText(@"../../Data/Factbook.json");
            dynamic d    = JObject.Parse(json);

            using (TextWriter tw = new StreamWriter(@"../../../../Data/CountryData.dat"))
            {
                tw.WriteLine(SimCountryData.CSVHeader);
                List <SimCountryData> countries = new List <SimCountryData>();
                //foreach (string countryName in countriesOfInterest)

                List <String> skipList = new List <string>(m_skipList);
                // Special Cases:
                // d["countries"]["Chad"].energy.electricity.access.total_electrification = 33;
                JObject chadElectricity = d["countries"]["chad"].data.energy.electricity as JObject;
                chadElectricity.Add("access", JObject.Parse(@"{""populationWithElectricity"":{""value"":""33""}}")); // From 'population without electricity' and 'population' attributes.
                //JObject nauruElectricity = d["countries"]["nauru"].data.energy.electricity as JObject;
                //nauruElectricity.Add("access", JObject.Parse(@"{""populationWithElectricity"":{""value"":""66""}}"));
                JObject taiwanElectricity = d["countries"]["taiwan"].data.energy.electricity as JObject;
                taiwanElectricity.Add("access", JObject.Parse(@"{""populationWithElectricity"":{""value"":""99""}}"));
                JObject FalklandsElectricity = d["countries"]["falkland_islands_islas_malvinas"].data.energy.electricity as JObject;
                FalklandsElectricity.Add("access", JObject.Parse(@"{""populationWithElectricity"":{""value"":""99""}}"));
                JObject WesternSaharaElectricity = d["countries"]["western_sahara"].data.energy.electricity as JObject;
                WesternSaharaElectricity.Add("access", JObject.Parse(@"{""populationWithElectricity"":{""value"":""99""}}"));

                foreach (var country in d["countries"])
                {
                    string name     = "Unknown";
                    string failedAt = "name";
                    try
                    {
                        var _countryData = country.First.data;

                        name = _countryData.name.Value;
                        if (skipList.Contains(name))
                        {
                            continue;
                        }

                        string countryCode;
                        if (!countryCodeForName.TryGetValue(name, out countryCode))
                        {
                            Console.WriteLine("Failed to get country code for " + name);
                        }

                        failedAt = "totalLand";
                        double totalLand = AttemptToRead(
                            () => _countryData.geography.area.land.value.Value,
                            () => _countryData.geography.area.total.value.Value
                            );

                        failedAt = "population";
                        if (_countryData.people == null)
                        {
                            continue;
                        }
                        var population = (double)_countryData.people.population.total.Value;

                        failedAt = "birthRate";
                        var birthRate = (double)_countryData.people.birth_rate.births_per_1000_population.Value / 365.0;

                        failedAt = "deathRate";
                        var deathRate = (double)_countryData.people.death_rate.deaths_per_1000_population.Value / 365.0;

                        failedAt = "sanitation";
                        var sanitation = AttemptToRead(
                            () => _countryData.people.sanitation_facility_access.unimproved.total.value.Value / 100.0,
                            () => MISSING_SANITATION
                            );

                        failedAt = "drsPerCap";
                        double drsPerCap = AttemptToRead(
                            () => _countryData.people.physicians_density.physicians_per_1000_population.Value / 1000.0,
                            () => AVERAGE_DRS_PER_CAP
                            );

                        failedAt = "healthSpendGDP";
                        var healthSpendGDP = AttemptToRead(
                            () => _countryData.people.health_expenditures.percent_of_gdp.Value / 100.0,
                            () => MISSING_GDP_HEALTH_SPEND
                            );

                        failedAt = "totalGDP";
                        var totalGDP = (double)_countryData.economy.gdp.purchasing_power_parity.annual_values[0].value.Value;

                        failedAt = "literacy";
                        var literacy = AttemptToRead(
                            () => _countryData.people.literacy.total_population.value / 100.0,
                            () => AVERAGE_LITERACY
                            );

                        failedAt = "populationWithElectricity";
                        double populationWithElectricity = AttemptToRead(
                            () => _countryData.energy.electricity.access.total_electrification.value / 100.0,
                            () => _countryData.energy.electricity.access.populationWithElectricity.value / 100.0
                            );

                        failedAt = "socialStability";
                        var socialStability = Math.Sqrt(((literacy * literacy) + (populationWithElectricity * populationWithElectricity)) / 2.0);

                        SimCountryData simCountryData = new SimCountryData()
                        {
                            Name              = name,
                            BirthRate         = birthRate / 365.0,
                            DeathRate         = deathRate / 365.0,
                            HealthSpendPerCap = healthSpendGDP * totalGDP / population,
                            PhysiciansPerCap  = drsPerCap,
                            PopDensity        = population / totalLand,
                            Population        = (int)population,
                            Sanitation        = 1.0 - sanitation,
                            SocialStability   = socialStability,
                            CountryCode       = countryCode
                        };
                        countries.Add(simCountryData);
                        tw.WriteLine(simCountryData.AsCSV);
                    }
                    catch (RuntimeBinderException rbe)
                    {
                        Console.WriteLine($"\"{name}\" read failed at {failedAt}");
                        // TODO: Log failure
                    }
                }
            }
        }
Example #3
0
        private void InitialUI_Load(object sender, EventArgs e)
        {
            m_worldModel = new WorldModel(m_data, SimCountryData.LoadFrom(@"../../../Data/CountryData.dat"));
            m_mapControl.AssignWorldModel(m_worldModel);

            PlotForm dc1 = new PlotForm("Mortality");

            dc1.Bind(m_worldModel,
                     new[] {
                GetTotal(n => n.Killed),
                GetTotal(n => n.Dead)
            },
                     new[] {
                "Killed",
                "Dead"
            });

            PlotForm dc2 = new PlotForm("Disease Stages");

            dc2.Bind(m_worldModel,
                     new[] {
                GetTotal(n => n.ContagiousAsymptomatic),
                GetTotal(n => n.ContagiousSymptomatic),
                GetTotal(n => n.NonContagiousInfected),
                GetTotal(n => n.Immune),
            },
                     new[]
            {
                "ContagiousAsymptomatic",
                "ContagiousSymptomatic",
                "NonContagiousInfected",
                "Immune"
            });

            m_mapControl.Show();
            dc1.Show();
            dc2.Show();



            /*PlotForm m_plotWindow1 = new PlotForm("Killed");
             * m_plotWindow1.Bind(m_worldModel, GetTotal(n => n.Killed));
             * m_plotWindow1.Show();
             *
             * PlotForm m_plotWindow2 = new PlotForm("Immune");
             * m_plotWindow2.Bind(m_worldModel, GetTotal(n => n.Immune));
             * m_plotWindow2.Show();
             *
             * PlotForm m_plotWindow3 = new PlotForm("Total Population");
             * m_plotWindow3.Bind(m_worldModel, GetTotal(n => n.Population));
             * m_plotWindow3.Show();
             *
             * PlotForm m_plotWindow4 = new PlotForm("Immunization Effort");
             * m_plotWindow4.Bind(m_worldModel, GetTotal(n => n.Flows[2](n)));
             * m_plotWindow4.Show();*/


            m_mapControl.MouseMove += (o, args) =>
            {
                double lat, lon;
                int    x, y;
                GraphicalUtilities.GraphicsCoordsToMapCoords(panel1.Size, m_worldModel.Size, args.X, args.Y, out x,
                                                             out y);
                m_data.DataXYToLatLon(x, y, out lat, out lon);
                string where = ReverseGeocodeService.CountryNameForLatAndLong(lat, lon + 2) ?? "Unknown";
                DiseaseNode n = m_worldModel.NodeAt(x, y);
                toolStripStatusLabel1.Text = $"data[{x},{y}] is {where}, Lat {lat:f2}/Lon {lon:f2} {n:d4}";
                Console.WriteLine(toolStripStatusLabel1.Text);
            };

            toolStripStatusLabel1.TextChanged += (o, args) => Console.WriteLine(((ToolStripStatusLabel)o).Text);
        }
Example #4
0
        private void LoadNewDefaultModelAndExtraStuff()
        {
            m_console = new DockableConsole("Log");
            Locator.Register(() => m_console, "console");

            List <OutbreakResponseTeam> orts = new List <OutbreakResponseTeam>();

            Dictionary <string, Tuple <int, Color> > ortCounts = new Dictionary <string, Tuple <int, Color> >();
            string  json = File.ReadAllText(@"Data/Governments.dat");
            dynamic d    = JObject.Parse(json);

            foreach (dynamic govt in d["Governments"])
            {
                string cc           = govt["cc"];
                int    numberOfORTs = govt["ORTs"];
                Color  color        = Color.FromName(govt["Color"].ToString());
                ortCounts.Add(cc, new Tuple <int, Color> (numberOfORTs, color));
            }

            WorldModel = new WorldModel(MapData.LoadFrom("Data/MapData.dat"), SimCountryData.LoadFrom("Data/CountryData.dat"), ortCounts);
            WorldModel.Executive.ClockAboutToChange += exec =>
            {
                DateTime newTime = ((IExecEvent)exec.EventList[0]).When;
                double   howMuch = 100 * (newTime - WorldModel.ExecutionParameters.StartTime).TotalHours /
                                   (WorldModel.ExecutionParameters.EndTime - WorldModel.ExecutionParameters.StartTime).TotalHours;

                m_statusStrip.InvokeIfRequired(strip =>
                {
                    ((ToolStripProgressBar)strip.Items["Progress"]).Value      = (int)howMuch;
                    ((ToolStripStatusLabel)strip.Items["DateTimeStatus"]).Text = newTime.ToString("dd MMM yyy HH:mm:ss");
                });
            };
            WorldModel.Controller.StateChanged += HandleStateChange;

            m_map = new DockableMap();
            m_map.AssignWorldModel(WorldModel);
            DockableTrendChart dc1 = new DockableTrendChart("Mortality");

            dc1.Bind(WorldModel,
                     new[]
            {
                GetTotal(n => n.Killed),
                GetTotal(n => n.Dead)
            },
                     new[]
            {
                "Killed",
                "Dead"
            });

            DockableTrendChart dc2 = new DockableTrendChart("Disease Stages");

            dc2.Bind(WorldModel,
                     new[]
            {
                GetTotal(n => n.ContagiousAsymptomatic),
                GetTotal(n => n.ContagiousSymptomatic),
                GetTotal(n => n.NonContagiousInfected),
                GetTotal(n => n.Immune),
            },
                     new[]
            {
                "ContagiousAsymptomatic",
                "ContagiousSymptomatic",
                "NonContagiousInfected",
                "Immune"
            });

            DockableRegionPieChart drpc1 = new DockableRegionPieChart("Nepal");

            drpc1.Bind(WorldModel, "NPL");
            drpc1.Show(m_dockPanel, DockState.DockLeft);

            DockableRegionPieChart drpc2 = new DockableRegionPieChart("Ireland");

            drpc2.Bind(WorldModel, "IRL");
            drpc2.Show(m_dockPanel, DockState.DockLeft);

            DockablePropertyGrid dpg = new DockablePropertyGrid()
            {
                SelectedObject = WorldModel.ExecutionParameters,
                TabText        = "Simulation Timing"
            };

            dpg.Show(m_dockPanel, DockState.DockLeft);

            DockablePropertyGrid country = new DockablePropertyGrid()
            {
                SelectedObject = WorldModel.CountryForCode("USA"),
                TabText        = "Selected Country",
                ToolTipText    = "Selected Country",
            };

            country.ToolbarVisible = false;
            m_map.CountrySelected += data => country.SelectedObject = data;

            m_map.MdiParent = this;
            m_map.Show(m_dockPanel, DockState.Document);
            ((DockableConsole)m_console).Show(m_dockPanel, DockState.DockBottom);
            country.Show(dpg.Pane, DockAlignment.Bottom, 0.6);
            dc1.Show(m_dockPanel, DockState.DockRight);
            dc2.Show(dc1.Pane, DockAlignment.Bottom, 0.5);
        }