From acbf64e44d012941ac6b1eac657a4beac38206ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr>
Date: Sat, 22 Jan 2022 21:20:10 +0100
Subject: [PATCH] =?UTF-8?q?script/onrn=20=09-=20ajout=20de=20balance=20=09?=
 =?UTF-8?q?-=20r=C3=A9organisation=20des=20variables?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Refs #7
---
 script/onrn.R | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/script/onrn.R b/script/onrn.R
index b966b56..bb96343 100644
--- a/script/onrn.R
+++ b/script/onrn.R
@@ -266,15 +266,19 @@ result = merge(result, temp, by = "commune", all.x = TRUE)
 
 ### Bilan Sinistre - Prime : estimation
 
-# balance = ratio * population * premium_hab
-population = 66992159 # INSEE (2018)
-premium = 1670000000 # (CCR2019a pour 2018)
-premium_hab = premium / population
-
+pop_france = 66992159 # INSEE (2018)
+premium_france = 1670000000 # (CCR2019a pour 2018)
+premium_hab = premium_france / pop_france
 result[["balance"]] = (1 - result[["ratio"]]) * geau::so_ii_population[ , "2018"] * premium_hab
 
+result = result[c(
+    "commune", "n_catnat", "freq_sin", "cost", "cost_mean", "cost_hab", "ratio", "balance",
+    "ppri_year", "ppri_state", "ppri_state_sub", "ppri_state_age", "ppri_age_min", "ppri_age_max",
+    "freq_sin_min", "freq_sin_max", "cost_min", "cost_max", "cost_mean_min", "cost_mean_max",
+    "cost_hab_min", "cost_hab_max", "ratio_min", "ratio_max"
+)]
+
 write.csv2(result, sprintf("data-common/so-ii/onrn/onrn-%s.csv", today), row.names = FALSE)
 
 unlink(onrn_raw, recursive = TRUE, force = TRUE)
 
-metropole@data$loss.absolute = metropole@data$POPULATION * (metropole@data$loss.ratio - 1) / metropole@data$area
-- 
GitLab