Adding endpoint of metrics
This commit is contained in:
parent
60579437bb
commit
6334120237
|
@ -15,6 +15,7 @@ from ereuse_devicehub.resources.documents import documents
|
|||
from ereuse_devicehub.resources.enums import PriceSoftware
|
||||
from ereuse_devicehub.resources.versions import versions
|
||||
from ereuse_devicehub.resources.allocate import definitions as allocate_def
|
||||
from ereuse_devicehub.resources.metric import definitions as metric_def
|
||||
|
||||
|
||||
class DevicehubConfig(Config):
|
||||
|
@ -29,8 +30,9 @@ class DevicehubConfig(Config):
|
|||
import_resource(documents),
|
||||
import_resource(inventory),
|
||||
import_resource(versions),
|
||||
import_resource(allocate_def)),
|
||||
)
|
||||
import_resource(allocate_def),
|
||||
import_resource(metric_def),
|
||||
),)
|
||||
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
|
||||
DB_USER = config('DB_USER', 'dhub')
|
||||
DB_PASSWORD = config('DB_PASSWORD', 'ereuse')
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
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
|
||||
from ereuse_devicehub.resources.device import models as m
|
||||
from ereuse_devicehub.resources.metric.schema import Metric
|
||||
|
||||
|
||||
class MetricsView(View):
|
||||
def find(self, args: dict):
|
||||
self.params = request.get_json()
|
||||
metrics = {
|
||||
"allocateds": self.allocated(),
|
||||
"live": 0,
|
||||
"null": 0,
|
||||
}
|
||||
return jsonify(metrics)
|
||||
|
||||
def allocated(self):
|
||||
return Allocate.query.filter(
|
||||
Allocate.start_time.between(
|
||||
self.params['start_time'], self.params['end_time']
|
||||
)
|
||||
).count()
|
||||
|
||||
|
||||
class MetricDef(Resource):
|
||||
__type__ = 'Metric'
|
||||
VIEW = MetricsView
|
||||
SCHEMA = Metric
|
||||
AUTH = True
|
|
@ -0,0 +1,11 @@
|
|||
from teal.resource import Schema
|
||||
from marshmallow.fields import DateTime
|
||||
|
||||
class Metric(Schema):
|
||||
"""
|
||||
This schema filter dates for search the metrics
|
||||
"""
|
||||
start_time = DateTime(data_key='start_time', required=True,
|
||||
description="Start date for search metrics")
|
||||
end_time = DateTime(data_key='end_time', required=True,
|
||||
description="End date for search metrics")
|
Reference in New Issue