Skip to content

Commit

Permalink
Adicionando a página de relatórios ao repositório
Browse files Browse the repository at this point in the history
  • Loading branch information
ktalmeida committed Dec 2, 2014
1 parent d5a557e commit 3a2243b
Show file tree
Hide file tree
Showing 9 changed files with 464 additions and 0 deletions.
Empty file added public/all.json
Empty file.
5 changes: 5 additions & 0 deletions public/css/bootstrap-theme.min.css

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions public/css/bootstrap.min.css

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions public/date-pt-BR.js

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>RELATORIO</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry"></script>
<script type="text/javascript" src="date-pt-BR.js"></script>
<script type="text/javascript" src="rawCollectedData.js"></script>
<script type="text/javascript" src="relatorioCodigo.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">RioBus - Relatórios</a>
</div>
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<h1> Preencha as informações abaixo</h1>

<form class="form-horizontal" role="form">

<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
<div class="checkbox">
<label>
<input name="report" type="radio" value="empty-lines" > Ônibus sem linha
</label>
</div>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
<div class="checkbox">
<label>
<input name="report" type="radio" value="stopped" > Ônibus parados
</label>
</div>
</div>
</div>
<div class="form-group">
<label for="lat" class="col-sm-2 control-label">Latitude</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="lat" placeholder="Latitude">
</div>
</div>

<div class="form-group">
<label for="lng" class="col-sm-2 control-label">Longitude</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="lng" placeholder="Longitude">
</div>
</div>

<div class="form-group">
<label for="r" class="col-sm-2 control-label">Raio</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="r" placeholder="Raio">
</div>
</div>

<div class="form-group">
<label for="minv" class="col-sm-2 control-label">Velocidade Mínima</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="minv" placeholder="Velocidade Mínima">
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
<div class="checkbox">
<label>
<input name="report" type="radio" value="outdated-gps" > GPS desatualizado
</label>
</div>
</div>
</div>

<div class="form-group">
<label for="hour" class="col-sm-2 control-label">Atraso (em horas)</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="hour" placeholder="Atraso (em horas)">
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
<div class="checkbox">
<label>
<input name="report" type="radio" value="line-counter-by-bus" > Linhas por quantidade de ônibus
</label>
</div>
</div>
</div>

<div class="form-group">
<label for="minq" class="col-sm-2 control-label">Qnt mínima de ônibus</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="minq" placeholder="Quantidade mínima de ônibus">
</div>
<label for="maxq" class="col-sm-2 control-label">Qnt máxima de ônibus</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="maxq" placeholder="Quantidade máxima de ônibus">
</div>
</div>
<hr>

<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
<div class="checkbox">
<label>
<input name="report" type="radio" value="buses-by-speed" > Ônibus por faixa de velocidade
</label>
</div>
</div>
</div>

<div class="form-group">
<label for="mins" class="col-sm-2 control-label">Velocidade Mínima</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="mins" placeholder="Velocidade Mínima">
</div>
<label for="maxs" class="col-sm-2 control-label">Velocidade Máxima</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="maxs" placeholder="Velocidade Máxima">
</div>
</div>

<div class="form-group">
<label for="lines" class="col-sm-2 control-label">Linhas</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="lines" placeholder="(Opcional, separe por vírgulas)">
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" id="button" class="btn btn-success"> Enviar </button>
</div>
</div>
<p id='resposta'></p>
<form>
</div>
</body>
</html>



