From 1fae5830fb301534be9573d7b3f065cb3b093f8f Mon Sep 17 00:00:00 2001
From: "louis.heraut" <louis.heraut@inrae.fr>
Date: Mon, 17 Jan 2022 12:06:31 +0100
Subject: [PATCH] Datasheet date type

---
 processing/format.R | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/processing/format.R b/processing/format.R
index 1068f98..ec84328 100644
--- a/processing/format.R
+++ b/processing/format.R
@@ -145,7 +145,7 @@ prepare_date = function(df_XEx, df_Xlist) {
     # }
     
     # df_XEx$values = dateExJul
-        
+
     dateStart_group = summarise(group_by(df_Xlist$data, group),
                                 Date = min(Date))
     # filter(group_by(df_Xlist$data, group), Date == min(Date))
@@ -166,8 +166,27 @@ prepare_date = function(df_XEx, df_Xlist) {
         OkdateStart_group = dateStart_group$group == group
         Shift = dateStart_group$Date_julian[OkdateStart_group]
         year = dateStart_group$Year[OkdateStart_group]
-        OkXEx = df_XEx$group1 == group & df_XEx$datetime == year
-        df_XEx$values[OkXEx] = df_XEx$values[OkXEx] + Shift        
+        OkXEx_code_year = df_XEx$group1 == group & df_XEx$datetime == year
+        df_XEx$values[OkXEx_code_year] =
+            df_XEx$values[OkXEx_code_year] + Shift
+
+        OkXEx_code = df_XEx$group1 == group        
+        XEx_code = df_XEx$values[OkXEx_code]
+        
+        # dXExUp = abs(XEx_code - c(XEx_code[2:length(XEx_code)],
+                                  # XEx_code[length(XEx_code)]))
+        # dXExDown = abs(XEx_code - c(XEx_code[1],
+                                    # XEx_code[1:(length(XEx_code) - 1)]))
+        # dExMean =  apply(rbind(dXExUp, dXExDown), 2, mean, na.rm=TRUE)
+
+        meanXEx_code = mean(XEx_code, na.rm=TRUE)
+        dXEx_code = abs(XEx_code - meanXEx_code)
+        stdXEx_code = sd(XEx_code, na.rm=TRUE)
+        print(stdXEx_code*2)
+        print(dXEx_code)
+        XEx_code[dXEx_code >= 365/3] = XEx_code[dXEx_code >= 365/3] + 365
+        # df_XEx$values[OkXEx_code] = XEx_code
+
     }
 
     return (df_XEx)
-- 
GitLab