Skip to content

Commit

Permalink
add point_levels (change base)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinaProsche committed Jul 28, 2023
1 parent 4fd8174 commit 99df8c8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 15 deletions.
8 changes: 7 additions & 1 deletion app/db/db_types.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -145,3 +146,8 @@ 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):
if str(self.score) in POINT_LEVELS:
point_levels = POINT_LEVELS[str(self.score)]
return point_levels
2 changes: 1 addition & 1 deletion app/main/check_packs/__init__.py
Original file line number Diff line number Diff line change
@@ -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
REPORT_TYPES, POINT_LEVELS
from .utils import init_criterions
6 changes: 4 additions & 2 deletions app/main/check_packs/base_criterion_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,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
Expand Down Expand Up @@ -43,7 +44,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
Expand Down
9 changes: 7 additions & 2 deletions app/main/check_packs/pack_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@
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 = {"0.2": "Message1",
"0.5": "Message2",
"0.714": "Допущен с рекомендацией значительно снизить оценку",
"0.929": "Допущен с рекомендацией снизить оценку",
"0.357": "Допущен"}

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")
}
4 changes: 3 additions & 1 deletion app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,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)
Expand Down Expand Up @@ -409,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

Expand Down
17 changes: 10 additions & 7 deletions app/templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ <h3 id="results_title" class="texteous ins">
</h3>
{% endif %}
<div>
{% if results.score == 1 %}
<h6 id="results_message" class="col text-left">
Уровень вашего допуска: <b>"Допущен"</b>.
</h6>
{% endif %}
{% if 0.5 < results.score < 1 %}
{% if results.point_levels %}
{% if results.point_levels == "Допущен" %}
<h6 id="results_message" class="col text-left">
<br>
<br>
<br> Уровень вашего допуска: <b>"Допущен"</b>.
</h6>
{% else %}
<h6 id="results_message" class="col text-left">

This comment has been minimized.

Copy link
@zmm

zmm Jul 28, 2023

Contributor

Я бы в целом заменил весь блок h6 на вывод results.point_levels - то есть, пусть выводится в лоб сообщение соответствующего уровня баллов. Почему так - потому что задачи разные и навязывать им семантику допуска на защиту ВКР не нужно (они могут быть вообще из другой области)

Вы набрали необходимый минимум для дальнейшего допуска на защиту ВКР с оценкой
<b>"Допущен с рекомендацией снизить оценку"</b>.
<b>"{{ results.point_levels }}"</b>.
<br>Однако, мы рекомендуем вам продолжить исправления презентации для получения максимального балла.
Это повысит ваш допуск до уровня <b>"Допущен"</b>.
</h6>
{% endif %}
<p>
{% endif %}
</div>
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/criterion_pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pack_form.submit((e) => {
fd.append('report_type', $("#report_type").val());
fd.append('min_score', $("#min_score").val());
fd.append('raw_criterions', raw_criterions_str);
fd.append('point_levels', $("#point_levels").val());
fetch(`/api/criterion_pack`, {method: "POST", body: fd})
.then(response => {
if (response.status === 200) {
Expand Down
16 changes: 15 additions & 1 deletion db_versioning/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ def update_database(cls, collections, prev_version):
raise Exception(f'Неподдерживаемый переход с версии {prev_version}')


class Version41(Version):
VERSION_NAME = '4.1'
CHANGES = 'В коллекцию criteria_pack добавлен атрибут point_levels'

@classmethod
def update_database(cls, collections, prev_version):
if prev_version in (Version31.VERSION_NAME,):
collections['criteria_pack'].update_many({}, {
'$set': {'point_levels': {"0.2": "Message1", "0.5": "Message2", "0.7": "Message3", "0.929": "Допущен с рекомендацией снизить оценку", "1.0": "Допущен"}}})

This comment has been minimized.

Copy link
@zmm

zmm Jul 28, 2023

Contributor

я бы во все паки критериев не добавлял уже заполненный point_levels - каждому паку нужен свой. здесь лучше добавить пустое значение, а в коде описать как оно устроено.

else:
raise Exception(f'Неподдерживаемый переход с версии {prev_version}')


VERSIONS = {
'1.0': Version10,
'1.1': Version11,
Expand All @@ -296,8 +309,9 @@ def update_database(cls, collections, prev_version):
'2.2': Version22,
'3.0': Version30,
'3.1': Version31,
'4.1': Version41,
}
LAST_VERSION = '3.1'
LAST_VERSION = '4.1'

for _, ver in VERSIONS.items():
print(ver.to_dict())

0 comments on commit 99df8c8

Please sign in to comment.