Exemple #1
0
    def increment_localCasePerCounty(self):
        report_date_list = self.getReportDate()
        county_list = self.getCounty()
        nb_cases_list = self.getNbCases()

        ## Initialize stock
        county_key_list = ['total'] + self.county_key_list
        stock = ccm.initializeStock_dailyCounts(county_key_list)

        ind_max = 0

        ## Loop over series
        for report_date, county, nb_cases in zip(report_date_list, county_list,
                                                 nb_cases_list):
            if 'unknown' == county:
                continue

            ind = ccm.indexForOverall(report_date)
            ind_max = max(ind_max, ind + 1)

            try:
                stock['total'][ind] += nb_cases
                stock[county][ind] += nb_cases
            except IndexError:  ## If NaN
                pass

        ind_today = ccm.getTodayOrdinal() - ccm.ISODateToOrd(ccm.ISO_DATE_REF)
        ind = max(ind_max, ind_today - 1)  ## Take the max of data date & today
        stock = {k: v[:ind] for k, v in stock.items()}

        ## Moving average
        for key in county_key_list:
            stock[key + '_avg'] = ccm.makeMovingAverage(stock[key])
        return stock
Exemple #2
0
    def increment_incidenceEvolutionByAge(self):
        report_date_list = self.getReportDate()
        age_list = self.getAge()
        nb_cases_list = self.getNbCases()

        ## Reverse
        age_key_list = ['total'] + self.age_key_list[::-1]

        ## Initialize stock
        stock = ccm.initializeStock_dailyCounts(age_key_list)

        ## Loop over series
        for report_date, age, nb_cases in zip(report_date_list, age_list,
                                              nb_cases_list):
            ind = ccm.indexForOverall(report_date)

            try:
                stock['total'][ind] += nb_cases
            except IndexError:
                pass
            else:
                try:
                    stock[age][ind] += nb_cases
                except KeyError:
                    pass

        return stock
Exemple #3
0
    def saveCsv_incidenceMap(self, mode='both'):
        if mode in ['data', 'both']:
            stock_dict = self.increment_incidenceMap()
            data_l = self.makeLabel_incidenceMap(do_im=True)
            data_l = pd.DataFrame(data_l)

        ## Loop over group
        for gr in ccm.GROUP_LIST:
            if mode in ['data', 'both']:
                stock_col = self.makeLabel_caseByAge(gr)
                col_tag_list = stock_col['key']

                stock = stock_dict[gr]
                data_c = {'county': ['total'] + self.county_key_list}
                data_c.update({
                    col_tag: case_hist.values()
                    for col_tag, case_hist in zip(col_tag_list, stock)
                })
                data_c = pd.DataFrame(data_c)

                ## Save
                name = '{}processed_data/{}/incidence_map.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data_c)
                name = '{}processed_data/{}/incidence_map_label.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data_l)

            if mode in ['readme', 'both']:
                self.makeReadme_incidenceMap(gr)
        return
  def increment_diffByTransmission(self):
    report_date_list = self.getReportDate()
    entry_date_list = self.getEntryDate()
    onset_date_list = self.getOnsetDate()
    trans_list = self.getTransmission()
    
    trans_key_list = ['total'] + self.trans_key_list
    stock = {key: [] for key in trans_key_list}
    stock_dict = ccm.initializeStockDict_general(stock)

    for report_date, entry_date, onset_date, trans in zip(report_date_list, entry_date_list, onset_date_list, trans_list):
      if trans != trans:
        continue
      
      if trans in ['imported', 'local']:
        key = trans
      else:
        key = 'others'
        
      ord_rep = ccm.ISODateToOrd(report_date)
      ord_entry = ccm.ISODateToOrd(entry_date) if entry_date == entry_date else 0
      ord_onset = ccm.ISODateToOrd(onset_date) if onset_date == onset_date else 0
      diff = min(ord_rep-ord_entry, ord_rep-ord_onset)
      
      index_list = ccm.makeIndexList(report_date)
      
      for ind, stock in zip(index_list, stock_dict.values()):
        if ind != ind: ## If NaN
          continue
        
        stock['total'].append(diff)
        stock[key].append(diff)
          
    return stock_dict
 def increment_ageSymptomCorr(self):
   report_date_list = self.getReportDate()
   trans_list = self.getTransmission()
   age_list = self.getAge()
   symp_list = self.getSymptom()
   
   stock = {'x_list_list': [], 'y_list_list': [], 'nb_dict': {'N_total': 0, 'N_data': 0}}
   stock_dict = ccm.initializeStockDict_general(stock)
   
   ## Loop over case
   for report_date, trans, age, symp in zip(report_date_list, trans_list, age_list, symp_list):
     if trans != trans:
       continue
     
     index_list = ccm.makeIndexList(report_date)
     
     for ind, stock in zip(index_list, stock_dict.values()):
       if ind != ind: ## If NaN
         continue
       
       stock['nb_dict']['N_total'] += 1
       
       ## Remove NaN
       if age != age or symp != symp:
         continue
       
       stock['nb_dict']['N_data'] += 1
       stock['x_list_list'].append(symp)
       stock['y_list_list'].append(age)
           
   return stock_dict
