component/UIChartController.js
/* 
    Prepare the X and Y data for chart
*/
Prepare the X and Y data for chart
Prepare the X and Y data for chart
async function prepareGraphData(sessions) {
    let data = { x: [], y: [], yLimit: [], yCompare: [] };
    var end = new Date();
    var start = new Date();
    if (_nDays === 1) {
        start.setHours(0, 0, 0, 0);
        end.setHours(23, 59, 59, 999);
        let format = "H";
        let hourlyUsage = await activity.getHourlyUsage(sessions, start, end, format);
        data.y = hourlyUsage.y;
        data.x = hourlyUsage.x;
        start.setDate(start.getDate() - 2);
        end.setDate(end.getDate() - 1);
        let dailyUsagePast = await activity.getHourlyUsage(sessions, start, end, format);
        data.yCompare = dailyUsagePast.y;
    } else {
        start.setDate(start.getDate() - _nDays + 1);
        start.setHours(0, 0, 0, 0);
        let format = _nDays < 14 ? "ddd" : "D";
        let dailyusage = await activity.getDailyUsage(sessions, start, end, format);
        data.y = dailyusage.y;
        data.x = dailyusage.x;
        start.setDate(start.getDate() - _nDays * 2);
        end.setDate(end.getDate() - _nDays);
        console.log(start);
        console.log(end);
        let dailyUsagePast = await activity.getDailyUsage(sessions, start, end, format);
        data.yCompare = dailyUsagePast.y;
    }
    data.yLimit = Array.from({ length: data.x.length }, (v, i) => UIRangeAlarm.value);
    return data;
}
async function prepareGraphData ( sessions ) { let data = { x : [ ] , y : [ ] , yLimit : [ ] , yCompare : [ ] } ; var end = new Date ( ) ; var start = new Date ( ) ; if ( _nDays === 1 ) { start . setHours ( 0 , 0 , 0 , 0 ) ; end . setHours ( 23 , 59 , 59 , 999 ) ; let format = "H" ; let hourlyUsage = await activity . getHourlyUsage ( sessions , start , end , format ) ; data . y = hourlyUsage . y ; data . x = hourlyUsage . x ; start . setDate ( start . getDate ( ) - 2 ) ; end . setDate ( end . getDate ( ) - 1 ) ; let dailyUsagePast = await activity . getHourlyUsage ( sessions , start , end , format ) ; data . yCompare = dailyUsagePast . y ; } else { start . setDate ( start . getDate ( ) - _nDays + 1 ) ; start . setHours ( 0 , 0 , 0 , 0 ) ; let format = _nDays < 14 ? "ddd" : "D" ; let dailyusage = await activity . getDailyUsage ( sessions , start , end , format ) ; data . y = dailyusage . y ; data . x = dailyusage . x ; start . setDate ( start . getDate ( ) - _nDays * 2 ) ; end . setDate ( end . getDate ( ) - _nDays ) ; console . log ( start ) ; console . log ( end ) ; let dailyUsagePast = await activity . getDailyUsage ( sessions , start , end , format ) ; data . yCompare = dailyUsagePast . y ; } data . yLimit = Array . from ( { length : data . x . length } , ( v , i ) => UIRangeAlarm . value ) ; return data ; }
Prepare the X and Y data for chart
Prepare the X and Y data for chart