Step 1:
Keep track of all the transactions that have been broadcast to the Bitcoin network which are not yet in a block. Keep a record of the size of the transactions, and the fee that each transaction is offering.
Step 2:
Keep track of the recent blocks that have been solved. Keep a record of the number of transactions included in the block and the fees that made it into the block.
Step 3: Perform a statistical analysis of the unconfirmed transactions that have been broadcast to the Bitcoin network, and (using your statistical model) attempt to predict the rates, quantities, sizes, and fees of the transactions that are likely to be created in the next few hours.
Step 4: Assume that the typical miner will make rational profit driven decisions and that they are not receiving any revenue outside of the transaction fees and block subsidy.
Step 5: Using your predictions of future transactions along with your knowledge of the current backlog, calculate the minimum fee that would make it into each of the blocks over the next few hours.
Step 6: Publish (or use) your results as a guideline on how big of a fee you'll need to pay if you want your transaction confirmed quickly.
Extra credit: You can improve your model if you can predict which transactions the typical mining pool is likely to drop from its mempool.
Thank you, however, I doubt this is how electrum (or bitcoin wallets) get the fees for Sending btc.
I am sure there is a simpler way