Browse Source

asdasd

asdasdasd
old
Yiğit Çolakoğlu 6 years ago
parent
commit
a90cebe3d9
31 changed files with 310 additions and 271028 deletions
  1. +15
    -5
      MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java
  2. +57
    -0
      bus_stop/qr_reader/main.py
  3. +5
    -0
      client_side/interface/UserData/denunciation_map.html
  4. +50
    -0
      client_side/interface/UserData/denunciation_view.html
  5. +29
    -4
      client_side/interface/UserData/ratings.html
  6. +7
    -3
      client_side/interface/UserData/voting_results.html
  7. +1
    -2
      server_side/api/app.py
  8. +0
    -208390
      server_side/api/modules/data.json
  9. +52
    -0
      server_side/api/modules/databases/denunciations.json
  10. +35
    -54
      server_side/api/modules/denunciation.py
  11. +0
    -62568
      server_side/api/modules/timely.json
  12. +21
    -2
      server_side/api/modules/user_info.py
  13. BIN
      traffic_analyzer/3bug90h684ie.jpg
  14. BIN
      traffic_analyzer/5y0qqefgf8pm.jpg
  15. BIN
      traffic_analyzer/6xj0sv03e1rp.jpg
  16. BIN
      traffic_analyzer/7u38saf39803.jpg
  17. BIN
      traffic_analyzer/8giefz6t7blg.jpg
  18. BIN
      traffic_analyzer/9hbgjp8pr9ml.jpg
  19. BIN
      traffic_analyzer/bhcabz3ylbps.jpg
  20. BIN
      traffic_analyzer/bka4e0uyj819.jpg
  21. BIN
      traffic_analyzer/f6tjfpenclkn.jpg
  22. BIN
      traffic_analyzer/f8tjw066xd8k.jpg
  23. BIN
      traffic_analyzer/hcw6jsi4snvy.jpg
  24. BIN
      traffic_analyzer/iyh7h75p89qb.jpg
  25. BIN
      traffic_analyzer/jmv0qy8gh2hu.jpg
  26. BIN
      traffic_analyzer/lynlxwlxzovj.jpg
  27. BIN
      traffic_analyzer/q7xf4ijepqh0.jpg
  28. BIN
      traffic_analyzer/snpw5fj1pm5y.jpg
  29. +38
    -0
      traffic_analyzer/traffic.py
  30. BIN
      traffic_analyzer/tsrrxuybcpd8.jpg
  31. BIN
      traffic_analyzer/wau45wn0y7vr.jpg

+ 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<>(); HashMap<String,String> args = new HashMap<>();
try { try {
args.put("id", MainActivity.userData.getString("id")); 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) { if(img != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@ -228,7 +233,12 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
try { try {
args.put("id", MainActivity.userData.getString("id")); args.put("id", MainActivity.userData.getString("id"));
}catch (JSONException e){} }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()); args.put("note",note.getText().toString());
if(img != null) { if(img != null) {


+ 57
- 0
bus_stop/qr_reader/main.py View File

@ -0,0 +1,57 @@
from imutils.video import VideoStream
from pyzbar import pyzbar
import requests
import imutils
import cv2
vs = VideoStream().start()
dates = []
reps = 0
barcodes = None
prevcode = None
def main(host):
global vs
global dates
global reps
global barcodes
global prevcode
while True:
try:
while (barcodes == None or barcodes == []):
frame = vs.read()
frame = imutils.resize(frame, width=400)
barcodes = pyzbar.decode(frame)
cv2.imshow("Image", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
barcodes = pyzbar.decode(frame)
# loop over the detected barcodes
for barcode in barcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
if (barcodeData != prevcode):
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (0, 0, 255), 2)
print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
requests.post('https://' + host + '/reduce', data={'id': barcodeData, 'reduce': 2.5})
reps += 1
prevcode = barcodeData
barcodes = None
cv2.imshow("Image", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except KeyboardInterrupt:
break
main(input('Host << '))
print("[INFO] cleaning up...")
cv2.destroyAllWindows()
vs.stop()

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

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

+ 29
- 4
client_side/interface/UserData/ratings.html View File

@ -4,8 +4,16 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Ratings</title> <title>Ratings</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head> </head>
<body> <body>
<div id="main" class="container">
<h1>Ratings</h1><br>
</div>
<br>
<div id="results" class="container">
</div>
<script> <script>
$.get("https://127.0.0.1:5000/ratings", function(dataStr, status){ $.get("https://127.0.0.1:5000/ratings", function(dataStr, status){
data = $.parseJSON(dataStr) data = $.parseJSON(dataStr)
@ -16,8 +24,8 @@
a.appendChild(linkText); a.appendChild(linkText);
a.title = element["name"]; a.title = element["name"];
a.href = "javascript:results(" + element["id"] + ");"; a.href = "javascript:results(" + element["id"] + ");";
document.body.appendChild(a);
document.body.appendChild(document.createElement("br"));
document.getElementById("main").appendChild(a);
document.getElementById("main").appendChild(document.createElement("br"));
}); });
} }
}); });
@ -28,13 +36,30 @@
if (status == "success") { if (status == "success") {
var results = document.getElementById("results") var results = document.getElementById("results")
results.innerHTML = ''; results.innerHTML = '';
for (var key in data["rates"]) { for (var key in data["rates"]) {
results.innerHTML += "<p>" + data["rates"][key]["note"] + "</p> " + data["rates"][key]["score"] + "/10 <br><br>"
var blockquote = document.createElement('blockquote');
blockquote.className = "blockquote text-right";
var text = document.createElement('p');
text.className = "mb-0";
text.innerHTML = data["rates"][key]["note"] + '<br>' + data["rates"][key]["score"] + '/10';
var by = document.createElement('footer');
by.className = "blockquote-footer";
$.get("https://127.0.0.1:5000/users/" + key, function(dataStr, status) {
data = $.parseJSON(dataStr)
by.innerHTML = data["realname"]
});
blockquote.appendChild(text);
blockquote.appendChild(by);
results.appendChild(blockquote);
} }
} }
}); });
} }
</script> </script>
<div id="results"></div>
</body> </body>
</html> </html>

