diff --git a/app/repositories/excel.py b/app/repositories/excel.py index efa1ca2..cad16cf 100644 --- a/app/repositories/excel.py +++ b/app/repositories/excel.py @@ -5,11 +5,12 @@ import pandas as pd import os from app.config import TaskEnv -from app.models.design_progress import DesignProgressModel, RecordModel, SubRecord, Record +from app.models.design_progress import DesignProgressModel, RecordModel, SubRecord, Record, UpdateDesignProgress from app.models.project import ProjectModel from core.service.mongo_db import use_collection import jdatetime from app.repositories.project import ProjectRepository +from app.repositories.design_progress import DesignProgressRepository class ExcelRepository(): async def addDesignSheet(self): @@ -183,6 +184,8 @@ class ExcelRepository(): await self.createRecord(my_row, 'مرتبه هفتم', 'seventh_time', progress_id) break print("code", my_row['code']) + + # faz zero------------------------------------------------------------------------ async def addProgressPhysical(self): base_dir = os.path.dirname(os.path.abspath(__file__)) project_root = os.path.abspath(os.path.join(base_dir, "../..")) @@ -231,13 +234,339 @@ class ExcelRepository(): break print("code", my_row['code']) + async def addProgressStudy(self): + base_dir = os.path.dirname(os.path.abspath(__file__)) + project_root = os.path.abspath(os.path.join(base_dir, "../..")) + excel_path = os.path.join(project_root, "faz_zero.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="study", dtype=str) + df = df.fillna("") + projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None) + for index, row in df.iterrows(): + my_row = row.to_dict() + print(f"سطر {index}: {row.to_dict()}") + print("code", my_row['code']) + for p in projects: + if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])): + print('projects', p) + my_project = p + progress_id = None + if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=2, + ) + progress_type.init_id().cu_at() + await use_collection("design_progress").insert_one(progress_type.mongo_dict()) + progress_id = progress_type.id + await self.createRecord(my_row, 'مرتبه اول', 'first_time', progress_id) + if 'second_time/send/date_at' in my_row and my_row[ + 'second_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if 'third_time/send/date_at' in my_row and my_row[ + 'third_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + break + print("code", my_row['code']) + async def addProgressAlternativeSite(self): + base_dir = os.path.dirname(os.path.abspath(__file__)) + project_root = os.path.abspath(os.path.join(base_dir, "../..")) + excel_path = os.path.join(project_root, "faz_zero.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="alternative_site", dtype=str) + df = df.fillna("") + projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None) + for index, row in df.iterrows(): + my_row = row.to_dict() + print(f"سطر {index}: {row.to_dict()}") + print("code", my_row['code']) + for p in projects: + if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])): + print('projects', p) + my_project = p + progress_id = None + if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=3, + ) + progress_type.init_id().cu_at() + await use_collection("design_progress").insert_one(progress_type.mongo_dict()) + progress_id = progress_type.id + await self.createRecord(my_row, 'مرتبه اول', 'first_time', progress_id) + if 'second_time/send/date_at' in my_row and my_row[ + 'second_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if 'third_time/send/date_at' in my_row and my_row[ + 'third_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if 'forth_time/send/date_at' in my_row and my_row[ + 'forth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + break + print("code", my_row['code']) + + async def addProgressAlternativeArchitecture(self): + base_dir = os.path.dirname(os.path.abspath(__file__)) + project_root = os.path.abspath(os.path.join(base_dir, "../..")) + excel_path = os.path.join(project_root, "faz_zero.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="alternative_architecture", dtype=str) + df = df.fillna("") + projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None) + for index, row in df.iterrows(): + my_row = row.to_dict() + print(f"سطر {index}: {row.to_dict()}") + print("code", my_row['code']) + for p in projects: + if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])): + print('projects', p) + my_project = p + progress_id = None + if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=4, + ) + progress_type.init_id().cu_at() + await use_collection("design_progress").insert_one(progress_type.mongo_dict()) + progress_id = progress_type.id + await self.createRecord(my_row, 'مرتبه اول', 'first_time', progress_id) + if 'second_time/send/date_at' in my_row and my_row[ + 'second_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if 'third_time/send/date_at' in my_row and my_row[ + 'third_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if 'forth_time/send/date_at' in my_row and my_row[ + 'forth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + if 'fifth_time/send/date_at' in my_row and my_row[ + 'fifth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + break + print("code", my_row['code']) + + async def completeProgressZero(self): + base_dir = os.path.dirname(os.path.abspath(__file__)) + project_root = os.path.abspath(os.path.join(base_dir, "../..")) + excel_path = os.path.join(project_root, "faz_zero.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="alternative_architecture", dtype=str) + df = df.fillna("") + projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None) + for index, row in df.iterrows(): + my_row = row.to_dict() + print(f"سطر {index}: {row.to_dict()}") + print("code", my_row['code']) + for p in projects: + if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])): + print('projects', p) + my_project = p + progress = await use_collection("design_progress").find_one( + {'project_id': my_project['_id'], 'type': 2}) + if progress and 'complete_at' in my_row and my_row['complete_at'] != '': + print('jjjjjjjjjjjjjjjjjjjj',progress["_id"]) + c = UpdateDesignProgress(complete_at=my_row['complete_at']) + await DesignProgressRepository().update(progress["_id"],c) + break + print("code", my_row['code']) + #---------------------------------------------------------------------------------------- + # faz one----------------------------------------------------------------- + async def addProgressFazOneArt(self): + base_dir = os.path.dirname(os.path.abspath(__file__)) + project_root = os.path.abspath(os.path.join(base_dir, "../..")) + excel_path = os.path.join(project_root, "faz_one.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="architecture", dtype=str) + df = df.fillna("") + projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None) + for index, row in df.iterrows(): + my_row = row.to_dict() + print(f"سطر {index}: {row.to_dict()}") + print("code",my_row['code']) + for p in projects: + if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])): + print('projects', p) + my_project = p + progress_id = None + if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'] + ) + progress.init_id().cu_at() + await use_collection("design_progress").insert_one(progress.mongo_dict()) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'], + parent_id= progress.id, + sub_type= 5, + ) + progress_type.init_id().cu_at() + await use_collection("design_progress").insert_one(progress_type.mongo_dict()) + progress_id = progress_type.id + await self.createRecord(my_row, 'مرتبه اول', 'first_time',progress_id) + if 'second_time/send/date_at' in my_row and my_row['second_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if 'third_time/send/date_at' in my_row and my_row['third_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if 'forth_time/send/date_at' in my_row and my_row['forth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + if 'fifth_time/send/date_at' in my_row and my_row['fifth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + if 'sixth_time/send/date_at' in my_row and my_row['sixth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه ششم', 'sixth_time', progress_id) + if 'seventh_time/send/date_at' in my_row and my_row['seventh_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه هفتم', 'seventh_time', progress_id) + if 'eighth_time/send/date_at' in my_row and my_row['eighth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه هشتم', 'eighth_time', progress_id) + break + print("code", my_row['code']) + async def addProgressFazOneUniversity(self): + base_dir = os.path.dirname(os.path.abspath(__file__)) + project_root = os.path.abspath(os.path.join(base_dir, "../..")) + excel_path = os.path.join(project_root, "faz_one.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="university", dtype=str) + df = df.fillna("") + projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None) + for index, row in df.iterrows(): + my_row = row.to_dict() + print(f"سطر {index}: {row.to_dict()}") + print("code", my_row['code']) + for p in projects: + if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])): + print('projects', p) + my_project = p + progress_id = None + if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':3}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=6, + ) + progress_type.init_id().cu_at() + await use_collection("design_progress").insert_one(progress_type.mongo_dict()) + progress_id = progress_type.id + await self.createRecord(my_row, 'مرتبه اول', 'first_time', progress_id) + if 'second_time/send/date_at' in my_row and my_row[ + 'second_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if 'third_time/send/date_at' in my_row and my_row[ + 'third_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if 'forth_time/send/date_at' in my_row and my_row[ + 'forth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + if 'fifth_time/send/date_at' in my_row and my_row[ + 'fifth_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + break + print("code", my_row['code']) + async def addProgressFazOneAll(self): + base_dir = os.path.dirname(os.path.abspath(__file__)) + project_root = os.path.abspath(os.path.join(base_dir, "../..")) + excel_path = os.path.join(project_root, "faz_one.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="university", dtype=str) + df = df.fillna("") + projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None) + for index, row in df.iterrows(): + my_row = row.to_dict() + print(f"سطر {index}: {row.to_dict()}") + print("code", my_row['code']) + for p in projects: + if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])): + print('projects', p) + my_project = p + progress_id = None + if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':3}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=7, + ) + progress_type.init_id().cu_at() + await use_collection("design_progress").insert_one(progress_type.mongo_dict()) + progress_id = progress_type.id + await self.createRecord(my_row, 'مرتبه اول', 'first_time', progress_id) + if 'second_time/send/date_at' in my_row and my_row[ + 'second_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if 'third_time/send/date_at' in my_row and my_row[ + 'third_time/send/date_at'] != "" and progress_id: + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + + break + print("code", my_row['code']) + + def createDate(self, date): year = int(date[:4]) month = int(date[4:6]) day = int(date[6:8]) jalali_date = jdatetime.date(year, month, day) gregorian_date = jalali_date.togregorian() - created_at = datetime.datetime.combine(gregorian_date, datetime.time()) + created_at = datetime.datetime.combine(gregorian_date, datetime.time.min) return created_at async def createRecord(self, my_row, _time_f, _time_e, progress_id): @@ -251,7 +580,8 @@ class ExcelRepository(): title=_time_f, send=send, ) - if my_row[f'{_time_e}/receive/date_at'] and my_row[f'{_time_e}/receive/date_at'] != "": + if f'{_time_e}/receive/date_at' in my_row and my_row[f'{_time_e}/receive/date_at'] != "": + print(my_row[f'{_time_e}/receive/date_at']) receive = SubRecord( date_at=self.createDate(my_row[f'{_time_e}/receive/date_at']), number=my_row[f'{_time_e}/receive/number'], diff --git a/app/urls/excel.py b/app/urls/excel.py index 451176f..09f92ef 100644 --- a/app/urls/excel.py +++ b/app/urls/excel.py @@ -23,4 +23,45 @@ def monitor(): def addProgress1(): pass +@router.get('/progress/physical', tags=_tag_base) +@shrink(repo.addProgressPhysical) +def addProgressPhysical(): + pass + +@router.get('/progress/study', tags=_tag_base) +@shrink(repo.addProgressStudy) +def addProgressStudy(): + pass + +@router.get('/progress/site', tags=_tag_base) +@shrink(repo.addProgressAlternativeSite) +def addProgressAlternativeSite(): + pass + +@router.get('/progress/art', tags=_tag_base) +@shrink(repo.addProgressAlternativeArchitecture) +def addProgressAlternativeArchitecture(): + pass + +@router.get('/progress/zero/complete', tags=_tag_base) +@shrink(repo.completeProgressZero) +def completeProgressZero(): + pass + +@router.get('/progress/one/art', tags=_tag_base) +@shrink(repo.addProgressFazOneArt) +def addProgressFazOneArt(): + pass + +@router.get('/progress/one/university', tags=_tag_base) +@shrink(repo.addProgressFazOneUniversity) +def addProgressFazOneUniversity(): + pass + + +@router.get('/progress/one/all', tags=_tag_base) +@shrink(repo.addProgressFazOneAll) +def addProgressFazOneAll(): + pass + app.include_router(router) \ No newline at end of file