Browse Source

denunciation improve

old
Efe Aydın 6 years ago
parent
commit
8bb3435893
9 changed files with 161 additions and 271020 deletions
  1. +15
    -5
      MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java
  2. +5
    -0
      client_side/interface/UserData/denunciation_map.html
  3. +50
    -0
      client_side/interface/UserData/denunciation_view.html
  4. +0
    -1
      server_side/api/app.py
  5. +0
    -208390
      server_side/api/modules/data.json
  6. +52
    -0
      server_side/api/modules/databases/denunciations.json
  7. +35
    -54
      server_side/api/modules/denunciation.py
  8. +0
    -62568
      server_side/api/modules/timely.json
  9. +4
    -2
      server_side/api/modules/user_info.py

+ 15
- 5
MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java View File

@ -101,11 +101,16 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
HashMap<String,String> args = new HashMap<>();
try {
args.put("id", MainActivity.userData.getString("id"));
}catch (JSONException e){}
args.put("emergency",emergency);
}catch (JSONException e) {}
String latitude = "39.9127897";
String longitude = "32.8073577";
args.put("latitude", latitude);
args.put("longitude", longitude);
args.put("note",note.getText().toString());
args.put("accepted","false");
args.put("emergency", emergency);
args.put("note", note.getText().toString());
args.put("accepted", "false");
if(img != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@ -228,7 +233,12 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
try {
args.put("id", MainActivity.userData.getString("id"));
}catch (JSONException e){}
args.put("emergency",emergency);
String latitude = "39.9127897";
String longitude = "32.8073577";
args.put("latitude", latitude);
args.put("longitude", longitude);
args.put("emergency", emergency);
args.put("note",note.getText().toString());
if(img != null) {


+ 5
- 0
client_side/interface/UserData/denunciation_map.html View File

@ -48,6 +48,11 @@
label: element["priority"].toString(),
title: element["info"]
});
marker.addListener('click', function() {
window.open(window.location.href.replace("denunciation_map", "denunciation_view") + "&id=" + element["id"]);
});
markers.push(marker);
});
}


+ 50
- 0
client_side/interface/UserData/denunciation_view.html View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Denunction Info</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
</head>
<body>
Denunciated by <div id="by"></div><br>
Information: <br>
<div id="info"></div><br>
Emergency Type: <div id="type"></div><br>
Priority: <div id="prio"></div>
<img src="" id="photo">
<script>
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
let den_id = findGetParameter("id");
$.get("https://127.0.0.1:5000/denunciations", function(dataStr, status){
data = $.parseJSON(dataStr)
if (status == "success") {
data.forEach(function(element) {
if (element["id"] == den_id) {
$.get("https://127.0.0.1:5000/users/" + element["reporter"], function(dataStr, status) {
data = $.parseJSON(dataStr)
document.getElementById("by").innerHTML = data["realname"]
});
document.getElementById("info").innerHTML = element["info"]
document.getElementById("type").innerHTML = element["emergency"]
document.getElementById("prio").innerHTML = element["priority"]
document.getElementById("photo").src = "data:image/jpeg;base64," + element["photo"]
}
});
}
});
</script>
</body>
</html>

+ 0
- 1
server_side/api/app.py View File

@ -29,7 +29,6 @@ if __name__ == '__main__':
api.add_resource(utility.Resources, '/resources', '/resources/')
api.add_resource(denunciation.Alert, '/denunciation', '/denunciation/')
api.add_resource(denunciation.Denounce, '/denounce', '/denounce/')
api.add_resource(denunciation.Denunciations, '/denunciations', '/denunciations/')
api.add_resource(navigation.Transit, '/transit', '/transit/')


+ 0
- 208390
server_side/api/modules/data.json
File diff suppressed because it is too large
View File


+ 52
- 0
server_side/api/modules/databases/denunciations.json
File diff suppressed because it is too large
View File


+ 35
- 54
server_side/api/modules/denunciation.py View File

@ -5,11 +5,6 @@ from flask_restful import Resource, Api, abort
import json
import os
import base64
from PIL import Image
import cv2
from io import BytesIO
import numpy as np
app = Flask(__name__)
api = Api(app)
@ -22,29 +17,42 @@ users_path = os.path.join(app.root_path, 'databases', 'users.json')
with open(users_path, 'r') as f:
users = json.load(f)
def readb64(base64_string):
sbuf = BytesIO()
sbuf.write(base64.b64decode(base64_string))
pimg = Image.open(sbuf)
return cv2.cvtColor(np.array(pimg), cv2.COLOR_RGB2BGR)
class Alert(Resource):
def post(self):
args = request.form
cvimg = readb64(args["photo"])
username= ""
for user in users:
if users[user]["id"] == args["id"]:
username=user
break
trust = int(users[username]["trustability"])
if trust > 20 or args["accepted"] == "true":
return {"success":True}
reporter = args['id']
user = utils.find_by_id(users.values(), reporter)
trust = int(user["trustability"])
if args["accepted"] == "true" or trust > 20:
photo = args["photo"]
if utils.find_by_id(users.values(), reporter):
denunciation_info = args['note']
denunciation_priority = 5
denunciation_location = {
"latitude": float(args['latitude']),
"longitude": float(args['longitude'])
}
denunciation = {
'id': len(denunciations) + 1,
'reporter': reporter,
'emergency': args['emergency'],
'info': denunciation_info,
'photo': photo,
'priority': denunciation_priority,
'location': denunciation_location
}
denunciations.append(denunciation)
with open(db_path, 'w') as f:
json.dump(denunciations, f, indent=4)
return {'success': True}
else:
return {'error': 'User doesn\'t exists'}
else:
return {"success":False,"penalty":"{}".format(100*(20-trust))}
return {"success": False, "penalty": "{}".format(100*(20-trust))}
class Denunciations(Resource):
@ -52,8 +60,11 @@ class Denunciations(Resource):
resp = Response(json.dumps([
{
'id' : v['id'],
"reporter": v["reporter"],
'info': v['info'],
'priority': v['priority'],
'emergency': v['emergency'],
'photo': v['photo'],
'location' : v['location']
}
for v in denunciations
@ -62,33 +73,3 @@ class Denunciations(Resource):
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
class Denounce(Resource):
def post(self):
args = request.form
reporter = args['id']
if utils.find_by_id(users.values(), reporter):
denunciation_info = args['info']
denunciation_priority = args['priority']
denunciation_location = {
"latitude": args['latitude'],
"longitude": args['longitude']
}
denunciation = {
'id': len(denunciations) + 1,
'reporter': reporter,
'info': denunciation_info,
'priority': denunciation_priority,
'location': denunciation_location
}
denunciations.append(denunciation)
with open(db_path, 'w') as f:
json.dump(denunciations, f, indent=4)
return denunciation
else:
return {'error': 'User doesn\'t exists'}

+ 0
- 62568
server_side/api/modules/timely.json
File diff suppressed because it is too large
View File


+ 4
- 2
server_side/api/modules/user_info.py View File

@ -5,7 +5,7 @@ import base64
from api.modules import utils
from flask import Flask, request
from flask import Flask, request, Response
from flask_restful import Resource, Api, abort
app = Flask(__name__)
@ -55,7 +55,9 @@ class User(Resource):
if not user:
raise Exception('User not found!')
del user['password']
return user
resp = Response(json.dumps(user))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
except:
abort(404, error="User {} doesn't exist".format(user_id))


Loading…
Cancel
Save