From 62ed9995d30ee7689d3711446bfd0633aec8a56b Mon Sep 17 00:00:00 2001
From: Romain Broucquart <romain.broucquart@synchrotron-soleil.fr>
Date: Thu, 17 Nov 2022 11:53:36 +0100
Subject: [PATCH] Fix Function ExtrBetweenDates_MinMaxMean

* Old 'self' attribute existed
* move to pandas.DataFrame return
---
 core/ArchiveExtractor.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/core/ArchiveExtractor.py b/core/ArchiveExtractor.py
index 6014495..24f5cc3 100755
--- a/core/ArchiveExtractor.py
+++ b/core/ArchiveExtractor.py
@@ -515,7 +515,7 @@ def ExtrBetweenDates(
 def ExtrBetweenDates_MinMaxMean(
         attribute,
         dateStart,
-        dateStop=datetime.datetime.now(),
+        dateStop=None,
         timeInterval=datetime.timedelta(seconds=60),
         db='H',
         ):
@@ -588,13 +588,13 @@ def ExtrBetweenDates_MinMaxMean(
         timeInterval= datetime.timedelta(seconds=int(timeInterval[:-1])*mul)
 
     # Get info about the attribute
-    info=self.infoattr(attribute)
-    self.logger.debug("Attribute information \n%s"%info)
+    info=infoattr(attribute)
+    logger.debug("Attribute information \n%s"%info)
 
     # Detect spectrum
     attrtype="scalar"
     if int(info["max_dim_x"]) > 1:
-        self.logger.error("Attribute is not a scalar. Cannot perform this kind of operation.")
+        logger.error("Attribute is not a scalar. Cannot perform this kind of operation.")
         return None
 
     # Cut data range in time chunks
@@ -603,7 +603,7 @@ def ExtrBetweenDates_MinMaxMean(
         cdates.append(cdates[-1]+timeInterval)
     cdates[-1] = dateStop
     mdates = np.asarray(cdates[:-1])+timeInterval/2
-    self.logger.debug("Cutting time range to %d chunks of time, %s each."%(len(cdates)-1, timeInterval))
+    logger.debug("Cutting time range to %d chunks of time, %s each."%(len(cdates)-1, timeInterval))
 
     # Prepare arrays
     value_min = np.empty(len(cdates)-1)
@@ -617,14 +617,14 @@ def ExtrBetweenDates_MinMaxMean(
                 [value_max, value_min, value_mean],
                 ):
             # Make requests
-            self.logger.debug("Perform GetAttData%sBetweenDates (%s, %s, %s)"%(
+            logger.debug("Perform GetAttData%sBetweenDates (%s, %s, %s)"%(
                 func,
                 attribute,
                 cdates[i_d].strftime(_DBDFMT2),
                 cdates[i_d+1].strftime(_DBDFMT2))
                 )
 
-            _val =getattr(self.extractor, "GetAttData%sBetweenDates"%func)([
+            _val =getattr(_extractors[{'H':0, 'T':1}[db]], "GetAttData%sBetweenDates"%func)([
                 attribute,
                 cdates[i_d].strftime(_DBDFMT2),
                 cdates[i_d+1].strftime(_DBDFMT2)
@@ -632,6 +632,12 @@ def ExtrBetweenDates_MinMaxMean(
 
             arr[i_d] = _val
 
-    self.logger.debug("Extraction done for %s."%attribute)
-    return [mdates, value_min, value_max, value_mean]
+    logger.debug("Extraction done for %s."%attribute)
+    return pd.DataFrame(
+            index=mdates,
+            data={
+                "Min":value_min,
+                "Mean":value_mean,
+                "Max":value_max,
+                },)
 
-- 
GitLab