Browse Source

Merge remote-tracking branch 'origin/efe' into efe

old
Efe Aydın 6 years ago
parent
commit
03876cb11a
6 changed files with 136 additions and 8 deletions
  1. +8
    -1
      client_side/interface/UserData/denunciation_map.html
  2. +38
    -0
      client_side/interface/UserData/ratings.html
  3. +76
    -0
      client_side/interface/UserData/voting_results.html
  4. +1
    -1
      server_side/api/modules/databases/votings.json
  5. +13
    -4
      server_side/api/modules/rating_system.py
  6. +0
    -2
      server_side/api/modules/voting_system.py

+ 8
- 1
client_side/interface/UserData/denunciation_map.html View File

@ -18,6 +18,7 @@
</style>
</head>
<body>
<audio id="audio" src="http://www.soundjay.com/button/beep-07.wav" autoplay="false"></audio>
<div id="map"></div>
<script>
var map;
@ -29,10 +30,12 @@
}
</script>
<script>
var sound = document.getElementById("audio");
var markers = [];
var denunciation_count = markers.length;
setInterval(function() {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
markers.pop().setMap(null);
}
$.get("https://127.0.0.1:5000/denunciations", function(data, status){
if (status == "success") {
@ -47,6 +50,10 @@
});
}
});
if (denunciation_count < markers.length) {
sound.play();
}
denunciation_count = markers.length;
}, 5000);
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBuOC03IHPA_6TPnfk18b0SAgD1uge4-dk&callback=initMap"


+ 38
- 0
client_side/interface/UserData/ratings.html View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ratings</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script>
$.get("https://127.0.0.1:5000/ratings", function(data, status){
if (status == "success") {
data.forEach(function(element) {
var a = document.createElement('a');
var linkText = document.createTextNode(element["name"]);
a.appendChild(linkText);
a.title = element["name"];
a.href = "javascript:results(" + element["id"] + ");";
document.body.appendChild(a);
document.body.appendChild(document.createElement("br"));
});
}
});
function results(id) {
$.get("https://127.0.0.1:5000/ratings/" + id, function(data, status){
if (status == "success") {
var results = document.getElementById("results")
results.innerHTML = '';
for (var key in data["rates"]) {
results.innerHTML += "<p>" + data["rates"][key]["note"] + "</p> " + data["rates"][key]["score"] + "/10 <br><br>"
}
}
});
}
</script>
<div id="results"></div>
</body>
</html>

+ 76
- 0
client_side/interface/UserData/voting_results.html View File

@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Voting Results</title>
<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>
</head>
<body>
<div id="canvas-holder" style="width:40%">
<canvas id="voteResults"></canvas>
</div>
<br>
<script>
var ctx = document.getElementById('voteResults').getContext('2d');
var config = {
type: 'pie',
data: {
datasets: [{
data: [
],
backgroundColor: [
],
label: ''
}],
labels: []
},
options: {
responsive: true
}
};
window.myPie = new Chart(ctx, config);
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
$.get("https://127.0.0.1:5000/votings", function(data, status){
if (status == "success") {
data.forEach(function(element) {
var a = document.createElement('a');
var linkText = document.createTextNode(element["name"]);
a.appendChild(linkText);
a.title = element["name"];
a.href = "javascript:graph(" + element["id"] + ");";
document.body.appendChild(a);
document.body.appendChild(document.createElement("br"));
});
}
});
function graph(id) {
$.get("https://127.0.0.1:5000/votings/" + id, function(data, status){
if (status == "success") {
config["data"]["datasets"][0]["label"] = data["name"]
config["data"]["datasets"][0]["data"] = []
config["data"]["datasets"][0]["backgroundColor"] = []
config["data"]["labels"] = []
for (var key in data["votes"]) {
config["data"]["datasets"][0]["data"].push(data["votes"][key]["votes"]);
config["data"]["datasets"][0]["backgroundColor"].push(getRandomColor());
config["data"]["labels"].push(data["votes"][key]["name"]);
}
window.myPie.update();
}
});
}
</script>
</body>
</html>

+ 1
- 1
server_side/api/modules/databases/votings.json View File

@ -37,7 +37,7 @@
"2": {
"name": "Yi\u011fit \u00c7olako\u011flu Park\u0131",
"desc": "Mahallemizin say\u0131n destek\u00e7isinin ad\u0131",
"votes": 0
"votes": 2
}
}
}

+ 13
- 4
server_side/api/modules/rating_system.py View File

@ -20,6 +20,17 @@ with open(user_db, 'r') as f:
class Ratings(Resource):
def get(self):
return [
{
'id' : v['id'],
'name': v['name'],
'desc': v['desc'],
'img' : v['img']
}
for v in ratings
]
def post(self):
"""
Example POST Data:
@ -74,9 +85,7 @@ class Ratings(Resource):
class Rating(Resource):
def get(self, rating_id):
try:
rating = copy.deepcopy(ratings[rating_id - 1])
del rating['rates']
return rating
return ratings[rating_id - 1]
except:
abort(404, error="Rating {} doesn't exist".format(rating_id))
@ -96,7 +105,7 @@ class Rate(Resource):
if 0 >= score >= 10:
abort(500, 'Score should be between 0 and 10')
note = request.form.get('note')
ratings[rating_id - 1]['rates'][rater_id] = {
ratings[rating_id - 1]['rates'][request.form['rater_id']] = {
'id': len(ratings[rating_id - 1]['rates']) + 1,
'rater': request.form['rater_id'],
'score': score,


+ 0
- 2
server_side/api/modules/voting_system.py View File

@ -77,8 +77,6 @@ class Voting(Resource):
def get(self, voting_id):
try:
voting = copy.deepcopy(votings[voting_id - 1])
for i in range(len(voting['votes'])):
del voting['votes'][str(i + 1)]['votes']
del voting['voters']
return voting


Loading…
Cancel
Save