Ejemplo n.º 1
0
    public void PlotConfirmed(Covid19Data data)
    {
        Debug.Log(".CountryORRegion");
        ConfirmedGraph.gameObject.SetActive(true);
        ConfirmedGraph.PlotGraph(data);

        if (data.ProvinceORState == "")
        {
            State.text = "Not mentioned";
        }
        else
        {
            State.text = data.ProvinceORState;
        }

        Country.text = data.CountryORRegion;
    }
Ejemplo n.º 2
0
    public void PlotGraph(Covid19Data covidData)
    {
        CovidData = covidData;
        PlotGraph(CovidData.DayByDayData, lr);
        //int[] data = covidData.DayByDayData;
        //Latest.text = data[data.Length -1] + "";
        //ClearGraph();
        //rectTransform = graphContainer.GetComponent<RectTransform>();
        //dx = rectTransform.sizeDelta.x / data.Length;

        //if (data[data.Length - 1] != 0)
        //    dy = rectTransform.sizeDelta.y / data[data.Length - 1];
        //lr.positionCount = data.Length;
        //lr.startWidth = 0.01f;
        //lr.endWidth = 0.01f;
        //for (int i = 0; i<data.Length; i++)
        //{
        //    float x = dx * (i+1);
        //    float y = dy * data[i];
        //    CreateGraphPt(new Vector2(x, y), i);
        //}
    }
Ejemplo n.º 3
0
 public void PlotRecovered(Covid19Data data)
 {
     Debug.Log(".PlotRecovered");
     RecoveredGraph.gameObject.SetActive(true);
     RecoveredGraph.PlotGraph(data);
 }
Ejemplo n.º 4
0
 public void PlotDeath(Covid19Data data)
 {
     Debug.Log(".PlotDeath");
     DeathGraph.gameObject.SetActive(true);
     DeathGraph.PlotGraph(data);
 }
