Here's a start for you:
http://sheetmetal.me/formulas-and-functions/k-factor/
FWIW I did mine this exact way back in 2013 with a very small "fine tuning" adjustment in 2017. Now when I fill up, the fuel remaining indication is within 1gal of actual.(computed fuel used / actual fuel used) * your current K factor.
I used this to set mine up over several flights and now it's about 99% accurate.