Spaces:
Runtime error
Runtime error
from typing import Dict, List | |
import pandas as pd | |
from config import CONFIG | |
from .entities import Employee, WorkingTime | |
def get_data(data: pd.DataFrame) -> pd.DataFrame: | |
data.columns = data.iloc[1, :] | |
data = data.iloc[2:, ] | |
data = data[['Mã N.Viên', "Tên nhân viên", "Ngày", "Vào", "Ra"]] | |
data = data.groupby(by=['Mã N.Viên', 'Ngày']).aggregate({ | |
"Tên nhân viên": max, | |
"Vào": sum, | |
"Ra": sum | |
}).reset_index() | |
return data | |
def parse(data: pd.DataFrame) -> List[Employee]: | |
employees: List[Employee] = [] | |
for (id, name), v in data.groupby(by=['Mã N.Viên', 'Tên nhân viên']): | |
employee = Employee(id=id, name=name, workdate={}) | |
for val in v.values: | |
working_time = WorkingTime(date=val[1], | |
checkin=val[3], | |
checkout=val[4], | |
config=CONFIG) | |
date, work_time = working_time.to_tuple() | |
employee.workdate[date] = work_time | |
employees.append(employee) | |
return employees | |
def make_table(employees: List[Employee]) -> pd.DataFrame: | |
id_list: List[str] = [] | |
name_list: List[str] = [] | |
work_date: List[Dict] = [] | |
for employee in employees: | |
id_list.append(employee.id) | |
name_list.append(employee.name) | |
work_date.append(employee.workdate) | |
work_df: pd.DataFrame = pd.DataFrame(work_date, dtype=int) | |
info_df: pd.DataFrame = pd.DataFrame({ | |
'Mã nhân viên': id_list, | |
'Tên nhân viên': name_list | |
}) | |
working_table: pd.DataFrame = pd.concat(objs=[info_df, work_df], axis=1) | |
return working_table | |