Ejemplo n.º 5
0
        private void UpdateWorldOMetersData()
        {
            ApplicationDbContext _dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                       .UseSqlServer(_configuration.GetConnectionString("DefaultConnection"))
                                                                       .Options);


            try
            {
                //Get data per country
                Covid19DataManager cov19DataManager = new Covid19DataManager();
                Covid19Data        cov19Data        = (Covid19Data)cov19DataManager.GetData(new Covid19WebDataSource()
                {
                    Id = "WorldOMeters"
                });

                WorldOMetersDataProvider  worldOMetersDataProvider = (WorldOMetersDataProvider)cov19DataManager.DataProviders.Where(d => d.DataSource.Id == "WorldOMeters").FirstOrDefault();
                WorldOMetersCountriesData countriesData            = worldOMetersDataProvider.GetCountries();

                if (countriesData != null && countriesData.Countries.Count() > 0)
                {
                    foreach (var countryData in countriesData.Countries)
                    {
                        //Add or update a country and its global region
                        if (_dbContext.CountriesAffected.Any(c => c.Name == countryData.Name.ToUpper())) //Update Country
                        {
                            // _logger.LogInformation($"Updating data for {countryData.Name}", DateTimeOffset.Now);

                            var dbCountry = _dbContext.CountriesAffected.Where(c => c.Name == countryData.Name.ToUpper()).FirstOrDefault();
                            var dbRegion  = _dbContext.Regions.Where(d => d.CountryId == dbCountry.Id).FirstOrDefault();

                            var dbDailyUpdate = _dbContext.DailyUpdates.Where(update => update.RegionId == dbRegion.Id && update.Date.Date == DateTime.Now.Date).FirstOrDefault();

                            if (dbDailyUpdate != null)
                            {
                                dbDailyUpdate.Date             = DateTime.Now;
                                dbDailyUpdate.TotalCases       = countryData.TotalCases < dbDailyUpdate.TotalCases ? dbDailyUpdate.TotalCases : countryData.TotalCases;                 //countryData.TotalCases;
                                dbDailyUpdate.NewCases         = countryData.NewCases;
                                dbDailyUpdate.TotalDeaths      = countryData.TotalDeaths < dbDailyUpdate.TotalDeaths ? dbDailyUpdate.TotalDeaths : countryData.TotalDeaths;             //countryData.TotalDeaths;
                                dbDailyUpdate.NewDeaths        = countryData.NewDeaths;
                                dbDailyUpdate.TotalRecovered   = countryData.TotalRecovered < dbDailyUpdate.TotalRecovered ? dbDailyUpdate.TotalRecovered : countryData.TotalRecovered; //countryData.TotalRecovered;
                                dbDailyUpdate.ActiveCases      = countryData.ActiveCases;
                                dbDailyUpdate.SeriouOrCritical = countryData.SeriouOrCritical;
                                dbDailyUpdate.MildCondition    = countryData.ActiveCases - countryData.SeriouOrCritical;
                                dbDailyUpdate.TotalTests       = countryData.TotalTests;
                                dbDailyUpdate.TotalCasesPerOneMillionPopulation  = countryData.TotalCasesPerOneMillionPopulation;
                                dbDailyUpdate.TotalDeathsPerOneMillionPopulation = countryData.TotalDeathsPerOneMillionPopulation;
                                dbDailyUpdate.TotalTestsPerOneMillionPopulation  = countryData.TotalTestsPerOneMillionPopulation;

                                //Check for missing data, and compose it
                                //Compute recovered cases
                                //if (dbDailyUpdate.TotalRecovered <= 0)
                                //{
                                //    dbDailyUpdate.TotalRecovered = dbDailyUpdate.TotalCases - dbDailyUpdate.TotalDeaths - dbDailyUpdate.ActiveCases;
                                //}
                                ////Compute mild condition
                                //if (dbDailyUpdate.MildCondition <= 0 && dbDailyUpdate.ActiveCases > 0 && dbDailyUpdate.ActiveCases > dbDailyUpdate.SeriouOrCritical)
                                //{
                                //    dbDailyUpdate.MildCondition = dbDailyUpdate.ActiveCases - dbDailyUpdate.SeriouOrCritical;
                                //}
                                //if (dbDailyUpdate.ActiveCases <= 0)
                                //{
                                //    dbDailyUpdate.ActiveCases = 0;
                                //    dbDailyUpdate.MildCondition = 0;
                                //}

                                _dbContext.DailyUpdates.Update(dbDailyUpdate);
                            }
                            else
                            {
                                var dbDailyUpdateYesterday = _dbContext.DailyUpdates.Where(update => update.RegionId == dbRegion.Id && update.Date.Date == DateTime.Now.Date.AddDays(-1)).FirstOrDefault();

                                var dbNewDailyUpdate = new DailyUpdate()
                                {
                                    RegionId = dbRegion.Id,
                                    Region   = dbRegion,
                                    Date     = DateTime.Now,

                                    TotalCases       = dbDailyUpdateYesterday == null ? countryData.TotalCases : countryData.TotalCases >= dbDailyUpdateYesterday.TotalCases ? countryData.TotalCases : dbDailyUpdateYesterday.TotalCases,                     // countryData.TotalCases
                                    NewCases         = countryData.NewCases,
                                    TotalDeaths      = dbDailyUpdateYesterday == null ? countryData.TotalDeaths : countryData.TotalDeaths >= dbDailyUpdateYesterday.TotalDeaths ? countryData.TotalDeaths : dbDailyUpdateYesterday.TotalDeaths,                //countryData.TotalDeaths,
                                    NewDeaths        = countryData.NewDeaths,
                                    TotalRecovered   = dbDailyUpdateYesterday == null ? countryData.TotalRecovered : countryData.TotalRecovered >= dbDailyUpdateYesterday.TotalRecovered ? countryData.TotalRecovered : dbDailyUpdateYesterday.TotalRecovered, //countryData.TotalRecovered,
                                    ActiveCases      = countryData.ActiveCases,
                                    SeriouOrCritical = countryData.SeriouOrCritical,
                                    MildCondition    = countryData.ActiveCases - countryData.SeriouOrCritical,
                                    TotalTests       = countryData.TotalTests,
                                    TotalCasesPerOneMillionPopulation  = countryData.TotalCasesPerOneMillionPopulation,
                                    TotalDeathsPerOneMillionPopulation = countryData.TotalDeathsPerOneMillionPopulation,
                                    TotalTestsPerOneMillionPopulation  = countryData.TotalTestsPerOneMillionPopulation
                                };

                                //Check for missing data, and compose it
                                //Compute recovered cases
                                //if (dbNewDailyUpdate.TotalRecovered <= 0)
                                //{
                                //    dbNewDailyUpdate.TotalRecovered = dbNewDailyUpdate.TotalCases - dbNewDailyUpdate.TotalDeaths - dbNewDailyUpdate.ActiveCases;
                                //}
                                ////Compute mild condition
                                //if (dbNewDailyUpdate.MildCondition <= 0 && dbNewDailyUpdate.ActiveCases > 0 && dbNewDailyUpdate.ActiveCases > dbNewDailyUpdate.SeriouOrCritical)
                                //{
                                //    dbNewDailyUpdate.MildCondition = dbNewDailyUpdate.ActiveCases - dbNewDailyUpdate.SeriouOrCritical;
                                //}
                                //if (dbNewDailyUpdate.ActiveCases <= 0)
                                //{
                                //    dbNewDailyUpdate.ActiveCases = 0;
                                //    dbNewDailyUpdate.MildCondition = 0;
                                //}

                                _dbContext.DailyUpdates.Add(dbNewDailyUpdate);
                            }
                            _dbContext.Regions.Update(dbRegion);
                            _dbContext.CountriesAffected.Update(dbCountry);
                        }
                        else //Add Country and its global region
                        {
                            //_logger.LogInformation($"Adding data for {countryData.Name}", DateTimeOffset.Now);
                            var dbCountry = new Country()
                            {
                                Name = countryData.Name.ToUpper()
                            };
                            var dbRegion = new Region()
                            {
                                Name      = countryData.Name.ToUpper(),
                                CountryId = dbCountry.Id,
                                Country   = dbCountry
                            };

                            _dbContext.CountriesAffected.Add(dbCountry);
                            _dbContext.Regions.Add(dbRegion);

                            _dbContext.DailyUpdates.Add(new DailyUpdate()
                            {
                                RegionId         = dbRegion.Id,
                                Region           = dbRegion,
                                Date             = DateTime.Now,
                                TotalCases       = countryData.TotalCases,
                                NewCases         = countryData.NewCases,
                                TotalDeaths      = countryData.TotalDeaths,
                                NewDeaths        = countryData.NewDeaths,
                                TotalRecovered   = countryData.TotalRecovered,
                                ActiveCases      = countryData.ActiveCases,
                                SeriouOrCritical = countryData.SeriouOrCritical,
                                MildCondition    = countryData.ActiveCases - countryData.SeriouOrCritical,
                                TotalCasesPerOneMillionPopulation = countryData.TotalCasesPerOneMillionPopulation
                            });
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            try
            {
                //dataDB
                _dbContext.SaveChanges();
                _dbContext.Dispose();
            }
            catch (Exception e)
            {
                _logger.LogCritical(e, "Unable to save data", DateTimeOffset.Now);
            }
        }
Ejemplo n.º 6
0
    void PopulateData()
    {
        int row = Grid.GetUpperBound(0);
        int col = Grid.GetUpperBound(1);

        DateTime    StartDt, EndDt;
        CultureInfo culture = new CultureInfo("en-US");

        Debug.Log(Grid[4, 0] + ", " + Grid[row - 2, 0]);

        DateTime.TryParse(Grid[4, 0], culture, DateTimeStyles.None, out StartDt);
        DateTime.TryParse(Grid[row - 2, 0], culture, DateTimeStyles.None, out EndDt);
        int totalDays = (EndDt - StartDt).Days;

        GraphMaster.Instance.SetupDates(StartDt, EndDt);
        Debug.Log(StartDt + ", " + EndDt + ", days : " + totalDays);
        for (int i = 0; i < col; i++)
        {
            float lat, lon = 0;
            if (!float.TryParse(Grid[2, i], out lat))
            {
                continue;
            }

            if (!float.TryParse(Grid[3, i], out lon))
            {
                continue;
            }

            DateTime dt = DateTime.Now;

            int[] DayByDay = new int[totalDays];
            for (int j = 4; j < row - 2; ++j)
            {
                int val = 0;
                int.TryParse(Grid[j, i], out val);
                DayByDay[j - 4] = val;
            }

            Covid19Data covidData = new Covid19Data(Grid[0, i],
                                                    Grid[1, i],
                                                    lat,
                                                    lon,
                                                    StartDt,
                                                    EndDt,
                                                    status,
                                                    DayByDay
                                                    );

            string loc = covidData.CountryORRegion + lat.ToString() + lon.ToString();
            //Order of Priority
            //Confirmed is the primary Data, then death and then recovered
            //so the 3Dinstance is created based on confirmed and then updating that instance with death and recovered
            if (status == Covid19Data.Status.confirmed)
            {
                if (NoOfCasesConfirmed.ContainsKey(covidData.CountryORRegion))
                {
                    NoOfCasesConfirmed[covidData.CountryORRegion] += covidData.DayByDayData[covidData.DayByDayData.Length - 1];
                }
                else
                {
                    NoOfCasesConfirmed.Add(covidData.CountryORRegion, covidData.DayByDayData[covidData.DayByDayData.Length - 1]);
                }

                if (CountryConfirmedData.ContainsKey(covidData.CountryORRegion))
                {
                    CountryConfirmedData[covidData.CountryORRegion].Add(covidData);
                }
                else
                {
                    List <Covid19Data> list = new List <Covid19Data>();
                    list.Add(covidData);
                    CountryConfirmedData[covidData.CountryORRegion] = list;
                }
            }
            else if (status == Covid19Data.Status.dead)
            {
                if (NoOfCasesDead.ContainsKey(covidData.CountryORRegion))
                {
                    NoOfCasesDead[covidData.CountryORRegion] += covidData.DayByDayData[covidData.DayByDayData.Length - 1];
                }
                else
                {
                    NoOfCasesDead.Add(covidData.CountryORRegion, covidData.DayByDayData[covidData.DayByDayData.Length - 1]);
                }

                if (CountryDeathData.ContainsKey(covidData.CountryORRegion))
                {
                    CountryDeathData[covidData.CountryORRegion].Add(covidData);
                }
                else
                {
                    List <Covid19Data> list = new List <Covid19Data>();
                    list.Add(covidData);
                    CountryDeathData[covidData.CountryORRegion] = list;
                }
            }
            else if (status == Covid19Data.Status.recovered)
            {
                if (NoOfCasesRecovered.ContainsKey(covidData.CountryORRegion))
                {
                    NoOfCasesRecovered[covidData.CountryORRegion] += covidData.DayByDayData[covidData.DayByDayData.Length - 1];
                }
                else
                {
                    NoOfCasesRecovered.Add(covidData.CountryORRegion, covidData.DayByDayData[covidData.DayByDayData.Length - 1]);
                }

                if (CountryRecoveredData.ContainsKey(covidData.CountryORRegion))
                {
                    CountryRecoveredData[covidData.CountryORRegion].Add(covidData);
                }
                else
                {
                    List <Covid19Data> list = new List <Covid19Data>();
                    list.Add(covidData);
                    CountryRecoveredData[covidData.CountryORRegion] = list;
                }
            }



            if (CovidLoc.ContainsKey(loc))
            {
                //Debug.Log("Key Already Existing " + loc +", at : " + i);
                if (status == Covid19Data.Status.dead)
                {
                    //Debug.Log("Adding Covid19 death data");
                    CovidLoc[loc].GetComponent <CovidData3DInstance>().CovidData_Death = covidData;
                }
                else if (status == Covid19Data.Status.recovered)
                {
                    CovidLoc[loc].GetComponent <CovidData3DInstance>().CovidData_Recovered = covidData;
                }
            }
            else
            {
                GameObject dataPointClone = Instantiate(DataPointPrefab, transform) as GameObject;
                dataPointClone.GetComponent <CovidData3DInstance>().Init(covidData, transform, dataColor);
                CovidLoc.Add(loc, dataPointClone);

                if (covidData.CountryORRegion == "US")
                {
                    if (i % 10 != 0)
                    {
                        dataPointClone.SetActive(false);
                    }
                }
            }
        }

        //foreach(var entry in CountryConfirmedData)
        //{
        //    Debug.Log(entry.Key +" "+entry.Value.Count);
        //}

        isDataReceived = false;
    }
Ejemplo n.º 7
0
        public async Task <Covid19Data> ConstruirListaParaGraficos()
        {
            string _dia = null;
            string _mes = null;
            string _ano = null;

            Covid19Data CovidData = new Covid19Data()
            {
                ListaMes  = new List <Covid19Mensal>(),
                ListaDias = new List <Covid19Dia>()
            };

            for (int ano = 2020; ano <= DateTime.Now.Year; ano++)
            {
                _ano = ano.ToString();
                for (int mes = 1; mes <= DateTime.Now.Month; mes++)
                {
                    var quantidadeDeDias = 0;
                    if (DateTime.Now.Hour >= 21)
                    {
                        quantidadeDeDias = mes == DateTime.Now.Month ? DateTime.Now.Day : DateTime.DaysInMonth(ano, mes);
                    }
                    else
                    {
                        quantidadeDeDias = mes == DateTime.Now.Month ? DateTime.Now.Day - 1 : DateTime.DaysInMonth(ano, mes);
                    }

                    _mes = AdicionarZero(mes.ToString());
                    string MesNome = ReplacePorNomeDoMes(mes);

                    for (int dia = 1; dia <= quantidadeDeDias; dia++)
                    {
                        _dia = AdicionarZero(dia.ToString());
                        var objHj = await ConstruirObjetoDeHoje(_dia, _mes, _ano);

                        if (dia + 1 > quantidadeDeDias)
                        {
                            CovidData.ListaMes.Add(new Covid19Mensal()
                            {
                                Mes    = MesNome,
                                Mortos = double.Parse(objHj.Deaths),
                                InfectadosEmTratamento = double.Parse(objHj.Active),
                                InfectadosCurados      = double.Parse(objHj.Recovered),
                                CasosConfirmados       = double.Parse(objHj.Confirmed)
                            });
                        }

                        CovidData.ListaDias.Add(new Covid19Dia()
                        {
                            Mes    = MesNome,
                            Dia    = dia,
                            Mortos = double.Parse(objHj.Deaths),
                            InfectadosEmTratamento = double.Parse(objHj.Active),
                            InfectadosCurados      = double.Parse(objHj.Recovered),
                            CasosConfirmados       = double.Parse(objHj.Confirmed)
                        });
                    }
                }
            }

            return(CovidData);
        }
Ejemplo n.º 8
0
    public void Init(Covid19Data covidData, Transform earth, Color32 color)
    {
        initScale = transform.localScale;
        //SelectionHighlight.SetActive(false);
        CovidData_Confirmed = covidData;
        Earth                   = earth;
        posOnSphere             = AppUtils.LatLonToPositionOnSphere(CovidData_Confirmed.Lat, CovidData_Confirmed.Long, Earth.localScale.x * 2.1f);
        transform.localPosition = posOnSphere;
        Color                   = color;
        Vector3 dir      = new Vector3(0, 1, 0);
        Vector3 crossDir = Vector3.Cross(dir, posOnSphere);
        float   angle    = Vector3.Angle(dir, posOnSphere);

        transform.Rotate(crossDir, angle, Space.Self);
        float limit = 500;
        float val   = CovidData_Confirmed.DayByDayData[CovidData_Confirmed.DayByDayData.Length - 1];

        if (val < limit)
        {
            newVal = AppUtils.Remap(val, 0, limit, 0, 255);
        }
        else
        {
            newVal = 255;
        }

        UnSelectionColor = new Color32((byte)newVal, 255, 0, 255);
        sRenderer.color  = UnSelectionColor;

        if (CovidData_Confirmed.ProvinceORState == "")
        {
            locText.text = "Not mentioned";
        }
        else
        {
            locText.text = CovidData_Confirmed.ProvinceORState;
        }

        locText.text += ", " + CovidData_Confirmed.CountryORRegion;

        //Label.SetActive(false);
        Label2.SetActive(false);
        ClickedOnDataEvent         += AmINear;
        DataBars.ClickedOnBarEvent += ShowOrHideMe;
        RotationManipulator.RotationGestureHandler += UpdateLineRenderePos;
        sRenderer.enabled = false;

        if (covidData.CountryORRegion == "US")
        {
            if (UnityEngine.Random.Range(1, 100) % 2 == 0)
            {
                gameObject.SetActive(false);
            }
            //transform.localScale /= 10;
        }

        lr            = gameObject.GetComponent <LineRenderer>();
        lr.enabled    = false;
        lr.startWidth = lr.endWidth = 0.001f;

        countryText.text = CovidData_Confirmed.ProvinceORState;
        InitScale        = transform.localScale;
    }