|
16 | 16 | from bs4 import BeautifulSoup |
17 | 17 |
|
18 | 18 | import api.utils as ut |
19 | | -from api.evaluator import Evaluator |
| 19 | +from api.evaluator import ConfigTerms, Evaluator |
20 | 20 |
|
21 | 21 | logging.basicConfig( |
22 | 22 | stream=sys.stdout, level=logging.DEBUG, format="'%(name)s:%(lineno)s' | %(message)s" |
|
25 | 25 | logger = logging.getLogger(os.path.basename(__file__)) |
26 | 26 |
|
27 | 27 |
|
28 | | -class ConfigTerms(property): |
29 | | - def __init__(self, term_id): |
30 | | - self.term_id = term_id |
31 | | - |
32 | | - def __call__(self, wrapped_func): |
33 | | - @wraps(wrapped_func) |
34 | | - def wrapper(plugin, **kwargs): |
35 | | - metadata = plugin.metadata |
36 | | - has_metadata = True |
37 | | - |
38 | | - term_list = ast.literal_eval(plugin.config[plugin.name][self.term_id]) |
39 | | - # Get values in config for the given term |
40 | | - if not term_list: |
41 | | - msg = ( |
42 | | - "Cannot find any value for term <%s> in configuration" |
43 | | - % self.term_id |
44 | | - ) |
45 | | - has_metadata = False |
46 | | - else: |
47 | | - # Get metadata associated with the term ID |
48 | | - term_metadata = pd.DataFrame( |
49 | | - term_list, columns=["element", "qualifier"] |
50 | | - ) |
51 | | - term_metadata = ut.check_metadata_terms_with_values( |
52 | | - metadata, term_metadata |
53 | | - ) |
54 | | - if term_metadata.empty: |
55 | | - msg = ( |
56 | | - "No access information can be found in the metadata for: %s. Please double-check the value/s provided for '%s' configuration parameter" |
57 | | - % (term_list, self.term_id) |
58 | | - ) |
59 | | - has_metadata = False |
60 | | - |
61 | | - if not has_metadata: |
62 | | - logger.warning(msg) |
63 | | - return (0, [{"message": msg, "points": 0}]) |
64 | | - |
65 | | - # Update kwargs with collected metadata for the required terms |
66 | | - kwargs.update( |
67 | | - {self.term_id: {"list": term_list, "metadata": term_metadata}} |
68 | | - ) |
69 | | - return wrapped_func(plugin, **kwargs) |
70 | | - |
71 | | - return wrapper |
72 | | - |
73 | | - |
74 | 28 | class Plugin(Evaluator): |
75 | 29 | """A class used to define FAIR indicators tests. It is tailored towards the |
76 | 30 | DigitalCSIC repository. |
|
0 commit comments