diff --git a/ai_prompt.txt b/ai_prompt.txt new file mode 100644 index 0000000..cb66e6d --- /dev/null +++ b/ai_prompt.txt @@ -0,0 +1,17 @@ + +## **Quick Version (If you just want the code):** + +```text +Build a Python system that: +1. Analyzes CSV files in `sample_data/` folder +2. Creates SQLite database (`school_schedule.db`) +3. Migrates CSV data to SQLite with cleaning +4. Provides query application for school scheduling + +Key queries needed: +- Find student location by time +- Show student/teacher schedules +- Check room availability +- Detect schedule conflicts + +Use: Python, sqlite3, pandas, DB Browser SQLite compatible. \ No newline at end of file diff --git a/scheduler_bots/__pycache__/database.cpython-314.pyc b/scheduler_bots/__pycache__/database.cpython-314.pyc index 92ce904..7b63e43 100644 Binary files a/scheduler_bots/__pycache__/database.cpython-314.pyc and b/scheduler_bots/__pycache__/database.cpython-314.pyc differ diff --git a/scheduler_bots/database.py b/scheduler_bots/database.py index 8fd8c50..56fffce 100644 --- a/scheduler_bots/database.py +++ b/scheduler_bots/database.py @@ -152,95 +152,89 @@ class SchoolScheduleDB: self.conn.commit() - def update_database_from_csv(self, auto_update=True): - """Automatically update database from specific CSV files in the sample_data directory""" - # Updated path to look in the parent directory - sample_data_dir = "../sample_data" + def update_database_from_csv(self, auto_update=False): + """Update the database from CSV files in the sample_data directory""" + # Define the sample_data directory path + sample_data_dir = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/Projects/sample_data" + # Check if the directory exists if not os.path.exists(sample_data_dir): - print(f"Directory '{sample_data_dir}' not found. Trying local directory...") - sample_data_dir = "sample_data" - if not os.path.exists(sample_data_dir): - print(f"Directory '{sample_data_dir}' not found.") - return - - # Get all CSV files and filter out the schedule template and sheet files - all_csv_files = [f for f in os.listdir(sample_data_dir) if f.endswith('.csv')] + print(f"Directory {sample_data_dir} does not exist.") + return - # Keep only the actual student distribution files (not the sheets) - csv_files = [] - for filename in all_csv_files: - if 'first_sheet' not in filename and 'last_sheet' not in filename and 'template' not in filename: - csv_files.append(filename) + # Find all CSV files in the sample_data directory + csv_files = [f for f in os.listdir(sample_data_dir) if f.lower().endswith('.csv')] if not csv_files: - print(f"No student data CSV files found in '{sample_data_dir}' directory.") + print(f"No CSV files found in {sample_data_dir}") return print(f"Found {len(csv_files)} student data CSV file(s):") - for i, filename in enumerate(csv_files, 1): - print(f" {i}. {filename}") + for i, file in enumerate(csv_files, 1): + print(f" {i}. {file}") if auto_update: print("\nAuto-updating database with all student data CSV files...") - files_to_update = csv_files + print("\nUpdating database with {} file(s):".format(len(csv_files))) + for file in csv_files: + print(f" - {file}") + csv_path = os.path.join(sample_data_dir, file) + self.process_csv_with_teacher_mapping(csv_path) else: - response = input("\nUpdate database with CSV files? (yes/no): ").lower() + print("\nChoose an option:") + print("1. Update all CSV files") + print("2. Select specific CSV files") + print("3. Cancel") - if response not in ['yes', 'y', 'да']: - print("Skipping database update.") - return + choice = input("Enter your choice (1-3): ").strip() - print(f"\n0. Update all files") - - try: - selection = input(f"\nSelect file(s) to update (0 for all, or comma-separated numbers like 1,2,3): ") + if choice == "1": + print("\nUpdating database with all CSV files...") + for file in csv_files: + print(f"Processing {file}...") + csv_path = os.path.join(sample_data_dir, file) + self.process_csv_with_teacher_mapping(csv_path) + elif choice == "2": + print("\nAvailable CSV files:") + for i, file in enumerate(csv_files, 1): + print(f" {i}. {file}") - if selection.strip() == '0': - # Update all files - files_to_update = csv_files - else: - # Parse user selection - indices = [int(x.strip()) - 1 for x in selection.split(',')] - files_to_update = [csv_files[i] for i in indices if 0 <= i < len(csv_files)] - - if not files_to_update: - print("No valid selections made.") - return - except ValueError: - print("Invalid input. Please enter numbers separated by commas or '0' for all files.") - return - - # Populate the periods and days tables first - self.populate_periods_table() + selections = input("\nEnter the numbers of the files to process (comma-separated): ") + try: + indices = [int(x.strip()) - 1 for x in selections.split(',')] + valid_indices = [i for i in indices if 0 <= i < len(csv_files)] + + for i in valid_indices: + file = csv_files[i] + print(f"Processing {file}...") + csv_path = os.path.join(sample_data_dir, file) + self.process_csv_with_teacher_mapping(csv_path) + except ValueError: + print("Invalid input. Please enter comma-separated numbers.") + else: + print("Update cancelled.") - print(f"\nUpdating database with {len(files_to_update)} file(s):") - for filename in files_to_update: - print(f" - {filename}") - - csv_path = os.path.join(sample_data_dir, filename) - print(f"Processing {csv_path}...") - - self.process_csv_with_teacher_mapping(csv_path) + # Update teachers from the Teachers.csv file + teachers_file = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/Projects/Teachers.csv" + if os.path.exists(teachers_file): + print("Processing teachers from Teachers.csv...") + self.update_teachers_from_cheat_sheet(teachers_file) + else: + print("Teachers.csv file not found, skipping...") - # Update homeroom teachers from the dedicated CSV - self.update_homeroom_teachers_from_csv() + # Update homeroom teachers from the dedicated file + homeroom_file = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/Projects/Homeroom_teachers.csv" + if os.path.exists(homeroom_file): + print("Processing homeroom teachers...") + self.update_homeroom_teachers(homeroom_file) + else: + print("Homeroom teachers file not found, skipping...") print("Database updated successfully with selected CSV data.") - def update_homeroom_teachers_from_csv(self): + def update_homeroom_teachers(self, homeroom_file): """Update homeroom teachers from the dedicated CSV file""" - # Updated path to look in the parent directory - homeroom_csv_path = "../sample_data/Homeroom_teachers.csv" - - if not os.path.exists(homeroom_csv_path): - print(f"Homeroom teachers file '{homeroom_csv_path}' not found. Trying local directory...") - homeroom_csv_path = "sample_data/Homeroom_teachers.csv" - if not os.path.exists(homeroom_csv_path): - print(f"Homeroom teachers file '{homeroom_csv_path}' not found.") - return - - with open(homeroom_csv_path, 'r', encoding='utf-8') as file: + with open(homeroom_file, 'r', encoding='utf-8') as file: reader = csv.DictReader(file) for row in reader: @@ -958,4 +952,51 @@ class SchoolScheduleDB: '1 группа', '2 группа', 'все группы', 'гр 1', 'гр 2', 'all groups', 'group 1', 'group 2', 'A1', 'B1', 'C1', '4A', '4B', '4C', '4ABC'] - return text in common_groups \ No newline at end of file + return text in common_groups + + def update_teachers_from_cheat_sheet(self, teachers_csv_path): + """Update the teachers table from the Teachers.csv file""" + import csv + + with open(teachers_csv_path, 'r', encoding='utf-8') as file: + reader = csv.reader(file) + rows = list(reader) + + # Set to store unique teacher names + unique_teachers = set() + + # Process the CSV to extract teacher names + for row in rows: + for cell in row: + cell = cell.strip() + # Check if the cell looks like a teacher name (Russian/English name format) + if self._is_likely_teacher_name_enhanced(cell): + unique_teachers.add(cell) + + # Also check for names that might be combined with "/" (like "Name1 / Name2") + if '/' in cell: + parts = [part.strip() for part in cell.split('/')] + for part in parts: + if self._is_likely_teacher_name_enhanced(part): + unique_teachers.add(part) + + # Insert unique teachers into the database + for teacher_name in unique_teachers: + if teacher_name: # Make sure it's not an empty string + self.cursor.execute( + "INSERT OR IGNORE INTO teachers (name, email, phone) VALUES (?, NULL, NULL)", + (teacher_name,) + ) + + print(f"Added {len(unique_teachers)} unique teachers from Teachers.csv") + self.conn.commit() + + +# Main execution - just setup database +if __name__ == "__main__": + db = SchoolScheduleDB() + # Check if auto-update flag is passed as argument + auto_update = len(sys.argv) > 1 and sys.argv[1] == '--auto' + db.update_database_from_csv(auto_update=auto_update) + db.close() + diff --git a/scheduler_bots/school_schedule.db b/scheduler_bots/school_schedule.db index e3e463c..2d1d507 100644 Binary files a/scheduler_bots/school_schedule.db and b/scheduler_bots/school_schedule.db differ diff --git a/scheduler_bots/school_schedule.db-journal b/scheduler_bots/school_schedule.db-journal deleted file mode 100644 index 3886ef9..0000000 Binary files a/scheduler_bots/school_schedule.db-journal and /dev/null differ