cl1-solutions 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cl1_solutions/__init__.py +26 -0
- cl1_solutions/__main__.py +6 -0
- cl1_solutions/cli.py +175 -0
- cl1_solutions/core.py +190 -0
- cl1_solutions/datasets/City_Air_Quality.csv +366 -0
- cl1_solutions/datasets/Iris.csv +151 -0
- cl1_solutions/datasets/Neighborhood_Demographics.csv +7 -0
- cl1_solutions/datasets/RealEstate_Prices.csv +801 -0
- cl1_solutions/datasets/Retail_Sales_Data.csv +1501 -0
- cl1_solutions/datasets/Social_Network_Ads.csv +401 -0
- cl1_solutions/datasets/Stock_Prices.csv +521 -0
- cl1_solutions/datasets/Telecom_Customer_Churn.csv +1201 -0
- cl1_solutions/datasets/Wine.csv +179 -0
- cl1_solutions/datasets/car_evaluation.csv +1729 -0
- cl1_solutions/datasets/cc_data_sample.csv +1001 -0
- cl1_solutions/datasets/diabetes.csv +769 -0
- cl1_solutions/datasets/sales_sample.csv +201 -0
- cl1_solutions/datasets/sales_sample.json +2402 -0
- cl1_solutions/datasets/sales_sample.xlsx +0 -0
- cl1_solutions/datasets/uber_fares_sample.csv +2001 -0
- cl1_solutions/notebooks/01_Feature_Transformation.ipynb +499 -0
- cl1_solutions/notebooks/02_Regression_Analysis.ipynb +536 -0
- cl1_solutions/notebooks/03_Classification_Analysis.ipynb +463 -0
- cl1_solutions/notebooks/04_Clustering_Analysis.ipynb +421 -0
- cl1_solutions/notebooks/05_Ensemble_Learning.ipynb +415 -0
- cl1_solutions/notebooks/06_Reinforcement_Learning.ipynb +839 -0
- cl1_solutions/notebooks/07_Data_Loading_Storage.ipynb +263 -0
- cl1_solutions/notebooks/08_Interacting_With_Web_APIs.ipynb +320 -0
- cl1_solutions/notebooks/09_Data_Cleaning_Preparation.ipynb +302 -0
- cl1_solutions/notebooks/10_Data_Wrangling.ipynb +270 -0
- cl1_solutions/notebooks/11_Data_Visualization.ipynb +282 -0
- cl1_solutions/notebooks/12_Data_Aggregation.ipynb +230 -0
- cl1_solutions/notebooks/13_Time_Series_Analysis.ipynb +279 -0
- cl1_solutions-1.0.0.dist-info/METADATA +158 -0
- cl1_solutions-1.0.0.dist-info/RECORD +39 -0
- cl1_solutions-1.0.0.dist-info/WHEEL +5 -0
- cl1_solutions-1.0.0.dist-info/entry_points.txt +4 -0
- cl1_solutions-1.0.0.dist-info/licenses/LICENSE +0 -0
- cl1_solutions-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cl1_solutions: All-in-One Retrieval Package for Computational Lab 1 Problem Solutions.
|
|
3
|
+
Includes all 20 individual Jupyter Notebooks and sample datasets.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = "1.0.0"
|
|
7
|
+
__author__ = "CL1 Contributor"
|
|
8
|
+
|
|
9
|
+
from .core import (
|
|
10
|
+
PROBLEMS_REGISTRY,
|
|
11
|
+
list_all_problems,
|
|
12
|
+
get_problem_by_id,
|
|
13
|
+
copy_notebooks,
|
|
14
|
+
copy_datasets,
|
|
15
|
+
retrieve_all
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"PROBLEMS_REGISTRY",
|
|
20
|
+
"list_all_problems",
|
|
21
|
+
"get_problem_by_id",
|
|
22
|
+
"copy_notebooks",
|
|
23
|
+
"copy_datasets",
|
|
24
|
+
"retrieve_all",
|
|
25
|
+
]
|
|
26
|
+
|
cl1_solutions/cli.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import argparse
|
|
4
|
+
from .core import (
|
|
5
|
+
PROBLEMS_REGISTRY,
|
|
6
|
+
list_all_problems,
|
|
7
|
+
get_problem_by_id,
|
|
8
|
+
copy_notebooks,
|
|
9
|
+
copy_datasets,
|
|
10
|
+
retrieve_all
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
BANNER = r"""
|
|
14
|
+
____ _ _ ____ _
|
|
15
|
+
/ ___| | / | / ___| ___ _ __| |__ ___ _ __
|
|
16
|
+
| | | | | | \___ \ / _ \| '__| '_ \ / _ \ '__|
|
|
17
|
+
| |___| |___| | ___) | (_) | | | |_) | __/ |
|
|
18
|
+
\____|_____|_| |____/ \___/|_| |_.__/ \___|_|
|
|
19
|
+
=====================================================
|
|
20
|
+
Computational Lab 1: All-in-One Problem Solutions (1-13)
|
|
21
|
+
=====================================================
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def print_table(items):
|
|
25
|
+
print(f"\n{'No.':<4} | {'Category':<24} | {'Notebook / Solution':<38}")
|
|
26
|
+
print("-" * 72)
|
|
27
|
+
for p in items:
|
|
28
|
+
print(f"{p['id']:<4} | {p['category']:<24} | {p['notebook']:<38}")
|
|
29
|
+
print("-" * 72)
|
|
30
|
+
|
|
31
|
+
def cmd_list():
|
|
32
|
+
print(BANNER)
|
|
33
|
+
print("Available Problem Statements & Jupyter Notebooks (1 to 13):\n")
|
|
34
|
+
print_table(PROBLEMS_REGISTRY)
|
|
35
|
+
print(f"\nTotal: {len(PROBLEMS_REGISTRY)} complete problem notebooks available.")
|
|
36
|
+
print("\nTo extract all notebooks and datasets to a folder, run:")
|
|
37
|
+
print(" cl1-get")
|
|
38
|
+
print("or:")
|
|
39
|
+
print(" cl1-get all --dest ./my_solutions\n")
|
|
40
|
+
|
|
41
|
+
def cmd_info(prob_id: str):
|
|
42
|
+
p = get_problem_by_id(prob_id)
|
|
43
|
+
if not p:
|
|
44
|
+
print(f"Error: Problem '{prob_id}' not found. Valid numbers are 1 to 13. Run 'cl1-get list' to view all.")
|
|
45
|
+
return
|
|
46
|
+
print(BANNER)
|
|
47
|
+
print(f"Problem No. : {p['id']}")
|
|
48
|
+
print(f"Category : {p['category']}")
|
|
49
|
+
print(f"Title : {p['title']}")
|
|
50
|
+
print(f"Notebook File : {p['notebook']}")
|
|
51
|
+
print(f"Datasets : {p['dataset']}")
|
|
52
|
+
print(f"Summary : {p['description']}")
|
|
53
|
+
print("\nTo retrieve this notebook, run:")
|
|
54
|
+
print(f" cl1-get {p['id']}\n")
|
|
55
|
+
|
|
56
|
+
def cmd_get_single(prob_id: str, dest: str):
|
|
57
|
+
p = get_problem_by_id(prob_id)
|
|
58
|
+
if not p:
|
|
59
|
+
print(f"Error: Problem '{prob_id}' not found. Valid numbers are 1 to 13.")
|
|
60
|
+
return
|
|
61
|
+
out_dir = os.path.abspath(dest)
|
|
62
|
+
copied = copy_notebooks(out_dir, [p['id']])
|
|
63
|
+
print(f"\nRetrieved Problem {p['id']} ({p['notebook']}):")
|
|
64
|
+
for f in copied:
|
|
65
|
+
print(f" -> Saved to: {os.path.join(out_dir, f)}")
|
|
66
|
+
|
|
67
|
+
# Also copy datasets if needed
|
|
68
|
+
data_dir = os.path.join(out_dir, "datasets")
|
|
69
|
+
copy_datasets(data_dir)
|
|
70
|
+
print(f" -> Datasets copied to: {data_dir}")
|
|
71
|
+
|
|
72
|
+
def cmd_get_all(dest: str, no_data: bool):
|
|
73
|
+
print(BANNER)
|
|
74
|
+
target_dir = os.path.abspath(dest)
|
|
75
|
+
print(f"Extracting all 13 solutions into: {target_dir} ...\n")
|
|
76
|
+
|
|
77
|
+
res = retrieve_all(target_dir, include_datasets=not no_data)
|
|
78
|
+
|
|
79
|
+
print(f"SUCCESS! Extracted {len(res['notebooks'])} Jupyter Notebooks (1 to 13):")
|
|
80
|
+
for nb in res['notebooks']:
|
|
81
|
+
print(f" [+] {nb}")
|
|
82
|
+
|
|
83
|
+
if res['datasets']:
|
|
84
|
+
print(f"\nExtracted {len(res['datasets'])} Datasets:")
|
|
85
|
+
for d in res['datasets']:
|
|
86
|
+
print(f" [*] datasets/{d}")
|
|
87
|
+
|
|
88
|
+
print(f"\nTarget Folder: {target_dir}")
|
|
89
|
+
print("\nNext Steps:")
|
|
90
|
+
print(f" 1. cd {dest}")
|
|
91
|
+
print(" 2. jupyter notebook (or open folder in VS Code / JupyterLab)")
|
|
92
|
+
print(" 3. Run the notebook for the problem statement you need!")
|
|
93
|
+
|
|
94
|
+
def cmd_pypi_help():
|
|
95
|
+
print(BANNER)
|
|
96
|
+
print("""
|
|
97
|
+
HOW TO PUBLISH THIS PACKAGE TO PyPI:
|
|
98
|
+
-----------------------------------
|
|
99
|
+
1. Build distribution archives:
|
|
100
|
+
python -m pip install --upgrade build twine
|
|
101
|
+
python -m build
|
|
102
|
+
|
|
103
|
+
2. Upload to PyPI:
|
|
104
|
+
python -m twine upload dist/*
|
|
105
|
+
(Enter your PyPI API token when prompted)
|
|
106
|
+
|
|
107
|
+
3. Install from any computer:
|
|
108
|
+
pip install cl1-solutions
|
|
109
|
+
|
|
110
|
+
4. Extract all files anytime with one command:
|
|
111
|
+
cl1-get
|
|
112
|
+
""")
|
|
113
|
+
|
|
114
|
+
def main():
|
|
115
|
+
parser = argparse.ArgumentParser(
|
|
116
|
+
description="Retrieve Jupyter Notebook solutions and datasets for all CL1 problem statements (1-13).",
|
|
117
|
+
prog="cl1-get"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
subparsers = parser.add_subparsers(dest="command", help="Available subcommands")
|
|
121
|
+
|
|
122
|
+
# 'all' subcommand
|
|
123
|
+
all_parser = subparsers.add_parser("all", help="Retrieve all 13 notebooks and datasets (default)")
|
|
124
|
+
all_parser.add_argument("-d", "--dest", default="./cl1_solutions", help="Destination directory (default: ./cl1_solutions)")
|
|
125
|
+
all_parser.add_argument("--no-data", action="store_true", help="Do not include datasets folder")
|
|
126
|
+
|
|
127
|
+
# 'list' subcommand
|
|
128
|
+
subparsers.add_parser("list", help="List all 13 available problem statements")
|
|
129
|
+
|
|
130
|
+
# 'get' subcommand
|
|
131
|
+
get_parser = subparsers.add_parser("get", help="Retrieve specific problem notebook by number (1 to 13)")
|
|
132
|
+
get_parser.add_argument("problem_id", help="Problem Number (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)")
|
|
133
|
+
get_parser.add_argument("-d", "--dest", default="./cl1_solutions", help="Destination directory")
|
|
134
|
+
|
|
135
|
+
# 'info' subcommand
|
|
136
|
+
info_parser = subparsers.add_parser("info", help="View description of a problem statement")
|
|
137
|
+
info_parser.add_argument("problem_id", help="Problem Number (1 to 13)")
|
|
138
|
+
|
|
139
|
+
# 'data' subcommand
|
|
140
|
+
data_parser = subparsers.add_parser("data", help="Retrieve only datasets")
|
|
141
|
+
data_parser.add_argument("-d", "--dest", default="./datasets", help="Destination directory for datasets")
|
|
142
|
+
|
|
143
|
+
# 'pypi-help' subcommand
|
|
144
|
+
subparsers.add_parser("pypi-help", help="Instructions for uploading this package to PyPI")
|
|
145
|
+
|
|
146
|
+
# Optional root arguments for default shorthand usage: e.g. "cl1-get" or "cl1-get 6" or "cl1-get -d ./my_dir"
|
|
147
|
+
parser.add_argument("-d", "--dest", default="./cl1_solutions", help="Destination directory (default: ./cl1_solutions)")
|
|
148
|
+
parser.add_argument("--no-data", action="store_true", help="Do not copy datasets")
|
|
149
|
+
parser.add_argument("shortcut", nargs="?", default=None, help="Shortcut: 'all', 'list', or a problem number like '1', '6', '13'")
|
|
150
|
+
|
|
151
|
+
# Parse arguments
|
|
152
|
+
args = parser.parse_args()
|
|
153
|
+
|
|
154
|
+
if args.command == "list" or args.shortcut == "list":
|
|
155
|
+
cmd_list()
|
|
156
|
+
elif args.command == "info":
|
|
157
|
+
cmd_info(args.problem_id)
|
|
158
|
+
elif args.command == "data":
|
|
159
|
+
target = os.path.abspath(args.dest)
|
|
160
|
+
copied = copy_datasets(target)
|
|
161
|
+
print(f"Extracted {len(copied)} datasets to: {target}")
|
|
162
|
+
elif args.command == "pypi-help" or args.shortcut == "pypi-help":
|
|
163
|
+
cmd_pypi_help()
|
|
164
|
+
elif args.command == "get":
|
|
165
|
+
cmd_get_single(args.problem_id, args.dest)
|
|
166
|
+
elif args.shortcut and args.shortcut.lstrip("#") in [p['id'] for p in PROBLEMS_REGISTRY]:
|
|
167
|
+
cmd_get_single(args.shortcut, args.dest)
|
|
168
|
+
else:
|
|
169
|
+
# Default action: extract all!
|
|
170
|
+
dest = args.dest if hasattr(args, 'dest') else "./cl1_solutions"
|
|
171
|
+
no_data = args.no_data if hasattr(args, 'no_data') else False
|
|
172
|
+
cmd_get_all(dest, no_data)
|
|
173
|
+
|
|
174
|
+
if __name__ == "__main__":
|
|
175
|
+
main()
|
cl1_solutions/core.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
from typing import List, Dict, Optional
|
|
4
|
+
|
|
5
|
+
PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
6
|
+
NOTEBOOKS_DIR = os.path.join(PACKAGE_DIR, "notebooks")
|
|
7
|
+
DATASETS_DIR = os.path.join(PACKAGE_DIR, "datasets")
|
|
8
|
+
|
|
9
|
+
PROBLEMS_REGISTRY: List[Dict[str, str]] = [
|
|
10
|
+
{
|
|
11
|
+
"id": "1",
|
|
12
|
+
"category": "Feature Transformation",
|
|
13
|
+
"title": "Feature Transformation (PCA & LDA)",
|
|
14
|
+
"notebook": "01_Feature_Transformation.ipynb",
|
|
15
|
+
"dataset": "Wine.csv, Iris.csv",
|
|
16
|
+
"description": "PCA on Wine dataset (unsupervised dimensionality reduction) & LDA on Iris dataset (supervised classification)."
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "2",
|
|
20
|
+
"category": "Regression Analysis",
|
|
21
|
+
"title": "Regression Analysis (Uber Price Prediction & Diabetes)",
|
|
22
|
+
"notebook": "02_Regression_Analysis.ipynb",
|
|
23
|
+
"dataset": "uber_fares_sample.csv, diabetes.csv",
|
|
24
|
+
"description": "Uber ride fare prediction (Linear, Ridge, Lasso, Outliers, Correlation) & Diabetes dataset analysis (Univariate, Bivariate, Multiple Regression)."
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "3",
|
|
28
|
+
"category": "Classification Analysis",
|
|
29
|
+
"title": "Classification Analysis (SVM Digits & KNN Social Ads)",
|
|
30
|
+
"notebook": "03_Classification_Analysis.ipynb",
|
|
31
|
+
"dataset": "Built-in Digits, Social_Network_Ads.csv",
|
|
32
|
+
"description": "SVM with Linear/Poly/RBF kernels for handwritten digit recognition (0-9) & KNN on Social Network Ads (Confusion Matrix, Accuracy, Error Rate, Precision, Recall)."
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "4",
|
|
36
|
+
"category": "Clustering Analysis",
|
|
37
|
+
"title": "Clustering Analysis (K-Means Elbow & K-Medoids Silhouette)",
|
|
38
|
+
"notebook": "04_Clustering_Analysis.ipynb",
|
|
39
|
+
"dataset": "Iris.csv, cc_data_sample.csv",
|
|
40
|
+
"description": "K-Means clustering on Iris with Elbow method & K-Medoids (PAM) on Credit Card dataset with Silhouette method."
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "5",
|
|
44
|
+
"category": "Ensemble Learning",
|
|
45
|
+
"title": "Ensemble Learning (Random Forest & Multi-Ensemble Comparison)",
|
|
46
|
+
"notebook": "05_Ensemble_Learning.ipynb",
|
|
47
|
+
"dataset": "car_evaluation.csv, Iris.csv",
|
|
48
|
+
"description": "Random Forest classifier for car safety prediction & comparison of Voting (Hard/Soft), AdaBoost, GBM, and XGBoost on Iris dataset."
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "6",
|
|
52
|
+
"category": "Reinforcement Learning",
|
|
53
|
+
"title": "Reinforcement Learning (Maze, Taxi Problem, Tic-Tac-Toe)",
|
|
54
|
+
"notebook": "06_Reinforcement_Learning.ipynb",
|
|
55
|
+
"dataset": "GridWorld Maze, Taxi Environment, Tic-Tac-Toe Board",
|
|
56
|
+
"description": "Tabular Q-learning agent in a 6x6 Maze, solving the Taxi problem (Taxi-v3), and building/training a complete Tic-Tac-Toe game agent."
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"id": "7",
|
|
60
|
+
"category": "Data Formats",
|
|
61
|
+
"title": "Data Loading, Storage and File Formats (Sales Data CSV, Excel, JSON)",
|
|
62
|
+
"notebook": "07_Data_Loading_Storage.ipynb",
|
|
63
|
+
"dataset": "sales_sample (CSV, Excel, JSON)",
|
|
64
|
+
"description": "Load multiple formats, quality exploration, cleaning missing/duplicates, unified dataframe, derived metrics, bar/pie/box plots."
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "8",
|
|
68
|
+
"category": "Web APIs",
|
|
69
|
+
"title": "Interacting with Web APIs (OpenWeatherMap Weather Data)",
|
|
70
|
+
"notebook": "08_Interacting_With_Web_APIs.ipynb",
|
|
71
|
+
"dataset": "OpenWeatherMap API / Weather Forecast",
|
|
72
|
+
"description": "API connection, weather attribute extraction (temp, humidity, wind, precip), data modeling, time series/bar/scatter plots, daily aggregations, heatmaps."
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "9",
|
|
76
|
+
"category": "Data Cleaning",
|
|
77
|
+
"title": "Data Cleaning and Preparation (Telecom Customer Churn)",
|
|
78
|
+
"notebook": "09_Data_Cleaning_Preparation.ipynb",
|
|
79
|
+
"dataset": "Telecom_Customer_Churn.csv",
|
|
80
|
+
"description": "11 Tasks: missing values, deduplication, inconsistent format, types, outliers, feature engineering, scaling, train-test split, export."
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"id": "10",
|
|
84
|
+
"category": "Data Wrangling",
|
|
85
|
+
"title": "Data Wrangling on Real Estate Market",
|
|
86
|
+
"notebook": "10_Data_Wrangling.ipynb",
|
|
87
|
+
"dataset": "RealEstate_Prices.csv, Neighborhood_Demographics.csv",
|
|
88
|
+
"description": "7 Tasks: sanitize column headers, handle nulls, demographic merge, subsetting, categorical encoding, summary statistics, outlier handling."
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "11",
|
|
92
|
+
"category": "Data Visualization",
|
|
93
|
+
"title": "Data Visualization using Matplotlib (City Air Quality Index AQI)",
|
|
94
|
+
"notebook": "11_Data_Visualization.ipynb",
|
|
95
|
+
"dataset": "City_Air_Quality.csv",
|
|
96
|
+
"description": "9 Tasks: AQI line plots with threshold bands, individual pollutant subplots (PM2.5, PM10, CO), monthly bar charts, box/violin distributions, bubble charts."
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"id": "12",
|
|
100
|
+
"category": "Data Aggregation",
|
|
101
|
+
"title": "Data Aggregation (Sales Performance by Region in Retail Company)",
|
|
102
|
+
"notebook": "12_Data_Aggregation.ipynb",
|
|
103
|
+
"dataset": "Retail_Sales_Data.csv",
|
|
104
|
+
"description": "8 Tasks: regional total sales aggregation, bar/pie distribution, top performers, region x category matrix, stacked/grouped bar plots."
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"id": "13",
|
|
108
|
+
"category": "Time Series",
|
|
109
|
+
"title": "Time Series Data Analysis (Stock Market Data & ARIMA Forecasting)",
|
|
110
|
+
"notebook": "13_Time_Series_Analysis.ipynb",
|
|
111
|
+
"dataset": "Stock_Prices.csv",
|
|
112
|
+
"description": "8 Tasks: datetime index, price/volume trends, 20/50 SMA & EMA, seasonality decomposition, correlation, ARIMA forecasting with confidence intervals."
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
def list_all_problems() -> List[Dict[str, str]]:
|
|
117
|
+
"""Returns the full list of problem dictionaries."""
|
|
118
|
+
return PROBLEMS_REGISTRY
|
|
119
|
+
|
|
120
|
+
def get_problem_by_id(problem_id: str) -> Optional[Dict[str, str]]:
|
|
121
|
+
"""Lookup a problem entry by its numeric ID (e.g. '1', '6', '13')."""
|
|
122
|
+
pid = problem_id.strip().lstrip("#").lower()
|
|
123
|
+
for item in PROBLEMS_REGISTRY:
|
|
124
|
+
if item["id"].lower() == pid:
|
|
125
|
+
return item
|
|
126
|
+
return None
|
|
127
|
+
|
|
128
|
+
def copy_notebooks(dest_dir: str, problem_ids: Optional[List[str]] = None) -> List[str]:
|
|
129
|
+
"""
|
|
130
|
+
Copies specified (or all) notebooks into dest_dir.
|
|
131
|
+
Returns list of copied filenames.
|
|
132
|
+
"""
|
|
133
|
+
os.makedirs(dest_dir, exist_ok=True)
|
|
134
|
+
copied = []
|
|
135
|
+
|
|
136
|
+
if problem_ids:
|
|
137
|
+
targets = []
|
|
138
|
+
for pid in problem_ids:
|
|
139
|
+
p = get_problem_by_id(pid)
|
|
140
|
+
if p:
|
|
141
|
+
targets.append(p)
|
|
142
|
+
else:
|
|
143
|
+
print(f"Warning: Problem ID '{pid}' not found.")
|
|
144
|
+
else:
|
|
145
|
+
targets = PROBLEMS_REGISTRY
|
|
146
|
+
|
|
147
|
+
for item in targets:
|
|
148
|
+
src = os.path.join(NOTEBOOKS_DIR, item["notebook"])
|
|
149
|
+
dst = os.path.join(dest_dir, item["notebook"])
|
|
150
|
+
if os.path.exists(src):
|
|
151
|
+
shutil.copy2(src, dst)
|
|
152
|
+
copied.append(item["notebook"])
|
|
153
|
+
|
|
154
|
+
return copied
|
|
155
|
+
|
|
156
|
+
def copy_datasets(dest_dir: str) -> List[str]:
|
|
157
|
+
"""
|
|
158
|
+
Copies all dataset files from package into dest_dir.
|
|
159
|
+
"""
|
|
160
|
+
os.makedirs(dest_dir, exist_ok=True)
|
|
161
|
+
copied = []
|
|
162
|
+
if os.path.exists(DATASETS_DIR):
|
|
163
|
+
for fname in os.listdir(DATASETS_DIR):
|
|
164
|
+
src = os.path.join(DATASETS_DIR, fname)
|
|
165
|
+
dst = os.path.join(dest_dir, fname)
|
|
166
|
+
if os.path.isfile(src):
|
|
167
|
+
shutil.copy2(src, dst)
|
|
168
|
+
copied.append(fname)
|
|
169
|
+
return copied
|
|
170
|
+
|
|
171
|
+
def retrieve_all(dest_dir: str = "./cl1_solutions", include_datasets: bool = True) -> Dict[str, List[str]]:
|
|
172
|
+
"""
|
|
173
|
+
Retrieves all 13 notebooks and all datasets into the specified folder.
|
|
174
|
+
"""
|
|
175
|
+
nb_dir = os.path.join(dest_dir, "notebooks") if dest_dir != "." else "./notebooks"
|
|
176
|
+
data_dir = os.path.join(dest_dir, "datasets") if dest_dir != "." else "./datasets"
|
|
177
|
+
|
|
178
|
+
os.makedirs(nb_dir, exist_ok=True)
|
|
179
|
+
copied_nb = copy_notebooks(nb_dir)
|
|
180
|
+
|
|
181
|
+
copied_data = []
|
|
182
|
+
if include_datasets:
|
|
183
|
+
os.makedirs(data_dir, exist_ok=True)
|
|
184
|
+
copied_data = copy_datasets(data_dir)
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
"dest_dir": os.path.abspath(dest_dir),
|
|
188
|
+
"notebooks": copied_nb,
|
|
189
|
+
"datasets": copied_data
|
|
190
|
+
}
|