included ai prompt text
This commit is contained in:
17
ai_prompt.txt
Normal file
17
ai_prompt.txt
Normal 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.
|
||||||
Binary file not shown.
@@ -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"
|
|
||||||
if not os.path.exists(sample_data_dir):
|
|
||||||
print(f"Directory '{sample_data_dir}' not found.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get all CSV files and filter out the schedule template and sheet files
|
# Find all CSV files in the sample_data directory
|
||||||
all_csv_files = [f for f in os.listdir(sample_data_dir) if f.endswith('.csv')]
|
csv_files = [f for f in os.listdir(sample_data_dir) if f.lower().endswith('.csv')]
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
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)))
|
||||||
else:
|
for file in csv_files:
|
||||||
response = input("\nUpdate database with CSV files? (yes/no): ").lower()
|
print(f" - {file}")
|
||||||
|
csv_path = os.path.join(sample_data_dir, file)
|
||||||
if response not in ['yes', 'y', 'да']:
|
|
||||||
print("Skipping database update.")
|
|
||||||
return
|
|
||||||
|
|
||||||
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 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()
|
|
||||||
|
|
||||||
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)
|
self.process_csv_with_teacher_mapping(csv_path)
|
||||||
|
else:
|
||||||
|
print("\nChoose an option:")
|
||||||
|
print("1. Update all CSV files")
|
||||||
|
print("2. Select specific CSV files")
|
||||||
|
print("3. Cancel")
|
||||||
|
|
||||||
# Update homeroom teachers from the dedicated CSV
|
choice = input("Enter your choice (1-3): ").strip()
|
||||||
self.update_homeroom_teachers_from_csv()
|
|
||||||
|
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}")
|
||||||
|
|
||||||
|
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.")
|
||||||
|
|
||||||
|
# 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 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.")
|
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:
|
||||||
@@ -959,3 +953,50 @@ class SchoolScheduleDB:
|
|||||||
'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.
Binary file not shown.
Reference in New Issue
Block a user