diff --git a/src/skore/project.py b/src/skore/project.py index 4ccdf1f56..0971360b9 100644 --- a/src/skore/project.py +++ b/src/skore/project.py @@ -1,30 +1,123 @@ -Path = None -Item = None +"""""" + +import json +from pathlib import Path +from typing import Any, List + def get_filepath_from_project_name(project_name) -> Path: return None + +class Item: + """An item in the project.""" + + +class JSONItem(Item): + """An item that is a JSON serializable Python object.""" + + def __init__(self, value): + self.value = json.dumps(value) + + +class DataFrameItem(Item): + """An item that is a pandas or polars data frame.""" + + +class NumpyArrayItem(Item): + """An item that is a Numpy Array.""" + + +class MediaItem(Item): + """An item that is a media object.""" + + +class ScikitLearnModelItem(Item): + """An item that is a Scikit-Learn model.""" + + def __init__(self, value): + self.value = value + + @staticmethod + def transform(value): + return html + + class Transformer: @staticmethod def transform(value) -> Item: - ... + """Transform a value into an Item.""" + # Get the class of the value as a string + value_class = type(value).__name__ + + # Map the class name to the corresponding Item subclass + item_class_map = { + "dict": JSONItem, + "list": JSONItem, + "tuple": JSONItem, + "int": JSONItem, + "float": JSONItem, + "str": JSONItem, + "bool": JSONItem, + # TODO: Add + # pandas.DataFrame DataFrameItem + # polars.DataFrame DataFrameItem + # numpy.ndarray NumpyArrayItem + # matplotlib.figure.Figure MediaItem (as SVG) + # PIL.Image.Image MediaItem (as PNG) + # altair.Chart MediaItem (as Vega-Lite JSON) + # bytes + media type MediaItem + # str + media type MediaItem + # Scikit-learn model ScikitLearnModelItem + } + + # Check if the value's class is in our mapping + if value_class in item_class_map: + return item_class_map[value_class](value) + + # For scikit-learn models, we need to check if it's a BaseEstimator + if hasattr(value, "fit") and hasattr(value, "predict"): + return ScikitLearnModelItem(value) + + # If we don't have a specific Item subclass for this type, + # we'll use the base Item class + return Item(value) + class Project: + """A project is a collection of items that are stored in a storage.""" + def __init__(self, transformer, storage): self.transformer = transformer self.storage = storage def put(self, key, value): + """Put a value into the project.""" self.storage.save( key, self.transformer.transform(value), ) def put_item(self, key, item): + """Put an item into the project.""" self.storage.save( key, item, ) + def get(self, key) -> Any: + """Get an item from the project.""" + + def get_item(self, key) -> Item: + """Get an item from the project.""" + + def list_keys(self) -> List[str]: + """List all keys in the project.""" + + def delete_item(key: str): + """Delete an item from the project.""" + + def load(project_name: str) -> Project: + """Load a project from a file.""" filepath = get_filepath_from_project_name(project_name)