Grafana doesn’t do any sums or conversions, it gets its data pre-calculated from influx (or other sources). But I think you are asking about the origins of the data in the IoTaWatt.
The rate and timing of samples is driven primarily by the number of channels configured and then influenced by other activities, like servicing web server requests.
The individual samples are accumulated as Watt-milliseconds. At approximately five second intervals, the total is converted to double precision Watt-hours and added to a running total for that input.
When you query for Wh, the IoTaWatt returns the difference between the totals at the beginning and end of the interval.
IoTaWatt also maintains a running total of measured hours in the datalog. So when you query for average Watts, the Wh are calculated as above, and that is divided by the difference in measured hours for the interval. In that way, if there was a power outage during the interval, it will not effect the average power while actually measuring.
Same basic methodology for Voltage and VA with the datalog recording cumulative Volt-hours and VA-hours respectively.