-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from wri/arg_extra2
Argentina government deforestation reporting (2nd update)
- Loading branch information
Showing
16 changed files
with
421 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...rystats/forest_change_diagnostic/ForestChangeDiagnosticDataLossApproxYearlyCategory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.globalforestwatch.summarystats.forest_change_diagnostic | ||
|
||
import frameless.Injection | ||
import io.circe.syntax._ | ||
import io.circe.parser.decode | ||
|
||
import org.globalforestwatch.layers.ApproxYear | ||
|
||
// One level of categorization that leads to approximate yearly forest loss objects | ||
// (ForestChangeDiagnosticDataLossApproxYearly). | ||
case class ForestChangeDiagnosticDataLossApproxYearlyCategory( | ||
value: Map[String, ForestChangeDiagnosticDataLossApproxYearly] | ||
) extends ForestChangeDiagnosticDataParser[ | ||
ForestChangeDiagnosticDataLossApproxYearlyCategory | ||
] { | ||
def merge( | ||
other: ForestChangeDiagnosticDataLossApproxYearlyCategory | ||
): ForestChangeDiagnosticDataLossApproxYearlyCategory = { | ||
|
||
ForestChangeDiagnosticDataLossApproxYearlyCategory(value ++ other.value.map { | ||
case (key, otherValue) => | ||
key -> value | ||
.getOrElse(key, ForestChangeDiagnosticDataLossApproxYearly.empty) | ||
.merge(otherValue) | ||
}) | ||
} | ||
|
||
def formatAndRound: Map[String, Map[String, Double]] = | ||
this.value.map { | ||
case (key, value) => | ||
key -> value.formatAndRound | ||
} | ||
|
||
def toJson: String = { | ||
val x = this.formatAndRound | ||
x.asJson | ||
.noSpaces | ||
} | ||
} | ||
|
||
object ForestChangeDiagnosticDataLossApproxYearlyCategory { | ||
def empty: ForestChangeDiagnosticDataLossApproxYearlyCategory = | ||
ForestChangeDiagnosticDataLossApproxYearlyCategory(Map()) | ||
|
||
// There is a breakdown by one level of category before the breakdown into | ||
// approx-yearly forest loss. | ||
def fill( | ||
className: String, | ||
lossYear: ApproxYear, | ||
areaHa: Double, | ||
noData: List[String] = List("", "Unknown", "Not applicable"), | ||
include: Boolean = true | ||
): ForestChangeDiagnosticDataLossApproxYearlyCategory = { | ||
|
||
if (noData.contains(className)) | ||
ForestChangeDiagnosticDataLossApproxYearlyCategory.empty | ||
else | ||
ForestChangeDiagnosticDataLossApproxYearlyCategory( | ||
Map( | ||
className -> ForestChangeDiagnosticDataLossApproxYearly | ||
.fill(lossYear, areaHa, include) | ||
) | ||
) | ||
} | ||
|
||
def fromString( | ||
value: String | ||
): ForestChangeDiagnosticDataLossApproxYearlyCategory = { | ||
|
||
val categories: Map[String, String] = | ||
decode[Map[String, String]](value).getOrElse(Map()) | ||
val newValues = categories.map { | ||
case (k, v) => (k, ForestChangeDiagnosticDataLossApproxYearly.fromString(v)) | ||
} | ||
|
||
ForestChangeDiagnosticDataLossApproxYearlyCategory(newValues) | ||
|
||
} | ||
|
||
// See https://typelevel.org/frameless/Injection.html and | ||
// https://typelevel.org/frameless/TypedEncoder.html | ||
// Has an implicit TypedEncoder based on this injection in package.scala | ||
implicit def injection: Injection[ForestChangeDiagnosticDataLossApproxYearlyCategory, String] = Injection(_.toJson, fromString) | ||
//implicit def convertToString(f: ForestChangeDiagnosticDataLossApproxYearlyCategory): String = f.toJson | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
...tats/forest_change_diagnostic/ForestChangeDiagnosticDataLossApproxYearlyTwoCategory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.globalforestwatch.summarystats.forest_change_diagnostic | ||
|
||
import frameless.Injection | ||
import io.circe.syntax._ | ||
import io.circe.parser.decode | ||
|
||
import org.globalforestwatch.layers.ApproxYear | ||
|
||
// Two levels of categorization that lead to approximate yearly forest loss objects | ||
// (ForestChangeDiagnosticDataLossApproxYearly). | ||
case class ForestChangeDiagnosticDataLossApproxYearlyTwoCategory( | ||
value: Map[String, ForestChangeDiagnosticDataLossApproxYearlyCategory] | ||
) extends ForestChangeDiagnosticDataParser[ | ||
ForestChangeDiagnosticDataLossApproxYearlyTwoCategory | ||
] { | ||
def merge( | ||
other: ForestChangeDiagnosticDataLossApproxYearlyTwoCategory | ||
): ForestChangeDiagnosticDataLossApproxYearlyTwoCategory = { | ||
|
||
ForestChangeDiagnosticDataLossApproxYearlyTwoCategory(value ++ other.value.map { | ||
case (key, otherValue) => | ||
key -> value | ||
.getOrElse(key, ForestChangeDiagnosticDataLossApproxYearlyCategory.empty) | ||
.merge(otherValue) | ||
}) | ||
} | ||
|
||
def toJson: String = { | ||
val x = this.value | ||
.map { | ||
case (key, value) => | ||
key -> value.formatAndRound | ||
} | ||
|
||
x.asJson | ||
.noSpaces | ||
} | ||
} | ||
|
||
object ForestChangeDiagnosticDataLossApproxYearlyTwoCategory { | ||
def empty: ForestChangeDiagnosticDataLossApproxYearlyTwoCategory = | ||
ForestChangeDiagnosticDataLossApproxYearlyTwoCategory(Map()) | ||
|
||
// There is a breakdown by two levels of categories before the breakdown into | ||
// approx-yearly forest loss. | ||
def fill( | ||
categoryName: String, | ||
categoryName2: String, | ||
lossYear: ApproxYear, | ||
areaHa: Double, | ||
noData: List[String] = List("", "Unknown", "Not applicable"), | ||
include: Boolean = true | ||
): ForestChangeDiagnosticDataLossApproxYearlyTwoCategory = { | ||
|
||
if (noData.contains(categoryName)) | ||
ForestChangeDiagnosticDataLossApproxYearlyTwoCategory.empty | ||
else | ||
ForestChangeDiagnosticDataLossApproxYearlyTwoCategory( | ||
Map( | ||
categoryName -> ForestChangeDiagnosticDataLossApproxYearlyCategory | ||
.fill(categoryName2, lossYear, areaHa, include = include) | ||
) | ||
) | ||
} | ||
|
||
def fromString( | ||
value: String | ||
): ForestChangeDiagnosticDataLossApproxYearlyTwoCategory = { | ||
|
||
val categories: Map[String, String] = | ||
decode[Map[String, String]](value).getOrElse(Map()) | ||
val newValues = categories.map { | ||
case (k, v) => (k, ForestChangeDiagnosticDataLossApproxYearlyCategory.fromString(v)) | ||
} | ||
|
||
ForestChangeDiagnosticDataLossApproxYearlyTwoCategory(newValues) | ||
|
||
} | ||
|
||
// See https://typelevel.org/frameless/Injection.html and | ||
// https://typelevel.org/frameless/TypedEncoder.html | ||
// Has an implicit TypedEncoder based on this injection in package.scala | ||
implicit def injection: Injection[ForestChangeDiagnosticDataLossApproxYearlyTwoCategory, String] = Injection(_.toJson, fromString) | ||
} |
Oops, something went wrong.