more chnages
This commit is contained in:
@@ -25,6 +25,7 @@ from template_controller import build_schedule # noqa: E402
|
||||
from conflict_checker import check_all_conflicts # noqa: E402
|
||||
from conflict_checker.student_conflict_checker import format_student_conflicts # noqa: E402
|
||||
from conflict_checker.teacher_conflict_checker import format_teacher_conflicts # noqa: E402
|
||||
from template_logger import reset_log, log_error, log_info # noqa: E402
|
||||
|
||||
from batch_wise_template import generate_batch_wise_templates # noqa: E402
|
||||
from department_wise_template import generate_department_wise_templates # noqa: E402
|
||||
@@ -36,6 +37,8 @@ RESULT_DIR = os.path.join(ROOT_DIR, "result", "templates")
|
||||
|
||||
|
||||
def main():
|
||||
reset_log()
|
||||
|
||||
data_csv_marker = os.path.join(ROOT_DIR, "data", "dummy", "blocks", "rooms.csv")
|
||||
if not os.path.exists(data_csv_marker):
|
||||
print("Dummy data not found — generating it first...")
|
||||
@@ -48,19 +51,19 @@ def main():
|
||||
data, sessions = build_schedule()
|
||||
print(f"Scheduled {len(sessions)} sessions.\n")
|
||||
|
||||
print("Running conflict checks (student/batch and teacher)...")
|
||||
log_info("Running conflict checks (student/batch and teacher)...")
|
||||
report = check_all_conflicts(sessions)
|
||||
if report["has_conflicts"]:
|
||||
for line in format_student_conflicts(report["student_conflicts"]):
|
||||
print(f" STUDENT CONFLICT: {line}")
|
||||
log_error(f"STUDENT CONFLICT: {line}")
|
||||
for line in format_teacher_conflicts(report["teacher_conflicts"]):
|
||||
print(f" TEACHER CONFLICT: {line}")
|
||||
print(
|
||||
log_error(f"TEACHER CONFLICT: {line}")
|
||||
log_error(
|
||||
f"Found {len(report['student_conflicts'])} student conflict(s) and "
|
||||
f"{len(report['teacher_conflicts'])} teacher conflict(s).\n"
|
||||
f"{len(report['teacher_conflicts'])} teacher conflict(s)."
|
||||
)
|
||||
else:
|
||||
print("No conflicts found — schedule is clash-free for students and teachers.\n")
|
||||
log_info("No conflicts found — schedule is clash-free for students and teachers.")
|
||||
|
||||
generators = [
|
||||
("batch-wise", generate_batch_wise_templates),
|
||||
|
||||
48
app/template_logger.py
Normal file
48
app/template_logger.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Simple run-scoped logger for the template generator.
|
||||
|
||||
The log file under logs/ is erased and recreated at the start of every run
|
||||
(see reset_log()) so it only ever reflects the most recent generation.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import os
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
LOGS_DIR = os.path.join(ROOT_DIR, "logs")
|
||||
LOG_FILE = os.path.join(LOGS_DIR, "template_generator.log")
|
||||
|
||||
_log_path = None
|
||||
|
||||
|
||||
def reset_log():
|
||||
"""Erases any previous log and starts a fresh one for this run."""
|
||||
global _log_path
|
||||
os.makedirs(LOGS_DIR, exist_ok=True)
|
||||
_log_path = LOG_FILE
|
||||
with open(_log_path, "w", encoding="utf-8") as f:
|
||||
f.write(f"Timetable generation log - started {datetime.datetime.now().isoformat()}\n")
|
||||
f.write("=" * 80 + "\n")
|
||||
return _log_path
|
||||
|
||||
|
||||
def log_error(message):
|
||||
"""Appends an ERROR line to the current run's log file and prints it."""
|
||||
_write("ERROR", message)
|
||||
|
||||
|
||||
def log_warning(message):
|
||||
_write("WARNING", message)
|
||||
|
||||
|
||||
def log_info(message):
|
||||
_write("INFO", message)
|
||||
|
||||
|
||||
def _write(level, message):
|
||||
if _log_path is None:
|
||||
reset_log()
|
||||
line = f"[{datetime.datetime.now().strftime('%H:%M:%S')}] {level}: {message}"
|
||||
with open(_log_path, "a", encoding="utf-8") as f:
|
||||
f.write(line + "\n")
|
||||
print(line)
|
||||
Reference in New Issue
Block a user