def getData(self): jsonOndeFoiRoubado = self.getJsonFromOndeFoiRoubado() jsonOndeTemTiro = self.getJsonFromOnteTemTiro() postgre = Postgres() postgre.open() postgre.insertOndeFoiRoubado(jsonOndeFoiRoubado) postgre.insertOndeTemTiro(jsonOndeTemTiro) postgre.close()
def type(): postgre = Postgres() postgre.open() results = postgre.getType() postgre.close() types = fromResultsToType(results) return Response(json.dumps(types), status=200, mimetype='application/json')
def agregaPorTipo(): postgre = Postgres() postgre.open() results = postgre.getViolenceGroupByType() postgre.close() types = fromResultsToNeighborhood(results) return Response(json.dumps(types), status=200, mimetype='application/json')
def amount(): postgre = Postgres() postgre.open() results = postgre.getAmountOfLost() postgre.close() return Response(json.dumps({'amount': str(results[0][0])}), status=200, mimetype='application/json')
def neighborhood(): postgre = Postgres() postgre.open() results = postgre.getViolenceGroupByNeighborhood() postgre.close() neighborhoods = fromResultsToNeighborhood(results) return Response(json.dumps(neighborhoods), status=200, mimetype='application/json')
def list_type(type, quantidade): postgre = Postgres() postgre.open() results = postgre.getViolenceByType(type, quantidade) postgre.close() violences = fromResultsToJson(results) return Response(json.dumps(violences), status=200, mimetype='application/json')
def list_all(): postgre = Postgres() postgre.open() results = postgre.getVeolance(0) postgre.close() violences = fromResultsToJson(results) return Response(json.dumps(violences), status=200, mimetype='application/json')
def run_ml_filtered(tipo): postgre = Postgres() postgre.open() results = postgre.getVeolanceFilterByType(3000, tipo) postgre.close() violences = fromResultsToJson(results) ml = MachineLearnning() result = ml.run(violences) return Response(json.dumps(result), status=200, mimetype='application/json')
def run_kde_filtered(tipo): postgre = Postgres() postgre.open() results = postgre.getVeolanceFilterByType(1000, tipo) postgre.close() violences = fromResultsToJson(results) kde = KDE() result = kde.run(violences) return Response(json.dumps(result), status=200, mimetype='application/json')
def gender(): postgre = Postgres() postgre.open() results = postgre.getLostBySex() print(results) masc = results[0][1] / (results[0][1] + results[1][1]) fem = results[1][1] / (results[0][1] + results[1][1]) postgre.close() return Response(json.dumps({ 'masculino': masc, 'feminino': fem }), status=200, mimetype='application/json')