diff --git a/ereuse_devicehub/resources/metric/definitions.py b/ereuse_devicehub/resources/metric/definitions.py index 134db628..4c90c77f 100644 --- a/ereuse_devicehub/resources/metric/definitions.py +++ b/ereuse_devicehub/resources/metric/definitions.py @@ -1,59 +1,6 @@ -from flask import request, g, jsonify -from ereuse_devicehub.resources.action import schemas -from teal.resource import Resource, View - -from ereuse_devicehub.resources.action.models import Allocate, Live, Action, ToRepair, ToPrepare -from ereuse_devicehub.resources.device import models as m +from teal.resource import Resource from ereuse_devicehub.resources.metric.schema import Metric - - -class MetricsView(View): - def find(self, args: dict): - - self.params = dict(request.args) - unvalid = self.schema.validate(self.params) - if unvalid: - res = jsonify(unvalid) - res.status = 404 - return res - - metrics = { - "allocateds": self.allocated(), - "live": self.live(), - "null": self.nulls(), - } - return jsonify(metrics) - - def allocated(self): - return Allocate.query.filter( - Allocate.start_time.between( - self.params['start_time'], self.params['end_time'] - ), - Action.author==g.user - ).count() - - def live(self): - return Live.query.filter( - Live.created.between( - self.params['start_time'], self.params['end_time'] - ), - Action.author==g.user - ).distinct(Live.serial_number).count() - - def nulls(self): - to_repair = ToRepair.query.filter( - ToRepair.created.between( - self.params['start_time'], self.params['end_time'] - ), - Action.author==g.user - ).count() - to_prepare = ToPrepare.query.filter( - ToPrepare.created.between( - self.params['start_time'], self.params['end_time'] - ), - Action.author==g.user - ).count() - return to_repair + to_prepare +from ereuse_devicehub.resources.metric.views import MetricsView class MetricDef(Resource): diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 5806afc7..b976d28f 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -52,7 +52,7 @@ def test_simple_metrics(user: UserClient): data = {"start_time": today-delta, "end_time": today+delta } - metrics = {'allocateds': 1, 'live': 1, 'null': 0} + metrics = {'allocateds': 1, 'live': 1} res, _ = user.get("/metrics/", query_string=data) assert res == metrics @@ -98,7 +98,7 @@ def test_second_hdd_metrics(user: UserClient): data = {"start_time": today-delta, "end_time": today+delta } - metrics = {'allocateds': 1, 'live': 2, 'null': 0} + metrics = {'allocateds': 1, 'live': 2} res, _ = user.get("/metrics/", query_string=data) assert res == metrics