From 6d8a53052203c28f10db786a223d12cee0ac535e Mon Sep 17 00:00:00 2001 From: romflorod Date: Mon, 20 Dec 2021 18:41:53 +0100 Subject: [PATCH] =?UTF-8?q?Finalizaci=C3=B3n=20HuntingtonHill=20y=20testea?= =?UTF-8?q?do?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 16 ++++++++++++ decide/postproc/tests.py | 26 +++++++++++++++++++ decide/postproc/views.py | 54 ++++++++++++++++++++++------------------ decide/voting/tests.py | 13 ++++++++++ 4 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..e191e8ed8c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Python: Django", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/decide/manage.py", + "args": [ + "runserver", + "0.0.0.0:8000" + ], + "django": true, + "justMyCode": false, + } + ] +} \ No newline at end of file diff --git a/decide/postproc/tests.py b/decide/postproc/tests.py index 1a6a27e86c..6b20f5851f 100644 --- a/decide/postproc/tests.py +++ b/decide/postproc/tests.py @@ -42,3 +42,29 @@ def test_identity(self): values = response.json() self.assertEqual(values, expected_result) + + def testHuntington(self): + data = { + 'type': 'HUNTINGTONHILL', + 'options': [ + {'option':'A','number':1,'votes': 95000}, + {'option':'B', 'number':2,'votes': 75000}, + {'option':'C', 'number':3,'votes': 25000}, + {'option':'D', 'number':4,'votes': 15000} + ], 'numEscanyos': 8 + + } + + expected_result = [ + {'option':'A','number':1,'votes': 95000,'postproc':4}, + {'option':'B', 'number':2,'votes': 75000,'postproc':3}, + {'option':'C', 'number':3,'votes': 25000,'postproc':1}, + {'option':'D', 'number':4,'votes': 15000,'postproc':0} +] + response = self.client.post('/postproc/', data, format='json') + + self.assertEqual(response.status_code, 200) + values = response.json() + + + self.assertEqual(values, expected_result) diff --git a/decide/postproc/views.py b/decide/postproc/views.py index 73024fae72..89104a6ee4 100644 --- a/decide/postproc/views.py +++ b/decide/postproc/views.py @@ -19,35 +19,34 @@ def identity(self, options): out.sort(key=lambda x: -x['postproc']) return Response(out) - def HuntingtonHill(self,numEscanos,options): + def HuntingtonHill(self,options,numEscanyos): votosTotales = 0 for x in options: votosTotales += x['votes'] - if votosTotales > 0 and numEscanos > 0: + if votosTotales > 0 and numEscanyos > 0: - limite = votosTotales/numEscanos + limit = votosTotales/numEscanyos - #Crear parametros para metodo rounding rule - rounding = limite*0.001 - lower = limite-rounding - upper = limite+rounding + #Vamos a aplicar la regla rounding + rounding = limit*0.001 + lower = limit-rounding + upper = limit+rounding - numEscanosAsig = 0 + numEscanyosAsig = 0 - while(numEscanosAsig != numEscanos): + while(numEscanyosAsig != numEscanyos): - #si llegamos a aplicar rounding rule y no llegamos al numero igual de escanos, - #reseteamos de nuevo el numero de escanos asig y empezamos de nuevo - numEscanosAsig = 0 + ##si no se cumple la regla reseteamos cero + numEscanyosAsig = 0 for x in options: - if(x['votes']