diff --git a/app/db/db_types.py b/app/db/db_types.py index eeeb26d9..f3c6ef2b 100644 --- a/app/db/db_types.py +++ b/app/db/db_types.py @@ -1,7 +1,7 @@ from bson import ObjectId from flask_login import UserMixin -from main.check_packs import BASE_PACKS, BaseCriterionPack, DEFAULT_TYPE_INFO, DEFAULT_REPORT_TYPE_INFO +from main.check_packs import BASE_PACKS, BaseCriterionPack, DEFAULT_TYPE_INFO, DEFAULT_REPORT_TYPE_INFO, POINT_LEVELS class Packable: def __init__(self, dictionary): @@ -104,6 +104,7 @@ def __init__(self, dictionary=None): self.is_failed = dictionary.get('is_failed', None) self.is_ended = dictionary.get('is_ended', True) self.is_passed = dictionary.get('is_passed', int(self.score) == 1) + self.point_levels = self.get_point_levels() def calc_score(self): # check after implementation criterion pack @@ -145,3 +146,13 @@ def none_to_false(x): is_ended = none_to_true(self.is_ended) # None for old checks => True, True->True, False->False is_failed = none_to_false(self.is_failed) # None for old checks => False, True->True, False->False return {'is_ended': is_ended, 'is_failed': is_failed} + + def get_point_levels(self): + try: + for key in POINT_LEVELS: + value = POINT_LEVELS[key] + if value[0] < self.score < value[1]: + point_levels = key + return point_levels + except TypeError: + return None diff --git a/app/main/check_packs/__init__.py b/app/main/check_packs/__init__.py index aa36041f..77d96fb8 100644 --- a/app/main/check_packs/__init__.py +++ b/app/main/check_packs/__init__.py @@ -1,4 +1,4 @@ from .base_criterion_pack import BaseCriterionPack from .pack_config import BASE_PACKS, DEFAULT_TYPE, DEFAULT_TYPE_INFO, DEFAULT_PRES_TYPE_INFO, DEFAULT_REPORT_TYPE_INFO, \ - REPORT_TYPES, BASE_PRES_CRITERION, BASE_REPORT_CRITERION + REPORT_TYPES, POINT_LEVELS, BASE_PRES_CRITERION, BASE_REPORT_CRITERION from .utils import init_criterions diff --git a/app/main/check_packs/base_criterion_pack.py b/app/main/check_packs/base_criterion_pack.py index c478fd6b..b15bfbaa 100644 --- a/app/main/check_packs/base_criterion_pack.py +++ b/app/main/check_packs/base_criterion_pack.py @@ -8,12 +8,13 @@ class BaseCriterionPack: - def __init__(self, raw_criterions, file_type, min_score=1.0, name=None, **kwargs): + def __init__(self, raw_criterions, file_type, point_levels, min_score=1, name=None, **kwargs): self.file_type = file_type self.name = name if name else self.__class__.__name__ self.raw_criterions = raw_criterions self.criterions = [] self.min_score = min_score # min score to pass + self.point_levels = point_levels def init(self, file_info): # create criterion objects, ignore errors - validation was performed earlier @@ -50,7 +51,8 @@ def to_json(self): 'name': self.name, 'raw_criterions': self.raw_criterions, 'file_type': self.file_type, - 'min_score': self.min_score + 'min_score': self.min_score, + 'point_levels': self.point_levels, } @staticmethod diff --git a/app/main/check_packs/pack_config.py b/app/main/check_packs/pack_config.py index 598c3cc2..9258f5c3 100644 --- a/app/main/check_packs/pack_config.py +++ b/app/main/check_packs/pack_config.py @@ -50,10 +50,16 @@ DEFAULT_REPORT_TYPE_INFO = {'type': 'report', 'report_type': REPORT_TYPES[1]} DEFAULT_PRES_TYPE_INFO = {'type': 'pres'} DEFAULT_TYPE_INFO = DEFAULT_PRES_TYPE_INFO +POINT_LEVELS = {"message1": [0.4, 0.6], + 'Message2': [0.6, 0.7], + 'Вы набрали необходимый минимум для дальнейшего допуска на защиту ВКР с оценкой "Допущен с рекомендацией значительно снизить оценку". Однако, мы рекомендуем вам продолжить исправления презентации для получения максимального балла. Это повысит ваш допуск до уровня "Допущен".': [0.7, 0.8], + 'Вы набрали необходимый минимум для дальнейшего допуска на защиту ВКР с оценкой "Допущен с рекомендацией снизить оценку". Однако, мы рекомендуем вам продолжить исправления презентации для получения максимального балла. Это повысит ваш допуск до уровня "Допущен".': [0.8, 0.998], + 'Уровень Вашего допуска "Допущен"': [0.999, 1.01] +} BASE_PACKS = { - 'pres': BaseCriterionPack(BASE_PRES_CRITERION, DEFAULT_PRES_TYPE_INFO, min_score=1.0, + 'pres': BaseCriterionPack(BASE_PRES_CRITERION, DEFAULT_PRES_TYPE_INFO, point_levels=POINT_LEVELS, min_score=1.0, name="BasePresentationCriterionPack"), - 'report': BaseCriterionPack(BASE_REPORT_CRITERION, DEFAULT_REPORT_TYPE_INFO, min_score=1.0, + 'report': BaseCriterionPack(BASE_REPORT_CRITERION, DEFAULT_REPORT_TYPE_INFO, point_levels=POINT_LEVELS, min_score=1.0, name="BaseReportCriterionPack") } diff --git a/app/servants/pre_luncher.py b/app/servants/pre_luncher.py index 9e1b3331..ef4148d3 100644 --- a/app/servants/pre_luncher.py +++ b/app/servants/pre_luncher.py @@ -2,7 +2,7 @@ import logging from db.db_methods import add_user, get_user, get_client, edit_user, save_criteria_pack -from main.check_packs.pack_config import BASE_PACKS, DEFAULT_REPORT_TYPE_INFO +from main.check_packs.pack_config import BASE_PACKS, DEFAULT_REPORT_TYPE_INFO, DEFAULT_PRES_TYPE_INFO from pymongo.errors import ConnectionFailure from server import ALLOWED_EXTENSIONS @@ -36,8 +36,10 @@ def init(app, debug): user.is_admin = True edit_user(user) - user.file_type = DEFAULT_REPORT_TYPE_INFO - file_type = DEFAULT_REPORT_TYPE_INFO['type'] + # user.file_type = DEFAULT_REPORT_TYPE_INFO + user.file_type = DEFAULT_PRES_TYPE_INFO + # file_type = DEFAULT_REPORT_TYPE_INFO['type'] + file_type = DEFAULT_PRES_TYPE_INFO['type'] user.criteria = BASE_PACKS[file_type].name user.formats = list(ALLOWED_EXTENSIONS.get(file_type)) user.two_files = True diff --git a/app/server.py b/app/server.py index 9cb6ea69..8d3e2940 100644 --- a/app/server.py +++ b/app/server.py @@ -362,6 +362,7 @@ def criteria_pack(name): if not pack: abort(404) pack['raw_criterions'] = json.dumps(pack['raw_criterions'], indent=4, ensure_ascii=False) + pack['point_levels'] = json.dumps(pack['point_levels'], indent=4, ensure_ascii=False) return render_template('./criteria_pack.html', pack=pack, name=current_user.name, navi_upload=True) @@ -377,6 +378,7 @@ def api_criteria_pack(): file_type = form_data.get('file_type') report_type = form_data.get('report_type') min_score = float(form_data.get('min_score', '1')) + point_levels = form_data.get('point_levels') # weak validation try: raw_criterions = json.loads(raw_criterions) @@ -387,6 +389,7 @@ def api_criteria_pack(): raw_criterions = raw_criterions if type(raw_criterions) is list else None file_type = file_type if file_type in BASE_PACKS.keys() else None min_score = min_score if min_score and (0 <= min_score <= 1) else None + point_levels = json.loads(point_levels) if point_levels else None if not (raw_criterions and file_type and min_score): msg = f"Конфигурация набора критериев должна содержать список критериев (непустой список в формате JSON)," \ f"тип файла (один из {list(BASE_PACKS.keys())})," \ @@ -407,7 +410,8 @@ def api_criteria_pack(): 'name': pack_name, 'raw_criterions': raw_criterions, 'file_type': file_type_info, - 'min_score': min_score + 'min_score': min_score, + 'point_levels': point_levels }) return {'data': f"Набор '{pack_name}' сохранен", 'time': datetime.now()}, 200 diff --git a/app/templates/criteria_pack.html b/app/templates/criteria_pack.html index e923e565..f6b5dbab 100644 --- a/app/templates/criteria_pack.html +++ b/app/templates/criteria_pack.html @@ -4,7 +4,7 @@ {% if not (pack is defined) %} {% set pack = {'name': '', 'file_type': 'report', 'min_score': '1', - 'raw_criterions': "[[\"criterion_name\", \"criterion_params_as_dict\"]]"} %} + 'raw_criterions': "[[\"criterion_name\", \"criterion_params_as_dict\"]]", 'point_levels': ""} %} {% endif %} {% block main %}
{% include "header.html" %}
@@ -45,14 +45,24 @@ required>