calculate and update ratio