글또9기10기:영국직장:데이터과학

런던직장: 주말공부2

채유나 chaeyoonaaa 2024. 11. 17. 13:26
반응형

점심약속이 있었다. 일부 노던라인 구간이 정비중이라 버스를 대신 타면서 추가 시간이 걸렸고, 오랜만의 약속 자리가 흥겨운 나머지 생각보다 오래 밖에서 시간을 보냈다. 생산적으로 보낼 시간이 줄어들어 살짝 후회하기도 ... 내일 테스트해볼 수도코드 정리 완료해두는게 것으로 만족한다.


from pyspark.sql import SparkSession, functions as F

class CP_Demand_Model:
    def __init__(self, global_params, ip_params, dispensing_params, clinics_params, selfcare_params, vaccinations_params, intervention_flag=False):
        self.spark = SparkSession.builder.appName("CP Demand Model").getOrCreate()
        self.global_params = global_params
        self.ip_params = ip_params
        self.dispensing_params = dispensing_params
        self.clinics_params = clinics_params
        self.selfcare_params = selfcare_params
        self.vaccinations_params = vaccinations_params
        self.intervention_flag = intervention_flag

    def IP(self):
        # ... (implementation as before, using class attributes)
        return df

    def Dispensing(self):
        # ... (implementation as before, using class attributes)
        return df

    def Clinics(self):
        # ... (implementation as before, using class attributes)
        return df

    def Selfcare(self):
        # ... (implementation as before, using class attributes)
        return df

    def Vaccinations(self):
        # ... (implementation as before, using class attributes)
        return df

    def Supervision(self):
        # ... (implementation as before, using class attributes)
        return df

    def CP_demands_counterfactuals(self, dfs):
        # ... (implementation as before, using class attributes)
        return df

    def CP_demands_counterfactuals_technicians(self, total_df, dispensing_df, clinics_df, vaccinations_df):
        # ... (implementation as before, using class attributes)
        return df

    def CP_demand_interventions(self):
        # ... (implementation as before, using class attributes)
        return df

    def union_counterfactuals(self, dfs):
        # ... (implementation as before)
        return df

    def get_final_df(self):
        dispensing_df = self.Dispensing()
        ip_df = self.IP()
        clinics_df = self.Clinics()
        selfcare_df = self.Selfcare()
        vaccinations_df = self.Vaccinations()
        supervision_df = self.Supervision()

        # ... (rest of the code to calculate counterfactuals and technicians)

        if self.intervention_flag:
            interventions_df = self.CP_demand_interventions()
            combined_df = self.union_counterfactuals([total_pharmacists_df, total_technicians_df, interventions_df])
        else:
            combined_df = self.union_counterfactuals([total_pharmacists_df, total_technicians_df])

        return combined_df

반응형

'글또9기10기:영국직장:데이터과학' 카테고리의 다른 글

런던직장: 출근길 낭만  (2) 2024.11.19
런던직장: 주말공부3  (2) 2024.11.18
런던직장: 디펜스  (2) 2024.11.12
런던직장: 효율 높이기  (0) 2024.11.11
런던직장: 주말공부  (0) 2024.11.10