import math


def measurement_reward(old_measurements, new_measurements):
    """Computes the reward based on action, old and new frame rate and bit rate.

    Parameters
    ----------
    old_measurements : dict
        A dictionary of the previous measurements
    new_measurements : dict
        A dictionary of the latest measurements

    Returns
    -------
    reward : float
        The computed measurement-based reward

    """
    reward = 0
    for metric in ['framerate_aggr', 'bitrate_aggr']:
        old_value, new_value = old_measurements[metric], new_measurements[metric]
        old_value = 0.001 if old_value == 0 else old_value
        reward += ((new_value - old_value) / old_value) * 100
    if reward == 0:
        return reward
    magnitude = int(math.log10(abs(reward)))
    if magnitude >= 1:
        reward /= math.pow(10, magnitude)
    return reward