浏览代码

calculate times and get weather

master
mahmoud 2 年前
父节点
当前提交
c1112d64df
共有 4 个文件被更改,包括 53 次插入17 次删除
  1. 25
    5
      server/app.js
  2. 8
    4
      server/cars.json
  3. 18
    6
      server/inputs.json
  4. 2
    2
      server/stations.json

+ 25
- 5
server/app.js 查看文件

@@ -45,12 +45,12 @@ const isTheCarInStation = (carId, stationId) => {
}

const distanceBetweenTwoPoint = (start, end) => {
return geodist(start, end, {'unit': 'meters'})
return geodist(start, end, {'unit': 'meters'}) // todo: meters
}

const calculateCarTimeToStation = (carId, stationId) => {
// Time = Distance/Speed
// Hourse = `KM` / `KM/H`
// Hours = `KM` / `KM/H`
let lastUpdate = getCarLastUpdate(carId)

if (! lastUpdate) return null
@@ -99,14 +99,34 @@ const getStationData = stationId => {
.map(car => {
console.log(car)
car.distanceBetweenCarAndStation = distanceBetweenCarAndStation(car.id, stationId)
car.stationTraficCondition = getStationTraficCondition(stationId)
car.isInStation = isTheCarInStation(car.id, stationId)
car.CarTimeToStation = calculateCarTimeToStation(car.id, stationId)
car.traffic = getStationTraficCondition(stationId)
car.status = isTheCarInStation(car.id, stationId) ? 'Boarding' : 'Departed'

let carTimeToStationInHours = calculateCarTimeToStation(car.id, stationId)
car.eta = (carTimeToStationInHours * 60) + " minutes"

// var date = new Date().getTime()
// date += (carTimeToStationInHours * 60 * 60 * 1000)
// date = new Date(date)

// car.eta = ("0" + date.getHours()).slice(-2) + ':' +
// ("0" + date.getMinutes()).slice(-2);

// Mocked data
car.time = "20 min"
car.load = Math.floor(Math.random() * Math.floor(7))
const weathers = ['clear-day', 'partly-cloudy-night', 'rain', 'fog', 'snow']
car.weather = weathers[Math.floor(Math.random()*weathers.length)]

return car
})
}

const carDepartureTime = carId => {

}

console.log(distanceBetweenCarAndStation(1,1))

module.exports = {
getCarLastUpdate,

+ 8
- 4
server/cars.json 查看文件

@@ -1,18 +1,22 @@
{
"1" :{
"id": 1,
"stations_ids": [1, 2]
"stations_ids": [1, 2],
"driverName": "Mohmoud Taweel"
},
"2": {
"id": 2,
"stations_ids": [1, 2]
"stations_ids": [1, 2],
"driverName": "Mahmoud Damery"
},
"3": {
"id": 3,
"stations_ids": [1, 2]
"stations_ids": [1, 2],
"driverName": "Ameer.a"
},
"4": {
"id": 4,
"stations_ids": [1, 2]
"stations_ids": [1, 2],
"driverName": "Hammam.s"
}
}

+ 18
- 6
server/inputs.json 查看文件

@@ -1,16 +1,28 @@
[
{
"car_id": 1,
"lat": 13.1835,
"lon": -54.93733,
"lat": 31.895255,
"lon": 35.1652892,
"speed": 40,
"timestamp": 1533831400
"timestamp": 1533831420
}, {
"car_id": 1,
"lat": 13.1837,
"lon": -54.93738,
"lat": 31.895256,
"lon": 35.1652893,
"speed": 10,
"timestamp": 1533831419
"timestamp": 1533831421
}, {
"car_id": 1,
"lat": 31.895257,
"lon": 35.1652894,
"speed": 10,
"timestamp": 1533831422
}, {
"car_id": 1,
"lat": 31.895958,
"lon": 35.1659895,
"speed": 15,
"timestamp": 1533831423
}, {
"car_id": 2,
"lat": 14.9837,

+ 2
- 2
server/stations.json 查看文件

@@ -3,8 +3,8 @@
"id:": 1,
"source": "Nablus",
"destination": "Ramallah",
"lat": 13.9837,
"lon": -54.93738,
"lat": 31.897376,
"lon": 35.1673012,
"max_speed": 90
},
"2": {

正在加载...
取消
保存