<jupyter_start><jupyter_text>Generate TT_final<jupyter_code># cs = pd.read_csv("case_time_series.csv")
# cs.columns
# cs.tail()
# import timedelta
# delta_date = str((datetime.datetime.now() - timedelta.Timedelta(days=1)).date())
delta_date = str(pDate)
delta_date
# ind = cs[cs['Date_YMD']==delta_date].index[0]<jupyter_output><empty_output><jupyter_text>Integrate is CS only<jupyter_code># states_df = pd.read_csv("states.csv")
# cs = states_df
# ind = cs[(cs['Date']==delta_date) & (cs["State"] == "India")].index[0]
# ind<jupyter_output><empty_output><jupyter_text>Reading from Raw<jupyter_code>cs = pd.read_csv("../RAWCSV/"+delta_date+"/TT_final.csv")
# cs.columns
# TT_df["deltaConfirmedForState"] = TT_df["cumulativeConfirmedNumberForState"] - cs["Confirmed"][ind]
# TT_df["deltaDeceasedForState"] = TT_df["cumulativeDeceasedNumberForState"] - cs["Deceased"][ind]
# TT_df["deltaRecoveredForState"] = TT_df["cumulativeRecoveredNumberForState"] - cs["Recovered"][ind]
TT_df["deltaConfirmedForState"] = TT_df["cumulativeConfirmedNumberForState"] - cs["cumulativeConfirmedNumberForState"][0]
TT_df["deltaDeceasedForState"] = TT_df["cumulativeDeceasedNumberForState"] - cs["cumulativeDeceasedNumberForState"][0]
TT_df["deltaRecoveredForState"] = TT_df["cumulativeRecoveredNumberForState"] - cs["cumulativeRecoveredNumberForState"][0]
TT_df["deltaTestedForState"] = TT_df["cumulativeTestedNumberForState"] - cs["cumulativeTestedNumberForState"][0]
delta_date
import urllib.request, json 
with urllib.request.urlopen("https://api.cowin.gov.in/api/v1/reports/v2/getPublicReports?date="+str(cowinDate)) as url:
    data = json.loads(url.read().decode())
# TT_df["cumulativeVaccinated1NumberForState"] = data["topBlock"]["vaccination"]["tot_dose_1"]
# TT_df["cumulativeVaccinated2NumberForState"] = data["topBlock"]["vaccination"]["tot_dose_2"]
# TT_df["cumulativeVaccinatedNumberForState"] = data["topBlock"]["vaccination"]["total_doses"]
print(data["topBlock"]["vaccination"]["tot_pd"])
print(data["topBlock"]["vaccination"]["tot_dose_2"])
print(data["topBlock"]["vaccination"]["tot_dose_1"])
print(data["topBlock"]["vaccination"]["total_doses"])
TT_df["deltaVaccinated3ForState"] = TT_df["cumulativeVaccinated3NumberForState"] - data["topBlock"]["vaccination"]["tot_pd"]
TT_df["deltaVaccinated2ForState"] = TT_df["cumulativeVaccinated2NumberForState"] - data["topBlock"]["vaccination"]["tot_dose_2"]
TT_df["deltaVaccinated1ForState"] = TT_df["cumulativeVaccinated1NumberForState"] - data["topBlock"]["vaccination"]["tot_dose_1"]
TT_df["deltaVaccinatedForState"] = TT_df["cumulativeVaccinatedNumberForState"] - data["topBlock"]["vaccination"]["total_doses"]
print(TT_df["deltaVaccinated3ForState"][0])
print(TT_df["deltaVaccinated1ForState"][0])
print(TT_df["deltaVaccinated2ForState"][0])
print(TT_df["deltaVaccinatedForState"][0])
# TT_df["deltaVaccinatedForState"]
states = []
vaccinated = []
vaccinated1 = []
vaccinated2 = []
vaccinated3 = []
for sta in data['getBeneficiariesGroupBy']:
    if (sta['title'].lower() == "dadra and nagar haveli") or (sta['title'].lower() == "daman and diu"):
        states.append('Dadra and Nagar Haveli and Daman and Diu')
    else:
        states.append(sta['title'])
    vaccinated.append(sta['total'])
    vaccinated1.append(sta['partial_vaccinated'])
    vaccinated2.append(sta['totally_vaccinated'])
    vaccinated3.append(sta['precaution_dose'])
