20 lines
665 B
Python
20 lines
665 B
Python
|
def mangrove_country_schema(data):
|
||
|
return {
|
||
|
"country_with_parent": str(data["country_with_parent"]),
|
||
|
"original_pixels": int(data["original_pixels"]),
|
||
|
"total_n_pixels": int(data["total_n_pixels"]),
|
||
|
"cumulative_pixels_diff": int(data["cumulative_pixels_diff"]),
|
||
|
"cumulative_pct_diff": float(data["cumulative_pct_diff"]),
|
||
|
}
|
||
|
|
||
|
|
||
|
class DataSerializer:
|
||
|
def __init__(self, schema_func):
|
||
|
self.schema_func = schema_func
|
||
|
|
||
|
def serialize_one(self, data) -> dict:
|
||
|
return self.schema_func(data)
|
||
|
|
||
|
def serialize_many(self, data_list) -> list:
|
||
|
return [self.serialize_one(data) for data in data_list]
|