Exemple #6
0
    def setCaseCounts(self):
        date_list = self.getDate()
        new_soldiers_list = self.getNewSoldiers()
        new_impored_list = self.getNewImported()
        new_local_list = self.getNewLocal()
        new_unclear_list = self.getNewUnclear()

        new_others_list = new_soldiers_list + new_unclear_list
        new_cases_list = new_impored_list + new_local_list + new_others_list

        stock = {'date': date_list[:-1], 'total': new_cases_list[:-1]}
        stock = pd.DataFrame(stock)
        stock = ccm.adjustDateRange(stock)

        cum_cases_dict = {}
        for gr in ccm.GROUP_LIST:
            data = ccm.truncateStock(stock, gr)
            cum_cases = data['total'].values
            ind = ~pd.isna(cum_cases)
            cum_cases_dict[gr] = cum_cases[ind].sum()

        self.n_total = int(cum_cases_dict[ccm.GROUP_OVERALL])
        self.n_latest = int(cum_cases_dict[ccm.GROUP_LATEST])
        for year in ccm.GROUP_YEAR_LIST:
            self.n_year_dict[year] = int(cum_cases_dict[year])
        return
    def increment_deathDelay(self):
        report_date_list = self.getReportDate()
        confirmed_date_list = self.getConfirmedDate()

        stock = {'list': []}
        stock_dict = ccm.initializeStockDict_general(stock)

        for report_date, confirmed_date in zip(report_date_list,
                                               confirmed_date_list):
            if confirmed_date != confirmed_date:
                continue

            ord_rep = ccm.ISODateToOrd(report_date)
            ord_cf = ccm.ISODateToOrd(confirmed_date)
            diff = ord_rep - ord_cf

            index_list = ccm.makeIndexList(report_date)

            for ind, stock in zip(index_list, stock_dict.values()):
                if ind != ind:  ## If NaN
                    continue

                stock['list'].append(diff)

        return stock_dict
Exemple #8
0
    def saveCsv_statusEvolution(self, mode='both'):
        if mode in ['data', 'both']:
            date_list = self.getDate()
            cum_deaths_list = self.getCumDeaths()
            cum_dis_list = self.getCumDischarged()
            cum_hosp_list = self.getCumHospitalized()

            stock = {
                'date': date_list,
                'discharged': cum_dis_list,
                'hospitalized': cum_hosp_list,
                'death': cum_deaths_list
            }
            stock = pd.DataFrame(stock)
            stock = ccm.adjustDateRange(stock)

        for gr in ccm.GROUP_LIST:
            if mode in ['data', 'both']:
                data = ccm.truncateStock(stock, gr)

                ## Save
                name = '{}processed_data/{}/status_evolution.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data)

            if mode in ['readme', 'both']:
                self.makeReadme_statusEvolution(gr)
        return
