Filled in functions in calculate.py

This is a very crappy, way too large commit that should have been broken
up into several smaller commits but in this case I cba.