Ejemplo n.º 1
0
        void DrawMap()
        {
            if (pbox_map.Width == 0)
            {
                return;
            }
            var saved         = new Dictionary <string, Country>();
            int maximInfected = 0;

            foreach (var country in countries.Values)
            {
                if (country.infected.Count > 1)
                {
                    maximInfected = Math.Max(maximInfected, country.infected.Last());
                }
            }
            bmp = new Bitmap(this.pbox_map.Width * 2, this.pbox_map.Height * 2);
            Graphics g = Graphics.FromImage(bmp);

            countries.Values.ToList().ForEach((country) => {
                country.polygons.ForEach((poly) => {
                    Brush brsh;
                    var imagePoly = HelperFunctions.PolygonToImagePoly(poly, bmp.Size).ToArray();
                    brsh          = new SolidBrush(Color.FromArgb(255, 255, 255));
                    try
                    {
                        g.FillPolygon(brsh, imagePoly);
                    }
                    catch { }
                    if (country.infected.Count > 0 && country.infected[slider_timeline.Value] > 0)
                    {
                        var clr = Color.FromArgb(Math.Max(20, Math.Min(255, (int)(255 * (((double)country.infected[slider_timeline.Value] * 5) / ((double)maximInfected))))), mainColor);
                        if (mainColor == Color.Transparent)
                        {
                            clr = Color.FromArgb(Math.Max(20, Math.Min(255, (int)(255 * (((double)country.infected[slider_timeline.Value] * 5) / ((double)maximInfected))))), HelperFunctions.GetRandomColor());
                        }
                        brsh = new SolidBrush(clr);
                        try
                        {
                            g.FillPolygon(brsh, imagePoly);
                        }
                        catch { }
                    }
                });
            });
            countries.Values.ToList().ForEach((country) => {
                country.polygons.ForEach((poly) => {
                    Pen pn = new Pen(mainColor, 3);
                    if (mainColor == Color.Transparent)
                    {
                        pn.Color = HelperFunctions.GetRandomColor();
                    }
                    try
                    {
                        g.DrawPolygon(pn, HelperFunctions.PolygonToImagePoly(poly, bmp.Size).ToArray());
                    }
                    catch { }
                });
            });
            this.pbox_map.Image = bmp;
        }