Exemple #9
0
    def saveCsv_caseByAge(self, mode='both'):
        if mode in ['data', 'both']:
            stock_dict = self.increment_caseByAge()

        ## Loop over group
        for gr in ccm.GROUP_LIST:
            if mode in ['data', 'both']:
                data_l = self.makeLabel_caseByAge(gr)
                data_l = pd.DataFrame(data_l)
                col_tag_list = data_l['key']

                stock = stock_dict[gr]
                data_c = {'age': self.age_key_list}
                data_c.update({
                    col_tag: case_hist.values()
                    for col_tag, case_hist in zip(col_tag_list, stock)
                })
                data_c = pd.DataFrame(data_c)

                ## Save
                name = '{}processed_data/{}/case_by_age.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data_c)
                name = '{}processed_data/{}/case_by_age_label.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data_l)

            if mode in ['readme', 'both']:
                self.makeReadme_caseByAge(gr)
        return
    def saveCsv_deathDelay(self, mode='both'):
        if mode in ['data', 'both']:
            stock_dict = self.increment_deathDelay()
            stock_dict = self.makeHist_deathDelay(stock_dict)
            stock_dict_c, stock_dict_l = self.makeStock_deathDelay(stock_dict)

        for gr in ccm.GROUP_LIST:
            if mode in ['data', 'both']:
                data_c = stock_dict_c[gr]
                data_c = pd.DataFrame(data_c)

                data_l = stock_dict_l[gr]
                data_l = pd.DataFrame(data_l)

                ## Save
                name = '{}processed_data/{}/death_delay.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data_c)
                name = '{}processed_data/{}/death_delay_label.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data_l)

            if mode in ['readme', 'both']:
                self.makeReadme_deathDelay(gr)
        return
Exemple #11
0
    def increment_incidenceMap(self):
        report_date_list = self.getReportDate()
        county_list = self.getCounty()
        nb_cases_list = self.getNbCases()

        ## Initialize stock dict
        county_key_list = ['total'] + self.county_key_list
        case_hist = {key: 0 for key in county_key_list}
        stock = [case_hist.copy() for i in range(13)]
        stock_dict = ccm.initializeStockDict_general(stock)

        ## Add empty hist for overall (all year + 12 months per year)
        nb_years = len(ccm.GROUP_YEAR_LIST)
        for i in range(13 * nb_years - 12):
            stock_dict[ccm.GROUP_OVERALL].append(case_hist.copy())

        ## Loop over series
        for report_date, county, nb_cases in zip(report_date_list, county_list,
                                                 nb_cases_list):
            if 'unknown' == county:
                continue

            index_list = ccm.makeIndexList(report_date)

            for ind, gr, stock in zip(index_list, stock_dict.keys(),
                                      stock_dict.values()):
                if ind != ind:
                    continue

                stock[0]['total'] += nb_cases
                stock[0][county] += nb_cases

                if ccm.GROUP_LATEST == gr:
                    lookback_week = (
                        ind - ccm.NB_LOOKBACK_DAYS
                    ) // 7  ## ind - ccm.NB_LOOKBACK_DAYS in [-90, -1]; this will be in [-13, -1]
                    if lookback_week >= -12:
                        stock[-lookback_week]['total'] += nb_cases
                        stock[-lookback_week][county] += nb_cases

                elif ccm.GROUP_OVERALL == gr:
                    y_ind = int(report_date[:4]) - 2020
                    m_ind = int(report_date[5:7])
                    yy_ind = 1 + 13 * y_ind
                    ym_ind = 1 + m_ind + 13 * y_ind
                    stock[yy_ind]['total'] += nb_cases
                    stock[yy_ind][county] += nb_cases
                    stock[ym_ind]['total'] += nb_cases
                    stock[ym_ind][county] += nb_cases

                else:
                    mm = int(report_date[5:7])
                    stock[mm]['total'] += nb_cases
                    stock[mm][county] += nb_cases

        return stock_dict
    def saveCsv_evtTimeline(self, mode='both'):
        if mode in ['data', 'both']:
            data = self.makeStock_evtTimeline()
            data = pd.DataFrame(data)

            name = '{}processed_data/event_timeline_zh-tw.csv'.format(
                ccm.DATA_PATH)
            ccm.saveCsv(name, data)

        if mode in ['readme', 'both']:
            self.makeReadme_evtTimeline()
        return
