#def getData():
# global df
# for index,row in atk_data.iterrows():
# if row["Pending"]:
# time.sleep(0.1)
# cid = row["CitizenId"]
# print(cid)
# response = requests.get(f"http://122.154.73.46:8000/immunization/getdatatarget.php?cid={cid}")
# json = response.json()
# if response.status_code == 200:
# if "Invalid CID" in json["Message"]:
# print(f"{cid} is not found")
# atk_data.loc[atk_data.index == index,"Pending"] = False
# continue
# vaccinations = []
# for certificate in json["result"]["vaccine_certificate"]:
# for vaccination in certificate["vaccination_list"]:
# vaccinations.append(vaccination)
# person_df = pd.DataFrame.from_records(vaccinations)
# person_df["CitizenId"] = cid
# df = pd.concat([df,person_df])
# atk_data.loc[atk_data.index == index,"Pending"] = False
fig = px.pie(merged.value_counts("last_vaccine_dose").to_frame().reset_index(),values=0,names="last_vaccine_dose",title="สัดส่วนของจำนวนการได้รับวัคซีนของบุคคลากรโรงพยาบาล 18 July 2022",labels={"0":"จำนวนเจ้าหน้าที่","last_vaccine_dose":"จำนวน Dose ที่ฉีด"})
fig.update_traces(texttemplate="เข็มที่ %{label} %{percent} <br> (%{value} ราย)")
fig.update_layout(legend_title="จำนวนวัคซีนที่ได้รับ")
fig.show()
p = merged.rename(columns={"last_vaccine_dose":"จำนวนวัคซีนที่ได้รับ","should_inject":"ถึงเวลาได้รับวัคซีนรอบต่อไป"})
p["จำนวนวัคซีนที่ได้รับ"] = pd.to_numeric(p["จำนวนวัคซีนที่ได้รับ"],downcast="integer")
groupby_vaccine_display = p.rename(columns={"last_vaccine_dose":"จำนวนวัคซีนที่ได้รับ","should_inject":"ถึงเวลาได้รับวัคซีนรอบต่อไป"}).value_counts(["จำนวนวัคซีนที่ได้รับ","ถึงเวลาได้รับวัคซีนรอบต่อไป"]).sort_index().to_frame("จำนวน")
groupby_vaccine_display.style
groupby_vaccine = merged.value_counts(["last_vaccine_dose","should_inject"]).sort_index().to_frame("people_count")
groupby_vaccine.reset_index(inplace=True)
groupby_vaccine["should_inject"] = np.where(groupby_vaccine["should_inject"],"สามารถรับวัคซีนเข็มถัดไป","ยังไม่ถึงเวลารับวัคซีนเข็มถัดไป")
fig = px.bar(groupby_vaccine,x="last_vaccine_dose",y="people_count",color="should_inject",labels={"people_count":"จำนวนเจ้าหน้าที่ (คน)","last_vaccine_dose":"จำนวนวัคซีนที่ได้รับ ณ ปัจจุบัน (เข็ม)","should_inject":""},title="สัดส่วนของผู้ที่สามารถรับวัคซีน COVID-19 เข็มต่อไปได้ แบ่งตามจำนวนวัคซีนที่ได้รับ ณ 18 กรกฎาคม 2565", color_discrete_sequence=["hsl(0,0%,45%)","hsl(0,0%,80%)"])
fig.update_traces(texttemplate="%{value}")
fig.show()
department
divisions = pd.Series(["ทั้งหมด",*merged.loc[merged["Department"]==department]["Division"].unique()])
divisions
division
if division == "0":
groupby_vaccine_by_dep_and_div = merged.loc[merged["Department"]==department].value_counts(["last_vaccine_dose","should_inject"]).sort_index().to_frame("people_count")
else:
groupby_vaccine_by_dep_and_div = merged.loc[(merged["Department"]==department) & (merged["Division"]==divisions.iloc[int(division)])].value_counts(["last_vaccine_dose","should_inject"]).sort_index().to_frame("people_count")
fig = px.bar(groupby_vaccine_by_dep_and_div.reset_index(),x="last_vaccine_dose",y="people_count",color="should_inject",labels={"people_count":"จำนวนเจ้าหน้าที่","last_vaccine_dose":"จำนวนวัคซีนที่ได้รับ","should_inject":"ถึงเวลาได้รับวัคซีนรอบต่อไป"},title=f"{department}:{divisions.iloc[int(division)]}")
fig.update_traces(texttemplate="%{value}")
fig.show()