Exemple #1
0
def parseAdministered(file, vacc_data):
    idxGeoRegion = 0
    idxDate = 0
    idxSumTotal = 0
    idxPer100PersonsTotal = 0
    idxType = 0
    csvreader = csv.reader(open(file, "r"), delimiter=',', quotechar='"')
    for row in csvreader:
        if row[0] == "date":  # skip header line
            idxGeoRegion, idxDate, idxSumTotal, idxPer100PersonsTotal, idxType = extractIdx(
                row, 'geoRegion', 'date', 'sumTotal', 'per100PersonsTotal',
                'type')
            continue
        # print(', '.join(row))
        date = row[idxDate]
        canton = row[idxGeoRegion]
        if canton in ["all", "neighboring_chfl", "unknown"]:
            continue
        total = row[idxSumTotal]
        per100 = row[idxPer100PersonsTotal]
        dtype = row[idxType]
        if date not in vacc_data:
            vacc_data[date] = {}
        if canton not in vacc_data[date]:
            vacc_data[date][canton] = {}
        if dtype == "COVID19VaccDosesAdministered":
            vacc_data[date][canton]["administeredTotal"] = total
            vacc_data[date][canton]["administeredPer100"] = per100
    return vacc_data
def parse_hosp(file, data):
    idxGeoRegion = 0
    idxDate = 0
    idxCurrIcu = 0
    idxCurrHosp = 0
    csvreader = csv.reader(open(file, "r"), delimiter=',', quotechar='"')
    for row in csvreader:
        if row[0] == "date":
            idxGeoRegion, idxDate, idxCurrIcu, idxCurrHosp = extractIdx(
                row, 'geoRegion', 'date', 'ICU_Covid19Patients',
                'Total_Covid19Patients')
            continue
        canton = row[idxGeoRegion]
        date = row[idxDate]
        currHosp = row[idxCurrHosp]
        currIcu = row[idxCurrIcu]
        if canton not in data:
            data[canton] = {}
        if date not in data[canton]:
            data[canton][date] = {
                "total": 0,
                "current_hosp": 0,
                "current_icu": 0,
                "death": 0
            }
        data[canton][date]["current_hosp"] = currHosp
        data[canton][date]["current_icu"] = currIcu
    return data
def parse_timestamps(file, data):
    idxVariant = 0
    idxVersion = 0
    csvreader = csv.reader(open(file, "r"), delimiter=',', quotechar='"')
    for row in csvreader:
        if row[0] == "type":
            idxVariant, idxVersion = extractIdx(row, 'type_variant', 'version')
            continue
        variant = row[idxVariant][10:]
        timestamp = row[idxVersion]
        data[variant] = timestamp
    return data
def parsePersons(file, data):
    idxGeoRegion = 0
    idxPop = 0
    idxAgeGroup = 0
    csvreader = csv.reader(open(file, "r"), delimiter=',', quotechar='"')
    for row in csvreader:
        if row[0] == "date": # skip header line
            idxGeoRegion, idxPop, idxAgeGroup = extractIdx(row, 'geoRegion', 'pop', 'age_group')
            continue
        # print(', '.join(row))
        if (row[idxAgeGroup] != 'total_population'):
            continue
        if not row[idxPop].isnumeric():
            continue
        canton = row[idxGeoRegion]
        pop = row[idxPop]
        data[canton] = pop
    return data
def parse_death(file, data):
    idxGeoRegion = 0
    idxDatum = 0
    idxSumTotal = 0
    csvreader = csv.reader(open(file, "r"), delimiter=',', quotechar='"')
    for row in csvreader:
        if row[0] == "geoRegion":
            idxGeoRegion, idxDatum, idxSumTotal = extractIdx(
                row, 'geoRegion', 'datum', 'sumTotal')
            continue
        canton = row[idxGeoRegion]
        date = row[idxDatum]
        total = row[idxSumTotal]
        if canton not in data:
            data[canton] = {}
        if date not in data[canton]:
            data[canton][date] = {
                "total": 0,
                "current_hosp": 0,
                "current_icu": 0,
                "death": 0
            }
        data[canton][date]["death"] = total
    return data
Exemple #6
0
def parseVaccPersons(file, vacc_data):
    idxGeoRegion = 0
    idxDate = 0
    idxSumTotal = 0
    idxPer100PersonsTotal = 0
    idxType = 0
    csvreader = csv.reader(open(file, "r"), delimiter=',', quotechar='"')
    for row in csvreader:
        if row[0] == "date":  # skip header line
            idxGeoRegion, idxDate, idxSumTotal, idxPer100PersonsTotal, idxType, idxAgeGroup = extractIdx(
                row, 'geoRegion', 'date', 'sumTotal', 'per100PersonsTotal',
                'type', 'age_group')
            continue
        # print(', '.join(row))
        date = row[idxDate]
        canton = row[idxGeoRegion]
        if canton in ["all", "neighboring_chfl", "unknown"]:
            continue
        total = row[idxSumTotal]
        per100 = row[idxPer100PersonsTotal]
        dtype = row[idxType]
        ageGroup = row[idxAgeGroup]
        if ageGroup != "total_population":
            continue
        if date not in vacc_data:
            vacc_data[date] = {}
        if canton not in vacc_data[date]:
            vacc_data[date][canton] = {}
        if dtype == "COVID19FullyVaccPersons":
            vacc_data[date][canton]["fullyVaccTotal"] = total
            vacc_data[date][canton]["fullyVaccPer100"] = per100
    return vacc_data
def parseVaccPersons(file, vacc_data_total, vacc_data_twelveplus):
    idxGeoRegion = 0
    idxDate = 0
    idxSumTotal = 0
    idxPer100PersonsTotal = 0
    idxType = 0
    csvreader = csv.reader(open(file, "r"), delimiter=',', quotechar='"')
    for row in csvreader:
        if row[0] == "date":  # skip header line
            idxGeoRegion, idxDate, idxSumTotal, idxPer100PersonsTotal, idxType, idxAgeGroup, idxPop = extractIdx(
                row, 'geoRegion', 'date', 'sumTotal', 'per100PersonsTotal',
                'type', 'age_group', 'pop')
            continue
        # print(', '.join(row))
        date = row[idxDate]
        canton = row[idxGeoRegion]
        if canton in ["all", "neighboring_chfl", "unknown"]:
            continue
        total = row[idxSumTotal]
        per100 = row[idxPer100PersonsTotal]
        dtype = row[idxType]
        ageGroup = row[idxAgeGroup]
        pop = row[idxPop]
        if ageGroup == "total_population":
            vacc_data_total = getVaccData(vacc_data_total, date, canton, pop,
                                          dtype, total, per100)
        elif ageGroup == "12+":
            vacc_data_twelveplus = getVaccData(vacc_data_twelveplus, date,
                                               canton, pop, dtype, total,
                                               per100)
    return vacc_data_total, vacc_data_twelveplus