def saveCsv_all():
    mode = 'both'
    ccm.initializeReadme()

    print()
    case_sheet = COVID_case.CaseSheet()
    case_sheet.saveCsv(mode=mode)

    print()
    status_sheet = COVID_status.StatusSheet()
    status_sheet.saveCsv(mode=mode)

    print()
    test_sheet = COVID_test.TestSheet()
    test_sheet.saveCsv(mode=mode)

    print()
    border_sheet = COVID_border.BorderSheet()
    border_sheet.saveCsv(mode=mode)

    print()
    timeline_sheet = COVID_timeline.TimelineSheet()
    timeline_sheet.saveCsv(mode=mode)

    print()
    county_sheet = COVID_county.CountySheet()
    county_sheet.saveCsv(mode=mode)

    print()
    vacc_sheet = COVID_vaccination.VaccinationSheet()
    vacc_sheet.saveCsv(mode=mode)

    print()
    vc_sheet = COVID_vaccination_county.VaccinationCountySheet()
    vc_sheet.saveCsv(mode=mode)

    print()
    death_sheet = COVID_death.DeathSheet()
    death_sheet.saveCsv(mode=mode)

    print()
    saveCsv_others(status_sheet,
                   test_sheet,
                   border_sheet,
                   county_sheet,
                   death_sheet,
                   mode=mode)

    print()
    ccm.saveMarkdown_readme()

    print()
    return
Exemple #14
0
    def makeStock_caseFatalityRates(self):
        date_list = self.getDate()
        new_soldiers_list = self.getNewSoldiers()
        new_imported_list = self.getNewImported()
        new_local_list = self.getNewLocal()
        new_unclear_list = self.getNewUnclear()
        new_deaths_list = self.getNewDeaths()
        cum_deaths_list = self.getCumDeaths()

        new_case_list = new_imported_list + new_local_list + new_soldiers_list + new_unclear_list
        cum_case_list = np.cumsum(new_case_list)

        offset_days = 12
        offset_case_list = np.concatenate([[0] * offset_days,
                                           new_case_list[:-offset_days]])

        offset_case_list = ccm.sevenDayMovingAverage(offset_case_list)
        new_deaths_list = ccm.sevenDayMovingAverage(new_deaths_list)
        cum_case_list, _ = ccm.pandasNAToZero(cum_case_list)
        cum_deaths_list, _ = ccm.pandasNAToZero(cum_deaths_list)

        with wng.catch_warnings():  ## Avoid division by zero
            wng.simplefilter('ignore')

            front = (offset_case_list != offset_case_list) + (offset_case_list
                                                              == 0)
            back = front.copy()
            front[-7:] = False  ## Front blank forced to 0
            back[:7] = False  ## Back blank forced to NaN

            inst_cfr_list = new_deaths_list / offset_case_list
            inst_cfr_list = np.around(inst_cfr_list, decimals=6)
            inst_cfr_list[front] = 0
            inst_cfr_list[back] = np.nan

            front = (cum_case_list != cum_case_list) + (cum_case_list == 0)
            back = front.copy()
            front[-7:] = False  ## Front blank forced to 0
            back[:7] = False  ## Back blank forced to NaN

            cum_cfr_list = cum_deaths_list / cum_case_list
            cum_cfr_list = np.around(cum_cfr_list, decimals=6)
            cum_cfr_list[front] = 0
            cum_cfr_list[back] = np.nan

        stock = {
            'date': date_list,
            'inst_CFR': inst_cfr_list,
            'cumul_CFR': cum_cfr_list
        }
        return stock
