From f9025e5dfd8f1596057bd58e45475205540a77cb Mon Sep 17 00:00:00 2001 From: Shibshankar0909 <123229119+Shibshankar0909@users.noreply.github.com> Date: Fri, 5 Apr 2024 22:31:06 +0530 Subject: [PATCH] bugs fixed --- graph_game/views.py | 25 +++++++++++++++---------- mindsweeper_website/settings.py | 6 ++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/graph_game/views.py b/graph_game/views.py index 5cfa1ff..4c0636a 100644 --- a/graph_game/views.py +++ b/graph_game/views.py @@ -57,7 +57,7 @@ def formattedTree(): edgeContainer = generate_random_tree(7) listOfEdgesOfUI = [] for tup in edgeContainer: - formatted_string = { "source": tup[0], "target": tup[1], "value": "1" } + formatted_string = { "source": str(tup[0]), "target": str(tup[1]), "value": "1" } listOfEdgesOfUI.append(formatted_string) #final_string = ",\n".join(listOfEdgesOfUI) @@ -89,8 +89,9 @@ def formattedTree(): def process_graph_data(data): #data = json.loads(json_string) - nodes = data.get('nodes', []) - links = data.get('links', []) + input = data.get('input') + nodes = input.get('nodes', []) + links = input.get('links', []) adjacency_matrix = [[0] * len(nodes) for _ in range(len(nodes))] node_values = {} @@ -109,18 +110,22 @@ def process_graph_data(data): def validateTreeFunction(data): adjacency_matrix, node_values = process_graph_data(data) - validity = list("1111111") + validity = list("1" * len(adjacency_matrix)) edgeDifferences = set() - for i in range(0, 7): - for j in range(0, 7): - if(adjacency_matrix[i][j]): - if(abs(node_values[i + 1] - node_values[j + 1]) in edgeDifferences): + for i in range(len(adjacency_matrix)): + for j in range(len(adjacency_matrix[i])): + if adjacency_matrix[i][j]: + if abs(node_values[i + 1] - node_values[j + 1]) in edgeDifferences: validity[i] = '0' validity[j] = '0' + else: + validity[i] = '1' + validity[j] = '1' edgeDifferences.add(abs(node_values[i + 1] - node_values[j + 1])) return validity + class GraphGameView(APIView): authentication_classes = [JWTAuthentication] permission_classes = [IsAuthenticated] @@ -150,7 +155,7 @@ class CreateGraphGameView(APIView): permission_classes = [IsAuthenticated] def post(self, request): - phone_number = request.data('phone') + phone_number = request.data.get('phone') try: profile = Profile.objects.get(phone_number=phone_number) @@ -192,7 +197,7 @@ def post(self, request): game_instance.moves = 0 game_instance.save() - return JsonResponse(status=200, data={'message': 'Done'}) + return JsonResponse(status=200, data=game_instance.tree_structure) class GetGraphView(APIView): diff --git a/mindsweeper_website/settings.py b/mindsweeper_website/settings.py index 782cf5e..b63511a 100644 --- a/mindsweeper_website/settings.py +++ b/mindsweeper_website/settings.py @@ -26,8 +26,10 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] - +ALLOWED_HOSTS = [ + "127.0.0.1", + ] +CORS_ALLOW_CREDENTIALS = True CORS_ORIGIN_ALLOW_ALL = True