6 changes: 6 additions & 0 deletions public/js/bootstrap.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/js/jquery.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/rawCollectedData.js

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions public/relatorioCodigo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
window.onload = function() {

// 'data' é uma variavel ja definida no outro arquivo javascript. vc precisa manipular essa variavel 'data'.

var emptyLines = function(data) {
var l = data.DATA.length;
var busesByLine = {};
for (var i = l - 1; i >= 0; i--) {
var bus = data.DATA[i];
var key = ("" + bus[2]).trim(); // trimming whitespaces to normalize keys
if (busesByLine[key])
busesByLine[key].push(bus);
else
busesByLine[key] = [bus];
}
var emptyLinesData = busesByLine[""]; // empty lines is represented by empty strings
return {
"emptyLines": emptyLinesData.length,
"emptyLinesBuses": emptyLinesData
};
}


var stopedInArea = function(data, lat, lng, r, minvelocity) {
minvelocity = minvelocity || 0; // if minvelocity is set, check if bus is at most at this velocity
var l = data.DATA.length;
var center = new google.maps.LatLng(lat, lng);
var stoped = [];
for (var i = l - 1; i >= 0; i--) {
var bus = data.DATA[i];
// making use of googles magical function to calculate if point given is inside of circle
// because lat and lng are not equally spaced (our planet is a (almost) sphere)
if (google.maps.geometry.spherical.computeDistanceBetween(center, new google.maps.LatLng(bus[3], bus[4])) < r &&
bus[5] <= minvelocity)
stoped.push(bus);
}
return {
"totalStoped": stoped.length,
"stopedBuses": stoped,
};
}

// GPS outdated
function busesWithGPSoutDated(hour, data) {
var buses = data.DATA;
var outDatedBuses = [];

var dateTimeBoundary = getDateTimeBoundary(hour);
var bus;

for (var i = 0; i < buses.length; i++) {
bus = buses[i];

if (toDateTime(bus[0]) <= dateTimeBoundary)
outDatedBuses.push(bus);
}

return outDatedBuses;
}

function getDateTimeBoundary(hour) {
var now = new Date();
var offset = hour * 60 * 60 * 1000;

return new Date(now.getTime() - offset);
}

function toDateTime(dateTimeString) {
var dateBR = dateTimeString.substring(3, 6) + dateTimeString.substring(0, 2) + dateTimeString.substring(5);

return new Date(Date.parse(dateBR));
}

// lines by buses count
function line_counter_by_bus_range(min_limit, max_limit, data) {
var busArray = data["DATA"];
var bus_lines = [];
var output_list = [];

// sort each bus to it's respective line
for (var i = busArray.length - 1; i >= 0; i--) {
var bus = busArray[i];
var key = "" + bus[2];
if (bus_lines[key]) { // if key already exists in data structure.
bus_lines[key].push(bus); // add this bus to this key (add bus to its respective line).
} else { // if key doesn't exist.
bus_lines[key] = [bus]; // instantiate an array in the key with this bus inside it.
}
}

// check if bus line is in bus counter range
for (var i = bus_lines.length - 1; i >= 0; i--) {
if (bus_lines[i]) { // check if bus line exists
var bus_counter = bus_lines[i].length;
if (bus_counter <= max_limit && bus_counter >= min_limit) {
output_list.push(i);
}
}
}

// prepare output
var output = {
"number of lines": output_list.length,
"lines": output_list
};

return output;
}


function buses_in_speed_range(min_speed, max_speed, data, lines) {

lines = lines || []; // default: no lines to validate
var busArray = data["DATA"];
var in_range_buses = [];
var skip_line_validator = true;

// checks if should validate lines
if (lines.length != 0) {
skip_line_validator = false;
}

// find buses in speed range
for (var i = busArray.length - 1; i >= 0; i--) {
var speed = busArray[i][5];
if ((speed <= max_speed && speed >= min_speed) // checks speed range
&& (skip_line_validator || (lines.indexOf("" + busArray[i][2]) > -1))) // checks whether should validate lines and bus lines array
{
in_range_buses.push(busArray[i]);
}
}

// prepare output
var output = {
"number of buses": in_range_buses.length,
"buses": in_range_buses
};

return output;
}

function getData() {

};
$(document).on('click', '#button', function() {
var selected = $('input[name="report"]:checked').val();
$.getJSON('http://192.168.1.128:8080/all?callback=?', function(data, status) {
switch (selected) {
case "empty-lines":
result = emptyLines(data)
break;
case "stoped":
var lat = $('#lat').val(),
lng = $('#lng').val(),
r = $('#r').val(),
minv = $('#minv').val();
result = stopedInArea(data, lat, lng, r, minv);
break;
case "outdated-gps":
var hour = $('#hour').val();
result = busesWithGPSoutDated(hour, data);
break;
case "line-counter-by-bus":
var minq = $('#minq').val(),
maxq = $('#maxq').val();
result = line_counter_by_bus_range(minq, maxq, data);
break;
case "buses-by-speed":
var mins = $('#mins').val(),
maxs = $('#maxs').val(),
lines = $('#lines').val();
if (lines)
lines = lines.split(/\s*,\s*/g);
result = buses_in_speed_range(mins, maxs, data, lines);
break;
}
document.getElementById("resposta").innerHTML = JSON.stringify(result);
});
});
}

0 comments on commit 3a2243b

Please sign in to comment.