0

I have a CSV file with data like this -

time,a,b,c,d,e,f,g
2020-06-18 14:59:34.585143,2,0,0,2,1,1,0
2020-06-18 14:59:38.302183,2,0,0,2,1,0,1
..
..
2020-06-18 15:04:11.529016,1,0,0,1,0,0,0
2020-06-18 15:04:11.874480,1,0,0,1,0,0,0
2020-06-18 15:04:12.213976,1,0,0,1,0,0,0

I am reading it using node-csv package and sending it to Angular based frontend to be later drawn on a chart using ChartJS.

The chart looks ugly due to the density of data(every second).

I'm looking to round-off the data from the CSV which should be-

  1. From the last 6 hours from the latest entry.
  2. Should be rounded-off to 30 minutes with the aggregation of the corresponding values of a,b,c,d... from the CSV.
Vibhor Dube
  • 4,173
  • 1
  • 22
  • 32
  • 1
    This is a filtering problem. The solution of which is to find all records in latest 6 hours and serve that. The csv file is at the point of reading static. This means you are looking to turn that data into JSON , or array representation. From there it's just using an array.map statement to find all the items where the data time is within the 6 hour view. Can node-csv represent the data a wither JSON or an Array? You may need to write a regex expression in the map statement. – JWP Jul 11 '20 at 15:21

1 Answers1

0

I think you need to create a custom parser, like in this answer.

And then create a key from the DateTime value so that it's rounded to every 30 minutes, so like "2020-06-18 14:59:34.585143" to key "202006181430", see example in this answer.

BdR
  • 2,770
  • 2
  • 17
  • 36