kookmin-sw / capstone-2023-05

capstone-2023-05 created by GitHub Classroom
https://capstone-2023-05.vercel.app
0 stars 0 forks source link

Back/refactor/vote current round #76

Closed seungholee-dev closed 1 year ago

seungholee-dev commented 1 year ago

추가 기능

테스팅 방법

테스팅 결과

라운드가 시작되지 않았거나, 진행중인 라운드가 없거나, 라운드가 모두 끝났거나의 경우에는 반영할수없다는 메시지를 리턴해줍니다. 라운드 진행 중이라면 반영했다는 성공 메시지가 와요!

Jaewook-Lee commented 1 year ago

제가 올렸던 #74 PR에서 초기 투표 케이스를 해결하기 위해 round 값으로 0을 주는 방법을 사용했었습니다. 그리고 여기 PR은 이제 프론트에서 round 값을 받지 않습니다.
그러면 여기서는 최초 라운드 시작하기 전의 초기 투표의 경우는 어떻게 다루고 있는 건가요?
initJoin 하고 나서 #74 PR 대로 round 값에 0을 주고 vote 진행하니 "Either no rounds are on-going or the battle has ended" 메세지를 받았어요.

Binsk-dev commented 1 year ago

바뀐 코드를 봤는데 제가 생각한 방향이랑 살짝 다르네요. 일단 현재 라운드 정보를 프론트 측에서 제공받지 않는다는 가정까지는 동일한데, 저는 재욱님이 추가하신 DynamoDB에 있는 currRound 필드값을 읽어와 Support 테이블 인스턴스를 생성한다고 생각했는데 이 PR은 get_single_current_round() 를 호출해서 가져오네요.

제 생각에는 사전에 라운드가 바뀌는 상황이 발생하면 만드신 get_single_current_round()를 통해서 currRound를 미리 바꾸어두고 나머지 API에서 이 필드를 이용하는 방식이 좋아보입니다.

seungholee-dev commented 1 year ago

앗 그렇네요 저희 보통 투표를 라운드가 끝나고 하는 건가요 아니면 끝나기 전에 투표하나요??

seungholee-dev commented 1 year ago

초기 투표 상황도 바꾸어줘야겠네용

Jaewook-Lee commented 1 year ago

@PricelessCode

앗 그렇네요 저희 보통 투표를 라운드가 끝나고 하는 건가요 아니면 끝나기 전에 투표하나요??

Figma 그림 참고하시면 됩니다~

seungholee-dev commented 1 year ago

라운드 없이 요청할 수 있도록 수정했어요!

추가 기능 -midresult 기능 추가 -라운드 없이 action 요청 가능 -배틀 생성 시 round 0 추가 생성

테스팅 방법

  1. 새로 pull 해주세용
  2. createBattle해주세요
  3. 몇몇의 참가자가 initJoin -> 호스트 startBattle (게임 시작) -> 호스트 startRound 호출(라운드 0시작입니다) -> 유저들 vote -> endRound -> startRound -> vote -> endRound 무한 반복. DB와 DynamoDB에 정상 반영되는지 확인해주세요

게임 핵심 진행이어서 됏으면 조켓네영 ㅎㅎ

Jaewook-Lee commented 1 year ago

테스트 진행했습니다. 진행하면서 에러 메세지는 없었습니다. 하지만 하나의 문제점을 발견했습니다.
토론 참여자가 vote 를 하면 DynamoDB에 "currRound" 필드가 사라집니다.
아래의 코드가 원인인 것 같습니다.

# src/game/app.py > vote_handler
dynamo_db.put_item(
        TableName=config.DYNAMODB_WS_CONNECTION_TABLE,
        Item={
            'connectionID': {'S': connection_id},
            'battleID': {'S': battle_id},
            'teamID': {'S': team_id},
            'userID': {'S': user_id},
            'nickname': {'S': nickname}
        }
    )

Boto3 문서를 보면 아래와 같이 설명했습니다.

If an item that has the same primary key as the new item already exists in the specified table, the new item completely replaces the existing item.

initJoin 했을 때 DynamoDB에 등록하고 vote 를 하면 "currRound" 필드가 없는 버전으로 새롭게 덮어쓰게 됩니다. 이에 대한 해결책이 필요합니다.
문서를 추가적으로 읽어보니 update_item 함수가 있는데 이를 사용하면 되지 않을까 싶습니다. 한 번 읽어보길 바랍니다.
update_item 함수 설명

seungholee-dev commented 1 year ago

가이드 감사드립니다! 혹시 저희 currRound 필드가 현재 라운드를 알지 못해서 보관하는 것으로 이해했었는데 혹시 currRound 저희 DynamoDB에 유지하는 것으로 진행하나용?

Jaewook-Lee commented 1 year ago

@PricelessCode
DynamoDB에 유지하는걸로 진행해보고 아니다 싶으면 다른 방안을 찾아봐요.

