|
5 | 5 |
|
6 | 6 | from fiboa_cli.util import load_file
|
7 | 7 |
|
8 |
| -from .dictobject import DictObject |
9 | 8 |
|
| 9 | +class EuroCropsConverterMixin: |
| 10 | + license = "CC-BY-SA-4.0" |
10 | 11 |
|
11 |
| -def add_eurocrops(base, year=None): |
12 |
| - if isinstance(base, dict): |
13 |
| - base = DictObject(base) |
14 |
| - |
15 |
| - ID = base.ID |
16 |
| - if not base.ID.startswith("ec_"): |
17 |
| - ID = "ec_" + ID |
18 |
| - |
19 |
| - SUFFIX = " - Eurocrops" |
20 |
| - if year is not None: |
21 |
| - SUFFIX += " " + str(year) |
22 |
| - |
23 |
| - TITLE = base.TITLE + SUFFIX |
24 |
| - |
25 |
| - SHORT_NAME = base.SHORT_NAME + SUFFIX |
26 |
| - |
27 |
| - DESCRIPTION = ( |
28 |
| - base.DESCRIPTION.strip() |
29 |
| - + """ |
30 |
| -
|
31 |
| -This dataset is an extended version of the original dataset, with additional columns and attributes added by the EuroCrops project. |
32 |
| -
|
33 |
| -The project developed a new **Hierarchical Crop and Agriculture Taxonomy (HCAT)** that harmonises all declared crops across the European Union. |
34 |
| -In the data you'll find this as additional attributes: |
35 |
| -
|
36 |
| -- `EC_trans_n`: The original crop name translated into English |
37 |
| -- `EC_hcat_n`: The machine-readable HCAT name of the crop |
38 |
| -- `EC_hcat_c`: The 10-digit HCAT code indicating the hierarchy of the crop |
39 |
| - """ |
40 |
| - ) |
| 12 | + ec_mapping_csv = None |
| 13 | + mapping_file = None |
| 14 | + ec_mapping = None |
41 | 15 |
|
42 |
| - PROVIDERS = base.PROVIDERS + [ |
43 |
| - {"name": "EuroCrops", "url": "https://github.com/maja601/EuroCrops", "roles": ["processor"]} |
44 |
| - ] |
| 16 | + def __init__(self, *args, year=None, **kwargs): |
| 17 | + super().__init__(*args, **kwargs) |
| 18 | + if not self.id.startswith("ec_"): |
| 19 | + self.id = "ec_" + self.id |
45 | 20 |
|
46 |
| - EXTENSIONS = getattr(base, "EXTENSIONS", None) or set() |
47 |
| - EXTENSIONS.add("https://fiboa.github.io/hcat-extension/v0.1.0/schema.yaml") |
48 |
| - COLUMNS = base.COLUMNS | { |
49 |
| - "EC_trans_n": "ec:translated_name", |
50 |
| - "EC_hcat_n": "ec:hcat_name", |
51 |
| - "EC_hcat_c": "ec:hcat_code", |
52 |
| - } |
| 21 | + suffix = " - Eurocrops" |
| 22 | + if year is not None: |
| 23 | + suffix = f"{suffix} {year}" |
53 | 24 |
|
54 |
| - LICENSE = "CC-BY-SA-4.0" |
| 25 | + self.title += suffix |
| 26 | + self.short_name += suffix |
55 | 27 |
|
56 |
| - return ID, SHORT_NAME, TITLE, DESCRIPTION, PROVIDERS, EXTENSIONS, COLUMNS, LICENSE |
| 28 | + self.description = ( |
| 29 | + self.description.strip() |
| 30 | + + """ |
57 | 31 |
|
| 32 | + This dataset is an extended version of the original dataset, with additional columns and attributes added by the EuroCrops project. |
58 | 33 |
|
59 |
| -class EuroCropsConverterMixin: |
60 |
| - ec_mapping_csv = None |
61 |
| - mapping_file = None |
62 |
| - ec_mapping = None |
| 34 | + The project developed a new **Hierarchical Crop and Agriculture Taxonomy (HCAT)** that harmonises all declared crops across the European Union. |
| 35 | + In the data you'll find this as additional attributes: |
63 | 36 |
|
64 |
| - def __init__(self, *args, year=None, **kwargs): |
65 |
| - super().__init__(*args, **kwargs) |
66 |
| - # Some meta-magic to reuse existing add_eurocrops routine |
67 |
| - attributes = ( |
68 |
| - "ID, SHORT_NAME, TITLE, DESCRIPTION, PROVIDERS, EXTENSIONS, COLUMNS, LICENSE".split( |
69 |
| - ", " |
70 |
| - ) |
| 37 | + - `EC_trans_n`: The original crop name translated into English |
| 38 | + - `EC_hcat_n`: The machine-readable HCAT name of the crop |
| 39 | + - `EC_hcat_c`: The 10-digit HCAT code indicating the hierarchy of the crop |
| 40 | + """ |
71 | 41 | )
|
72 |
| - base = {k: getattr(self, k.lower()) for k in attributes} |
73 |
| - for k, v in zip(attributes, add_eurocrops(base, year=year)): |
74 |
| - setattr(self, k.lower(), v) |
| 42 | + |
| 43 | + self.providers += [ |
| 44 | + { |
| 45 | + "name": "EuroCrops", |
| 46 | + "url": "https://github.com/maja601/EuroCrops", |
| 47 | + "roles": ["processor"], |
| 48 | + } |
| 49 | + ] |
| 50 | + |
| 51 | + self.extensions = getattr(self, "extensions", set()) |
| 52 | + self.extensions.add("https://fiboa.github.io/hcat-extension/v0.1.0/schema.yaml") |
| 53 | + self.columns |= { |
| 54 | + "EC_trans_n": "ec:translated_name", |
| 55 | + "EC_hcat_n": "ec:hcat_name", |
| 56 | + "EC_hcat_c": "ec:hcat_code", |
| 57 | + } |
| 58 | + self.license = "CC-BY-SA-4.0" |
75 | 59 |
|
76 | 60 | def convert(self, *args, **kwargs):
|
77 | 61 | self.mapping_file = kwargs.get("mapping_file")
|
|
0 commit comments