70 lines
1.7 KiB
Python
70 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
|
|
|
|
"""
|
|
df = eval_df.copy()
|
|
for c in ["Bareme", "Mark", "Mark_barem"]:
|
|
try:
|
|
df[c+"_old"]
|
|
except KeyError:
|
|
df[c+"_old"] = df[c]
|
|
|
|
df["Bareme"] = new_scale
|
|
|
|
TRANFS = {"min": new_scale_min,
|
|
"prop": new_scale_proportionnal,
|
|
}
|
|
try:
|
|
t = TRANFS[method]
|
|
except KeyError:
|
|
df["Mark"] = df.apply(method)
|
|
else:
|
|
df["Mark"] = df.apply(t, axis=1)
|
|
|
|
df["Mark_barem"] = compute_mark_barem(df)
|
|
return df
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------
|
|
# Reglages pour 'vim'
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
# cursor: 16 del
|