I have an application that measures that continuously. (About every second - it depends on the device)
For example sake, let's say that data is CPUTemp (as used as an example in an answer to a related question: Clean Architecure: Creating an entity from a set of other entities)
Each measurement's data is written to the CPU_TEMP_SAMPLE table.
At the end of each day I compress the data calculating the min, max and average for that day and writing the data to a CPU_TEMP_DAY table.
I have a CpuTempRepository that get's the data either by calculating it from the CPU_TEMP_SAMPLE table (if it is for the current day) or just reading it from the CPU_TEMP_DAY table if it is for a previous day.
I want to be able to get the min and max reading for specific intervals from the CPU_TEMP_SAMPLE. (So instead of just returning the max temperature sample for that day I want to get the max temperature recorded over 30 seconds - so I am actually compressing 30 seconds worth of measurements into one sample)
How would I do this?
One way is to write each interval's min, max and average data to a new table CPU_TEMP_INTERVAL every 30 seconds and then get the max & min from there, but I am not sure if this is the right way - what if I need to calculate for different intervals?