prevdayVACC_df = pd.DataFrame(list(zip(states,vaccinated,vaccinated1,vaccinated2,vaccinated3))).groupby(0, as_index=False).sum()
prevdayVACC_df = prevdayVACC_df.rename(columns={0:"District",1:"cumulativeVaccinatedNumberForDistrict",2:"cumulativeVaccinated1NumberForDistrict",3:"cumulativeVaccinated2NumberForDistrict",4:"cumulativeVaccinated3NumberForDistrict"})
lst = ["Vaccinated1","Vaccinated2","Vaccinated3","Vaccinated"]
for val in lst:
    TT_df["delta{}ForDistrict".format(val)] = None
    for idx in TT_df.index:
        TT_df["delta{}ForDistrict".format(val)][idx] = TT_df["cumulative{}NumberForDistrict".format(val)][idx] - prevdayVACC_df[prevdayVACC_df["District"] == TT_df["District"][idx]]["cumulative{}NumberForDistrict".format(val)].item()
# states_df = pd.read_csv("states.csv")<jupyter_output><empty_output><jupyter_text>No reading states<jupyter_code>states_df = cs[["Date","District","cumulativeConfirmedNumberForDistrict","cumulativeRecoveredNumberForDistrict","cumulativeDeceasedNumberForDistrict"]]
# states_df
# deltaConfirmedForDistrict",
#                  "deltaDeceasedForDistrict",
#                  "deltaRecoveredForDistrict",
lst = ["Confirmed","Recovered","Deceased"]
for val in lst:
    TT_df["delta{}ForDistrict".format(val)] = None
    for idx in TT_df.index:
        TT_df["delta{}ForDistrict".format(val)][idx] = int(TT_df["cumulative{}NumberForDistrict".format(val)][idx]) - int(states_df[(states_df["District"] == TT_df["District"][idx]) & (states_df["Date"] == delta_date)]["cumulative{}NumberForDistrict".format(val)].item())
delta_date
lst = ["Vaccinated1","Vaccinated2","Vaccinated3","Vaccinated"]
for val in lst:
    TT_df["delta{}ForDistrict".format(val)] = None
    for idx in TT_df.index:
        TT_df["delta{}ForDistrict".format(val)][idx] = TT_df["cumulative{}NumberForDistrict".format(val)][idx] - prevdayVACC_df[prevdayVACC_df["District"] == TT_df["District"][idx]]["cumulative{}NumberForDistrict".format(val)].item()
# TT_df 7dma Cummulative
cs.tail()
# cs = pd.read_csv("case_time_series.csv")
# states_df = pd.read_csv("states.csv")<jupyter_output><empty_output><jupyter_text>Remenber to read CS and states<jupyter_code># from datetime import datetime, timedelta
# lst = ["Confirmed","Recovered","Deceased"]
# for val in lst:
#     value = 0
#     for i in range(7):
#         if i == 0:
#             value = TT_df["cumulative{}NumberForState".format(val)]
#         else:
#             prev_date=datetime.strptime("2021-10-31","%Y-%m-%d")+timedelta(days=(-1*i))
#             ind = cs[cs['Date_YMD']==str(prev_date.date())].index[0]
#             value =+ cs["Total {}".format(val)][ind]
#     TT_df["7Dma{}ForState".format(val)] = value/7
# import urllib.request, json 
# va1 = 0
# va2 = 0
# va = 0
# for i in range(7):
#     prev_date=datetime.strptime("2021-10-31","%Y-%m-%d")+timedelta(days=(-1*i))
#     with urllib.request.urlopen("https://api.cowin.gov.in/api/v1/reports/v2/getPublicReports?date="+str(prev_date.date())) as url:
#         data = json.loads(url.read().decode())
#         va1 += data["topBlock"]["vaccination"]["tot_dose_1"]
#         va2 += data["topBlock"]["vaccination"]["tot_dose_2"]
#         va += data["topBlock"]["vaccination"]["total_doses"]

