Browse Source

[MNT] modify search results

tags/v0.3.2
bxdd 2 years ago
parent
commit
83d6592bba
3 changed files with 18 additions and 12 deletions
  1. +3
    -4
      docs/about/dev.rst
  2. +14
    -7
      learnware/market/base.py
  3. +1
    -1
      learnware/market/easy/searcher.py

+ 3
- 4
docs/about/dev.rst View File

@@ -1,8 +1,7 @@
.. _dev: .. _dev:

=============
Code Standard
=============
================
For Developer
================


Docstring Docstring
============ ============


+ 14
- 7
learnware/market/base.py View File

@@ -3,12 +3,12 @@ from __future__ import annotations
import traceback import traceback
import zipfile import zipfile
import tempfile import tempfile
from typing import Tuple, Any, List, Union, Dict
from typing import Tuple, Any, List, Union, Dict, Optional
from dataclasses import dataclass from dataclasses import dataclass
from ..learnware import Learnware, get_learnware_from_dirpath from ..learnware import Learnware, get_learnware_from_dirpath
from ..logger import get_module_logger from ..logger import get_module_logger


logger = get_module_logger("market_base", "INFO")
logger = get_module_logger("market_base")




class BaseUserInfo: class BaseUserInfo:
@@ -55,18 +55,25 @@ class BaseUserInfo:
""" """
self.stat_info[name] = item self.stat_info[name] = item



@dataclass @dataclass
class SearchItem: class SearchItem:
score: float score: float
learnware_list: List[Learnware]
learnwares: Union[Learnware, List[Learnware]]


class SearchResults: 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]]): 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 = [SearchItem(score, learnware_list) for score, learnware_list in zip(score_list, learnware_lists)]
search_terms = sorted(search_terms, key=lambda x:x.score) search_terms = sorted(search_terms, key=lambda x:x.score)


+ 1
- 1
learnware/market/easy/searcher.py View File

@@ -6,7 +6,7 @@ from typing import Tuple, List, Union


from .organizer import EasyOrganizer from .organizer import EasyOrganizer
from ..utils import parse_specification_type from ..utils import parse_specification_type
from ..base import BaseUserInfo, BaseSearcher
from ..base import BaseUserInfo, BaseSearcher, SearchResults
from ...learnware import Learnware from ...learnware import Learnware
from ...specification import RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification, rkme_solve_qp from ...specification import RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification, rkme_solve_qp
from ...logger import get_module_logger from ...logger import get_module_logger


Loading…
Cancel
Save