Exemple #15
0
 def saveCsv_caseByDetection(self, mode='both'):
   gr = ccm.GROUP_2020
   
   if mode in ['data', 'both']:
     stock_r, stock_o = self.increment_caseByDetection()
     
     stock_r = pd.DataFrame(stock_r)
     stock_r = ccm.adjustDateRange(stock_r)
     
     stock_o = pd.DataFrame(stock_o)
     stock_o = ccm.adjustDateRange(stock_o)
     
     ## Make data frame
     data_r = ccm.truncateStock(stock_r, gr)
     data_o = ccm.truncateStock(stock_o, gr)
     
     ## Save
     name = '{}processed_data/{}/case_by_detection_by_report_day.csv'.format(ccm.DATA_PATH, gr)
     ccm.saveCsv(name, data_r)
     name = '{}processed_data/{}/case_by_detection_by_onset_day.csv'.format(ccm.DATA_PATH, gr)
     ccm.saveCsv(name, data_o)
   
   if mode in ['readme', 'both']:
     self.makeReadme_caseByDetection(gr)
   return
    def __init__(self, verbose=True):
        self.coltag_row_id = 'id'
        self.coltag_report_date = '公布日'
        self.coltag_id = '案號'
        self.coltag_gender = '性別'
        self.coltag_age = '年齡'
        self.coltag_comorbidity = '慢性病史'
        self.coltag_vacc_status = '是否接種COVID19疫苗'
        self.coltag_contact_hist = '活動接觸史'
        self.coltag_onset_date = '發病日'
        self.coltag_symptoms = '症狀'
        self.coltag_tested_date = '採檢日'
        self.coltag_isolation_date = '住院/隔離日'
        self.coltag_confirmed_date = '確診日'
        self.coltag_death_date = '死亡日'

        name = '{}raw_data/COVID-19_in_Taiwan_raw_data_death.csv'.format(
            ccm.DATA_PATH)
        data = ccm.loadCsv(name, verbose=verbose)
        ## https://covid-19.nchc.org.tw/api/[email protected]&querydata=4002
        ## https://covid-19.nchc.org.tw/api/download/covidtable_taiwan_cdc_death_2022-06-22.csv

        self.data = data
        self.correctData()
        self.n_total = self.getNbRows()

        self.age_key_list = [
            '0-9', '10-19', '20-29', '30-39', '40-49', '50-59', '60-69',
            '70-79', '80-89', '90-99', '100+'
        ]

        if verbose:
            print('N_total = {:d}'.format(self.n_total))
        return
 def __init__(self, verbose=True):
   self.coltag_row_id = 'ID'
   self.coltag_report_date = '發佈統計日期'
   self.coltag_county = '縣市'
   self.coltag_age = '群組'
   self.coltag_1st_dose = '第1劑'
   self.coltag_2nd_dose = '第2劑'
   self.coltag_3rd_dose_2 = '加強劑'
   self.coltag_3rd_dose_1 = '追加劑'
   
   name = '{}raw_data/COVID-19_in_Taiwan_raw_data_vaccination_county.csv'.format(ccm.DATA_PATH)
   data = ccm.loadCsv(name, verbose=verbose)
   ## https://covid-19.nchc.org.tw/api/[email protected]&querydata=2006
   ## https://covid-19.nchc.org.tw/api/download/vaccineCityLevel_2022-06-22.csv
   
   self.data = data
   self.n_total = len(set(self.getDate()))
   
   self.county_key_list = [
     'Keelung', 'Taipei', 'New_Taipei', 'Taoyuan', 'Hsinchu', 'Hsinchu_C', 'Miaoli', 
     'Taichung', 'Changhua', 'Nantou', 'Yunlin', 
     'Chiayi' ,'Chiayi_C', 'Tainan', 'Kaohsiung', 'Pingtung', 
     'Yilan', 'Hualien', 'Taitung', 
     'Penghu', 'Kinmen', 'Matsu', 
   ]
   self.age_key_list = ['6-11', '12-17', '18-29', '30-49', '50-64', '65-74', '75+']
   
   if verbose:
     print('N_total = {:d}'.format(self.n_total))
   return
