Skip to content

Commit

Permalink
Merge branch 'v1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Bertrand committed Nov 23, 2016
2 parents cd141e5 + 4eee066 commit 2d1999b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 36 deletions.
6 changes: 3 additions & 3 deletions lib/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var getIntermediatePoints = function(firstPosition, secondPosition, distance) {
var latArray = getSteps(firstPosition.lat, secondPosition.lat, nbSteps);

var res = [];
for (var i = 0; i <= nbSteps; i++) {
for (var i = 0; i < nbSteps-1; i++) {
res[i] = { lat: latArray[i], lng: lngArray[i] };
}
return res;
Expand All @@ -135,8 +135,8 @@ var getIntermediatePoints = function(firstPosition, secondPosition, distance) {
var getSteps = function(firstPosition, secondPosition, nbSteps) {
var res = [];
var interval = (secondPosition - firstPosition)/nbSteps;
for (var i = 0; i <= nbSteps; i++) {
res[i] = firstPosition + interval * i;
for (var i = 0; i < nbSteps-1; i++) {
res[i] = firstPosition + interval * (i+1);
}
return res;
};
Expand Down
1 change: 1 addition & 0 deletions lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ queue.process('destroy_bot', function(job, done) {
});

var job_destroy_bot = function(id_bot, done) {
var io = require('./socket');
var Bot = require('../models/bot');
Bot.remove({ _id: id_bot })
.then(function(result) {
Expand Down
24 changes: 9 additions & 15 deletions lib/trip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var maps = require('@google/maps');
var polylineLib = require('polyline');
var config = require('dotenv').config();
var googleMapsClient = maps.createClient({
key: process.env.GOOGLE_API_KEY
Expand Down Expand Up @@ -29,16 +30,16 @@ var generate_trip = function(bot, origin, callback) {
var coords = { origin: start_points, destination: end_points };
generate_directions(coords, function(directions) {
// generate_road(directions, callback);
var steps = geometry.splitTrip(directions, bot.speed);
steps.forEach(function(step, index) {
// var steps = geometry.splitTrip(directions, 40);
directions.forEach(function(step, index) {
if(index != 0) {
var brng = geometry.calcBearing(step, steps[index-1]);
var brng = geometry.calcBearing(step, directions[index-1]);
} else {
var brng = 0;
}
step.brng = brng;
});
callback(steps);
callback(directions);
});
};

Expand All @@ -48,18 +49,11 @@ var generate_directions = function(coords, callback) {
console.log(err)
return false; // Should also return err
} else {
var steps = response.json.routes[0].legs[0].steps;
var encodePolyline = response.json.routes[0].overview_polyline.points;
var polyline = polylineLib.decode(encodePolyline);
tripPoints = [];
steps.forEach(function(step, index) {
var lat, lng;
if (index == steps.length) {
lat = step.end_location.lat;
lng = step.end_location.lng;
} else {
lat = step.start_location.lat;
lng = step.start_location.lng;
}
var stepLatLng = { lat: lat, lng: lng };
polyline.forEach(function(step) {
var stepLatLng = { lat: step[0], lng: step[1] };
tripPoints.push(stepLatLng);
});
callback(tripPoints);
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"bugs": {
"url": "https://github.com/Ecotaco/bumblebee-bot/issues"
},
"engines" : { "node" : ">=7.0.0" },
"engines": {
"node": ">=7.0.0"
},
"homepage": "https://github.com/Ecotaco/bumblebee-bot#readme",
"scripts": {
"start": "nodemon ./bin/www",
Expand All @@ -33,6 +35,7 @@
"mongoose-timestamp": "^0.6.0",
"morgan": "~1.7.0",
"node-sass-middleware": "0.9.8",
"polyline": "^0.2.0",
"pug": "~2.0.0-beta6",
"serve-favicon": "~2.3.0",
"socket.io": "^1.5.1"
Expand Down
45 changes: 28 additions & 17 deletions public/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var styleLayer = L.mapbox.styleLayer('mapbox://styles/ecotaco/civ00flry01gx2jl8d
var featureGroup = L.featureGroup().addTo(map);
var polygon = null;
var drivers = [];
var socket = io('https://bumblebee-bot.herokuapp.com');
var host_back = window.location.origin;
var socket = io(host_back);

var drawControl = new L.Control.Draw({
edit: {
featureGroup: featureGroup,
Expand Down Expand Up @@ -78,16 +80,25 @@ $('#add').click(function() {
title: 'Generate the bot',
html:
'<input id="bot_name" name="bot_name" class="swal2-input" autofocus placeholder="Bot name" required />' +
'<input id="nb_driver" name="nb_driver" class="swal2-input" type="number" min="0" value="5" placeholder="Number of generated bot" required />',
'<input id="nb_driver" name="nb_driver" class="swal2-input" type="number" min="0" max="50" placeholder="Number of generated bot" required />' +
'<input id="accuracy" name="accuracy" class="swal2-input" type="number" min="10" max="100" step="10" placeholder="Accuracy" required />',
confirmButtonText: 'Generate',
showCancelButton: true,
preConfirm: function() {
return new Promise(function(resolve) {
resolve({
name: $('#bot_name').val(),
nb_driver: parseInt($('#nb_driver').val()),
zone: polygon,
})
return new Promise(function(resolve, reject) {
var name = $('#bot_name').val();
var nb_driver = parseInt($('#nb_driver').val());
var accuracy = parseInt($('#accuracy').val());

if (parseInt($('#nb_driver').val()) < 50) {
resolve({
name: name,
nb_driver: nb_driver,
zone: polygon,
})
} else {
reject('50 drivers maximum!')
}
})
}
}
Expand Down Expand Up @@ -132,7 +143,7 @@ $('#list').click(function() {
})

$.ajax({
url : 'https://bumblebee-bot.herokuapp.com/bots',
url : host_back + '/bots',
success : function(data){
var html = '';
data.forEach(function(bot){
Expand Down Expand Up @@ -302,33 +313,33 @@ function display_trips() {
}

function display_points() {
socket.on('trip', function(data) {
data.ride.forEach(function(step){
L.marker(L.latLng(step.lat, step.lng)).addTo(map);
});
});
socket.on('trip', function(data) {
data.ride.forEach(function(step){
L.marker(L.latLng(step.lat, step.lng)).addTo(map);
});
});
}

function delete_bot(id) {
$.ajax({
type: 'DELETE',
url : 'https://bumblebee-bot.herokuapp.com/bots/' + id
url : host_back + '/bots/' + id
});
swal.close();
}

function pause_bot(id) {
$.ajax({
type: 'POST',
url : 'https://bumblebee-bot.herokuapp.com/bots/' + id + '/deactivate'
url : host_back + '/bots/' + id + '/deactivate'
});
swal.close();
}

function active_bot(id) {
$.ajax({
type: 'POST',
url : 'https://bumblebee-bot.herokuapp.com/bots/' + id + '/active'
url : host_back + '/bots/' + id + '/active'
});
swal.close();
}

0 comments on commit 2d1999b

Please sign in to comment.