feat(week-from-obj): return array of trips count
This commit is contained in:
parent
6526b849ef
commit
a486b29389
|
@ -3,7 +3,7 @@ function getAryThisWeek(date){
|
||||||
let dateIncrement=new Date(dateToday);
|
let dateIncrement=new Date(dateToday);
|
||||||
const aryThisWeek=[];
|
const aryThisWeek=[];
|
||||||
for(var i=0;i<7;i++){
|
for(var i=0;i<7;i++){
|
||||||
aryThisWeek[i]=new Date(dateIncrement);
|
aryThisWeek[i]=new Date(new Date(dateIncrement).setHours(0, 0, 0, 0));
|
||||||
dateIncrement=new Date(dateIncrement.setDate(dateIncrement.getDate()+1));
|
dateIncrement=new Date(dateIncrement.setDate(dateIncrement.getDate()+1));
|
||||||
}
|
}
|
||||||
return aryThisWeek;
|
return aryThisWeek;
|
||||||
|
|
|
@ -3,7 +3,7 @@ function getAryThisWeek(date){
|
||||||
let dateIncrement=new Date(dateToday);
|
let dateIncrement=new Date(dateToday);
|
||||||
const aryThisWeek=[];
|
const aryThisWeek=[];
|
||||||
for(var i=0;i<7;i++){
|
for(var i=0;i<7;i++){
|
||||||
aryThisWeek[i]=new Date(dateIncrement);
|
aryThisWeek[i]=new Date(new Date(dateIncrement).setHours(0, 0, 0, 0));
|
||||||
dateIncrement=new Date(dateIncrement.setDate(dateIncrement.getDate()+1));
|
dateIncrement=new Date(dateIncrement.setDate(dateIncrement.getDate()+1));
|
||||||
}
|
}
|
||||||
return aryThisWeek;
|
return aryThisWeek;
|
||||||
|
|
|
@ -35,7 +35,10 @@ async function run() {
|
||||||
let routeShortName=aryRoutes[i][1];
|
let routeShortName=aryRoutes[i][1];
|
||||||
debug('routeShortName: ' + routeShortName);
|
debug('routeShortName: ' + routeShortName);
|
||||||
if(routeShortName){
|
if(routeShortName){
|
||||||
routeService.getService(routeShortName);
|
let aryTripsCount=[0,0,0,0,0,0,0];
|
||||||
|
aryTripsCount=routeService.getTripsCountFromRoute(routeShortName,thisWeek);
|
||||||
|
//TODO Why is aryTripsCount undefined?
|
||||||
|
debug('aryTripsCount: '+aryTripsCount[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,25 +8,84 @@ getService().catch(err => {
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function getService(routeShortName) {
|
async function getTripsCountFromRoute(routeShortName,week) {
|
||||||
debug('getService started...')
|
debug('getTripsCountFromRoute started...')
|
||||||
//TODO clean up static final route
|
//TODO clean up static final route
|
||||||
routeShortName=565;
|
routeShortName=565;
|
||||||
debug('routeShortName: ' + routeShortName);
|
debug('routeShortName: ' + routeShortName);
|
||||||
let url = `http://localhost:65534/servicedays?routeshortname=${routeShortName}`;
|
let url = `http://localhost:65534/servicedays?routeshortname=${routeShortName}`;
|
||||||
debug('url: '+url);
|
debug('url: '+url);
|
||||||
|
let aryTripsCount=[0,0,0,0,0,0,0];
|
||||||
let resp={};
|
let resp={};
|
||||||
resp= await axios.get(url);
|
resp= await axios.get(url);
|
||||||
if('data' in resp){
|
if('data' in resp){
|
||||||
const objServiceDays=resp.data;
|
const objServiceDays=resp.data;
|
||||||
const aryServiceDays=Object.entries(objServiceDays);
|
const aryServiceDays=Object.entries(objServiceDays);
|
||||||
debug('aryServiceDays len: '+aryServiceDays.length);
|
debug('aryServiceDays len: '+aryServiceDays.length);
|
||||||
for(var i=0;i<1;i++){
|
for(var i=0;i<aryServiceDays.length;i++){
|
||||||
debug('i: '+i);
|
//debug('i: '+i);
|
||||||
let serviceDay=aryServiceDays[i][0];
|
let serviceDay=aryServiceDays[i][0];
|
||||||
debug('serviceDay: '+serviceDay);
|
//debug('serviceDay: '+serviceDay);
|
||||||
let dateFromDay=new Date(parseInt(serviceDay,10));
|
let dateFromDay=new Date(parseInt(serviceDay,10));
|
||||||
debug('dateFromDay: '+dateFromDay);
|
//debug('dateFromDay: '+dateFromDay);
|
||||||
|
dateFromDay=new Date(new Date(dateFromDay).setHours(0, 0, 0, 0));
|
||||||
|
//debug('dateFromDay: '+dateFromDay);
|
||||||
|
if(dateFromDay.getTime()===week[0].getTime()){
|
||||||
|
debug('found date 0: '+dateFromDay);
|
||||||
|
let trips=aryServiceDays[i][1];
|
||||||
|
const aryTrip = Object.keys(trips);
|
||||||
|
const tripCount=aryTrip.length;
|
||||||
|
debug('tripCount: '+tripCount);
|
||||||
|
aryTripsCount[0]=tripCount;
|
||||||
|
}
|
||||||
|
else if(dateFromDay.getTime()===week[1].getTime()){
|
||||||
|
debug('found date 1: '+dateFromDay);
|
||||||
|
let trips=aryServiceDays[i][1];
|
||||||
|
const aryTrip = Object.keys(trips);
|
||||||
|
const tripCount=aryTrip.length;
|
||||||
|
debug('tripCount: '+tripCount);
|
||||||
|
aryTripsCount[1]=tripCount;
|
||||||
|
}
|
||||||
|
else if(dateFromDay.getTime()===week[2].getTime()){
|
||||||
|
debug('found date 2: '+dateFromDay);
|
||||||
|
let trips=aryServiceDays[i][1];
|
||||||
|
const aryTrip = Object.keys(trips);
|
||||||
|
const tripCount=aryTrip.length;
|
||||||
|
debug('tripCount: '+tripCount);
|
||||||
|
aryTripsCount[2]=tripCount;
|
||||||
|
}
|
||||||
|
else if(dateFromDay.getTime()===week[3].getTime()){
|
||||||
|
debug('found date 3: '+dateFromDay);
|
||||||
|
let trips=aryServiceDays[i][1];
|
||||||
|
const aryTrip = Object.keys(trips);
|
||||||
|
const tripCount=aryTrip.length;
|
||||||
|
debug('tripCount: '+tripCount);
|
||||||
|
aryTripsCount[3]=tripCount;
|
||||||
|
}
|
||||||
|
else if(dateFromDay.getTime()===week[4].getTime()){
|
||||||
|
debug('found date 4: '+dateFromDay);
|
||||||
|
let trips=aryServiceDays[i][1];
|
||||||
|
const aryTrip = Object.keys(trips);
|
||||||
|
const tripCount=aryTrip.length;
|
||||||
|
debug('tripCount: '+tripCount);
|
||||||
|
aryTripsCount[4]=tripCount;
|
||||||
|
}
|
||||||
|
else if(dateFromDay.getTime()===week[5].getTime()){
|
||||||
|
debug('found date 5: '+dateFromDay);
|
||||||
|
let trips=aryServiceDays[i][1];
|
||||||
|
const aryTrip = Object.keys(trips);
|
||||||
|
const tripCount=aryTrip.length;
|
||||||
|
debug('tripCount: '+tripCount);
|
||||||
|
aryTripsCount[5]=tripCount;
|
||||||
|
}
|
||||||
|
else if(dateFromDay.getTime()===week[6].getTime()){
|
||||||
|
debug('found date 6: '+dateFromDay);
|
||||||
|
let trips=aryServiceDays[i][1];
|
||||||
|
const aryTrip = Object.keys(trips);
|
||||||
|
const tripCount=aryTrip.length;
|
||||||
|
debug('tripCount: '+tripCount);
|
||||||
|
aryTripsCount[6]=tripCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,9 +98,10 @@ async function getService(routeShortName) {
|
||||||
}else{
|
}else{
|
||||||
debug('no data in resp');
|
debug('no data in resp');
|
||||||
}
|
}
|
||||||
debug('getService done.')
|
debug('getTripsCountFromRoute done.')
|
||||||
|
return aryTripsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports={
|
module.exports={
|
||||||
getService
|
getTripsCountFromRoute
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue