File size: 857 Bytes
da43440
d75dae7
a000469
d75dae7
 
 
 
 
 
 
 
a000469
d75dae7
da43440
a000469
da43440
 
 
 
d75dae7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

class SubmitAnswersResponse:
    def __init__(self, username: str, score: float, correct_count: int, total_attempted: int, message: str, timestamp: str):
        self.username = username
        self.score = score
        self.correct_count = correct_count
        self.total_attempted = total_attempted
        self.message = message
        self.timestamp = timestamp

def to_submit_answers_response(json_data) -> SubmitAnswersResponse:
    print(f"Original Response:\n {json_data}")
    return SubmitAnswersResponse(
        username=json_data['username'] or '<unknown>',
        score=json_data['score'] or 0.0,
        correct_count=json_data['correct_count'] or 0,
        total_attempted=json_data['total_attempted'] or 0,
        message=json_data['message'] or 'No message received.',
        timestamp=json_data['timestamp'] or '<unknown>'
    )