seungholee-dev commented 1 year ago

완성 했으요~ 위의 기능들 종합한 결과 입니다. 테스트 부탁드려요 좀 길지만요 ㅠ

추가기능

테스팅 형식이 정해진 것은 아니지만 한 게임 진행해보시면 위의 결과 보실 수 있을거예요. 감사합니다.

Binsk-dev commented 1 year ago

해당 구현에서 dynamodb에 있는 currRound 값이 유지되면서 계속 업데이트 되는게 맞죠?

seungholee-dev commented 1 year ago

@Binsk-dev 재욱님이랑 실시간으로 상의한 결과 dynamoDB에 있는 currRound의 값이 필요가 없어서 삭제했습니다. 가져오는 방식은 비슷하지만 SQL문으로 currentRound를 가져온다고 보시면 됩니다. 편의 함수로 만들어놔서 재사용했습니다.

Jaewook-Lee commented 1 year ago

각 팀에서 의견 1개씩 작성하고 호스트 측에서 preparationStart 해봤는데 newAds가 빈 리스트로 와요...

seungholee-dev commented 1 year ago

@Jaewook-Lee startPreparation 알고리즘 부분은 건드리지 않았는데 한 번 확인해 볼게요! 혹시 여러개의 의견에서도 동일한 증상 나타나나요?! 로컬에서 여러 개의 의견으로 테스트 해봤는데, newAds에 값 들어있는게 확인이 돼서용

Jaewook-Lee commented 1 year ago

이거 원인이 제가 테스트 하는 순서가 달라서 그런 것 같은데 저는 startRound -> sendOpinion(양 팀에서 1개씩) -> preparationStart -> vote -> endRound 이런 순서로 테스트를 하고 있는데 로컬 테스트 어떤 순서로 진행하셨나요?

seungholee-dev commented 1 year ago

음 저는 아래와 같이 진행했어요

  1. host initJoin / user 2명 initJoin
  2. host startBattle
  3. host startRound (라운드 0 시작)
  4. user 2명 서로 다른 팀 vote
  5. host endRound
  6. host startRound (라운드 1 시작)
  7. host startPreparation 호출
  8. user 2명 send opinion
  9. host에서 startpreparation 끝났다는 메시지 기다림 10.host endRound 호출

자료는 저번에 주신 csv파일에 들은 여러 의견들을 바탕으로 했어용

Jaewook-Lee commented 1 year ago

그러면 라운드 1 ~ 3 때 vote는 언제 진행하셨나요?

seungholee-dev commented 1 year ago

아아 그 부분은 호스트가 endround를 호출하기 전에 진행하는 걸로 생각하긴했습니다. startPreparation이 끝나면 프론트에서 투표 화면을 피그마처럼 보여주고 프론트에서 시간이 끝나면 endRound를 호출해줘서 mid Result를 받는걸루용 혹시 개선부분 잇을까용?

Jaewook-Lee commented 1 year ago

뭔가 이해가 안 되네요...?

select_query = f"""SELECT ("Opinion"."userId","Opinion"."order","Opinion"."noOfLikes","Opinion"."content", "Opinion"."publishTime", "Opinion"."dropTime", "Opinion"."status","Support"."vote") FROM "Opinion", "Support" 
        WHERE "Opinion"."userId" = "Support"."userId" and "Opinion"."battleId" = '{my_battle_id}' and "Support"."battleId" = '{my_battle_id}' and "Opinion"."roundNo" = {curr_round} and "Support"."roundNo" = {curr_round} and status != 'REPORTED'"""

위의 SQL 쿼리를 보면 Opinion 테이블의 "roundNo" 값과 Support 테이블의 "roundNo" 값이 모두 curr_round로 같을 때 의견들을 가져올 수 있을텐데 얘기하신 순서대로 하면 가져와지는 의견 자체가 없어요. 초기 투표를 하면 Support 테이블에는 0라운드에 대한 투표 기록만 남고, 이후에 1라운드는 시작돼서 Opinion에 있는 의견들의 roundNo 값은 모두 1일텐데 SQL 쿼리 조건을 만족하지 않아서 빈 리스트가 오는 것이라 생각했는데 승호 님이 로컬 테스트에서 됐다고 하니 뭔가 이상하네요...
혹시 로컬 테스트 하실 때 전의 csv 파일을 싹 다 테이블에 박고 테스트를 진행하신건가요?

seungholee-dev commented 1 year ago

코드 확인해보니깐 그렇네용 아마도 잔유했던 DB정보 데이터 정보가 문제 없이 동작했나봐요 Sql시에 curr_round 대신 curr_round -1로 수정하려고 하는데 어떤가요?

Jaewook-Lee commented 1 year ago

저도 방금 딱 그 생각을 했어요!!

seungholee-dev commented 1 year ago

