def load_classes_and_courses(): with open(fn('course_codes_list.json')) as f: course_codes_list = json.load(f) with open(fn('classes_of_course.json')) as f: classes_of_course = json.load(f) return course_codes_list, classes_of_course
def peek(): if os.path.exists(fn(config.SCHEDULER_RESULT_FILE)): return SUCCESS pid = running_pid() if pid: try: process = psutil.Process(pid) if process.status() == psutil.STATUS_ZOMBIE: return ZOMBIE return RUNNING except psutil.NoSuchProcess: clear_running_file() if os.path.exists(fn(config.SCHEDULER_OUTPUT_FILE)): return FAILURE return CLEAN
def read_feedback(enc='utf-8'): global percent, last_line, line with open(fn(config.SCHEDULER_OUTPUT_FILE), encoding=enc) as h: for line in h: last_line = line if '+' in line: # Vinícius imprime um char para cada 2% de progresso percent = 2 * len(line.strip())
def clear_files(): files = [ config.SCHEDULER_RUNNING_FILE, config.SCHEDULER_OUTPUT_FILE, config.SCHEDULER_ERROR_FILE, config.SCHEDULER_RESULT_FILE ] for file in files: try: os.remove(fn(file)) except FileNotFoundError: pass
def xlsx2csvs(filename): wb = xlrd.open_workbook(filename) sheet_names = wb.sheet_names() csv_filenames = dict() for name in sheet_names: csv_basename = f'{name}.{time()}.csv' csv_filename = fn(csv_basename) csv_filenames[name] = csv_filename sh = wb.sheet_by_name(name) with open(csv_filename, 'w') as f: wr = csv.writer(f, delimiter=config.CSV_DELIMITER, quotechar=config.CSV_QUOTECHAR, quoting=csv.QUOTE_MINIMAL) for row_num in range(sh.nrows): wr.writerow(sh.row_values(row_num)) return csv_filenames
def get_progress(): if not os.path.exists(fn(config.SCHEDULER_OUTPUT_FILE)): return 0 def read_feedback(enc='utf-8'): last_line = '' with open(fn(config.SCHEDULER_OUTPUT_FILE), encoding=enc) as h: for line in h: last_line = line if '+' in line: # Vinícius imprime um char para cada 2% de progresso return 2 * len(line.strip()) return last_line try: return read_feedback() except UnicodeDecodeError: return read_feedback('latin1')
def clear_running_file(): try: os.remove(fn(config.SCHEDULER_RUNNING_FILE)) except IOError: pass
def get_logs_filenames(): return config.SCHEDULER_OUTPUT_FILE, fn(config.SCHEDULER_OUTPUT_FILE)
def get_result_filenames(): return config.SCHEDULER_RESULT_FILE, fn(config.SCHEDULER_RESULT_FILE)
def save_students(students_list): with open(fn('students_list.json'), 'w') as f: json.dump(students_list, f)
def save_parameters(param_list): with open(fn('param_list.json'), 'w') as f: json.dump(param_list, f)
def load_criteria(): with open(fn('criteria_list.json')) as f: criteria_list = json.load(f) return criteria_list
def save_criteria(criteria_list: list): with open(fn('criteria_list.json'), 'w') as f: json.dump(criteria_list, f)
def save_classes_and_courses(course_codes_list: list, classes_of_course: dict): with open(fn('course_codes_list.json'), 'w') as f: json.dump(course_codes_list, f) with open(fn('classes_of_course.json'), 'w') as f: json.dump(classes_of_course, f)
def load_students(): with open(fn('students_list.json')) as f: students_list = json.load(f) return students_list
def load_parameters(): with open(fn('param_list.json')) as f: param_list = json.load(f) return param_list
save_parameters, create_students_index, save_students assert len(sys.argv) == 3, 'execute.py <max_search> <default_parameter>' max_search = int(sys.argv[1]) default_parameter = int(sys.argv[2]) # DISCIPLINAS E TURMAS log('processando disciplinas e turmas...') classes_of_course, classes, criteria_list = get_courses_and_classes_data() course_codes_list = list(classes_of_course.keys()) save_classes_and_courses(course_codes_list, classes_of_course) save_criteria(criteria_list) criteria_expr2index, index2criteria_expr = create_criteria_indexes( criteria_list) with open(fn('disciplinas'), 'w') as f: for i, code in enumerate(course_codes_list): n = len(classes_of_course[code]) f.write(f'{i}:{n}\n') with open(fn('turmas'), 'w') as f: for i, code in enumerate(course_codes_list): for j, class_code in enumerate(classes_of_course[code]): k = criteria_expr2index[classes[class_code]['criteria']] carga = classes[class_code]['load'] vagas = classes[class_code]['vacancies'] encontros = parse_schedule(classes[class_code]['schedule']) ne = len(encontros) encontros_str = ','.join([str(encontro) for encontro in encontros]) f.write(f'{i}:{j}:{k},0;{carga};{vagas};{ne},{encontros_str}\n')