Cross-Platform Script to Find % of AVW (With a GUI too)

in Gridcoin (GRC)3 years ago

In Short

There's a new Python script that can run on almost any machine to find the % of AVW of most v2 polls. It has a simple GUI with it too

If you want to run it, read the setup section of the README. There are .exe files available for Windows and executables for Linux to make this easier to run

Let me know if you run into any issues with the program

Background

Active Vote Weight (AVW) is an estimate of what amount of vote weight would come from users active on the network if they all voted.

For a poll to be validated, it must get a certain % of AVW to have voted on that poll. For whitelist polls that's 40%, for others it's less. If a poll fails to reach the required number, its results don't matter and its as if it never happened. See the voting wiki page for more information.

More Context

Earlier, I had written a bash script to find the % of AVW of polls, but this was limited to Linux users and only had a command-line interface (no GUI) It was also not very efficient among other problems.

This new version has both a GUI and a command line version, can run on almost every OS, is more efficient, and I was able to bundle the Python interpreter and all for Windows and Linux which makes it easier to use

Things I Learned (or Relearned)

There's more overhead than I thought from running bash commands and using gridcoinresearchd. The python version of this ran much faster even before I tried doing any optimizations

Reusing old code makes you realize how bad your old code was and make you spend more time than you'd like to cleaning it up. (I may have taken some old Python code for RPC calls, perhaps)

Don't forget about binary searches. I spent some time trying to make the algorithm to find the end block of a poll more efficient than the naive approach I was using. I tried using more complicated things with block timing, but a simple binary search beat out all of them. I went from 100s of RPC call average case to closer to 23 at the worst case (as of right now - it depends on the blockchain height)

There's a really nice library for Python called Gooey which makes it much easier to build GUIs without really having to do much. It is basically a wrapper over a command line interface and helped make this program more user friendly. I am going to be using this a lot in the future

Packaging things with Pyinstaller is both simple, but deceptively not simple in some ways. There were various packaging and dependency problems I didn't anticipate and one that I wasn't able to fix with MacOS (sorry MacOS users).

Some Thanks

Thanks to sweede and Greger for helping me test the program and test some of the packaging with Pyinstaller

Screenshots of the GUI Version

Screenshot of the GUI program at startup

Screenshot of the GUI program after completing