Added rating calculation.

It doesn't get to the same result as the old java based version. Will look into that later.