Skip to content

Commit e5fe129

Browse files
committed
feat: Add tree type to meta data
The tree type can either be `coniferous` or `deciduous`.
1 parent 81744dd commit e5fe129

File tree

9 files changed

+97
-50
lines changed

9 files changed

+97
-50
lines changed

api/templates/yield-table-meta.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ <h2 class="mb-2 mt-10 text-xl font-semibold text-gray-900">
3434
yield_class_step
3535
</th>
3636
<th scope="col" class="px-6 py-3 font-mono">age_step</th>
37+
<th scope="col" class="px-6 py-3 font-mono">treey_type</th>
3738
<th scope="col" class="px-6 py-3 font-mono">
3839
available_columns
3940
</th>
@@ -77,6 +78,9 @@ <h2 class="mb-2 mt-10 text-xl font-semibold text-gray-900">
7778
<td class="px-6 py-4 font-mono text-right">
7879
{{data.age_step}}
7980
</td>
81+
<td class="px-6 py-4 font-mono text-right">
82+
{{data.tree_type.value}}
83+
</td>
8084
<td class="px-6 py-4 font-mono">
8185
<ul class="list-disc list-inside">
8286
{% for available_column in data.available_columns %}

api/templates/yield-tables-meta.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ <h2 class="mb-2 mt-10 text-xl font-semibold text-gray-900">
3434
yield_class_step
3535
</th>
3636
<th scope="col" class="px-6 py-3 font-mono">age_step</th>
37+
<th scope="col" class="px-6 py-3 font-mono">tree_type</th>
3738
</tr>
3839
</thead>
3940
<tbody>
@@ -86,6 +87,9 @@ <h2 class="mb-2 mt-10 text-xl font-semibold text-gray-900">
8687
<td class="px-6 py-4 font-mono text-right">
8788
{{yield_table_meta.age_step}}
8889
</td>
90+
<td class="px-6 py-4 font-mono text-right">
91+
{{yield_table_meta.tree_type.value}}
92+
</td>
8993
</tr>
9094
{% endfor %}
9195
</tbody>

docs/data_model.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The CSV files are structured as follows:
1717
- `link`: A link to the source of the yield table or the yield table itself.
1818
- `yield_class_step`: The step between the yield classes.
1919
- `age_step`: The step between the ages.
20+
- `tree_type`: The tree type: `coniferous` or `deciduous`.
2021

2122
* `yield_tables.csv`: Contains the yield tables.
2223
- `id`: The unique identifier of the yield table.

src/openyieldtables/data/yield_tables_meta.csv

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

src/openyieldtables/models/yieldtable.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
from enum import Enum
12
from typing import List, Optional, Union
23

34
from pydantic import BaseModel
45

56

7+
class TreeType(str, Enum):
8+
coniferous = "coniferous"
9+
deciduous = "deciduous"
10+
11+
612
class YieldTableMeta(BaseModel):
713
id: int
814
title: str
@@ -13,6 +19,7 @@ class YieldTableMeta(BaseModel):
1319
yield_class_step: Optional[float] = None
1420
age_step: Optional[int] = None
1521
available_columns: List[str]
22+
tree_type: TreeType
1623

1724

1825
class YieldClassRow(BaseModel):

src/openyieldtables/yieldtables.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pathlib import Path
33
from typing import Dict, List, Optional, TypedDict, Union, cast
44

