69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
#! /usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# vim:fenc=utf-8
|
|
#
|
|
# Copyright © 2017 lafrite <lafrite@Poivre>
|
|
#
|
|
# Distributed under terms of the MIT license.
|
|
|
|
"""
|
|
Manipulating rating scale of an evaluation.
|
|
|
|
Those functions are made to be applied over eval_df
|
|
"""
|
|
|
|
from .df_marks_manip import round_half_point, compute_mark_barem
|
|
|
|
__all__ = []
|
|
|
|
def new_scale_min(x):
|
|
""" Change the scale by selecting min between scale and mark """
|
|
return min(x["Mark_old"], x["Bareme"])
|
|
|
|
def new_scale_proportionnal(x):
|
|
""" Changing the scale proportionally """
|
|
return round_half_point(x["Mark_old"] * x["Bareme"] / x["Bareme_old"])
|
|
|
|
def tranform_scale(eval_df, new_scale, method):
|
|
""" Change the rating scale of the exam
|
|
|
|
It backups Bareme, Mark, Mark_barem columns adding "_old". The backup is done once then it is ignored.
|
|
|
|
It changes Bareme value to new_scale, applies method to marks and remake mark_bareme
|
|
|
|
:param eval_df: dataframe on evaluations
|
|
:param new_scale: replacement scale value
|
|
:param method: "min", "prop" or a function on eval_df rows
|
|
:returns: the transformed eval_df
|
|
|
|
"""
|
|
for c in ["Bareme", "Mark", "Mark_barem"]:
|
|
try:
|
|
eval_df[c+"_old"]
|
|
except KeyError:
|
|
eval_df[c+"_old"] = eval_df[c]
|
|
|
|
eval_df["Bareme"] = new_scale
|
|
|
|
TRANFS = {"min": new_scale_min,
|
|
"prop": new_scale_proportionnal,
|
|
}
|
|
try:
|
|
t = TRANFS[method]
|
|
except KeyError:
|
|
eval_df["Mark"] = eval_df.apply(method)
|
|
else:
|
|
eval_df["Mark"] = eval_df.apply(t, axis=1)
|
|
|
|
eval_df["Mark_barem"] = compute_mark_barem(eval_df)
|
|
return eval_df
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------
|
|
# Reglages pour 'vim'
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
# cursor: 16 del
|