Exemplo n.º 1
0
 private void CountryPopUpEvent(object sender, EventArgs e)
 {
     try
     {
         foreach (var country in countries.Values)
         {
             bool here = false;
             foreach (var poly in country.polygons)
             {
                 if (HelperFunctions.IsPointInPolygon(poly, new PointF((pbox_map.PointToClient(MousePosition)).X * 2,
                                                                       (pbox_map.PointToClient(MousePosition)).Y * 2),
                                                      bmp.Size))
                 {
                     here = true;
                 }
             }
             if (here)
             {
                 customCountryPopUp = new CountryPopUp(country, this.slider_timeline.Value, dates, this)
                 {
                     Location = this.PointToClient(MousePosition)
                 };
                 this.Controls.Add(customCountryPopUp);
                 customCountryPopUp.BringToFront();
                 customCountryPopUp.BringToFront();
                 break;
             }
         }
     }
     catch { }
 }
Exemplo 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();
        }