Move the calculation of input/output weights into commonlib

See https://bugs.launchpad.net/oq-engine/+bug/1370380 and the companion https://github.com/gem/oq-commonlib/pull/65.
The tests are running here: https://ci.openquake.org/job/zdevel_oq-engine/821