Spaces:
Sleeping
Sleeping
Download tasks/easy_task.py from hackrock18/cloud-data-janitor: direct link, hf CLI and curl.
- Browser
- Download file 4.01 kB
-
https://huggingface.co/spaces/hackrock18/cloud-data-janitor/resolve/main/tasks/easy_task.py
- Command line
-
hf download hf://spaces/hackrock18/cloud-data-janitor/tasks/easy_task.py
-
curl -L -o easy_task.py https://huggingface.co/spaces/hackrock18/cloud-data-janitor/resolve/main/tasks/easy_task.py
4.01 kB
| # tasks/easy_task.py | |
| import random | |
| import json | |
| from datetime import datetime, timedelta | |
| from config import INITIAL_STATE_FILE | |
| def generate_easy_initial_state(seed: int = 42) -> dict: | |
| """ | |
| Generate a chaotic root directory of 50 loose files mixing .pdf and .jpg files | |
| (plus a few other types as distractors). | |
| Easy Task Goal: Move all .pdf files into 'Documents' and all .jpg into 'Images'. | |
| """ | |
| random.seed(seed) | |
| pdf_names = [ | |
| "report_q1.pdf", "resume.pdf", "invoice_march.pdf", "lecture_notes.pdf", | |
| "thesis_final.pdf", "budget_2023.pdf", "contract_v2.pdf", "manual_printer.pdf", | |
| "summary_meeting.pdf", "tax_return.pdf", "handbook_employee.pdf", "research_paper.pdf", | |
| "presentation_slides.pdf", "policy_document.pdf", "legal_agreement.pdf", | |
| ] | |
| jpg_names = [ | |
| "vacation_beach.jpg", "birthday_party.jpg", "profile_photo.jpg", "cat_sleeping.jpg", | |
| "sunset_view.jpg", "family_reunion.jpg", "graduation_photo.jpg", "dog_playing.jpg", | |
| "concert_night.jpg", "wedding_photo.jpg", "landscape_mountain.jpg", "food_pizza.jpg", | |
| "selfie_park.jpg", "baby_shower.jpg", "office_team.jpg", | |
| ] | |
| other_names = [ | |
| "notes.txt", "script.py", "data_dump.csv", "app_backup.zip", | |
| "config.json", "readme.md", "todo_list.txt", "analysis.xlsx", | |
| "old_code.js", "music_playlist.mp3", | |
| "video_clip.mp4", "presentation.pptx", "design.svg", "database.sql", | |
| "archive_old.tar", | |
| "spreadsheet.xls", "photo.png", "sample.docx", "audio_note.wav", | |
| "temp_file.tmp", | |
| ] | |
| def make_file(name: str, size_mb: float, days_ago: int) -> dict: | |
| accessed = (datetime.now() - timedelta(days=days_ago)).isoformat() | |
| created = (datetime.now() - timedelta(days=days_ago + 30)).isoformat() | |
| ext = "." + name.rsplit(".", 1)[-1] if "." in name else "" | |
| return { | |
| "type": "file", | |
| "extension": ext, | |
| "size_mb": round(size_mb, 2), | |
| "created_date": created, | |
| "last_accessed": accessed, | |
| } | |
| root = {} | |
| for name in pdf_names: | |
| root[name] = make_file(name, random.uniform(0.5, 5.0), random.randint(10, 500)) | |
| for name in jpg_names: | |
| root[name] = make_file(name, random.uniform(1.0, 8.0), random.randint(5, 400)) | |
| for name in other_names: | |
| root[name] = make_file(name, random.uniform(0.1, 20.0), random.randint(1, 600)) | |
| state = {"root": root} | |
| return state | |
| def get_easy_task_description() -> str: | |
| return ( | |
| "EASY TASK – File Grouping:\n" | |
| "You have 50 loose files in the root directory. Your job is to:\n" | |
| "1. Create a folder called 'Documents' and move ALL .pdf files into it.\n" | |
| "2. Create a folder called 'Images' and move ALL .jpg files into it.\n" | |
| "3. Leave all other files exactly where they are.\n" | |
| "Complete the task when all .pdf files are in 'Documents' and all .jpg files are in 'Images'." | |
| ) | |
| def get_easy_grading_criteria(initial_state: dict) -> dict: | |
| """Return the expected final state criteria for grading.""" | |
| root = initial_state["root"] | |
| pdf_files = [name for name, meta in root.items() | |
| if isinstance(meta, dict) and name.endswith(".pdf")] | |
| jpg_files = [name for name, meta in root.items() | |
| if isinstance(meta, dict) and name.endswith(".jpg")] | |
| other_files = [name for name, meta in root.items() | |
| if isinstance(meta, dict) and not name.endswith((".pdf", ".jpg"))] | |
| return { | |
| "files_to_move_to_Documents": pdf_files, | |
| "files_to_move_to_Images": jpg_files, | |
| "files_to_leave_untouched": other_files, | |
| } | |
| if __name__ == "__main__": | |
| state = generate_easy_initial_state() | |
| print(f"Generated {len(state['root'])} files.") | |
| with open(INITIAL_STATE_FILE, "w") as f: | |
| import os; os.makedirs("data", exist_ok=True) | |
| json.dump(state, f, indent=2) | |
| print(f"Saved to {INITIAL_STATE_FILE}") |