def makeStock_testPositiveRate(status_sheet, test_sheet):
    stock = {}
    status_sheet.updateNewCaseCounts(stock)
    test_sheet.updateNewTestCounts(stock)

    ## Smooth
    for key, value_arr in stock.items():
        if 'date' == key:
            continue

        value_arr = ccm.sevenDayMovingAverage(value_arr)
        ind = value_arr != value_arr
        value_arr[ind] = 0

        ## Push back
        stock[key] = value_arr

    stock_new = {}
    stock_new['date'] = stock['date']

    with wng.catch_warnings():  ## Avoid division by zero
        wng.simplefilter('ignore')

        ind = stock['new_tests'] == 0
        value_arr = stock['new_cases'] / stock['new_tests']
        value_arr = np.around(value_arr, decimals=4)
        value_arr[ind] = np.nan
        stock_new['positivity'] = value_arr
    return stock_new
Exemple #19
0
    def __init__(self, verbose=True):
        self.coltag_date = '日期'
        self.coltag_week_nb = '週次'
        self.coltag_new_cases = '新增確診'
        self.coltag_new_cases_per_week = '每週新增確診'
        self.coltag_cum_cases = '確診總人數'
        self.coltag_new_males = '新增男性'
        self.coltag_cum_males = '男性總數'
        self.coltag_male_frac = '確診男性率'
        self.coltag_new_females = '新增女性'
        self.coltag_cum_females = '女性總數'
        self.coltag_female_frac = '確診女性率'
        self.coltag_new_soldiers = '新增軍人'
        self.coltag_cum_soldiers = '敦睦總人數'
        self.coltag_soldier_frac = '軍隊率'
        self.coltag_new_imported = '新增境外'
        self.coltag_cum_imported = '境外總人數'
        self.coltag_imported_frac = '境外率'
        self.coltag_new_local = '新增本土'
        self.coltag_cum_local = '本土總人數'
        self.coltag_local_frac = '本土率'
        self.coltag_new_unclear = '新增不明'
        self.coltag_cum_unclear = '不明總人數'
        self.coltag_unclear_frac = '不明率'
        self.coltag_new_deaths = '新增死亡'
        self.coltag_cum_deaths = '死亡總人數'
        self.coltag_death_frac = '死亡率'
        self.coltag_new_unknown = '當日未知感染源數'
        self.coltag_cum_unknown = '未知感染源總數'
        self.coltag_cum_known = '已知感染源數'
        self.coltag_new_dis = '新增解除隔離'
        self.coltag_cum_dis = '解除隔離數'
        self.coltag_cum_dis_and_deaths = '解除隔離+死亡'
        self.coltag_cum_hosp = '未解除隔離數'
        self.coltag_notes = '備註'

        self.n_total = 0
        self.n_latest = 0
        self.n_year_dict = {}
        self.ind_2021 = None
        self.ind_2022 = None
        self.ind_2023 = None
        ## new_year_token

        name = '{}raw_data/COVID-19_in_Taiwan_raw_data_status_evolution.csv'.format(
            ccm.DATA_PATH)
        data = ccm.loadCsv(name, verbose=verbose)

        self.setData(data)
        self.setCaseCounts()

        self.trans_key_list = ['imported', 'local', 'others']

        if verbose:
            print('N_total = {:d}'.format(self.n_total))
            print('N_latest = {:d}'.format(self.n_latest))
            for year in ccm.GROUP_YEAR_LIST:
                print('N_{} = {:d}'.format(year, self.n_year_dict[year]))
        return
def saveCsv_incidenceRates(status_sheet, border_sheet, mode='both'):
    if mode in ['data', 'both']:
        stock = makeStock_incidenceRates(status_sheet, border_sheet)
        stock = pd.DataFrame(stock)

    for gr in ccm.GROUP_LIST:
        if mode in ['data', 'both']:
            data = ccm.truncateStock(stock, gr)

            ## Save
            name = '{}processed_data/{}/incidence_rates.csv'.format(
                ccm.DATA_PATH, gr)
            ccm.saveCsv(name, data)

        if mode in ['readme', 'both']:
            makeReadme_incidenceRates(gr)
    return
def saveCsv_testPositiveRate(status_sheet, test_sheet, mode='both'):
    if mode in ['data', 'both']:
        stock = makeStock_testPositiveRate(status_sheet, test_sheet)
        stock = pd.DataFrame(stock)

    for gr in ccm.GROUP_LIST:
        if mode in ['data', 'both']:
            data = ccm.truncateStock(stock, gr)

            ## Save
            name = '{}processed_data/{}/test_positive_rate.csv'.format(
                ccm.DATA_PATH, gr)
            ccm.saveCsv(name, data)

        if mode in ['readme', 'both']:
            makeReadme_testPositiveRate(gr)
    return
