import click


def _cb_agreement(ctx, param, value):

    """
    Click callback to convert agreement to a float if necessary.
    Also does validation.
    """

    if value.lower() == 'mean':
        return 'mean'
    else:
        try:
            value = float(value)
            if 0 <= value <= 1:
                return value
            else:
                raise click.BadParameter("Float values must be >= 0 and <= 1.")
        except ValueError:
            raise click.BadParameter("Must be 'mean' or a float.")