included ai prompt text

This commit is contained in:
2026-02-05 11:01:13 +03:00
parent c8773de6ec
commit bf043896fc
5 changed files with 127 additions and 69 deletions

17
ai_prompt.txt Normal file
View File

@@ -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.

View File

@@ -152,95 +152,89 @@ class SchoolScheduleDB:
self.conn.commit() self.conn.commit()
def update_database_from_csv(self, auto_update=True): def update_database_from_csv(self, auto_update=False):
"""Automatically update database from specific CSV files in the sample_data directory""" """Update the database from CSV files in the sample_data directory"""
# Updated path to look in the parent directory # Define the sample_data directory path
sample_data_dir = "../sample_data" 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): if not os.path.exists(sample_data_dir):
print(f"Directory '{sample_data_dir}' not found. Trying local directory...") print(f"Directory {sample_data_dir} does not exist.")
sample_data_dir = "sample_data" return
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')]
# Keep only the actual student distribution files (not the sheets) # Find all CSV files in the sample_data directory
csv_files = [] csv_files = [f for f in os.listdir(sample_data_dir) if f.lower().endswith('.csv')]
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)
if not csv_files: 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 return
print(f"Found {len(csv_files)} student data CSV file(s):") print(f"Found {len(csv_files)} student data CSV file(s):")
for i, filename in enumerate(csv_files, 1): for i, file in enumerate(csv_files, 1):
print(f" {i}. {filename}") print(f" {i}. {file}")
if auto_update: if auto_update:
print("\nAuto-updating database with all student data CSV files...") 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: 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', 'да']: choice = input("Enter your choice (1-3): ").strip()
print("Skipping database update.")
return
print(f"\n0. Update all files") if choice == "1":
print("\nUpdating database with all CSV files...")
try: for file in csv_files:
selection = input(f"\nSelect file(s) to update (0 for all, or comma-separated numbers like 1,2,3): ") 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': selections = input("\nEnter the numbers of the files to process (comma-separated): ")
# Update all files try:
files_to_update = csv_files indices = [int(x.strip()) - 1 for x in selections.split(',')]
else: valid_indices = [i for i in indices if 0 <= i < len(csv_files)]
# Parse user selection
indices = [int(x.strip()) - 1 for x in selection.split(',')] for i in valid_indices:
files_to_update = [csv_files[i] for i in indices if 0 <= i < len(csv_files)] file = csv_files[i]
print(f"Processing {file}...")
if not files_to_update: csv_path = os.path.join(sample_data_dir, file)
print("No valid selections made.") self.process_csv_with_teacher_mapping(csv_path)
return except ValueError:
except ValueError: print("Invalid input. Please enter comma-separated numbers.")
print("Invalid input. Please enter numbers separated by commas or '0' for all files.") else:
return print("Update cancelled.")
# Populate the periods and days tables first
self.populate_periods_table()
print(f"\nUpdating database with {len(files_to_update)} file(s):") # Update teachers from the Teachers.csv file
for filename in files_to_update: teachers_file = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/Projects/Teachers.csv"
print(f" - {filename}") if os.path.exists(teachers_file):
print("Processing teachers from Teachers.csv...")
csv_path = os.path.join(sample_data_dir, filename) self.update_teachers_from_cheat_sheet(teachers_file)
print(f"Processing {csv_path}...") else:
print("Teachers.csv file not found, skipping...")
self.process_csv_with_teacher_mapping(csv_path)
# Update homeroom teachers from the dedicated CSV # Update homeroom teachers from the dedicated file
self.update_homeroom_teachers_from_csv() 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.") 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""" """Update homeroom teachers from the dedicated CSV file"""
# Updated path to look in the parent directory with open(homeroom_file, 'r', encoding='utf-8') as file:
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:
reader = csv.DictReader(file) reader = csv.DictReader(file)
for row in reader: for row in reader:
@@ -958,4 +952,51 @@ class SchoolScheduleDB:
'1 группа', '2 группа', 'все группы', 'гр 1', 'гр 2', 'all groups', '1 группа', '2 группа', 'все группы', 'гр 1', 'гр 2', 'all groups',
'group 1', 'group 2', 'A1', 'B1', 'C1', '4A', '4B', '4C', '4ABC'] 'group 1', 'group 2', 'A1', 'B1', 'C1', '4A', '4B', '4C', '4ABC']
return text in common_groups 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()

Binary file not shown.