diff --git a/docs/about/dev.rst b/docs/about/dev.rst index 8586d10..309d1dc 100644 --- a/docs/about/dev.rst +++ b/docs/about/dev.rst @@ -1,8 +1,7 @@ .. _dev: - -============= -Code Standard -============= +================ +For Developer +================ Docstring ============ diff --git a/learnware/market/base.py b/learnware/market/base.py index ea966f4..0779126 100644 --- a/learnware/market/base.py +++ b/learnware/market/base.py @@ -3,12 +3,12 @@ from __future__ import annotations import traceback import zipfile import tempfile -from typing import Tuple, Any, List, Union, Dict +from typing import Tuple, Any, List, Union, Dict, Optional from dataclasses import dataclass from ..learnware import Learnware, get_learnware_from_dirpath from ..logger import get_module_logger -logger = get_module_logger("market_base", "INFO") +logger = get_module_logger("market_base") class BaseUserInfo: @@ -55,18 +55,25 @@ class BaseUserInfo: """ self.stat_info[name] = item + @dataclass class SearchItem: score: float - learnware_list: List[Learnware] + learnwares: Union[Learnware, List[Learnware]] class SearchResults: - def __init__(self): - self.search_results: Dict[str, List[SearchItem]] = {} + def __init__(self, single_results: Optional[List[SearchItem]] = None, multiple_results: Optional[List[SearchItem]] = None): + self.single_results: List[SearchItem] = [] if single_results is None else single_results + self.multiple_results: List[SearchItem] = [] if multiple_results is None else multiple_results + + def get_single_results(self): + return self.single_results - def get_types(self): - return list(self.search_results.keys()) + def get_multiple_results(self): + return self.multiple_results + def update_single_results(self, score_list: List[float], learnware_list:List[Learnware]): + def update(self, type, score_list: List[float], learnware_lists: List[List[Learnware]]): search_terms = [SearchItem(score, learnware_list) for score, learnware_list in zip(score_list, learnware_lists)] search_terms = sorted(search_terms, key=lambda x:x.score) diff --git a/learnware/market/easy/searcher.py b/learnware/market/easy/searcher.py index 5820ee9..1ae5e15 100644 --- a/learnware/market/easy/searcher.py +++ b/learnware/market/easy/searcher.py @@ -6,7 +6,7 @@ from typing import Tuple, List, Union from .organizer import EasyOrganizer from ..utils import parse_specification_type -from ..base import BaseUserInfo, BaseSearcher +from ..base import BaseUserInfo, BaseSearcher, SearchResults from ...learnware import Learnware from ...specification import RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification, rkme_solve_qp from ...logger import get_module_logger