Skip to content

Commit

Permalink
Move to port 8080 and accept quiz results.
Browse files Browse the repository at this point in the history
  • Loading branch information
mopore committed Aug 1, 2023
1 parent d6e4564 commit 340f2f1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
container_name: marcel_knowhow_backend
image: marcel_knowhow_backend
ports:
- 8080:8000
- 8080:8080
environment:
- MARCEL_DB_URI=bolt://marcel_knowhow_db:7687
restart: unless-stopped
Expand Down
5 changes: 0 additions & 5 deletions src/jni_item.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/jni_item_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jni_item import Item
from jni_types import Item
from jni_neo_bridge import NeoBridge


Expand Down
4 changes: 2 additions & 2 deletions src/jni_neo_bridge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from neo4j import GraphDatabase, Driver
from jni_item import Item
from jni_types import Item

NEO_URI_ENV_NAME = "MARCEL_DB_URI"
NEO_USERNAME = "neo4j"
Expand Down Expand Up @@ -49,7 +49,7 @@ def _read_items(self) -> list[Item]:
id = record['q.id']
question = record['q.question']
yes_answer = record['q.yes_answer']
item = Item(id, question, yes_answer)
item = Item(id=id, question=question, yes_answer=yes_answer)
items.append(item)
return items

Expand Down
12 changes: 12 additions & 0 deletions src/jni_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pydantic import BaseModel


class Item(BaseModel):
id: int
question: str
yes_answer: bool


class ResultsServerRequest(BaseModel):
questions: list[Item]
answers: list[bool]
22 changes: 15 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from jni_item_provider import ItemProvider
from jni_types import ResultsServerRequest


app = FastAPI()
Expand Down Expand Up @@ -37,13 +38,20 @@ async def read_items():


@app.post("/quizz_results")
async def create_quizz_results():
# TODO Create a quizz results class
# json_content = message.content.strip()
# dict = json.loads(json_content)
# selected_option = dict["selected_option"]
pass
async def create_quizz_results(request: ResultsServerRequest):
questions = request.questions
answers = request.answers

# Count the number of correct answers.
correct_answers = 0
for i in range(len(questions)):
if questions[i].yes_answer == answers[i]:
correct_answers += 1

# Compute and return the ratio of correct answers.
correctness_ratio = correct_answers / len(questions)
return {"ratio": correctness_ratio}


if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="0.0.0.0", port=8080)

0 comments on commit 340f2f1

Please sign in to comment.