mirror of
https://github.com/Faridik/Carolyn.git
synced 2026-07-08 13:21:53 +00:00
Добавил комментарии к домашкам
This commit is contained in:
parent
aa474abeaa
commit
93b313690e
@ -26,6 +26,8 @@ ASSIGNMENT_SUBJECT = 3
|
|||||||
ASSIGNMENT_WEIGHTS = 4
|
ASSIGNMENT_WEIGHTS = 4
|
||||||
ASSIGNMENT_RANGES = 5
|
ASSIGNMENT_RANGES = 5
|
||||||
ASSIGNMENT_ALLOWS = 6
|
ASSIGNMENT_ALLOWS = 6
|
||||||
|
ASSIGNMENT_HOW_TO_DISPLAY = 7
|
||||||
|
ASSIGNMENT_NOTES_RANGES = 8
|
||||||
TOKEN_FILE = pathlib.Path() / ".secrets" / "token.json"
|
TOKEN_FILE = pathlib.Path() / ".secrets" / "token.json"
|
||||||
CLIENT_SECRET_FILE = pathlib.Path() / ".secrets" / "client_secret.json"
|
CLIENT_SECRET_FILE = pathlib.Path() / ".secrets" / "client_secret.json"
|
||||||
|
|
||||||
@ -211,14 +213,24 @@ class Manager:
|
|||||||
|
|
||||||
f = lambda row: student.group_id == row[GROUP_IDS] # TODO add subject
|
f = lambda row: student.group_id == row[GROUP_IDS] # TODO add subject
|
||||||
for row in filter(f, values):
|
for row in filter(f, values):
|
||||||
assignment_value = self.get_values(row[ASSIGNMENT_RANGES])
|
assignment_values = self.get_values(row[ASSIGNMENT_RANGES])
|
||||||
toFloat = lambda x: float(x.replace(",", "."))
|
toFloat = lambda x: float(x.replace(",", "."))
|
||||||
ass_values = list(map(toFloat, assignment_value[student.number]))
|
assignment_value = list(map(toFloat, assignment_values[student.number-1]))
|
||||||
|
notes_range, n_row = row[ASSIGNMENT_NOTES_RANGES].split(',')
|
||||||
|
note = self.get_values(notes_range)[student.number-1][int(n_row)]
|
||||||
|
if note == '-':
|
||||||
|
note = "Замечаний по работе нет."
|
||||||
|
else:
|
||||||
|
note = f"Замечания:\n {note}"
|
||||||
student.add_assignment(
|
student.add_assignment(
|
||||||
Assignment(
|
Assignment(
|
||||||
row[ASSIGNMENT_NAMES], ass_values,
|
name=row[ASSIGNMENT_NAMES],
|
||||||
toFloat(row[ASSIGNMENT_WEIGHTS]),
|
points=assignment_value,
|
||||||
row[ASSIGNMENT_SUBJECT]
|
weight=toFloat(row[ASSIGNMENT_WEIGHTS]),
|
||||||
|
subject=row[ASSIGNMENT_SUBJECT],
|
||||||
|
allow_to_display=bool(int(row[ASSIGNMENT_ALLOWS])),
|
||||||
|
how_to_display=row[ASSIGNMENT_HOW_TO_DISPLAY],
|
||||||
|
notes=note
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,20 @@
|
|||||||
|
from logging import addLevelName
|
||||||
|
|
||||||
|
|
||||||
class Assignment(dict):
|
class Assignment(dict):
|
||||||
"""Задание."""
|
"""Задание."""
|
||||||
|
|
||||||
def __init__(self, name: str, points: list, weight: float = 1, subject: str = None):
|
def __init__(self, name: str, points: list, weight: float = 1,
|
||||||
|
subject: str = None, allow_to_display: bool = False,
|
||||||
|
how_to_display: str = 'z,1,1',
|
||||||
|
notes: str = 'Замечаний по работе нет.'):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.subject = subject
|
self.subject = subject
|
||||||
self.weight = weight
|
self.weight = weight
|
||||||
self.points = points
|
self.points = points
|
||||||
|
self.allow_to_display = allow_to_display
|
||||||
|
self.how_to_display = how_to_display
|
||||||
|
self.notes = notes
|
||||||
dict.__init__(
|
dict.__init__(
|
||||||
self,
|
self,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
@ -13,6 +22,9 @@ class Assignment(dict):
|
|||||||
weight=self.weight,
|
weight=self.weight,
|
||||||
points=self.points,
|
points=self.points,
|
||||||
total=self.total,
|
total=self.total,
|
||||||
|
allow_to_display=self.allow_to_display,
|
||||||
|
how_to_display=self.how_to_display,
|
||||||
|
notes=self.notes,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@ -95,15 +95,17 @@ def grades(update: Update, context: CallbackContext):
|
|||||||
context.user_data["subjects"] = subjects
|
context.user_data["subjects"] = subjects
|
||||||
context.user_data["all_assignments"] = assignments
|
context.user_data["all_assignments"] = assignments
|
||||||
reply_markup = build_menu_of_subjects(subjects)
|
reply_markup = build_menu_of_subjects(subjects)
|
||||||
update.message.reply_text(
|
msg = update.message.reply_text(
|
||||||
text=MESSAGES.Assignments.SELECT_COURSE, reply_markup=reply_markup
|
text=MESSAGES.Assignments.SELECT_COURSE, reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
context.user_data["assignments"] = assignments
|
context.user_data["assignments"] = assignments
|
||||||
reply_markup = build_menu_of_assignments(assignments)
|
reply_markup = build_menu_of_assignments(assignments)
|
||||||
update.message.reply_text(
|
msg = update.message.reply_text(
|
||||||
text=MESSAGES.Assignments.SELECT_ASSNT, reply_markup=reply_markup
|
text=MESSAGES.Assignments.SELECT_ASSNT, reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
|
||||||
|
context.user_data["msg"] = msg
|
||||||
return_value = GRADES_CALLBACK
|
return_value = GRADES_CALLBACK
|
||||||
|
|
||||||
except:
|
except:
|
||||||
@ -125,9 +127,10 @@ def callback(update: Update, context: CallbackContext):
|
|||||||
if "$back$" in call:
|
if "$back$" in call:
|
||||||
subjects = context.user_data["subjects"]
|
subjects = context.user_data["subjects"]
|
||||||
reply_markup = build_menu_of_subjects(subjects)
|
reply_markup = build_menu_of_subjects(subjects)
|
||||||
update.callback_query.message.edit_text(
|
msg = update.callback_query.message.edit_text(
|
||||||
text=MESSAGES.Assignments.SELECT_COURSE, reply_markup=reply_markup
|
text=MESSAGES.Assignments.SELECT_COURSE, reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
context.user_data["msg"] = msg
|
||||||
return GRADES_CALLBACK
|
return GRADES_CALLBACK
|
||||||
|
|
||||||
assignments = context.user_data["assignments"]
|
assignments = context.user_data["assignments"]
|
||||||
@ -139,13 +142,15 @@ def callback(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
f = lambda ass: ass["name"] == name and ass["subject"] == subject
|
f = lambda ass: ass["name"] == name and ass["subject"] == subject
|
||||||
assignment = next(filter(f, assignments))
|
assignment = next(filter(f, assignments))
|
||||||
update.callback_query.message.edit_text(
|
msg = update.callback_query.message.edit_text(
|
||||||
text=MESSAGES.Assignments.get(assignment['name'],
|
text=MESSAGES.Assignments.get(assignment['name'],
|
||||||
assignment['points'],
|
assignment['points'],
|
||||||
assignment['how_to_display']),
|
assignment['how_to_display'],
|
||||||
|
assignment['notes']),
|
||||||
parse_mode=ParseMode.HTML,
|
parse_mode=ParseMode.HTML,
|
||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
context.user_data["msg"] = msg
|
||||||
|
|
||||||
# Нажатие кнопок при выборе дисциплины
|
# Нажатие кнопок при выборе дисциплины
|
||||||
if call.startswith("subject#"):
|
if call.startswith("subject#"):
|
||||||
@ -158,9 +163,10 @@ def callback(update: Update, context: CallbackContext):
|
|||||||
context.user_data["has_back_button"] = True
|
context.user_data["has_back_button"] = True
|
||||||
|
|
||||||
reply_markup = build_menu_of_assignments(assignments, has_back_button=True)
|
reply_markup = build_menu_of_assignments(assignments, has_back_button=True)
|
||||||
update.callback_query.message.edit_text(
|
msg = update.callback_query.message.edit_text(
|
||||||
MESSAGES.Assignments.SELECT_ASSNT, reply_markup=reply_markup
|
MESSAGES.Assignments.SELECT_ASSNT, reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
context.user_data["msg"] = msg
|
||||||
|
|
||||||
if call.startswith("cancel#"):
|
if call.startswith("cancel#"):
|
||||||
update.callback_query.message.edit_text(
|
update.callback_query.message.edit_text(
|
||||||
@ -171,21 +177,19 @@ def callback(update: Update, context: CallbackContext):
|
|||||||
return GRADES_CALLBACK
|
return GRADES_CALLBACK
|
||||||
|
|
||||||
def timeout(update: Update, context: CallbackContext):
|
def timeout(update: Update, context: CallbackContext):
|
||||||
update.callback_query.message.edit_text(
|
msg = context.user_data["msg"]
|
||||||
|
msg.edit_text(
|
||||||
MESSAGES.Assignments.TIMEOUT,
|
MESSAGES.Assignments.TIMEOUT,
|
||||||
)
|
)
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
|
||||||
def grades_end(update: Update, context: CallbackContext):
|
def grades_end(update: Update, context: CallbackContext):
|
||||||
update.message.edit_text(
|
msg = context.user_data["msg"]
|
||||||
MESSAGES.Assignments.TIMEOUT,
|
msg.edit_text(
|
||||||
)
|
|
||||||
update.message.reply_text(
|
|
||||||
MESSAGES.Assignments.END
|
MESSAGES.Assignments.END
|
||||||
)
|
)
|
||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
|
||||||
|
|
||||||
def broadcast(update: Update, context: CallbackContext):
|
def broadcast(update: Update, context: CallbackContext):
|
||||||
"""Команда: разослать студентам."""
|
"""Команда: разослать студентам."""
|
||||||
access_message = update.message.reply_text("🔐 Проверка доступа...")
|
access_message = update.message.reply_text("🔐 Проверка доступа...")
|
||||||
@ -270,12 +274,12 @@ def main() -> None:
|
|||||||
ConversationHandler.TIMEOUT: [
|
ConversationHandler.TIMEOUT: [
|
||||||
MessageHandler(Filters.text | Filters.command, timeout)
|
MessageHandler(Filters.text | Filters.command, timeout)
|
||||||
],
|
],
|
||||||
# ConversationHandler.END: [
|
ConversationHandler.END: [
|
||||||
# MessageHandler(Filters.text | Filters.command, grades_end)
|
MessageHandler(Filters.text | Filters.command, grades_end)
|
||||||
# ]
|
]
|
||||||
},
|
},
|
||||||
fallbacks=[CommandHandler("cancel", cancel)],
|
fallbacks=[CommandHandler("cancel", cancel)],
|
||||||
conversation_timeout=10,
|
#conversation_timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
broadcast_handler = ConversationHandler(
|
broadcast_handler = ConversationHandler(
|
||||||
|
|||||||
@ -25,13 +25,26 @@ class Messages:
|
|||||||
START = "👀 Посмотрим (~3с) ..."
|
START = "👀 Посмотрим (~3с) ..."
|
||||||
SELECT_COURSE = "👇 Выбери дисциплину"
|
SELECT_COURSE = "👇 Выбери дисциплину"
|
||||||
SELECT_ASSNT = "👇 Выбери работу"
|
SELECT_ASSNT = "👇 Выбери работу"
|
||||||
|
END = "😉 Всего наилучшего"
|
||||||
|
TIMEOUT = "🕛 Время запроса вышло"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(grade, score, n_of_assignments):
|
def get(name: str, assignment: list, how_to_display: str, notes: str):
|
||||||
summary = (
|
is_float, n_cols, n_rows = how_to_display.split(',')
|
||||||
f"Ранг: <b>{score:.2f}</b> {n_of_assignments} зад.\n"
|
n_cols, n_rows = int(n_cols), int(n_rows)
|
||||||
+ f"Оценка: <b>{grade:.2f}</b>"
|
summary = f'<b>{name}</b>:\n'
|
||||||
)
|
if is_float == 'z':
|
||||||
|
d = {0 : '❎', 1 : '✅'}
|
||||||
|
for item in range(0, len(assignment), n_cols):
|
||||||
|
summary += ''.join(list(map(d.get,
|
||||||
|
assignment[item : item + n_cols]))) + '\n'
|
||||||
|
elif is_float == 'r':
|
||||||
|
to_str = lambda x: f'{x:.2f}'
|
||||||
|
for item in range(0, len(assignment), n_cols):
|
||||||
|
summary += ' '.join(list(map(to_str,
|
||||||
|
assignment[item: item + n_cols]))) + '\n'
|
||||||
|
summary += f'Σ: {to_str(sum(assignment))}\n'
|
||||||
|
summary += f"\n{notes}"
|
||||||
return summary
|
return summary
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -20,6 +20,8 @@ def build_menu_of_assignments(
|
|||||||
) -> InlineKeyboardMarkup:
|
) -> InlineKeyboardMarkup:
|
||||||
button_list = []
|
button_list = []
|
||||||
for assignment in assignments:
|
for assignment in assignments:
|
||||||
|
if not assignment['allow_to_display']:
|
||||||
|
continue
|
||||||
if pressed_name and assignment["name"] == pressed_name:
|
if pressed_name and assignment["name"] == pressed_name:
|
||||||
title = f'💁♀️ {assignment["name"]}'
|
title = f'💁♀️ {assignment["name"]}'
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user