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