diff --git a/src/utils/dataUtils.test.ts b/src/utils/dataUtils.test.ts index 67653ad..ba32be5 100644 --- a/src/utils/dataUtils.test.ts +++ b/src/utils/dataUtils.test.ts @@ -73,12 +73,11 @@ describe('padAndSortTimeSeries', () => { it('should return sorted and padded data for simple time series data for MINUTE interval', () => { //arrange const data = [ - [1712919540000, 1], //Friday, 12 April 2024 10:59:00 [1712919600000, 2], //Friday, 12 April 2024 11:00:00 [1712919720000, 5], //Friday, 12 April 2024 11:02:00 ]; - const startTimestamp = 1712919560000; //Friday, 12 April 2024 10:59:20 + const startTimestamp = 1712919540000; //Friday, 12 April 2024 10:59:00 const endTimestamp = 1712919780000; //Friday, 12 April 2024 11:03:00 //act @@ -86,23 +85,23 @@ describe('padAndSortTimeSeries', () => { //assert expect(result).toEqual([ - [1712919600000, 2], - [1712919660000, 0], - [1712919720000, 5], - [1712919780000, 0], + [1712919540000, 0], //Friday, 12 April 2024 10:59:00 + [1712919600000, 2], //Friday, 12 April 2024 11:00:00 + [1712919660000, 0], //Friday, 12 April 2024 11:01:00 + [1712919720000, 5], //Friday, 12 April 2024 11:02:00 + [1712919780000, 0], //Friday, 12 April 2024 11:03:00 ]); }); it('should return sorted and padded data for simple time series data for HOUR Interval', () => { //arrange const data = [ - [1712916000000, 1], //Friday, 12 April 2024 10:00:00 [1712919600000, 7], //Friday, 12 April 2024 11:00:00 [1712930400000, 5], //Friday, 12 April 2024 14:00:00 [1712934000000, 2], //Friday, 12 April 2024 15:00:00 ]; - const startTimestamp = 1712917444000; //Friday, 12 April 2024 10:24:04 + const startTimestamp = 1712916000000; //Friday, 12 April 2024 10:00:00 const endTimestamp = 1712935444000; //Friday, 12 April 2024 15:24:04 //act @@ -110,6 +109,7 @@ describe('padAndSortTimeSeries', () => { //assert expect(result).toEqual([ + [1712916000000, 0], //Friday, 12 April 2024 10:00:00 [1712919600000, 7], //Friday, 12 April 2024 11:00:00 [1712923200000, 0], //Friday, 12 April 2024 12:00:00 [1712926800000, 0], //Friday, 12 April 2024 13:00:00 @@ -121,12 +121,11 @@ describe('padAndSortTimeSeries', () => { it('should return sorted and padded data for simple time series data for DAY interval', () => { //arrange const data = [ - [1712917800000, 1], //Friday, 12 April 2024 10:30:00 [1713004200000, 2], //Saturday, 13 April 2024 10:30:00 [1713263400000, 5], //Tuesday, 16 April 2024 10:30:00 ]; - const startTimestamp = 1712919560000; //Friday, 12 April 2024 10:59:20 + const startTimestamp = 1712917800000; //Friday, 12 April 2024 10:30:00 const endTimestamp = 1713351560000; //Wednesday, 17 April 2024 10:59:20 //act @@ -134,6 +133,7 @@ describe('padAndSortTimeSeries', () => { //assert expect(result).toEqual([ + [1712917800000, 0], //Friday, 12 April 2024 10:30:00 [1713004200000, 2], //Saturday, 13 April 2024 10:30:00 [1713090600000, 0], //Sunday, 14 April 2024 10:30:00 [1713177000000, 0], //Monday, 15 April 2024 10:30:00 @@ -142,39 +142,61 @@ describe('padAndSortTimeSeries', () => { ]); }); - it('should return sorted and padded data for simple time series data for DAY interval', () => { + it('should return sorted and padded data for simple time series data for MONTH interval with start Day being the last of a month', () => { //arrange const data = [ - [1712917800000, 1], //Friday, 12 April 2024 10:30:00 - [1713004200000, 2], //Saturday, 13 April 2024 10:30:00 - [1713263400000, 5], //Tuesday, 16 April 2024 10:30:00 + [1706740200000, 1], //Wednesday, 31 January 2024 22:30:00 + [1711924200000, 2], //Sunday, 31 March 2024 22:30:00 + [1714516200000, 5], //Tuesday, 30 April 2024 22:30:00 ]; - const startTimestamp = 1712919560000; //Friday, 12 April 2024 10:59:20 - const endTimestamp = 1713351560000; //Wednesday, 17 April 2024 10:59:20 + const startTimestamp = 1706740200000; //Wednesday, 31 January 2024 22:30:00 + const endTimestamp = 1718454244000; //Saturday, 15 June 2024 12:24:04 //act - const result = padAndSortTimeSeries(data, startTimestamp, endTimestamp, 'DAY'); + const result = padAndSortTimeSeries(data, startTimestamp, endTimestamp, 'MONTH'); //assert expect(result).toEqual([ - [1713004200000, 2], //Saturday, 13 April 2024 10:30:00 - [1713090600000, 0], //Sunday, 14 April 2024 10:30:00 - [1713177000000, 0], //Monday, 15 April 2024 10:30:00 - [1713263400000, 5], //Tuesday, 16 April 2024 10:30:00 - [1713349800000, 0], //Wednesday, 17 April 2024 10:30:00 + [1706740200000, 1], //Wednesday, 31 January 2024 22:30:00 + [1709245800000, 0], //Thursday, 29 February 2024 22:30:00 + [1711924200000, 2], //Sunday, 31 March 2024 22:30:00 + [1714516200000, 5], //Tuesday, 30 April 2024 22:30:00 + [1717194600000, 0], // Friday, 31 May 2024 22:30:00 + ]); + }); + + it('should return sorted and padded data for simple time series data for MONTH interval with start Day being the first of a month', () => { + //arrange + const data = [ + [1712010600000, 2], //Monday, 1 April 2024 22:30:00 + [1714602600000, 5], //Wednesday, 1 May 2024 22:30:00 + ]; + + const startTimestamp = 1706826600000; //Thursday, 1 February 2024 22:30:00 + const endTimestamp = 1718454244000; //Saturday, 15 June 2024 12:24:04 + + //act + const result = padAndSortTimeSeries(data, startTimestamp, endTimestamp, 'MONTH'); + + //assert + expect(result).toEqual([ + [1706826600000, 0], //Thursday, 1 February 2024 22:30:00 + [1709332200000, 0], //Friday, 1 March 2024 22:30:00 + [1712010600000, 2], //Monday, 1 April 2024 22:30:00 + [1714602600000, 5], //Wednesday, 1 May 2024 22:30:00 + [1717281000000, 0], //Saturday, 1 June 2024 22:30:00 ]); }); it('should return sorted and padded data for grouped time series data for MINUTE interval', () => { //arrange const data = [ - [1712919540000, 'BROWSER', 'DEVICE_TYPE', 1], //Friday, 12 April 2024 10:59:00 [1712919600000, 'BROWSER', 'DEVICE_TYPE', 2], //Friday, 12 April 2024 11:00:00 [1712919720000, 'BROWSER', 'DEVICE_TYPE', 5], //Friday, 12 April 2024 11:02:00 ]; - const startTimestamp = 1712919560000; //Friday, 12 April 2024 10:59:20 + const startTimestamp = 1712919540000; //Friday, 12 April 2024 10:59:00 const endTimestamp = 1712919780000; //Friday, 12 April 2024 11:03:00 //act @@ -182,23 +204,23 @@ describe('padAndSortTimeSeries', () => { //assert expect(result).toEqual([ - [1712919600000, 'BROWSER', 'DEVICE_TYPE', 2], - [1712919660000, 'BROWSER', 'DEVICE_TYPE', 0], - [1712919720000, 'BROWSER', 'DEVICE_TYPE', 5], - [1712919780000, 'BROWSER', 'DEVICE_TYPE', 0], + [1712919540000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 12 April 2024 10:59:00 + [1712919600000, 'BROWSER', 'DEVICE_TYPE', 2], //Friday, 12 April 2024 11:00:00 + [1712919660000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 12 April 2024 11:01:00 + [1712919720000, 'BROWSER', 'DEVICE_TYPE', 5], //Friday, 12 April 2024 11:02:00 + [1712919780000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 12 April 2024 11:03:00 ]); }); it('should return sorted and padded data for grouped time series data for HOUR interval', () => { //arrange const data = [ - [1712916000000, 'BROWSER', 'DEVICE_TYPE', 1], //Friday, 12 April 2024 10:00:00 [1712919600000, 'BROWSER', 'DEVICE_TYPE', 7], //Friday, 12 April 2024 11:00:00 [1712930400000, 'BROWSER', 'DEVICE_TYPE', 5], //Friday, 12 April 2024 14:00:00 [1712934000000, 'BROWSER', 'DEVICE_TYPE', 2], //Friday, 12 April 2024 15:00:00 ]; - const startTimestamp = 1712917444000; //Friday, 12 April 2024 10:24:04 + const startTimestamp = 1712916000000; //Friday, 12 April 2024 10:00:00 const endTimestamp = 1712935444000; //Friday, 12 April 2024 15:24:04 //act @@ -206,6 +228,7 @@ describe('padAndSortTimeSeries', () => { //assert expect(result).toEqual([ + [1712916000000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 12 April 2024 10:00:00 [1712919600000, 'BROWSER', 'DEVICE_TYPE', 7], //Friday, 12 April 2024 11:00:00 [1712923200000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 12 April 2024 12:00:00 [1712926800000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 12 April 2024 13:00:00 @@ -217,12 +240,11 @@ describe('padAndSortTimeSeries', () => { it('should return sorted and padded data for grouped time series data for DAY interval', () => { //arrange const data = [ - [1712917800000, 'BROWSER', 'DEVICE_TYPE', 1], //Friday, 12 April 2024 10:30:00 [1713004200000, 'BROWSER', 'DEVICE_TYPE', 2], //Saturday, 13 April 2024 10:30:00 [1713263400000, 'BROWSER', 'DEVICE_TYPE', 5], //Tuesday, 16 April 2024 10:30:00 ]; - const startTimestamp = 1712919560000; //Friday, 12 April 2024 10:59:20 + const startTimestamp = 1712917800000; //Friday, 12 April 2024 10:30:00 const endTimestamp = 1713351560000; //Wednesday, 17 April 2024 10:59:20 //act @@ -230,6 +252,7 @@ describe('padAndSortTimeSeries', () => { //assert expect(result).toEqual([ + [1712917800000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 12 April 2024 10:30:00 [1713004200000, 'BROWSER', 'DEVICE_TYPE', 2], //Saturday, 13 April 2024 10:30:00 [1713090600000, 'BROWSER', 'DEVICE_TYPE', 0], //Sunday, 14 April 2024 10:30:00 [1713177000000, 'BROWSER', 'DEVICE_TYPE', 0], //Monday, 15 April 2024 10:30:00 @@ -238,6 +261,53 @@ describe('padAndSortTimeSeries', () => { ]); }); + it('should return sorted and padded data for grouped time series data for MONTH interval with start Day being the last of a month', () => { + //arrange + const data = [ + [1706740200000, 'BROWSER', 'DEVICE_TYPE', 1], //Wednesday, 31 January 2024 22:30:00 + [1711924200000, 'BROWSER', 'DEVICE_TYPE', 2], //Sunday, 31 March 2024 22:30:00 + [1714516200000, 'BROWSER', 'DEVICE_TYPE', 5], //Tuesday, 30 April 2024 22:30:00 + ]; + + const startTimestamp = 1706740200000; //Wednesday, 31 January 2024 22:30:00 + const endTimestamp = 1718454244000; //Saturday, 15 June 2024 12:24:04 + + //act + const result = padAndSortTimeSeries(data, startTimestamp, endTimestamp, 'MONTH'); + + //assert + expect(result).toEqual([ + [1706740200000, 'BROWSER', 'DEVICE_TYPE', 1], //Wednesday, 31 January 2024 22:30:00 + [1709245800000, 'BROWSER', 'DEVICE_TYPE', 0], //Thursday, 29 February 2024 22:30:00 + [1711924200000, 'BROWSER', 'DEVICE_TYPE', 2], //Sunday, 31 March 2024 22:30:00 + [1714516200000, 'BROWSER', 'DEVICE_TYPE', 5], //Tuesday, 30 April 2024 22:30:00 + [1717194600000, 'BROWSER', 'DEVICE_TYPE', 0], // Friday, 31 May 2024 22:30:00 + ]); + }); + + it('should return sorted and padded data for grouped time series data for MONTH interval with start Day being the first of a month', () => { + //arrange + const data = [ + [1712010600000, 'BROWSER', 'DEVICE_TYPE', 2], //Monday, 1 April 2024 22:30:00 + [1714602600000, 'BROWSER', 'DEVICE_TYPE', 5], //Wednesday, 1 May 2024 22:30:00 + ]; + + const startTimestamp = 1706826600000; //Thursday, 1 February 2024 22:30:00 + const endTimestamp = 1718454244000; //Saturday, 15 June 2024 12:24:04 + + //act + const result = padAndSortTimeSeries(data, startTimestamp, endTimestamp, 'MONTH'); + + //assert + expect(result).toEqual([ + [1706826600000, 'BROWSER', 'DEVICE_TYPE', 0], //Thursday, 1 February 2024 22:30:00 + [1709332200000, 'BROWSER', 'DEVICE_TYPE', 0], //Friday, 1 March 2024 22:30:00 + [1712010600000, 'BROWSER', 'DEVICE_TYPE', 2], //Monday, 1 April 2024 22:30:00 + [1714602600000, 'BROWSER', 'DEVICE_TYPE', 5], //Wednesday, 1 May 2024 22:30:00 + [1717281000000, 'BROWSER', 'DEVICE_TYPE', 0], //Saturday, 1 June 2024 22:30:00 + ]); + }); + it('should throw error when interval is not valid', () => { //arrange const data = [[0, 0]];