728x90

   def api_empolyee(self,resp): #직원현황
        employee = []
        em_num=[]
        em_year=[]
        em_salary=[]
opt1=0
opt2=0
opt3=0
        if resp['status'] == '000':  # 'status': '000' -> 응답이 정상'000' 상태
            for re in resp['list']:  # if resp in resp['list'] : [{ xxxxx ]}
                if re['fo_bbm'] in ['-'] :
opt1 = 1
em_num_x.append('-') //[-]
em_year_x.append('-')
em_salary_x.append('-')
elif re['fo_bbm'] in ['성별합계','성별 합계'] :
opt2 = 1
tmp_num = int(re['sm'].replace(",", "")) #숫자로 바꾸긴해야함
em_num.append(tmp_num) //[1300,1200]
tmp_year = float(re['avrg_cnwk_sdytrn'].replace("년", ".").replace("개월", "").replace(" ", ""))
em_year.append(tmp_year) //[10.1, 12.1]
tmp_salary= int(re['jan_salary_am'].replace(",", "")) 
em_salary.append(tmp_num*tmp_salary) //[1300*5000, 1200*6000]
else #그밖의 모든경우
opt3 = 1
tmp_num = int(re['sm'].replace(",", "")) #숫자로 바꾸긴해야함
em_num_etc.append(tmp_num) // [100,200,300,400] #etc
tmp_year = float(re['avrg_cnwk_sdytrn'].replace("년", ".").replace("개월", "").replace(" ", ""))
em_year_etc.append(tmp_year) //[10.1, 12.1,11.1,13.1] #etc
try: #삼성은 성별합계에만 1인당 연봉이 있고, 부서별론 '-'를 표시하므로 erorr발생 
tmp_salary= int(re['jan_salary_am'].replace(",", "")) 
except:
tmp_salary= 0 #etc
em_salary_etc.append(tmp_num*tmp_salary) //[1300*5000, 1200*6000] or [0,0]
if opt1==1:
employee.append(em_num_x)
employee.append(em_year_x)
employee.append(em_salary_x)
elif (opt2==1 and opt3==1) or (opt2==1 and opt3==0): #성별함계도 있거 일반 부서도 있을때->삼성 LG전자 case
employee.append(sum(em_num)))
employee.append(sum(em_year)/len(em_year))
employee.append(sum(em_salary)/sum(em_num))
else #일반적인경우
employee.append(sum(em_num_etc)))
employee.append(sum(em_year_etc)/len(em_year_etc))
employee.append(sum(em_salary_etc)/sum(em_num_etc))

        while True:
            if len(employee) == 3:
                break
            employee.append('-')
        self.result_empolyee.append(employee)

728x90

'파이썬+VBA' 카테고리의 다른 글

[Python] 다중기업 주요재무현황 추출  (0) 2023.01.06
vba - if 크고 작고고 좀 이상해  (0) 2022.12.19
매크로 만들기  (0) 2022.11.07
kosis 크롤링  (0) 2022.10.07
ipynb 파일을 py파일로 변환하기  (0) 2022.10.04

+ Recent posts