Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions graph_game/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions mindsweeper_website/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down