Skip to content
Snippets Groups Projects
Commit cbab1d74 authored by James Constantinos Ladd's avatar James Constantinos Ladd
Browse files

[COMP-351] moved traffic_ratio.py into network.py

parent f7274740
No related branches found
No related tags found
1 merge request!132[COMP-351] Added graph for commodity vs R&E traffic
This commit is part of merge request !132. Comments created here will be created in the context of that merge request.
......@@ -106,7 +106,7 @@ interface inputProps {
function TrafficRatioGraph({ roles = false }: inputProps) {
const { filterSelection, setFilterSelection } = useContext(FilterSelectionContext);
const { data: trafficRatioData, years, nrens } = useData<TrafficRatio>('/api/traffic-ratio/', setFilterSelection);
const { data: trafficRatioData, years, nrens } = useData<TrafficRatio>('/api/network/traffic-ratio', setFilterSelection);
const trafficRatioDataset = createTrafficRatioDataset(trafficRatioData, filterSelection.selectedYears[0]);
......
......@@ -23,7 +23,6 @@ from compendium_v2.routes.fibre_light import routes as fibre_light
from compendium_v2.routes.monitoring_tools import routes as monitoring_tools
from compendium_v2.routes.network import routes as network
from compendium_v2.routes.standards_and_policies import routes as standards_and_policies
from compendium_v2.routes.traffic_ratio import routes as traffic_ratio
routes = Blueprint('compendium-v2-api', __name__)
routes.register_blueprint(budget_routes, url_prefix='/budget')
......@@ -46,7 +45,6 @@ routes.register_blueprint(fibre_light, url_prefix='/fibre-light')
routes.register_blueprint(monitoring_tools, url_prefix='/monitoring-tools')
routes.register_blueprint(network, url_prefix='/network')
routes.register_blueprint(standards_and_policies, url_prefix='/standards-and-policies')
routes.register_blueprint(traffic_ratio, url_prefix='/traffic-ratio')
logger = logging.getLogger(__name__)
......
......@@ -2,7 +2,7 @@ from typing import Any
from compendium_v2.db.presentation_models import PertTeam, PassiveMonitoring, AlienWave, OpsAutomation, \
NetworkAutomation, TrafficStatistics, WeatherMap, NetworkMapUrls, NetworkFunctionVirtualisation, \
CertificateProviders, SiemVendors, Capacity, NonREPeers, DarkFibreLease
CertificateProviders, SiemVendors, Capacity, NonREPeers, DarkFibreLease, TrafficRatio
from compendium_v2.routes import common
from flask import Blueprint, jsonify
......@@ -286,6 +286,29 @@ DARK_FIBRE_LEASE_RESPONSE_SCHEMA = {
'items': {'$ref': '#/definitions/dark_fibre'}
}
TRAFFIC_RATIO_RESPONSE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'traffic_ratio': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
'nren_country': {'type': 'string'},
'year': {'type': 'integer'},
'r_and_e_percentage': {'type': 'number'},
'commodity_percentage': {'type': 'number'}
},
'required': ['nren', 'nren_country', 'year',
'r_and_e_percentage', 'commodity_percentage'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/traffic_ratio'}
}
def pert_team_extract_data(pert_team: PertTeam) -> dict:
return {
......@@ -804,3 +827,31 @@ def dark_fibre_lease_data_view() -> Any:
entries.append(dark_fibre_lease_extract_data(entry))
return jsonify(entries)
def traffic_ratio_extract_data(entry: TrafficRatio):
return {
'nren': entry.nren.name,
'nren_country': entry.nren.country,
'year': entry.year,
'r_and_e_percentage': float(entry.r_and_e_percentage),
'commodity_percentage': float(entry.commodity_percentage),
}
@routes.route('/traffic-ratio', methods=['GET'])
@common.require_accepts_json
def traffic_ratio_view() -> Any:
"""
handler for /api/traffic_ratio/ requests
response will be formatted as:
.. asjson::
compendium_v2.routes.network.TRAFFIC_RATIO_RESPONSE_SCHEMA
:return:
"""
entries = [traffic_ratio_extract_data(entry) for entry in common.get_data(TrafficRatio)]
return jsonify(entries)
import logging
from flask import Blueprint, jsonify
from compendium_v2.db.presentation_models import TrafficRatio
from compendium_v2.routes import common
from typing import Any
routes = Blueprint('traffic_ratio', __name__)
logger = logging.getLogger(__name__)
TRAFFIC_RATIO_RESPONSE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'traffic_ratio': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
'nren_country': {'type': 'string'},
'year': {'type': 'integer'},
'r_and_e_percentage': {'type': 'number'},
'commodity_percentage': {'type': 'number'}
},
'required': ['nren', 'nren_country', 'year',
'r_and_e_percentage', 'commodity_percentage'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/traffic_ratio'}
}
def traffic_ratio_extract_data(entry: TrafficRatio):
return {
'nren': entry.nren.name,
'nren_country': entry.nren.country,
'year': entry.year,
'r_and_e_percentage': float(entry.r_and_e_percentage),
'commodity_percentage': float(entry.commodity_percentage),
}
@routes.route('/', methods=['GET'])
@common.require_accepts_json
def traffic_ratio_view() -> Any:
"""
handler for /api/traffic_ratio/ requests
response will be formatted as:
.. asjson::
compendium_v2.routes.traffic_ratio.TRAFFIC_RATIO_RESPONSE_SCHEMA
:return:
"""
entries = [traffic_ratio_extract_data(entry) for entry in common.get_data(TrafficRatio)]
return jsonify(entries)
This diff is collapsed.
import json
import jsonschema
from compendium_v2.routes.traffic_ratio import TRAFFIC_RATIO_RESPONSE_SCHEMA
from compendium_v2.routes.network import TRAFFIC_RATIO_RESPONSE_SCHEMA
def test_traffic_ratio_response(client, test_traffic_ratio_data):
rv = client.get(
'/api/traffic-ratio/',
'/api/network/traffic-ratio',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment