adding latest api_datadisplay
This commit is contained in:
@@ -1,29 +1,56 @@
|
|||||||
from fastapi import FastAPI, Header, Path
|
from fastapi import FastAPI, Header, Path
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from random import randint
|
||||||
|
from starlette.routing import Route
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI(
|
||||||
|
title='Capacity API', description='API for returning metric data.',
|
||||||
|
version='1.0.0', redoc_url='/documentation'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MetricResponse(BaseModel):
|
class MetricResponse(BaseModel):
|
||||||
data: List = [1, 2, 3]
|
data: List[int]
|
||||||
metrics: str
|
time: List[int]
|
||||||
|
metric: str
|
||||||
|
|
||||||
|
|
||||||
@app.get("/metrics/{metric}", response_model=MetricResponse)
|
@app.get("/metrics/{metric}", response_model=MetricResponse)
|
||||||
def get_metrics(
|
def get_metric_data(
|
||||||
metric: str = Path(
|
metric: str = Path(
|
||||||
...,
|
...,
|
||||||
title='Metric',
|
title='Metric',
|
||||||
description='The metric needed. Must be one of "bets", "deposits" or '
|
description='A data metric. Valid metrics are ["bets", '
|
||||||
'"registrations"',
|
'"deposits", "registrations"]',
|
||||||
regex=r'^(bets$)|(deposits$)|(registrations$)',
|
regex=r'^(bets$)|(deposits$)|(registrations$)',
|
||||||
),
|
),
|
||||||
earliest: str = Header(None, title='Earliest time',),
|
earliest: str = Header(None, title='Earliest time',),
|
||||||
):
|
):
|
||||||
var = MetricResponse(metrics='s')
|
"""
|
||||||
return {'metric': 's'}
|
Will return metric data for a timespan.
|
||||||
|
"""
|
||||||
|
# do something
|
||||||
|
time = []
|
||||||
|
data = []
|
||||||
|
|
||||||
|
for i in range(0, 10):
|
||||||
|
time.append(randint(1582238840, 1582238890))
|
||||||
|
data.append(randint(1, 5000))
|
||||||
|
|
||||||
|
return {
|
||||||
|
'metric': metric,
|
||||||
|
'time': time,
|
||||||
|
'data': data,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test(request):
|
||||||
|
return 'request'
|
||||||
|
|
||||||
|
|
||||||
|
app.route('/test', [test])
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
class Item(BaseModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user