Ejemplo n.º 2
0
        void ProcessData()
        {
            Dictionary <string, string> savedLocations = new Dictionary <string, string>();
            StreamReader reader = new StreamReader("infected.csv");
            var          dates  = HelperFunctions.SplitCsv(reader.ReadLine());

            dates.Skip(4).ToList().ForEach((date) => this.dates.Add(DateTime.Parse(date)));

            while (!reader.EndOfStream)
            {
                var    entry  = HelperFunctions.SplitCsv(reader.ReadLine());
                PointD coords = new PointD(double.Parse(entry[2]), double.Parse(entry[3]));

                List <int> infected = new List <int>();
                entry.Skip(4).ToList().ForEach((infection) =>
                {
                    try { infected.Add(int.Parse(infection)); }
                    catch { try { infected.Add(infected.Last()); } catch { infected.Add(0); } }
                });
                if (savedLocations.ContainsKey(entry[1]))
                {
                    if (countries[savedLocations[entry[1]]].infected.Count == 0)
                    {
                        countries[savedLocations[entry[1]]].infected = infected;
                    }
                    else
                    {
                        for (int i = 0; i < countries[savedLocations[entry[1]]].infected.Count; i++)
                        {
                            countries[savedLocations[entry[1]]].infected[i] += infected[i];
                        }
                    }
                    continue;
                }
                if (countries.ContainsKey(entry[1]))
                {
                    if (countries[entry[1]].infected.Count == 0)
                    {
                        countries[entry[1]].infected = infected;
                    }
                    else
                    {
                        for (int i = 0; i < countries[entry[1]].infected.Count; i++)
                        {
                            countries[entry[1]].infected[i] += infected[i];
                        }
                    }
                    continue;
                }
                foreach (var country in countries.Values)
                {
                    bool inside = false;
                    foreach (var poly in country.polygons)
                    {
                        if (HelperFunctions.IsPointInPolygon(poly, HelperFunctions.CoordinateToPoint(coords, bmp.Size), bmp.Size))
                        {
                            inside = true;
                        }
                    }
                    if (inside)
                    {
                        savedLocations.Add(entry[1], country.name);
                        if (country.infected.Count == 0)
                        {
                            country.infected = infected;
                        }
                        else
                        {
                            for (int i = 0; i < country.infected.Count; i++)
                            {
                                country.infected[i] += infected[i];
                            }
                            this.slider_timeline.Maximum = country.infected.Count - 1;
                        }
                        break;
                    }
                }
            }
            reader = new StreamReader("dead.csv");
            reader.ReadLine();
            while (!reader.EndOfStream)
            {
                var        entry  = HelperFunctions.SplitCsv(reader.ReadLine());
                PointD     coords = new PointD(double.Parse(entry[2]), double.Parse(entry[3]));
                List <int> dead   = new List <int>();
                entry.Skip(4).ToList().ForEach((death) =>

                {
                    try { dead.Add(int.Parse(death)); }
                    catch { try { dead.Add(dead.Last()); } catch { dead.Add(0); } }
                });
                if (savedLocations.ContainsKey(entry[1]))
                {
                    if (countries[savedLocations[entry[1]]].dead.Count == 0)
                    {
                        countries[savedLocations[entry[1]]].dead = dead;
                    }
                    else
                    {
                        for (int i = 0; i < countries[savedLocations[entry[1]]].dead.Count; i++)
                        {
                            countries[savedLocations[entry[1]]].dead[i] += dead[i];
                        }
                    }
                    continue;
                }
                foreach (var country in countries.Values)
                {
                    bool inside = false;
                    foreach (var poly in country.polygons)
                    {
                        if (HelperFunctions.IsPointInPolygon(poly, HelperFunctions.CoordinateToPoint(coords, bmp.Size), bmp.Size))
                        {
                            inside = true;
                        }
                    }

                    if (inside)
                    {
                        if (country.dead.Count == 0)
                        {
                            country.dead = dead;
                        }
                        else
                        {
                            for (int i = 0; i < country.dead.Count; i++)
                            {
                                country.dead[i] += dead[i];
                            }
                        }
                        break;
                    }
                }
            }
            reader = new StreamReader("recovered.csv");
            reader.ReadLine();
            while (!reader.EndOfStream)
            {
                var        entry     = HelperFunctions.SplitCsv(reader.ReadLine());
                PointD     coords    = new PointD(double.Parse(entry[2]), double.Parse(entry[3]));
                List <int> recovered = new List <int>();
                entry.Skip(4).ToList().ForEach((recover) =>

                {
                    try { recovered.Add(int.Parse(recover)); }
                    catch { try { recovered.Add(recovered.Last()); } catch { recovered.Add(0); } }
                }); if (savedLocations.ContainsKey(entry[1]))
                {
                    if (countries[savedLocations[entry[1]]].recovered.Count == 0)
                    {
                        countries[savedLocations[entry[1]]].recovered = recovered;
                    }
                    else
                    {
                        for (int i = 0; i < countries[savedLocations[entry[1]]].recovered.Count; i++)
                        {
                            countries[savedLocations[entry[1]]].recovered[i] += recovered[i];
                        }
                    }
                    continue;
                }
                foreach (var country in countries.Values)
                {
                    bool inside = false;
                    foreach (var poly in country.polygons)
                    {
                        if (HelperFunctions.IsPointInPolygon(poly, HelperFunctions.CoordinateToPoint(coords, bmp.Size), bmp.Size))
                        {
                            inside = true;
                        }
                    }
                    if (inside)
                    {
                        if (country.recovered.Count == 0)
                        {
                            country.recovered = recovered;
                        }
                        else
                        {
                            for (int i = 0; i < country.recovered.Count; i++)
                            {
                                country.recovered[i] += recovered[i];
                            }
                        }
                        break;
                    }
                }
            }

            reader.Close();
        }