From a486b29389959d76350477466e337ac23c3a4316 Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Tue, 31 May 2022 15:05:43 +0200 Subject: [PATCH] feat(week-from-obj): return array of trips count --- ary-this-week/ary-this-week.js | 2 +- week-from-obj/ary-this-week.js | 2 +- week-from-obj/index.js | 5 ++- week-from-obj/service.js | 76 ++++++++++++++++++++++++++++++---- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/ary-this-week/ary-this-week.js b/ary-this-week/ary-this-week.js index 895250e..490ac3b 100644 --- a/ary-this-week/ary-this-week.js +++ b/ary-this-week/ary-this-week.js @@ -3,7 +3,7 @@ function getAryThisWeek(date){ let dateIncrement=new Date(dateToday); const aryThisWeek=[]; 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)); } return aryThisWeek; diff --git a/week-from-obj/ary-this-week.js b/week-from-obj/ary-this-week.js index 895250e..490ac3b 100644 --- a/week-from-obj/ary-this-week.js +++ b/week-from-obj/ary-this-week.js @@ -3,7 +3,7 @@ function getAryThisWeek(date){ let dateIncrement=new Date(dateToday); const aryThisWeek=[]; 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)); } return aryThisWeek; diff --git a/week-from-obj/index.js b/week-from-obj/index.js index ecc5ea6..8b3bce1 100644 --- a/week-from-obj/index.js +++ b/week-from-obj/index.js @@ -35,7 +35,10 @@ async function run() { let routeShortName=aryRoutes[i][1]; debug('routeShortName: ' + 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]); } } } diff --git a/week-from-obj/service.js b/week-from-obj/service.js index e1ebcef..3079884 100644 --- a/week-from-obj/service.js +++ b/week-from-obj/service.js @@ -8,25 +8,84 @@ getService().catch(err => { }); */ -async function getService(routeShortName) { - debug('getService started...') +async function getTripsCountFromRoute(routeShortName,week) { + debug('getTripsCountFromRoute started...') //TODO clean up static final route routeShortName=565; debug('routeShortName: ' + routeShortName); let url = `http://localhost:65534/servicedays?routeshortname=${routeShortName}`; debug('url: '+url); + let aryTripsCount=[0,0,0,0,0,0,0]; let resp={}; resp= await axios.get(url); if('data' in resp){ const objServiceDays=resp.data; const aryServiceDays=Object.entries(objServiceDays); debug('aryServiceDays len: '+aryServiceDays.length); - for(var i=0;i<1;i++){ - debug('i: '+i); + for(var i=0;i