Exemple #22
0
    def makeLabel_caseByAge(self, gr):
        key_list = ['total']
        label_list_en = ['Total']
        label_list_fr = ['Totaux']
        label_list_zh = ['合計']

        if gr == ccm.GROUP_LATEST:
            for i in range(12):
                str_ = '{:d}-{:d}'.format(7 * i, 7 * i + 6)
                key_list.append('week_-{:d}'.format(i + 1))
                label_list_en.append('{} days ago'.format(str_))
                label_list_fr.append('{} jours plus tôt'.format(str_))
                label_list_zh.append('{}天前'.format(str_))

        elif gr == ccm.GROUP_OVERALL:
            for year in ccm.GROUP_YEAR_LIST:
                key_list.append(year)
                label_list_en.append('{} all year'.format(year))
                label_list_fr.append('Année {}'.format(year))
                label_list_zh.append('{}全年'.format(year))

                for i in range(12):
                    str_ = '{:d}-{:d}'.format(7 * i, 7 * i + 6)
                    key_list.append('{}_{}'.format(ccm.numMonthToAbbr(i + 1),
                                                   year))
                    label_list_en.append('{} {}'.format(
                        ccm.MONTH_NAME_EN[i], year))
                    label_list_fr.append('{} {}'.format(
                        ccm.MONTH_NAME_FR[i], year))
                    label_list_zh.append('{}年{:d}月'.format(year, i + 1))

        elif gr in ccm.GROUP_YEAR_LIST:
            for i in range(12):
                str_ = '{:d}-{:d}'.format(7 * i, 7 * i + 6)
                key_list.append('{}'.format(ccm.numMonthToAbbr(i + 1)))
                label_list_en.append('{}'.format(ccm.MONTH_NAME_EN[i]))
                label_list_fr.append('{}'.format(ccm.MONTH_NAME_FR[i]))
                label_list_zh.append('{:d}月'.format(i + 1))

        stock = {
            'key': key_list,
            'label': label_list_en,
            'label_fr': label_list_fr,
            'label_zh': label_list_zh
        }
        return stock
Exemple #23
0
    def saveCsv_borderStats(self, mode='both'):
        if mode in ['data', 'both']:
            stock = self.makeStock_borderStats()
            stock = pd.DataFrame(stock)
            stock = ccm.adjustDateRange(stock)

        for gr in ccm.GROUP_LIST:
            if mode in ['data', 'both']:
                data = ccm.truncateStock(stock, gr)

                ## Save
                name = '{}processed_data/{}/border_statistics.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data)

            if mode in ['readme', 'both']:
                self.makeReadme_borderStats(gr)
        return
Exemple #24
0
    def updateNewEntryCounts(self, stock):
        ord_ref = ccm.ISODateToOrd(ccm.ISO_DATE_REF)
        ord_today = ccm.getTodayOrdinal()
        nb_days = ord_today - ord_ref

        stock['new_entries'] = np.zeros(nb_days, dtype=int) + np.nan

        date_list = self.getDate()
        entry_list = self.getEntry()

        for date, entry in zip(date_list, entry_list):
            ind = ccm.ISODateToOrd(date) - ord_ref
            if ind < 0 or ind >= nb_days:
                print('Bad ind_r = {:d}'.format(ind))
                continue

            stock['new_entries'][ind] = entry
        return
    def saveCsv_deathCounts(self, mode='both'):
        if mode in ['data', 'both']:
            stock = self.increment_deathCounts()
            stock = pd.DataFrame(stock)
            stock = ccm.adjustDateRange(stock)

        for gr in ccm.GROUP_LIST:
            if mode in ['data', 'both']:
                data = ccm.truncateStock(stock, gr)

                ## Save
                name = '{}processed_data/{}/death_counts.csv'.format(
                    ccm.DATA_PATH, gr)
                ccm.saveCsv(name, data)

            if mode in ['readme', 'both']:
                self.makeReadme_deathCounts(gr)
        return
