Hey guys, as I understand it, data analytics (like calculating averages etc) on blockchain data is usually done off-chain (ie. you obtain data from the blockchain via say a third party API call or directly from the blockchain and then do the data analytics off-chain someone else).

Is it possible and/or if it is possible, how do we do data analytics on-chain itself (which I assume would involve doing the data analytics on the smart contract itself)?

Would really appreciate any help or input. Thanks!