Skip to content

Commit

Permalink
[Patch] Router 버그 핸들링 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
sangin514 authored Nov 17, 2023
2 parents ae66bbe + 3be8c69 commit bd21c0a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions fastapi/src/chatting/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def create_intimacy(chatting_id: int, user_id: int = Depends(check_session),

curr_texts = service.get_all_texts(db, user_id, chatting_id, limit=20)
if is_default:
# we cannot calculate delta value with default intimacy
prev_texts = []
similarity = None
num_F = None
else:
prev_texts = service.get_all_texts(
db, user_id, chatting_id, limit=20, timestamp=recent_intimacy.timestamp)
initiator = chatting.initiator
Expand All @@ -130,11 +135,6 @@ def create_intimacy(chatting_id: int, user_id: int = Depends(check_session),
df_responder = get_user_dataframe(responder)
similarity = get_similarity(df_initiator, df_responder)
num_F = get_mbti_f(initiator, responder)
else:
# we cannot calculate delta value with default intimacy
prev_texts = []
similarity = None
num_F = None

intimacy = calculator.calculate(
user_id, curr_texts, prev_texts, recent_intimacy, similarity, num_F)
Expand All @@ -158,7 +158,7 @@ def get_topic_recommendation(
limit: int = Query(
1, description="how many topics to return"),
user_id: int = Depends(check_session),
db: DbSession = Depends(DbConnector.get_db)) -> TopicResponse:
db: DbSession = Depends(DbConnector.get_db)) -> List[TopicResponse]:
intimacy = service.get_recent_intimacy(db, user_id, chatting_id)
tag = service.intimacy_tag(intimacy)
topics = service.get_topics(db, tag, limit)
Expand Down
4 changes: 2 additions & 2 deletions fastapi/src/chatting/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ def get_all_texts(
)
if chatting_id is not None:
query = query.where(Chatting.id == chatting_id)
if limit is not None:
query = query.limit(limit=limit)
if timestamp is not None:
query = query.where(Text.timestamp <= timestamp)
if limit is not None:
query = query.limit(limit=limit)

return query.all()

Expand Down
2 changes: 1 addition & 1 deletion fastapi/src/user/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def create_user(req: CreateUserRequest, verification_id: int = Depends(check_ver
profile_id = service.create_profile(db, req.profile)
service.create_user(db, req, verification_id, profile_id, main_lang_id, salt, hash)
session_key = generate_session_key(profile_id)
create_session(db, profile_id)
create_session(db, session_key, profile_id)
db.commit()

return SessionResponse(access_token=session_key, token_type="bearer")
Expand Down
5 changes: 3 additions & 2 deletions fastapi/src/user/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ def get_similarity(df_me: pd.DataFrame, df_target: pd.DataFrame) -> float:
cnt += len(set(my_list) & set(target_list))
my_size += len(my_list)
target_size += len(target_list)
similarity = cnt / np.sqrt((my_size * target_size))

return similarity
if my_size == 0 or target_size == 0:
return None
return cnt / np.sqrt((my_size * target_size))


def get_mbti_f(initiator: User, responder: User) -> int:
Expand Down

0 comments on commit bd21c0a

Please sign in to comment.