When you dump the data, the current data in the function node is dropped. If you dump the data every x second, you can use the smooth node for more damping the data
Then you have the data flow:
Raw data a irregular intervall -> time_weighted_avg -> avg(time_weighted_avg)
[{"id":"1386b228cb3e1a1c","type":"function","z":"8eabc3a82cb1c5d6","name":"store","func":"if (msg.topic == 'dump') {\n let data = context.get('data') || []\n let times = context.get('times') || []\n \n msg.payload = {}\n msg.payload[\"data\"] = data\n msg.payload[\"times\"]= times\n\n context.set('data', [])\n context.set('times', [])\n\n} else {\n let payload = msg.payload\n let now = Date.now()\n let data = context.get('data') || []\n let times = context.get('times') || []\n\n data.push(payload)\n times.push(now)\n context.set('data',data)\n context.set('times',times)\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":340,"wires":[["39b19b80dbca327d"]]},{"id":"64c92e04ec4f3808","type":"inject","z":"8eabc3a82cb1c5d6","name":"add values","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"noise","v":"noise","vt":"flow"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$floor($random() * 10)\t\t","payloadType":"jsonata","x":150,"y":340,"wires":[["263120f34b38e12f"]]},{"id":"05ad16d40813b354","type":"inject","z":"8eabc3a82cb1c5d6","name":"dump","props":[{"p":"topic","vt":"str"}],"repeat":"15","crontab":"","once":false,"onceDelay":0.1,"topic":"dump","x":380,"y":400,"wires":[["1386b228cb3e1a1c"]]},{"id":"1f262f56255cd37a","type":"debug","z":"8eabc3a82cb1c5d6","name":"debug 78","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1180,"y":300,"wires":[]},{"id":"39b19b80dbca327d","type":"switch","z":"8eabc3a82cb1c5d6","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":340,"wires":[["fde7749eea9562dc"],["3eb39d92eb329e8d","6dcac8967fe192b6"]]},{"id":"fde7749eea9562dc","type":"function","z":"8eabc3a82cb1c5d6","name":"calculate stuff","func":"function timeWeightedAverage(data, timestamps) {\n if (data.length !== timestamps.length) {\n node.warn(\"array lenght is not equal\");\n }\n \n let total_weighted_sum = 0.0;\n let total_duration = 0.0;\n let total_area = 0.0\n \n for (let i = 1; i < data.length; i++) {\n let d_t = timestamps[i] - timestamps[i - 1];\n let v_1 = data[i -1]\n let v_2 = data[i]\n let area = ((v_1+v_2))/2 * d_t\n total_area += area\n const duration = timestamps[i] - timestamps[i - 1];\n total_duration += duration;\n }\n \n const time_weighted_avg = total_area / total_duration;\n return time_weighted_avg;\n}\n\n\nlet new_payload = {}\nconst data = msg.payload.data\nconst times = msg.payload.times\n\n\n//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max\nconst min = Math.min(...data)\nconst max = Math.max(...data)\n\n// https://stackoverflow.com/a/10624256\nconst sum = data.reduce((a, b) => a + b, 0);\n\n\nconst avg_qty = (sum / data.length) || 0;\nlet avg_time = timeWeightedAverage(data, times)\n\n\n\nnew_payload[\"min\"] = min\nnew_payload[\"max\"] = max\nnew_payload[\"sum\"] = sum\nnew_payload[\"avg_qty\"] = avg_qty\nnew_payload[\"avg_time\"] = avg_time\n\nmsg.payload = new_payload\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":300,"wires":[["1f262f56255cd37a","40bc9563f5d8199c"]]},{"id":"3eb39d92eb329e8d","type":"debug","z":"8eabc3a82cb1c5d6","name":"debug 80","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1060,"y":400,"wires":[]},{"id":"6dcac8967fe192b6","type":"change","z":"8eabc3a82cb1c5d6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"raw","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":480,"wires":[["3fb31fa63d166b47"]]},{"id":"3fb31fa63d166b47","type":"ui-chart","z":"8eabc3a82cb1c5d6","group":"b96c5dc1f181495b","name":"","label":"chart","order":9007199254740991,"chartType":"line","category":"topic","categoryType":"msg","xAxisProperty":"","xAxisPropertyType":"msg","xAxisType":"time","yAxisProperty":"","ymin":"","ymax":"","action":"append","pointShape":"circle","pointRadius":4,"showLegend":true,"removeOlder":"2","removeOlderUnit":"60","removeOlderPoints":"200","colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"width":6,"height":8,"className":"","x":1790,"y":440,"wires":[[]]},{"id":"40bc9563f5d8199c","type":"change","z":"8eabc3a82cb1c5d6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.avg_time","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"time_weighted_avg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":220,"wires":[["3fb31fa63d166b47","6b81f1075c570a7b"]]},{"id":"6b81f1075c570a7b","type":"smooth","z":"8eabc3a82cb1c5d6","name":"","property":"payload","action":"mean","count":"10","round":"","mult":"single","reduce":false,"x":1480,"y":200,"wires":[["236ec8d67c810693"]]},{"id":"f27f95968b05d2be","type":"ui-slider","z":"8eabc3a82cb1c5d6","group":"b96c5dc1f181495b","name":"add noise","label":"noise","tooltip":"","order":0,"width":0,"height":0,"passthru":false,"outs":"end","topic":"topic","topicType":"msg","thumbLabel":true,"min":"-10","max":10,"step":1,"className":"","x":200,"y":240,"wires":[["ea12657eb7300151"]]},{"id":"ea12657eb7300151","type":"change","z":"8eabc3a82cb1c5d6","name":"","rules":[{"t":"set","p":"noise","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":240,"wires":[[]]},{"id":"263120f34b38e12f","type":"change","z":"8eabc3a82cb1c5d6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload * noise","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":340,"wires":[["1386b228cb3e1a1c"]]},{"id":"b96c5dc1f181495b","type":"ui-group","name":"Group Name","page":"d2203bba5961af37","width":"6","height":"1","order":-1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"d2203bba5961af37","type":"ui-page","name":"Page Name","ui":"2c91ba6fb44ea823","path":"/page1","icon":"home","layout":"grid","theme":"e40d02373fbb58c8","order":-1,"className":"","visible":"true","disabled":"false"},{"id":"2c91ba6fb44ea823","type":"ui-base","name":"UI Name","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"e40d02373fbb58c8","type":"ui-theme","name":"Theme Name","colors":{"surface":"#ffffff","primary":"#0094ce","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]