Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

451 message about point #457

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

функция иногда возвращает None не лучше ли поднимать исключение?

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
19 changes: 17 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,25 @@
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": '''
Вы набрали необходимый минимум для дальнейшего допуска на защиту ВКР с оценкой "Допущен с рекомендацией значительно снизить оценку".\n
Однако, мы рекомендуем вам продолжить исправления презентации для получения максимального балла. Это повысит ваш допуск до уровня "Допущен".
''',
"0.929": '''
Вы набрали необходимый минимум для дальнейшего допуска на защиту ВКР с оценкой "Допущен с рекомендацией снизить оценку".\n
Однако, мы рекомендуем вам продолжить исправления презентации для получения максимального балла. Это повысит ваш допуск до уровня "Допущен".
''',
"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
9 changes: 8 additions & 1 deletion app/templates/results.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{# Accepts: header dependicies, results, id, filename #}


{% extends "root.html" %}

{% block title %}Результаты проверки{% endblock %}
Expand All @@ -19,6 +18,14 @@ <h3 id="results_title" class="texteous ins">
Результат проверки: {{ "" if results.correct() else "не" }} пройдена! <!-- threshold? -->
</h3>
{% endif %}
<div>
{% if results.point_levels %}
<h6 id="results_message" class="col text-left">
<b>{{ results.point_levels }}</b>
</h6>
<p>
{% endif %}
</div>
{% else %}
<h4 id="results_title" class="texteous ins">
<i>Производится проверка файла. Примерное время: {{ avg_process_time }} секунд (перезагрузите
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
18 changes: 17 additions & 1 deletion db_versioning/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,21 @@ def update_database(cls, collections, prev_version):
raise Exception(f'Неподдерживаемый переход с версии {prev_version}')


class Version41(Version):
VERSION_NAME = '4.1'
CHANGES = 'В коллекции criteria_pack и checks добавлен атрибут 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': {}}})
collections['checks'].update_many({}, {
'$set': {'point_levels': {}}})
else:
raise Exception(f'Неподдерживаемый переход с версии {prev_version}')


VERSIONS = {
'1.0': Version10,
'1.1': Version11,
Expand All @@ -296,8 +311,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())