Skip to content

Commit

Permalink
Merge pull request #5 from vitor-costa/master
Browse files Browse the repository at this point in the history
-Timeframe search: File System Version
-Relatórios adicionados
  • Loading branch information
marco-jardim committed Dec 17, 2014
2 parents 7f5ba65 + 88a53e2 commit 04f2d7b
Show file tree
Hide file tree
Showing 17 changed files with 776 additions and 99 deletions.
34 changes: 29 additions & 5 deletions dataQueuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ function callback(response) {

// Queue the requested data into queue.json
function appendDataAsync(data_to_append) {
fs.appendFile('queue.json', data_to_append, function (err) {
if (err) throw err;
});
//fs.appendFile('queue.json', data_to_append, function (err) {
//if (err) throw err;
//});
var date = new Date();
var file_name = moment(date).format("YYYYMMDDHH") + ".json";
// console.log(data_to_append);
fs.writeFile(__dirname + "/files/" + file_name, "" + data_to_append, function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
}

// Google's Big Query timestamp format, UTC time
Expand All @@ -61,14 +71,28 @@ function data_formatter() {
return formatted_data;
}

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

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

function toDateTime(dateTimeString) {
return new Date(dateTimeString);
}

// Grabs data from riob.us/all and enqueues it in the json file in time intervals
setInterval(function() {
// Make GET Request
http.request(options, callback).end();

// Checks if data already has been generated by JSON.parse.
if(data != null) {
var formatted_data = data_formatter();
appendDataAsync(formatted_data);
// var formatted_data = data_formatter();
if(toDateTime(data.LASTUPDATE) < getDateTimeBoundary(1)) {
data = JSON.parse("{}");
}
appendDataAsync(JSON.stringify(data));
}
}, intervalTime);
1 change: 1 addition & 0 deletions files/2014120410.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions files/2014120411.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions files/2014120412.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions files/2014120619.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "riobus-analytics",
"version": "0.1.1",
"description": "Riob.us analytics",
"main": "server.js",
"scripts": {
"start": "node riob-us/server.js"
},
"dependencies": {
"express": "~4.10.x",
"moment": "*"
},
"engines": {
"node": "0.10.x"
},
"keywords": [
"node",
"riobus"
],
"license": "GNU GPL2"
}
5 changes: 5 additions & 0 deletions public/css/bootstrap-datetimepicker.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/css/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#dvLoading {
background:url(loading.gif) no-repeat center center;
height: 100%;
width: 100%;
position: fixed;
left: 0;
top: 0;
margin: 0 0 0 0;
z-index: 2;

}

body {
z-index: 1;
}

#show-map{
height: 600px;
}
Binary file added public/fonts/glyphicons-halflings-regular.ttf
Binary file not shown.
Binary file added public/fonts/glyphicons-halflings-regular.woff
Binary file not shown.
80 changes: 72 additions & 8 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
<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/moment-with-locales.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="js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&amp;libraries=geometry&amp;sensor=false&amp;"></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">
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">



</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
Expand All @@ -34,21 +42,27 @@
<ul class="dropdown-menu" role="menu">
<li><a data-input-id="empty-lines">Ônibus sem linha</a></li>
<li class="divider"></li>
<li><a data-input-id="lines-with-no-buses">Linhas sem ônibus circulando</a></li>
<li class="divider"></li>
<li><a data-input-id="stopped">Ônibus parados</a></li>
<li class="divider"></li>
<li><a data-input-id="outdated-gps">GPS desatualizado</a></li>
<li class="divider"></li>
<li><a data-input-id="line-counter-by-bus">Linhas por quantidade de ônibus</a></li>
<li class="divider"></li>
<li><a data-input-id="buses-by-speed">Ônibus por faixa de velocidade</a></li>
<li class="divider"></li>
<li><a data-input-id="show-map">Localização das Garagens</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

<div class="container">
<div id="dvLoading" ></div>
<div class="container" id="main-container">

<h1> Preencha as informações abaixo</h1>

<form class="form-horizontal" role="form">
Expand All @@ -62,6 +76,16 @@ <h1> Preencha as informações abaixo</h1>
</div>
</div>
</div>

<div class="form-group" data-form-name="lines-with-no-buses">
<div class="col-sm-offset-1 col-sm-10">
<div class="checkbox">
<label>
<input name="report" type="radio" value="lines-with-no-buses" > Linhas sem ônibus circulando
</label>
</div>
</div>
</div>

<div class="form-group" data-form-name="stopped">
<div class="col-sm-offset-1 col-sm-10">
Expand Down Expand Up @@ -94,9 +118,9 @@ <h1> Preencha as informações abaixo</h1>
</div>

<div class="form-group" data-form-name="stopped">
<label for="minv" class="col-sm-2 control-label">Velocidade Mínima</label>
<label for="minv" class="col-sm-2 control-label">Velocidade Máxima</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="minv" placeholder="Velocidade Mínima">
<input type="text" class="form-control" id="minv" placeholder="Velocidade Máxima">
</div>
</div>

Expand Down Expand Up @@ -167,14 +191,54 @@ <h1> Preencha as informações abaixo</h1>
</div>
</div>

<div class="form-group">
<div class="form-group col-sm-12" data-form-name="show-map" id="show-map">
<iframe src="http://riob.us/relatorios/garagens.html" width="100%" height="100%"></iframe>
</div>

<div class="col-md-offset-1" >
<div class="radio-inline">
<label>
<input type="radio" name="dateNow" id="dateNow" checked>
Fazer análise a partir do último dado
</label>
</div>
<div class="radio-inline">
<label>
<input type="radio" name="dateNow" id="optionsRadios2" value="option2">
Fazer análise em um período de tempo
</label>
</div>
</div>

<div class="form-group" id="initial-date-container" >
<label for="initialDate" class="col-sm-2 control-label" data-date-format="DD/MM/YYYY - HH" >Data inicial</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="initialDate" placeholder="Insira a Data e Hora" data-date-format="DD/MM/YYYY - HH:00">
</div>
<label for="maxs" class="col-sm-2 control-label">Data final</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="finalDate" placeholder="Insira a Data e Hora" data-date-format="DD/MM/YYYY - HH:00">
</div>
</div>

<div class="form-group" id="final-date-container">
<div class="col-sm-offset-5 col-sm-6">
<button type="submit" id="button" class="btn btn-success"> Enviar </button>
<button type="button" id="button" class="btn btn-success"> Enviar </button>
<button type="button" id="info_btn" class="btn btn-info btn-xs" data-container="body" data-toggle="popover" data-placement="right" data-content="" data-trigger="hover">
Info
</button>
</div>
</div>
<p id='resposta'></p>
<div id='dataRioOut' style="display:none">O servidor da prefeitura encontra-se com problemas. Estamos mostrando o resultado da data: </div>
<button type="button" id="csv-button" class="btn btn-success" style="display:none"> Download CSV </button>
<div id='dados-analisados'></div>
<div id='resposta' >
<h2> </h2>
<table class='table table-bordered'><thead></thead><tbody></tbody></table>
</div>
<form>
</div>

</body>
</html>

Expand Down
1 change: 1 addition & 0 deletions public/js/bootstrap-datetimepicker.min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions public/js/moment-with-locales.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 04f2d7b

Please sign in to comment.