Correcting the error in getnetworkhashrateps

Why do you only look at cases where a specific (b = 5) number of blocks during the fixed interval? That must create a distortion.

If you fix the time window, the number of blocks found within it will be variable, and estimations should account for all of the possibilities observed.

In my simulation, even with a variable hashrate during the window, and variable difficulties during the window, the estimator sum(block.work for block in window) / window.duration) gives an unbiased estimate for the (average) hashrate during the window, without any correction factors.