forked from ConservationInternational/trends.earth-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporting.py
164 lines (126 loc) · 3.12 KB
/
reporting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import datetime
from dataclasses import field
from typing import List, Optional
from marshmallow_dataclass import dataclass
from marshmallow import validate
from schemas.schemas import AreaOfInterest
from schemas.land_cover import LCTransMatrix, LCLegendNesting
# Area summary schemas
@dataclass
class Value:
name: str
value: float
class Meta:
ordered = True
@dataclass
class AnnualValueList:
name: str
year: Optional[int]
unit: str
values: List[Value]
class Meta:
ordered = True
# Area summary schemas
@dataclass
class Area:
name: Optional[str]
area: float = field(metadata={"validate": validate.Range(min=0)})
class Meta:
ordered = True
@dataclass
class AreaList:
name: Optional[str]
unit: str = field(metadata={'validate': validate.OneOf(["m", "ha", "km sq"])})
areas: List[Area]
class Meta:
ordered = True
# Crosstab summary schemas
@dataclass
class CrossTabEntry:
initial_label: str
final_label: str
value: float
class Meta:
ordered = True
@dataclass
class CrossTab:
name: Optional[str]
#unit: str = field(metadata={'validate': validate.OneOf(["m", "ha", "km sq"])})
unit: str
initial_year: int
final_year: int
values: List[CrossTabEntry]
class Meta:
ordered = True
###
# Schemas to facilitate UNCCD reporting
@dataclass
class TrendsEarthVersion:
version: str
revision: str
release_date: datetime.datetime
class Meta:
ordered = True
datetimeformat = '%Y-%m-%dT%H:%M:%S+00:00'
@dataclass
class ReportMetadata:
title: str
date: datetime.datetime
trends_earth_version: TrendsEarthVersion
area_of_interest: AreaOfInterest
class Meta:
ordered = True
datetimeformat = '%Y-%m-%dT%H:%M:%S+00:00'
@dataclass
class SDG15Report:
summary: AreaList
class Meta:
ordered = True
@dataclass
class ProductivityReport:
summary: AreaList
crosstabs_by_productivity_class: List[CrossTab]
class Meta:
ordered = True
@dataclass
class LandCoverReport:
summary: AreaList
legend_nesting: LCLegendNesting
crosstab_by_land_cover_class: CrossTab
land_cover_areas_by_year: List[AnnualValueList]
class Meta:
ordered = True
@dataclass
class SoilOrganicCarbonReport:
summary: AreaList
crosstab_by_land_cover_class: CrossTab
soc_stock_by_year: List[AnnualValueList]
class Meta:
ordered = True
@dataclass
class LandConditionReport:
sdg: SDG15Report
productivity: ProductivityReport
land_cover: LandCoverReport
soil_organic_carbon: SoilOrganicCarbonReport
class Meta:
ordered = True
@dataclass
class AffectedPopulationReport:
pass
class Meta:
ordered = True
@dataclass
class DroughtReport:
pass
class Meta:
ordered = True
@dataclass
class TrendsEarthSummary:
metadata: ReportMetadata
land_condition: LandConditionReport
affected_population: AffectedPopulationReport
drought: DroughtReport
# TODO: Add datasets needed for reporting (band number and filename)
class Meta:
ordered = True