I'm currently developing a mining pool implementing Stratum 2 in Rust (SRI), and during development, the question arose of calculating a miner's hashrate based on the difficulty of the shares they submit. I conducted a small experimental study and found that the following algorithm provides the best accuracy:
1. I take the shares submitted by the miner over a period of time, say 10 minutes.
2. I calculate the difficulty (share_diff = max_target / hash) for each.
3. I find the share corresponding to the (1 - 1/e) percentile (this is approximately the 63rd percentile) in terms of difficulty.
4. I multiply the difficulty of the share found in step 3 by the total number of shares.
5. I multiply the result obtained in step 4 by 1/e (approximately 0.37).
6. I multiply by 2^32 and get the number of hashes that needed to be iterated through to find all these shares.
7. I divide by the number of seconds (for 10 minutes, this is 600 seconds) and get the hashes per second.
If someone understands code better (I don't vouch for the accuracy, it was generated by AI based on my description

def calculate_hashrate(shares_list, time_period_seconds=600):
max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
difficulties = np.array([max_target / hash_value for hash_value in shares_list])
percentile_difficulty = np.percentile(difficulties, (1 - 1/np.e) * 100)
total = percentile_difficulty * len(difficulties) * (1/np.e) * 2**32
return total / time_period_seconds
I have questions:
1) Is this technique commonly known? And what are the alternatives?
2) Why does this even work? I have a lot of work on the project right now, and I don't have time to delve into theoretical mathematics, but I'm very interested in this story with the number "e" - why does this particular number work? Can this algorithm be written in any other way?
Thank you.