# TT_df["7DmaVaccinated1ForState"] = va1
# TT_df["7DmaVaccinated2ForState"] = va2
# TT_df["7DmaVaccinatedForState"] = va
# 7dma District
# lst = ["Confirmed","Recovered","Deceased"]
# for val in lst:
#     value = 0
#     for idx in TT_df.index:
#         for i in range(7):
#             if i == 0:
#                 value = int(TT_df["cumulative{}NumberForDistrict".format(val)][0])
#             else:
#                 prev_date=datetime.strptime("2021-10-31","%Y-%m-%d")+timedelta(days=(-1*i))
#                 value += int(states_df[(states_df["State"] == TT_df["District"][idx]) & (states_df["Date"] == str(prev_date.date()))]['{}'.format(val)].item())
#     TT_df["7Dma{}ForDistrict".format(val)] = value/7          
# cowin = pd.read_csv("cowin_vaccine_data_statewise.csv")
# va1 = 0
# va2 = 0
# va = 0
# TT_df["7DmaVaccinatedForDistrict"] = 0
# TT_df["7DmaVaccinated1ForDistrict"] = 0
# TT_df["7DmaVaccinated2ForDistrict"] = 0
# for idx in TT_df.index:
#     for i in range(7):
#         if i == 0:
#             va = int(TT_df["cumulativeVaccinatedNumberForDistrict"][idx])
#             va1 = int(TT_df["cumulativeVaccinated1NumberForDistrict"][idx])
#             va2 = int(TT_df["cumulativeVaccinated2NumberForDistrict"][idx])
#         else:
#             prev_date=datetime.strptime("2021/10/31","%Y/%m/%d")+timedelta(days=(-1*i))
#             va += int(cowin[(cowin["Updated On"] ==  prev_date.strftime('%d/%m/%Y')) & (cowin["State"] == TT_df["District"][idx])]["Total Doses Administered"].item())
#             va1 += int(cowin[(cowin["Updated On"] ==  prev_date.strftime('%d/%m/%Y')) & (cowin["State"] == TT_df["District"][idx])]["First Dose Administered"].item())
#             va2 += int(cowin[(cowin["Updated On"] ==  prev_date.strftime('%d/%m/%Y')) & (cowin["State"] == TT_df["District"][idx])]["Second Dose Administered"].item())
# TT_df["7DmaVaccinatedForDistrict"][idx] = va/7
# TT_df["7DmaVaccinated1ForDistrict"][idx] = va1/7
# TT_df["7DmaVaccinated2ForDistrict"][idx] = va2/7
TT_df["7DmaTestedForState"] = None
TT_df["delta21_14confirmedForState"] = None
population = pd.read_csv("../CSV/StatePopulation.csv")
sources = pd.read_csv("../sources.csv")
population = population.merge(sources,how="left",left_on = "State", right_on = "StateCode")
# population
# population[["StateName","StatePop"]]
TT_df["statePopulation"] = population[population["StateName"] == "India"]["StatePop"].item()
# TT_df
TT_df = TT_df.merge(population[["StateName","StatePop"]],how="left",left_on = "District", right_on = "StateName")
TT_df = TT_df.rename(columns={"StatePop":"districtPopulation"})
today
TT_df["Date"] = str(today)
TT_df.to_csv('../RAWCSV/'+str(today)+'/TT_final.csv')
TT_df.to_csv('../RAWCSV/'+str(today)+'/TT_final-'+str(today)+'.csv')
TT_df["Date"] = str(pDate)
TT_df.to_csv('../RAWCSV/'+str(pDate)+'/TT_final.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18973872734934683, 'fraction_numerical': 0.01675094816687737, 'mean_word_length': 6.480693459416863, 'pattern_counts': {'":': 1, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '306679', 'license': 'MIT', 'n_tokens_mistral': 3643, 'n_tokens_neox': 3458, 'n_words': 394, 'path': 'src/getTT.ipynb', 'repo_name': 'incovid19/incovid19', 'size': '9492'}