From 62621474ac10c57969fb71e980f7834bb61e16e9 Mon Sep 17 00:00:00 2001
From: LETORT Sebastien <sebastien.letort@irisa.fr>
Date: Thu, 20 Feb 2020 09:33:35 +0100
Subject: [PATCH] New method app_metrics, with its doc.

---
 allgo/__init__.py | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/allgo/__init__.py b/allgo/__init__.py
index 0b81499..13c4853 100644
--- a/allgo/__init__.py
+++ b/allgo/__init__.py
@@ -56,7 +56,7 @@ from os.path import expanduser
 
 import requests
 
-__version__ = StrictVersion('1.0.0')
+__version__ = StrictVersion('1.1.0')
 
 #: The default Allgo url used.
 MAIN_INSTANCE_URL = "https://allgo18.inria.fr"
@@ -128,7 +128,7 @@ class Client:
        | verify_tls- does tls have to be verified ?
 
      methods
-       | app_metrics - *not implemented yet*.
+       | app_metrics - retrieve the metrics related to an app.
        | create_job  - create an app's job.
        | download_file - download a file generated by a job.
        | job_status  - get status of a job.
@@ -297,31 +297,26 @@ class Client:
     def app_metrics(self, app_id, what, from_=None, to_=None, step=None):
         """query the instance for some metrics.
 
-        **Not yet implemented.**
-
         Owner of an app can query the instance to get some metrics.
         metrics are the number of jobs over a period of time,
-        from 'from_' to 'to_', with data aggregate by 'step'
+        from 'from_' to 'to_', with data aggregated by 'step'
         3 kind of metrics are proposed ('what' param), they are an aggregate condition.
 
         Parameters
         ----------
-        app : string or int
-            application name or id.
-        what: { "per_user", "per_state", "created" }
+        app : int
+            application id.
+        what: { "per_user", "per_result", "created" }
             the kind of metrics we want.
-            "per_user"  : to get the # of job grouped by user.
-            "per_state" : to get the # of job grouped by state.
-            "created"   : to get the # of job grouped by date a creation.
+            "per_user"   : to get the # of job grouped by user.
+            "per_result" : to get the # of job grouped by result.
+            "created"    : to get the # of job grouped by date a creation.
         from_ : date
             date of begining in format (yyyy-mm-dd).
         to_   : date
             date of end in format (yyyy-mm-dd).
         step  : { "year", "month", "day" }, optional
             step period used to aggregate data.
-            "year" : to aggregate data by year.
-            "month" : to aggregate data by month.
-            "day" : to aggregate data by day.
             for more info cf. https://docs.djangoproject.com/en/1.11/ref/models/database-functions/#trunc
 
         Returns
@@ -334,9 +329,8 @@ class Client:
                 {
                     'data': [
                         {
-                            'uname': username,
-                            'time_period': date,
-                            'n': # of jobs
+                            Record format is specific to each 'what'
+                            cf https://allgo.gitlabpages.inria.fr/doc/api.html#output-format
                         },
                         ...
                     ],
@@ -346,7 +340,13 @@ class Client:
                 }
             }
         """
-        raise NotImplementedError("metrics API has not been integrated yet.")
+        url = 'metrics/{}/{}'.format(what, app_id)
+        params = {
+            'from' : from_,
+            'to'   : to_,
+            'step' : step,
+        }
+        return self._request_api('get', url, params=params)
 
     # --------------------------------------------
     # -- Accessory methods, to ease user work.
-- 
GitLab