@henryblu It sounds like you are going to need to write some specialized logic in JavaScript. I'd suggest adding a custom component via the user module, see https://help.infiniteautomation.com/getting-started-with-a-user-module/
You can leverage our maStatistics and maPointValues services to pull data from the REST API then process and output the data onto the page from the component. You can use the moment.js library directly inside your component, also we recently added the math.js library which might be useful. It has statistics and matrix functions.