Esempio n. 1
0
        public NemocniceData CelaCR()
        {
            NemocniceData cr  = new NemocniceData();
            List <Region> cdH = new List <Region>();
            var           fd  = NemocniceData.Aggregate(this.regions); //fd.regionId = 0;

            fd.name   = "Celá ČR";
            fd.region = "CR";
            cdH.Add(fd);
            cr.regions     = cdH.ToList();
            cr.lastUpdated = this.lastUpdated;

            return(cr);
        }
Esempio n. 2
0
        public NemocniceData PoKrajich()
        {
            NemocniceData krajF = new NemocniceData();
            List <Region> krajFH = new List <Region>();
            int           krajId = 0;
            List <string> kraje = new string[] { "PHA", "STC", "JHM", "MSK" }.Union(this.regions.Select(m => m.region).Distinct()).ToList();

            foreach (var kraj in kraje.OrderBy(o => kraje.IndexOf(o)))
            {
                var hsF = this.regions.Where(m => m.region == kraj).ToArray();
                var fd  = NemocniceData.Aggregate(hsF); //fd.regionId = ++krajId;
                fd.name = hsF.First().regionFull();
                krajFH.Add(fd);
            }
            krajF.regions = krajFH.ToList(); krajF.lastUpdated = this.lastUpdated;

            return(krajF);
        }
Esempio n. 3
0
        private static void OpenDataDIP()
        {
            List <NemocniceData.Region> raw = new List <NemocniceData.Region>();

            //process https://dip.mzcr.cz/api/v1/kapacity-intenzivni-pece-vlna-2.csv

            DateTime mindate = DateTime.Now.Date.AddDays(-120);

            using (var net = new System.Net.Http.HttpClient().GetStreamAsync("https://dip.mzcr.cz/api/v1/kapacity-intenzivni-pece-zdravotnicke-zarizeni-04-2021.csv"))
            {
                using (System.IO.StreamReader rr = new StreamReader(net.Result))
                {
                    var csv = new CsvHelper.CsvReader(rr, new CsvHelper.Configuration.CsvConfiguration(System.Globalization.CultureInfo.GetCultureInfo("cs"))
                    {
                        HasHeaderRecord = true, Delimiter = ","
                    });
                    csv.Read(); csv.ReadHeader();
                    //csv.Read();//skip second line
                    while (csv.Read())
                    {
                        DateTime?date = Devmasters.DT.Util.ParseDateTime(csv.GetField <string>("datum")?.Trim(), null);
                        if (date == null)
                        {
                            continue;
                        }
                        DateTime dt = date.Value;
                        if (dt < mindate)
                        {
                            continue;
                        }
                        Console.WriteLine(".");

                        string kraj_nuts_kod = csv.GetField <string>("kraj_nuts_kod");
                        string region        = Kraje[kraj_nuts_kod];
                        var    r             = new NemocniceData.Region();
                        r.lastModified = date.Value;
                        r.region       = region;
                        r.name         = csv.GetField <string>("zz_nazev");
                        r.UPV_celkem   = 0;
                        r.UPV_volna    = 0;

                        r.ECMO_celkem = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("ecmo_kapacita_celkem"), 0).Value;
                        r.ECMO_volna  = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("ecmo_kapacita_volna"), 0).Value;

                        r.CRRT_celkem = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("cvvhd_kapacita_celkem"), 0).Value;
                        r.CRRT_volna  = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("cvvhd_kapacita_volna"), 0).Value;

                        r.IHD_celkem = 0;
                        r.IHD_volna  = 0;

                        r.AROJIP_luzka_celkem  = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("luzka_upv_niv_kapacita_celkem"), 0).Value;
                        r.AROJIP_luzka_covid   = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("luzka_upv_niv_kapacita_volna_covid_pozitivni"), 0).Value;
                        r.AROJIP_luzka_necovid = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("luzka_upv_niv_kapacita_volna_covid_negativni"), 0).Value;

                        r.Standard_luzka_s_kyslikem_celkem  = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("luzka_standard_kyslik_kapacita_celkem"), 0).Value;
                        r.Standard_luzka_s_kyslikem_covid   = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("luzka_standard_kyslik_kapacita_volna_covid_pozitivni"), 0).Value;
                        r.Standard_luzka_s_kyslikem_necovid = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("luzka_standard_kyslik_kapacita_volna_covid_negativni"), 0).Value;

                        //r.Lekari_AROJIP_celkem = 0;
                        //r.Lekari_AROJIP_dostupni = 0;

                        //r.Sestry_AROJIP_celkem = 0;
                        //r.Sestry_AROJIP_dostupni = 0;
                        //r.Standard_luzka_celkem = 0;
                        //r.Standard_luzka_s_monitor_celkem = 0;

                        r.Ventilatory_prenosne_celkem    = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("ventilatory_prenosne_kapacita_celkem"), 0).Value;
                        r.Ventilatory_operacnisal_celkem = Devmasters.TextUtil.ConvertToInt(csv.GetField <string>("ventilatory_operacni_sal_kapacita_celkem"), 0).Value;


                        raw.Add(r);
                    }
                }
            }
            Devmasters.Logging.Logger.Root.Info("Saving");
            var dates = raw.Select(m => m.lastModified).Distinct();
            var kraje = raw.Select(m => m.region).Distinct();

            foreach (var dt in dates.Where(m => m > mindate))
            {
                Console.WriteLine(dt);

                NemocniceData nem = null; //new NemocniceData();
                var           id  = "id_" + dt.ToString("yyyy-MM-dd");
                List <NemocniceData.Region> nr = new List <NemocniceData.Region>();
                foreach (var kr in kraje)
                {
                    var lines = raw.Where(m => m.lastModified == dt && m.region == kr).ToArray();
                    var r     = NemocniceData.Aggregate(lines);
                    r.region = kr;
                    nr.Add(r);
                }

                try
                {
                    nem = ds.GetItem(id); // new NemocniceData();
                }
                catch (Exception)
                {
                }
                if (nem == null)
                {
                    nem = new NemocniceData();
                }
                nem.id          = id;
                nem.regions     = nr;
                nem.lastUpdated = dt;
                ds.AddOrUpdateItem(nem, HlidacStatu.Api.V2.Dataset.Typed.ItemInsertMode.rewrite);
            }
            //ds.AddOrUpdateItem(nd, HlidacStatu.Api.V2.Dataset.Typed.ItemInsertMode.rewrite);
        }