示例#1
0
        public ImmutableArray <StatsDaily> GetStatsFromRaw(string raw)
        {
            ImmutableArray <StatsDaily> result = ImmutableArray <StatsDaily> .Empty;

            string[]   lines    = raw.Split('\n');
            var        header   = ParseHeader(lines[0]);
            StatsDaily previous = null;

            foreach (string line in lines.Skip(1))
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    var dailyData = GetDailyStatsFromRaw(header, line, previous?.StatePerTreatment.DeceasedToDate, previous?.StatePerTreatment.OutOfHospitalToDate);
                    result   = result.Add(dailyData);
                    previous = dailyData;
                }
            }
            return(result);
        }
示例#2
0
        StatsDaily GetDailyStatsFromRaw(ImmutableDictionary <string, int> header, string line, int?previousDecasedToDate, int?previousOutOfHospitalToDate)
        {
            var fields              = ParseLine(line);
            int?deceasedToDate      = GetInt("state.deceased.todate", header, fields);
            int?deceased            = GetDelta(deceasedToDate, previousDecasedToDate);
            int?outOfHospitalToDate = GetInt("state.out_of_hospital.todate", header, fields);
            int?outOfHospital       = GetDelta(outOfHospitalToDate, previousOutOfHospitalToDate);
            var cases = new Cases(
                GetInt("cases.confirmed", header, fields),
                GetInt("cases.confirmed.todate", header, fields),
                GetInt("cases.recovered.todate", header, fields),
                GetInt("cases.closed.todate", header, fields),
                GetInt("cases.active", header, fields),
                new HealthSystemSCases(GetInt("cases.hs.employee.confirmed.todate", header, fields)),
                new RetirementHomeCases(
                    GetInt("cases.rh.employee.confirmed.todate", header, fields),
                    GetInt("cases.rh.occupant.confirmed.todate", header, fields)
                    ),
                new UnclassifiedCases(GetInt("cases.unclassified.confirmed.todate", header, fields))
                );
            var perTreatment = new PerTreatment(
                GetInt("state.in_hospital", header, fields),
                GetInt("state.in_hospital.todate", header, fields),
                GetInt("state.icu", header, fields),
                GetInt("state.critical", header, fields),
                deceasedToDate,
                deceased,
                outOfHospitalToDate,
                outOfHospital,
                GetInt("state.recovered.todate", header, fields)
                );
            var perRegion = ImmutableDictionary <string, int?> .Empty;

            foreach (var pair in header)
            {
                string[] keyParts = pair.Key.Split('.');
                if (keyParts.Length == 3 && keyParts[0] == "region" && keyParts[2] == "todate")
                {
                    perRegion = perRegion.Add(keyParts[1], GetInt(fields[pair.Value]));
                }
            }
            var perAgeSum = ImmutableArray <PerAgeBucket> .Empty;

            foreach (var bucket in ageBuckets)
            {
                var perAge = new PerAgeBucket(
                    bucket.AgeFrom,
                    bucket.AgeTo,
                    GetInt($"age.{bucket.Key}.todate", header, fields),
                    GetInt($"age.female.{bucket.Key}.todate", header, fields),
                    GetInt($"age.male.{bucket.Key}.todate", header, fields)
                    );
                perAgeSum = perAgeSum.Add(perAge);
            }
            var deceasedPerAge = ImmutableArray <PerAgeBucket> .Empty;

            foreach (var bucket in ageBuckets)
            {
                var perAge = new PerAgeBucket(
                    bucket.AgeFrom,
                    bucket.AgeTo,
                    GetInt($"deceased.{bucket.Key}.todate", header, fields),
                    GetInt($"deceased.female.{bucket.Key}.todate", header, fields),
                    GetInt($"deceased.male.{bucket.Key}.todate", header, fields)
                    );
                deceasedPerAge = deceasedPerAge.Add(perAge);
            }
            var date   = GetDate(fields[header["date"]]);
            var result = new StatsDaily(
                GetInt("day", header, fields) ?? 0,
                date.Year,
                date.Month,
                date.Day,
                fields[header["phase"]],
                GetInt("tests.performed.todate", header, fields),
                GetInt("tests.performed", header, fields),
                GetInt("tests.positive.todate", header, fields),
                GetInt("tests.positive", header, fields),
                new Tests(
                    performed: new CommonTests(
                        GetInt("tests.performed.todate", header, fields),
                        GetInt("tests.performed", header, fields)
                        ),
                    positive: new CommonTests(
                        GetInt("tests.positive.todate", header, fields),
                        GetInt("tests.positive", header, fields)
                        ),
                    regular: new RegularTests(
                        performed: new CommonTests(
                            GetInt("tests.regular.performed.todate", header, fields),
                            GetInt("tests.regular.performed", header, fields)
                            ),
                        positive: new CommonTests(
                            GetInt("tests.regular.positive.todate", header, fields),
                            GetInt("tests.regular.positive", header, fields)
                            )
                        ),
                    nSApr20: new RegularTests(
                        performed: new CommonTests(
                            GetInt("tests.ns-apr20.performed.todate", header, fields),
                            GetInt("tests.ns-apr20.performed", header, fields)
                            ),
                        positive: new CommonTests(
                            GetInt("tests.ns-apr20.positive.todate", header, fields),
                            GetInt("tests.ns-apr20.positive", header, fields)
                            )
                        )
                    ),
                GetInt("age.female.todate", header, fields),
                GetInt("age.male.todate", header, fields),
                cases,
                perTreatment,
                perRegion,
                perAgeSum,
                deceasedPerAge
                );

            return(result);
        }