5+
from openyieldtables.models.yieldtable import TreeType
6+
57
from .models import (
68
YieldClass,
79
YieldClassRow,
@@ -27,6 +29,7 @@ class YieldTableMetaCSVRow(TypedDict, total=False):
2729
yield_class_step: Optional[float]
2830
age_step: Optional[int]
2931
available_columns: List[str]
32+
tree_type: TreeType
3033

3134

3235
def get_yield_tables_meta() -> List[YieldTableMeta]:
@@ -73,6 +76,7 @@ def get_yield_tables_meta() -> List[YieldTableMeta]:
7376
"age_step": (
7477
int(row["age_step"]) if row.get("age_step") else None
7578
),
79+
"tree_type": row.get("tree_type"),
7680
"available_columns": find_available_columns(
7781
csv_path_yield_tables,
7882
"id",

tests/test_api_yieldtablesmeta.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from fastapi.testclient import TestClient
22

33
from api.main import app
4+
from openyieldtables.models.yieldtable import TreeType
45

56
client = TestClient(app, headers={"accept": "application/json"})
67

@@ -18,6 +19,7 @@ def test_read_yield_tables_meta():
1819
"link": "https://www.avbuch-shop.at/landwirtschaft/lehrbuecher/1347/hilfstafeln-fuer-die-forsteinrichtung", # noqa E501
1920
"yield_class_step": 1.0,
2021
"age_step": 10,
22+
"tree_type": TreeType.coniferous,
2123
"available_columns": [
2224
"id",
2325
"yield_class",
@@ -44,6 +46,7 @@ def test_read_yield_tables_meta():
4446
"link": "https://www.tirol.gv.at/umwelt/wald/waldwirtschaft/ertragstafeln-in-tirol/", # noqa E501
4547
"yield_class_step": 1.0,
4648
"age_step": 10,
49+
"tree_type": TreeType.coniferous,
4750
"available_columns": [
4851
"id",
4952
"yield_class",
@@ -75,6 +78,7 @@ def test_read_yield_table_meta():
7578
"link": "https://www.avbuch-shop.at/landwirtschaft/lehrbuecher/1347/hilfstafeln-fuer-die-forsteinrichtung", # noqa E501
7679
"yield_class_step": 1.0,
7780
"age_step": 10,
81+
"tree_type": TreeType.coniferous,
7882
"available_columns": [
7983
"id",
8084
"yield_class",

tests/test_models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
YieldTableData,
99
YieldTableMeta,
1010
)
11+
from openyieldtables.models.yieldtable import TreeType
1112

1213

1314
def test_yield_table_meta_valid():
@@ -21,6 +22,7 @@ def test_yield_table_meta_valid():
2122
"link": "https://example.com",
2223
"yield_class_step": 1,
2324
"age_step": 10,
25+
"tree_type": TreeType.coniferous,
2426
"available_columns": [
2527
"id",
2628
"name",
@@ -46,6 +48,22 @@ def test_yield_table_meta_invalid():
4648
"link": "https://example.com",
4749
"yield_class_step": 1,
4850
"age_step": 10,
51+
"tree_type": TreeType.coniferous,
52+
"available_columns": [],
53+
}
54+
with pytest.raises(ValidationError):
55+
YieldTableMeta(**invalid_data)
56+
57+
invalid_data = {
58+
"id": 1,
59+
"title": "yield_table_name",
60+
"country_codes": ["AT"],
61+
"type": "dgz_100",
62+
"source": "source",
63+
"link": "https://example.com",
64+
"yield_class_step": 1,
65+
"age_step": 10,
66+
"tree_type": "invalid_tree_type", # Invalid value for 'tree_type
4967
"available_columns": [],
5068
}
5169
with pytest.raises(ValidationError):
@@ -59,6 +77,7 @@ def test_yield_table_meta_defaults():
5977
"title": "yield_table_name",
6078
"country_codes": ["AT"],
6179
"source": "source",
80+
"tree_type": TreeType.coniferous,
6281
"available_columns": [
6382
"id",
6483
"name",
@@ -94,6 +113,7 @@ def test_yield_table_valid_data():
94113
title="yield_table_name",
95114
country_codes=["AT", "DE"],
96115
source="source",
116+
tree_type=TreeType.coniferous,
97117
available_columns=[
98118
"id",
99119
"name",

tests/test_openyieldtables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
from openyieldtables.models.yieldtable import TreeType
34
from openyieldtables.yieldtables import get_yield_table, get_yield_tables_meta
45

56

@@ -16,6 +17,7 @@ def test_get_yield_tables_meta():
1617
"link": "https://www.avbuch-shop.at/landwirtschaft/lehrbuecher/1347/hilfstafeln-fuer-die-forsteinrichtung", # noqa E501
1718
"yield_class_step": 1.0,
1819
"age_step": 10,
20+
"tree_type": TreeType.coniferous,
1921
"available_columns": [
2022
"id",
2123
"yield_class",
@@ -42,6 +44,7 @@ def test_get_yield_tables_meta():
4244
"link": "https://www.tirol.gv.at/umwelt/wald/waldwirtschaft/ertragstafeln-in-tirol/", # noqa E501
4345
"yield_class_step": 1.0,
4446
"age_step": 10,
47+
"tree_type": TreeType.coniferous,
4548
"available_columns": [
4649
"id",
4750
"yield_class",

0 commit comments

Comments
 (0)