Exemple #26
0
 def saveCsv_diffByTransmission(self, mode='both'):
   gr = ccm.GROUP_2020
   
   if mode in ['data', 'both']:
     stock_dict = self.increment_diffByTransmission()
     stock_dict = self.makeHist_diffByTransmission(stock_dict)
     
     col_tag_list = ['difference', 'total'] + self.trans_key_list
     
     stock = stock_dict[gr]
     data = {key: stock[key] for key in col_tag_list}
     data = pd.DataFrame(data)
     
     name = '{}processed_data/{}/difference_by_transmission.csv'.format(ccm.DATA_PATH, gr)
     ccm.saveCsv(name, data)
   
   if mode in ['readme', 'both']:
     self.makeReadme_diffByTransmission(gr)
   return
    def increment_deathCounts(self):
        report_date_list = self.getReportDate()

        ## Initialize stocks
        col_tag_list = ['death']
        stock = ccm.initializeStock_dailyCounts(col_tag_list)

        ## Loop over cases
        for report_date in report_date_list:
            try:
                ind = ccm.indexForOverall(report_date)
                stock['death'][ind] += 1
            except IndexError:  ## If NaN
                pass

        ## Make avg
        for key in col_tag_list:
            stock[key + '_avg'] = ccm.makeMovingAverage(stock[key])
        return stock
Exemple #28
0
 def increment_caseByTransmission(self):
   report_date_list = self.getReportDate()
   onset_date_list = self.getOnsetDate()
   trans_list = self.getTransmission()
   link_list = self.getLink()
   
   ## Initialize stocks
   trans_key_list = ['imported', 'linked', 'unlinked', 'fleet', 'plane', 'unknown']
   stock_r = ccm.initializeStock_dailyCounts(trans_key_list)
   stock_o = ccm.initializeStock_dailyCounts(trans_key_list)
   
   ## Loop over cases
   for report_date, onset_date, trans, link in zip(report_date_list, onset_date_list, trans_list, link_list):
     if trans != trans:
       continue
     
     ## Determine column tag
     if trans == 'local':
       if link == 'unlinked':
         key = link
       else:
         key = 'linked'
     else:
       key = trans
       
     try:
       ind = ccm.indexForOverall(report_date)
       stock_r[key][ind] += 1
     except IndexError: ## If NaN
       pass
       
     ## Check if NaN
     if onset_date != onset_date:
       continue
     
     try:
       ind = ccm.indexForOverall(onset_date)
       stock_o[key][ind] += 1
     except IndexError: ## If NaN
       pass
     
   return stock_r, stock_o
Exemple #29
0
 def updateNewTestCounts(self, stock):
   date_list = self.getDate()
   total_list = self.getTotal()
   
   stock_tmp = {'date': date_list, 'new_tests': total_list}
   stock_tmp = pd.DataFrame(stock_tmp)
   stock_tmp = stock_tmp[:-1] ## Trim the last
   stock_tmp = ccm.adjustDateRange(stock_tmp)
   
   stock['new_tests'] = stock_tmp['new_tests'].values
   return
 def saveCsv_vaccinationByAge(self, mode='both'):
   gr = ccm.GROUP_LATEST
   
   if mode in ['data', 'both']:
     stock = self.makeStock_vaccinationByAge()
     data_l = {'key': ['latest_date'], 'value': [stock['latest_date']]}
     data_l = pd.DataFrame(data_l)
     
     data_r = self.addLabel_vaccinationByAge(stock)
     data_r = pd.DataFrame(data_r)
     
     ## Save
     name = '{}processed_data/{}/vaccination_by_age.csv'.format(ccm.DATA_PATH, gr)
     ccm.saveCsv(name, data_r)
     name = '{}processed_data/{}/vaccination_by_age_label.csv'.format(ccm.DATA_PATH, gr)
     ccm.saveCsv(name, data_l)
   
   if mode in ['readme', 'both']:
     self.makeReadme_vaccinationByAge(gr)
   return