혹시 다들 이런 에러 가끔 나시나요? preparationStart하면서 제 세팅이 문제인지 아니면 가끔 엣지 케이스로 나는 에러인지 궁금해서요 저희 혹시 preparationStart에서 publish없이 drop되는 케이스가 추가 되었나용?

게임하면서 의견내는 과정에서 published 전환 없이 바로 drop되는 경우가 있는 것 같아서요 like를 안눌러주긴 했는데 혹시 아래와 같은 에러 생기시나요?

Traceback (most recent call last):
  File "/home/seungho/Desktop/CS/capstone-2023-05/backend/node_modules/serverless-offline/src/lambda/handler-runner/python-runner/invoke.py", line 97, in <module>

    result = handler(input['event'], context)
  File "/home/seungho/Desktop/CS/capstone-2023-05/backend/src/utility/websocket.py", line 37, in wrapper
    return func(event, context, wsclient)
  File "/home/seungho/Desktop/CS/capstone-2023-05/backend/src/lambda/handler.py", line 121, in preparation_start_handler

    return app.preparation_start_handler(event, context, wsclient)
  File "/home/seungho/Desktop/CS/capstone-2023-05/backend/src/game/app.py", line 447, in preparation_start_handler

    best_opinions = get_best_opinions(
  File "/home/seungho/Desktop/CS/capstone-2023-05/backend/src/game/app.py", line 292, in get_best_opinions
    best_opinions[team_i].sort(key=lambda x: helper(x), reverse=True)
  File "/home/seungho/Desktop/CS/capstone-2023-05/backend/src/game/app.py", line 292, in <lambda>
    best_opinions[team_i].sort(key=lambda x: helper(x), reverse=True)
  File "/home/seungho/Desktop/CS/capstone-2023-05/backend/src/game/app.py", line 269, in helper

    publish_time = datetime.strptime(
  File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime

    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%d %H:%M:%S.%f'

(λ: send-handler) RequestId: e2a27fa6-1cc7-4e6e-a642-2a50da9b1960  Duration: 43.45 ms  Billed Duration: 44 ms

image

seungholee-dev commented 1 year ago

우선 current_round -1로 하니깐 올린 의견 바로 보이네요! 커밋날렷어요!

Jaewook-Lee commented 1 year ago

@PricelessCode

preparationStart하면서 제 세팅이 문제인지 아니면 가끔 엣지 케이스로 나는 에러인지 궁금해서요 저희 혹시 preparationStart에서 publish없이 drop되는 케이스가 추가 되었나용?

저도 이 에러 오늘 테스트하다 봤어요.. 이거... 다시 preparationStart 뜯어봐야 할 것 같네요...(제기랄)

seungholee-dev commented 1 year ago

해당 부분 저도 빠른 디버깅을 위해서 함께 봐보도록할게용

지금까지 분석했던 것은 best 함수가 published 상태에서 dropped로 변경된다는 가정하에 dropped의 publishedTime을 가져오는 과정에서 여기서 empty string을 가져와서 그런 것 같습니다.

Jaewook-Lee commented 1 year ago

@PricelessCode preparationStart 액션 요청하고 cycle 끝날 때 서버에서 startPreparation 액션 이름으로 메세지 보내는데 이거 이름이 너무 헷갈려요... startPreparation 액션 이름을 다른 걸로 바꾸는거 어떨까요? 예를 들어 preparationEnd 라던지...

Jaewook-Lee commented 1 year ago

preparationStart하면서 제 세팅이 문제인지 아니면 가끔 엣지 케이스로 나는 에러인지 궁금해서요 저희 혹시 preparationStart에서 publish없이 drop되는 케이스가 추가 되었나용? 게임하면서 의견내는 과정에서 published 전환 없이 바로 drop되는 경우가 있는 것 같아서요 like를 안눌러주긴 했는데 혹시 아래와 같은 에러 생기시나요?

이거... 제가 여러 가지 테스트 해보니까 제가 전에 구현해던 로직이 불완전해서 생기는 에러인 것 같네요.. 코드 안에서 indexing 할 때 들어가지 말아야 할 값이 인덱스 범위에 포함돼서 생기는 에러로 추측됩니다.
전에 수정할 때 사용했던 브랜치에서 다시 보완하고 PR 새로 올리겠습니다.

Jaewook-Lee commented 1 year ago

78번 PR로 위 에러에 대한 수정 사항을 올렸으니 확인 바랍니다.
dev 브랜치가 아닌 여기 브랜치로 merge 시키려는 이유는.. 이 브랜치에서 에러 없이 테스트를 완료하고 싶어서...!
조속한 확인 부탁드립니다!

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
capstone-2023-05 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 25, 2023 6:18am
seungholee-dev commented 1 year ago

동작 확인했습니다! 에러 없이 잘 작동하는 것 같아요!

seungholee-dev commented 1 year ago

@Binsk-dev 혹시 테스트 해보시구 문제 발견하시면 Issue로 생성해주세요! 시간관계상 Merge 진행할게요!