Skip to content

Commit

Permalink
[feat] DB 매핑, DB 연동 성공
Browse files Browse the repository at this point in the history
  • Loading branch information
rover0811 committed Dec 25, 2022
1 parent a7ea3a7 commit 613b804
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion API/get_grade.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_webdriver(self) -> webdriver.Chrome:
webdriver.Chrome: 브라우저 컨트롤 객체
"""
options = webdriver.ChromeOptions()
# options.add_argument("headless") #CLI에서 실행
options.add_argument("headless") #CLI에서 실행
options.add_argument('no-sandbox') #GPU관련 작업 하지 않음
options.add_argument('disable-gpu') #GPU관련 작업 하지 않음
options.add_argument('disable-dev-shm-usage') #공유 메모리 사용하지 않음, 속도 개선을 위해
Expand Down
2 changes: 2 additions & 0 deletions API/insert_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def insert_data_db(insert_data:dict):
engine = create_engine(f"mysql+pymysql://root:[email protected]:3306/grade", encoding='utf-8')
# user = User(**insert_data)
session = Session(engine) #세션을 생성
insert_data["update_date"]=datetime.datetime.now()
session.query(User).filter(User.studentId==f"{insert_data['student_id']}").update(
{User.bigData:insert_data["big_data"],
User.businessManagement:insert_data["business_management"],
Expand All @@ -84,6 +85,7 @@ def insert_data_db(insert_data:dict):

except TimeoutError as e: #DB 연결을 위한 시간이 너무 오래 걸리는 경우
print("Exception in insert data to DB", e)


except IntegrityError as e: #기본 키 등의 제약이 지켜지지 않은 경우
print("Integirity Violence Errror!", e)
Expand Down
38 changes: 21 additions & 17 deletions API/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,32 @@ def get_token(token:Key):
subject_names = ['PHL', '융합전공을위한수학', '빅데이터프로그래밍언어',"IT기반의유통물류경영",'프로그래밍및실습']

grade_infos = [grade for grade in grade_first if grade['과목명'] in subject_names] #배열안에 딕셔너리

grade_simple=dict()
for i in grade_infos:
grade_simple[i["과목명"]]=i["성적"]
columns_names = ['phl','math','programming','business_management','big_data','com_score','soft_score']
grade_final={key:0 for key in columns_names}

grade_keys=grade_simple.keys()

for key in grade_keys:
if key=="PHL":
grade_final["phl"]=grade_simple["PHL"]
if key=="융합전공을위한수학":
grade_final["math"]=grade_simple["융합전공을위한수학"]
if key=="프로그래밍및실습":
grade_final["programming"]=grade_simple["프로그래밍및실습"]
if key=="IT기반의유통물류경영":
grade_final["business_management"]=grade_simple["IT기반의유통물류경영"]
if key=="빅데이터프로그래밍언어":
grade_final["big_data"]=grade_simple["빅데이터프로그래밍언어"]

#


#예외처리 필요
grade_simple["phl"]=grade_simple.pop("PHL")
grade_simple["math"]=grade_simple.pop("융합전공을위한수학")
grade_simple["programming"]=grade_simple.pop("프로그래밍및실습")
grade_simple["business_management"]=grade_simple.pop("IT기반의유통물류경영")
grade_simple["big_data"]=grade_simple.pop("빅데이터프로그래밍언어")

# grade_simple["com_score"]=0.2*int(grade_simple["phl"])+0.2*int(grade_simple["math"])
# +0.3*int(grade_simple["big_data"])+0.3*int(grade_simple["business_management"])
# grade_simple["soft_score"]=0.2*int(grade_simple["phl"])+0.2*int(grade_simple["math"])
# +0.3*int(grade_simple["big_data"])+0.3*int(grade_simple["programming"])

# insert_sql()
grade_final["com_score"]=round(0.2*int(grade_final["phl"])+0.2*int(grade_final["math"])+0.3*int(grade_final["big_data"])+0.3*int(grade_final["business_management"]),ndigits=3)
grade_final["soft_score"]=round(0.2*int(grade_final["phl"])+0.2*int(grade_final["math"])+0.3*int(grade_final["big_data"])+0.3*int(grade_final["programming"]),ndigits=3)
grade_final["student_id"]=token.id_
insert_sql.insert_data_db(grade_final)



return grade_simple
return grade_final

0 comments on commit 613b804

Please sign in to comment.