Exemplo n.º 1
0
        private static void ProcessPacienti()
        {
            DateTime startDt = DateTime.Now.Date.AddDays(-30);

            using (var reader = new StreamReader(new System.Net.Http.HttpClient().GetStreamAsync("https://onemocneni-aktualne.mzcr.cz/api/v2/covid-19/hospitalizace.csv").Result))
            {
                using (var csv = new CsvReader(reader, new CsvHelper.Configuration.CsvConfiguration(System.Globalization.CultureInfo.InvariantCulture)
                {
                    Delimiter = ",",
                    IgnoreBlankLines = true,
                    HasHeaderRecord = true,
                    TrimOptions = CsvHelper.Configuration.TrimOptions.Trim
                }))
                {
                    //csv.Context.RegisterClassMap<NemocniceMap>();
                    //var records = csv.GetRecords<Nemocnice>().ToArray();
                    csv.Read();
                    csv.ReadHeader();
                    while (csv.Read())
                    {
                        DateTime?dt = Devmasters.DT.Util.ParseDateTime(csv["datum"], null);

                        if (dt.HasValue && dt.Value >= startDt)
                        {
                            string id = "id_" + dt.Value.ToString("yyyy-MM-dd");
                            Console.Write(dt.Value.ToString("yyyy-MM-dd "));
                            NemocniceData data = null;
                            try
                            {
                                data = ds.GetItem(id);
                            }
                            catch (Exception)
                            {
                            }
                            if (data == null)
                            {
                                continue;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        static DateTime startDt = DateTime.Now.Date.AddDays(-10); //new DateTime(2020,09,04);
        public static void ProcessExcelObsazenost(string fn, HlidacStatu.Api.V2.Dataset.Typed.Dataset <NemocniceData> ds)
        {
            Devmasters.Logging.Logger.Root.Info($"ProcessExcelObsazenost {fn} ");

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            using (var p = new ExcelPackage(new System.IO.FileInfo(fn)))
            {
                foreach (var ws in p.Workbook.Worksheets)
                {
                    //first date  2020-09-04

                    for (int row = 11; row < 100000; row++)
                    {
                        var dt = ws.Cells[row, 1].GetValue <DateTime?>();
                        if (dt.HasValue && dt.Value >= startDt)
                        {
                            string id = "id_" + dt.Value.ToString("yyyy-MM-dd");
                            Console.Write(dt.Value.ToString("yyyy-MM-dd "));
                            NemocniceData data = null;
                            try
                            {
                                data = ds.GetItem(id);
                            }
                            catch (Exception)
                            {
                            }
                            if (data == null)
                            {
                                continue;
                            }

                            var region = data.regions.FirstOrDefault(m => m.region == NemocniceData.ExcelWorkBookToRegion(ws.Name));
                            if (region != null)
                            {
                                var idx = data.regions.IndexOf(region);
                                data.regions[idx].Pacienti_bezpriznaku = ws.Cells[row, 7].GetValue <int>();
                                data.regions[idx].Pacienti_lehky       = ws.Cells[row, 8].GetValue <int>();
                                data.regions[idx].Pacienti_stredni     = ws.Cells[row, 9].GetValue <int>();
                                data.regions[idx].Pacienti_tezky       = ws.Cells[row, 10].GetValue <int>();
                                data.regions[idx].Pacienti_zemreli     = ws.Cells[row, 22].GetValue <int>() - ws.Cells[row - 1, 22].GetValue <int>();

                                Devmasters.Logging.Logger.Root.Info($"ProcessExcelObsazenost save {ws.Name} - {dt.Value.ToString("yyyy-MM-dd ")} - {region.region} ");
                                ds.AddOrUpdateItem(data, HlidacStatu.Api.V2.Dataset.Typed.ItemInsertMode.rewrite);
                            }
                            else
                            {
                                Console.WriteLine("not found region " + ws.Name);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static void ProcessXML(Devmasters.Args args, string name)
        {
            logger.Debug($"Starting {name}.xml");
            if (System.IO.File.Exists(name + ".xml"))
            {
                if (args.Exists("/uselocal"))
                {
                    //skip next, use local file
                }
                else if (force || (DateTime.Now - new System.IO.FileInfo(name + ".xml").LastWriteTime).TotalDays > 4)
                {
                    logger.Debug($"downloading new {name}.xml");
                    Console.WriteLine($"Downloading new {name}");
                    DownloadFile(name);
                }
            }
            else
            {
                logger.Debug($"downloading new {name}.xml");
                Console.WriteLine($"Downloading {name}");
                DownloadFile(name);
            }

            if (!System.IO.File.Exists(name + ".xml"))
            {
                return;
            }

            rawXML d = null;

            Console.WriteLine($"Deserializing {name}");
            logger.Debug($"Deserializing {name}.xml");
            using (var xmlReader = new System.IO.StreamReader(name + ".xml"))
            {
                var serializer = new XmlSerializer(typeof(rawXML));
                d = (rawXML)serializer.Deserialize(xmlReader);
            }
            Console.WriteLine($"{d.Subjekt?.Count()} subjects");



            Devmasters.Batch.Manager.DoActionForAll <xmlSubjekt>(d.Subjekt //.Where(m=>m.ico== "3493661")  //debug
                                                                 , subj =>
            {
                majitele item = majitele.GetMajitele(subj);
                if (item != null && item?.skutecni_majitele?.Count() > 0)
                {
                    if (!ds.ItemExists(item.ico) || force)
                    {
                        item.UpdateOsobaId();
                        ds.AddOrUpdateItem(item, HlidacStatu.Api.V2.Dataset.Typed.ItemInsertMode.rewrite);
                    }
                    else
                    {
                        //check change
                        var old = ds.GetItem(item.ico);
                        if (old != null)
                        {
                            var same = true;
                            if (old.skutecni_majitele?.Count() != item.skutecni_majitele?.Count())
                            {
                                same = false;
                            }
                            else if (item.skutecni_majitele?.Count() == old.skutecni_majitele?.Count() && item.skutecni_majitele?.Count() > 0)
                            {
                                foreach (var sm in item.skutecni_majitele)
                                {
                                    same = same && old.skutecni_majitele.Any(m =>
                                                                             m.osoba_jmeno == sm.osoba_jmeno &&
                                                                             m.osoba_prijmeni == sm.osoba_prijmeni &&
                                                                             m.osoba_datum_narozeni == sm.osoba_datum_narozeni &&
                                                                             m.osoba_titul_pred == sm.osoba_titul_pred &&
                                                                             m.osoba_titul_za == sm.osoba_titul_za &&
                                                                             m.adresa_cast_obce == sm.adresa_cast_obce &&
                                                                             m.adresa_cislo_ev == sm.adresa_cislo_ev &&
                                                                             m.adresa_cislo_or == sm.adresa_cislo_or &&
                                                                             m.adresa_cislo_po == sm.adresa_cislo_po &&
                                                                             m.adresa_obec == sm.adresa_obec &&
                                                                             m.adresa_okres == sm.adresa_okres &&
                                                                             m.adresa_psc == sm.adresa_psc &&
                                                                             m.adresa_stat_nazev == sm.adresa_stat_nazev &&
                                                                             m.adresa_text == sm.adresa_text &&
                                                                             m.adresa_ulice == sm.adresa_ulice &&
                                                                             m.slovni_vyjadreni == sm.slovni_vyjadreni &&
                                                                             m.podil == sm.podil &&
                                                                             m.postaveni == sm.postaveni &&
                                                                             !string.IsNullOrEmpty(m.osobaId)
                                                                             );
                                }
                            }
                            if (same == false)
                            {
                                item.UpdateOsobaId();
                                ds.AddOrUpdateItem(item, HlidacStatu.Api.V2.Dataset.Typed.ItemInsertMode.rewrite);
                            }
                        }
                    }
                }
                return(new Devmasters.Batch.ActionOutputData());
            }, Devmasters.Batch.Manager.DefaultOutputWriter, Devmasters.Batch.Manager.DefaultProgressWriter,
                                                                 !System.Diagnostics.Debugger.IsAttached,
                                                                 maxDegreeOfParallelism: 4, prefix: $"{name} ITEMS ");
        }