+ 7
- 3
client_side/interface/UserData/voting_results.html View File

@ -5,11 +5,15 @@
<title>Voting Results</title> <title>Voting Results</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head> </head>
<body> <body>
<div id="canvas-holder" style="width:40%">
<div class="row">
<div class="col-md-6">
<canvas id="voteResults"></canvas> <canvas id="voteResults"></canvas>
</div> </div>
<div class="col-md-6" id="res"></div>
</div>
<br> <br>
<script> <script>
var ctx = document.getElementById('voteResults').getContext('2d'); var ctx = document.getElementById('voteResults').getContext('2d');
@ -50,8 +54,8 @@
a.appendChild(linkText); a.appendChild(linkText);
a.title = element["name"]; a.title = element["name"];
a.href = "javascript:graph(" + element["id"] + ");"; a.href = "javascript:graph(" + element["id"] + ");";
document.body.appendChild(a);
document.body.appendChild(document.createElement("br"));
document.getElementById("res").appendChild(a);
document.getElementById("res").appendChild(document.createElement("br"));
}); });
} }
}); });


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

@ -24,12 +24,11 @@ if __name__ == '__main__':
api.add_resource( user_info.Users, '/users', '/users/' ) api.add_resource( user_info.Users, '/users', '/users/' )
api.add_resource( user_info.User, '/users/<path:user_id>', '/users/<path:user_id>/' ) api.add_resource( user_info.User, '/users/<path:user_id>', '/users/<path:user_id>/' )
api.add_resource( user_info.Login, '/login', '/login/' ) api.add_resource( user_info.Login, '/login', '/login/' )
api.add_resource(user_info.ReducePoints, '/reduce', '/reduce/')
api.add_resource(utility.Resources, '/resources', '/resources/') api.add_resource(utility.Resources, '/resources', '/resources/')
api.add_resource(denunciation.Alert, '/denunciation', '/denunciation/') api.add_resource(denunciation.Alert, '/denunciation', '/denunciation/')
api.add_resource(denunciation.Denounce, '/denounce', '/denounce/')
api.add_resource(denunciation.Denunciations, '/denunciations', '/denunciations/') api.add_resource(denunciation.Denunciations, '/denunciations', '/denunciations/')
api.add_resource(navigation.Transit, '/transit', '/transit/') 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 json
import os import os
import base64
from PIL import Image
import cv2
from io import BytesIO
import numpy as np
app = Flask(__name__) app = Flask(__name__)
api = Api(app) 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: with open(users_path, 'r') as f:
users = json.load(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): class Alert(Resource):
def post(self): def post(self):
args = request.form 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: else:
return {"success":False,"penalty":"{}".format(100*(20-trust))}
return {"success": False, "penalty": "{}".format(100*(20-trust))}
class Denunciations(Resource): class Denunciations(Resource):
@ -52,8 +60,11 @@ class Denunciations(Resource):
resp = Response(json.dumps([ resp = Response(json.dumps([
{ {
'id' : v['id'], 'id' : v['id'],
"reporter": v["reporter"],
'info': v['info'], 'info': v['info'],
'priority': v['priority'], 'priority': v['priority'],
'emergency': v['emergency'],
'photo': v['photo'],
'location' : v['location'] 'location' : v['location']
} }
for v in denunciations for v in denunciations
@ -62,33 +73,3 @@ class Denunciations(Resource):
resp.headers['Access-Control-Allow-Origin'] = '*' resp.headers['Access-Control-Allow-Origin'] = '*'
return resp 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


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

@ -5,7 +5,7 @@ import base64
from api.modules import utils from api.modules import utils
from flask import Flask, request
from flask import Flask, request, Response
from flask_restful import Resource, Api, abort from flask_restful import Resource, Api, abort
app = Flask(__name__) app = Flask(__name__)
@ -55,7 +55,9 @@ class User(Resource):
if not user: if not user:
raise Exception('User not found!') raise Exception('User not found!')
del user['password'] del user['password']
return user
resp = Response(json.dumps(user))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
except: except:
abort(404, error="User {} doesn't exist".format(user_id)) abort(404, error="User {} doesn't exist".format(user_id))
@ -82,6 +84,23 @@ class Login(Resource):
return [False, {}] return [False, {}]
class ReducePoints(Resource):
def post(self):
user_id = request.form['id']
user = utils.find_by_id(users.values(), user_id)
if user:
username = ''
for k, v in users.items():
if user_id == v['id']:
username = k
users[username]['points'] -= request.form['reduce']
with open(db_path, 'w') as f:
json.dump(users, f, indent=4)
else:
abort(404, error="User {} doesn't exist".format(user_id))
if __name__ == '__main__': if __name__ == '__main__':
api.add_resource(Users, '/users', '/users/') api.add_resource(Users, '/users', '/users/')
api.add_resource(User, '/users/<path:user_id>', '/users/<path:user_id>/') api.add_resource(User, '/users/<path:user_id>', '/users/<path:user_id>/')


BIN
traffic_analyzer/3bug90h684ie.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 46 KiB

BIN
traffic_analyzer/5y0qqefgf8pm.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 55 KiB

BIN
traffic_analyzer/6xj0sv03e1rp.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 49 KiB

BIN
traffic_analyzer/7u38saf39803.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 48 KiB

BIN
traffic_analyzer/8giefz6t7blg.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 56 KiB

BIN
traffic_analyzer/9hbgjp8pr9ml.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 53 KiB

BIN
traffic_analyzer/bhcabz3ylbps.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 52 KiB

BIN
traffic_analyzer/bka4e0uyj819.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 54 KiB

BIN
traffic_analyzer/f6tjfpenclkn.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 53 KiB

BIN
traffic_analyzer/f8tjw066xd8k.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 56 KiB

BIN
traffic_analyzer/hcw6jsi4snvy.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 54 KiB

BIN
traffic_analyzer/iyh7h75p89qb.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 57 KiB

BIN
traffic_analyzer/jmv0qy8gh2hu.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 54 KiB

BIN
traffic_analyzer/lynlxwlxzovj.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 55 KiB

BIN
traffic_analyzer/q7xf4ijepqh0.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 55 KiB

BIN
traffic_analyzer/snpw5fj1pm5y.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 56 KiB

+ 38
- 0
traffic_analyzer/traffic.py View File

@ -0,0 +1,38 @@
import random, string
import numpy as np
import cv2
def generate_id(length=32):
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
cap = cv2.VideoCapture(1)
cars = [
[(420, 375), (500, 480)],
[(505, 340), (590, 440)],
[(415, 240), (495, 330)],
[(485, 235), (550, 320)]
]
ambulance = [(250, 130), (400, 240)]
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
key = cv2.waitKey(1) & 0xFF
if key == ord('s'):
cv2.imwrite(generate_id(12) + ".jpg", frame[100:600, 240:600])
for i in cars:
cv2.rectangle(frame, *i, (0, 0, 255), 2)
cv2.rectangle(frame, *ambulance, (255, 0, 0), 2)
frame = frame[100:600, 240:600]
cv2.imshow('frame', frame)
if key == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

BIN
traffic_analyzer/tsrrxuybcpd8.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 54 KiB

BIN
traffic_analyzer/wau45wn0y7vr.jpg View File

Before After
Width: 360  |  Height: 380  |  Size: 56 KiB

Loading…
Cancel
Save