You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
6.9 KiB
198 lines
6.9 KiB
# coding=utf-8
|
|
import os
|
|
import django
|
|
import sys
|
|
import datetime
|
|
|
|
sys.path.append("/var/www/projects/codemy/")
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
|
|
django.setup()
|
|
|
|
from journals.models import CourseMap, LessonJ, TeacherJ, HomeworkTry
|
|
from lms.tools import show_progress
|
|
|
|
_NEED_OPEN = LessonJ.objects.get(material__id='1154', student__email='parabellum07@gmail.com'.lower())
|
|
|
|
_TEACHERJ_FILTER = {'progress__gte': 0}
|
|
_TEACHERJ_EXCLUDE = {'teacher': None}
|
|
|
|
_READL_FILTER = {'f_date': None}
|
|
_READL_EXCLUDE = {'date': None}
|
|
|
|
_SUCCESSL_FILTER = {'success': True}
|
|
_SUCCESSL_EXCLUDE = {'date': None}
|
|
|
|
|
|
def get_all_journals():
|
|
return TeacherJ.objects.filter(**_TEACHERJ_FILTER).exclude(**_TEACHERJ_EXCLUDE).order_by('id')
|
|
|
|
|
|
def get_all_journals_count():
|
|
return TeacherJ.objects.filter(**_TEACHERJ_FILTER).exclude(**_TEACHERJ_EXCLUDE).count()
|
|
|
|
|
|
def get_last_lessons(__journal):
|
|
# Получить последний читаемый уроки и выполненный
|
|
_READL_FILTER['student'] = __journal.student
|
|
_READL_FILTER['material__course'] = __journal.course
|
|
_SUCCESSL_FILTER['student'] = __journal.student
|
|
_SUCCESSL_FILTER['material__course'] = __journal.course
|
|
return (LessonJ.objects.filter(**_READL_FILTER).exclude(**_READL_EXCLUDE).order_by('id').last(),
|
|
LessonJ.objects.filter(**_SUCCESSL_FILTER).exclude(**_SUCCESSL_EXCLUDE).order_by('id').last())
|
|
|
|
|
|
def open_lesson_befor_this(_lessonJ):
|
|
# Погружается объект последнего журнала урока
|
|
# Получаем все уроки этого журнала
|
|
_map = CourseMap.objects.get(lesson=_lessonJ.material)
|
|
for i in CourseMap.objects.filter(course=_map.course).exclude(lesson=None):
|
|
if i.sort < _map.sort:
|
|
try:
|
|
_j = LessonJ.objects.get(
|
|
material__token=i.token,
|
|
student=_lessonJ.student,
|
|
material__course=i.course
|
|
)
|
|
except LessonJ.DoesNotExist as e:
|
|
print(e)
|
|
else:
|
|
check_to_success(_j)
|
|
|
|
|
|
def check_to_access(_journal):
|
|
# Проверка материала на доступ в прохождению
|
|
_journal.open_material()
|
|
|
|
|
|
def check_to_success(_journal):
|
|
# Проверка материала на завершенность
|
|
_journal.saw_this()
|
|
|
|
|
|
def check_lesson_after_hw(__journal, _target):
|
|
# Проверить - доступны ли уроки до ДЗ со статусом success
|
|
# Проверить - доступны ли видео до ДЗ не блокированного или пройденного
|
|
_last = HomeworkTry.objects.filter(
|
|
student=__journal.student,
|
|
material__course=__journal.course
|
|
).order_by('id').last()
|
|
# Если стутс - success
|
|
_candidate = None
|
|
if _last:
|
|
try:
|
|
_candidate = CourseMap.objects.get(
|
|
sort=int(CourseMap.objects.get(token=_last.material.token).sort)+1,
|
|
course=__journal.course
|
|
)
|
|
except CourseMap.DoesNotExist:
|
|
print('Ошибка получения карты журнала')
|
|
|
|
else:
|
|
# Проверить - доступен ли журнал для чтения
|
|
if _candidate.lesson:
|
|
__candidate = LessonJ.objects.get(
|
|
material__token=_candidate.token,
|
|
student=_target.student,
|
|
material__course=__journal.course
|
|
)
|
|
check_to_access(__candidate)
|
|
|
|
if _candidate and _candidate.lesson and \
|
|
int(CourseMap.objects.get(
|
|
token=_target.material.token,
|
|
course=__journal.course).sort) \
|
|
< int(_candidate.sort):
|
|
|
|
_target = LessonJ.objects.get(
|
|
material__token=_candidate.token,
|
|
student=_target.student,
|
|
material__course=__journal.course)
|
|
print('Цель изменена: %s' % _target.material.title)
|
|
|
|
return _target
|
|
|
|
|
|
def main():
|
|
start = datetime.datetime.now()
|
|
_ERRORS = set()
|
|
_WARNING = set()
|
|
#for i in open('error.log'):
|
|
# _ERRORS.add(i.strip())
|
|
_GOOD = 0
|
|
_now = 0
|
|
big = []
|
|
if _NEED_OPEN:
|
|
open_lesson_befor_this(_NEED_OPEN)
|
|
|
|
else:
|
|
if not _ERRORS:
|
|
_journals = get_all_journals()
|
|
_jcount = get_all_journals_count()
|
|
print('Количество журналов на проверку: %s' % _jcount)
|
|
else:
|
|
_journals = list([i for i in TeacherJ.objects.filter(student__email__in=_ERRORS)])
|
|
_jcount = len(_journals)
|
|
print('Журналы с ошибками: %s' % _jcount)
|
|
|
|
for __journal in _journals:
|
|
_start = datetime.datetime.now()
|
|
show_progress(_jcount, _now)
|
|
print('\nЖурнал: %s' % __journal.student.email)
|
|
try:
|
|
read, success = get_last_lessons(__journal)
|
|
|
|
except Exception as e:
|
|
print('!!! Ошибка обработки')
|
|
print(e)
|
|
if __journal.course.id == 20:
|
|
_WARNING.add(__journal.student.email)
|
|
_ERROR_MAILS = open('error.log', 'a+')
|
|
_ERROR_MAILS.write('%s\n' % __journal.student.email)
|
|
_ERROR_MAILS.close()
|
|
|
|
else:
|
|
print('%s // %s' % (read.material.title if read else ' - ', success.material.title if success else ' - '))
|
|
|
|
if not success and read:
|
|
_target = read
|
|
|
|
elif read and (int(CourseMap.objects.get(lesson=read.material).sort) > int(CourseMap.objects.get(lesson=success.material).sort)):
|
|
_target = read
|
|
|
|
elif success:
|
|
_target = success
|
|
|
|
else:
|
|
_target = None
|
|
|
|
if _target:
|
|
open_lesson_befor_this(check_lesson_after_hw(__journal, _target))
|
|
|
|
_GOOD += 1
|
|
|
|
_now += 1
|
|
_finish = datetime.datetime.now()
|
|
_time_result = (_finish - _start).seconds
|
|
print('\nTIME: %s seconds' % _time_result)
|
|
if int(_time_result) > 1:
|
|
big.append(__journal.student.email)
|
|
print('Добавлено на проверку')
|
|
|
|
print('===========\n')
|
|
|
|
finish = datetime.datetime.now()
|
|
print('\nTIME: %s seconds' % (finish - start).seconds)
|
|
print('Нужно обратить внимание:')
|
|
for i in _WARNING:
|
|
print(i)
|
|
#print('Самые длительные записи:')
|
|
#print(big)
|
|
if _ERRORS:
|
|
if _GOOD == _now:
|
|
print('Все ошибки исправлены')
|
|
else:
|
|
print('Количество ошибок: %s' % int(_now - _GOOD))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|