Esempio n. 1
0
        private static bool IsDifferent(string filename, Landkreise landkreise)
        {
            var rawResult = JsonConvert.SerializeObject(landkreise);
            var localRaw  = File.ReadAllText(filename);

            return(localRaw.Length != rawResult.Length);
        }
Esempio n. 2
0
        private Landkreise ConvertToLandkreise(RkiCoronaLandkreiseResult result)
        {
            var lk = result.features.FirstOrDefault();

            if (lk == null)
            {
                return(new Landkreise());
            }

            var strLastUpdate = lk.attributes.last_update.RemoveTimeFromLastUpdateString();

            if (DateTime.TryParse(strLastUpdate, out var lastUpdate))
            {
                var landkreise = new Landkreise
                {
                    Date      = lastUpdate,
                    Districts = new List <Landkreis>()
                };

                foreach (var item in result.features)
                {
                    landkreise.Districts.Add(new Landkreis
                    {
                        Name          = item.attributes.GEN,
                        WeekIncidence = item.attributes.cases7_per_100k,
                        Cases         = item.attributes.cases,
                        Deaths        = item.attributes.deaths
                    });
                }

                return(landkreise);
            }

            return(new Landkreise());
        }
        public int Run(string path)
        {
            var newComponent = RkiCoronaLandkreiseComponent.GetInstance();
            var files        = this.GetRkiFiles(path).ToList();

            foreach (var item in files)
            {
                var legacyData = JsonConvert.DeserializeObject <LegacyDataFormat>(File.ReadAllText(item));

                var date = legacyData.lastUpdate.RemoveTimeFromLastUpdateString();

                var newFilename = $"{HelperExtension.SubFolderRkiData()}/{HelperExtension.RkiFilename}-{date}.json";

                if (File.Exists(newFilename))
                {
                    continue;
                }

                var landkreise = new Landkreise();
                var d          = DateTime.Parse(date);
                landkreise.Date      = d;
                landkreise.Districts = legacyData.districts.Select(s =>
                                                                   new Landkreis
                {
                    Name          = s.name,
                    Date          = d,
                    Deaths        = s.deaths,
                    WeekIncidence = s.weekIncidence
                }
                                                                   ).ToList();

                newComponent.SaveToFile(landkreise, newFilename);
            }

            return(files.Count());
        }
Esempio n. 4
0
        internal void SaveToFile(Landkreise landkreise, string filename)
        {
            var contentStr = JsonConvert.SerializeObject(landkreise);

            File.WriteAllText(filename, contentStr);
        }