Skip to content
Snippets Groups Projects
Commit f0d02272 authored by Saket Agrahari's avatar Saket Agrahari
Browse files

[COMP-344] : Weather Map

parent 7b49e456
No related branches found
No related tags found
1 merge request!113[COMP-344] : Weather Map
......@@ -28,6 +28,7 @@ import NetworkAlienWaveInternalPage from "./pages/NetworkAlienWaveInternal";
import OPsAutomationPage from "./pages/OPsAutomation";
import NetworkAutomationPage from "./pages/NetworkAutomation";
import NetworkTrafficUrlPage from "./pages/NetworkTrafficUrl";
import NetworkWeatherMapPage from "./pages/NetworkWeatherMap";
const router = createBrowserRouter([
{ path: "/budget", element: <BudgetPage /> },
......@@ -67,6 +68,7 @@ const router = createBrowserRouter([
{ path: "/ops-automation", element: <OPsAutomationPage /> },
{ path: "/network-automation", element: <NetworkAutomationPage /> },
{ path: "/traffic-stats", element: <NetworkTrafficUrlPage /> },
{ path: "/weather-map", element: <NetworkWeatherMapPage /> },
{ path: "*", element: <Landing /> },
]);
......
......@@ -79,6 +79,11 @@ export interface TrafficStatistics extends NrenAndYearDatapoint {
urls: (string | null)[]
}
export interface WeatherMap extends NrenAndYearDatapoint {
weather_map: boolean,
url: (string | null)
}
export interface NrenStaff extends NrenAndYearDatapoint {
permanent_fte: number,
subcontracted_fte: number,
......
......@@ -40,6 +40,11 @@ const NetworkSidebar = () => {
<span>Traffic Statistics </span>
</Link>
</Row>
<Row>
<Link to="/weather-map" className="link-text-underline">
<span>NREN Online Network Weather Maps </span>
</Link>
</Row>
<hr className="fake-divider" />
<h6 className="section-title" >Alienwave</h6>
<Row>
......
......@@ -188,6 +188,11 @@ function CompendiumData(): ReactElement {
<span>Traffic Statistics </span>
</Link>
</Row>
<Row>
<Link to="/weather-map" className="link-text-underline">
<span>NREN Online Network Weather Maps </span>
</Link>
</Row>
</div>
</CollapsibleBox>
<CollapsibleBox title={Sections.Services} startCollapsed>
......
import React, { useContext } from "react";
import { Table } from "react-bootstrap";
import { WeatherMap } from "../Schema";
import { createMatrixDataLookup } from "../helpers/dataconversion";
import DataPage from "../components/DataPage";
import Filter from "../components/graphing/Filter";
import { Sections } from "../helpers/constants";
import { FilterSelectionContext } from "../helpers/FilterSelectionProvider";
import ChartContainer from "../components/graphing/ChartContainer";
import { useData } from "../helpers/useData";
function NetworkWeatherMapPage(): React.ReactElement {
const { filterSelection, setFilterSelection } = useContext(FilterSelectionContext);
const { data: pertTeamData, years, nrens } = useData<WeatherMap>('/api/network/weather-map', setFilterSelection);
const selectedData = (pertTeamData).filter(data =>
filterSelection.selectedYears.includes(data.year) && filterSelection.selectedNrens.includes(data.nren)
);
const dataLookup = createMatrixDataLookup(selectedData, 'weather_map');
const filterNode = <Filter
filterOptions={{ availableYears: [...years], availableNrens: [...nrens.values()] }}
filterSelection={filterSelection}
setFilterSelection={setFilterSelection}
coloredYears
/>
const showYears = [...filterSelection.selectedYears.filter(year => years.has(year))].sort();
return (
<DataPage title="NREN Online Network Weather Maps "
description="This table shows the URL links to NREN websites showing weather map, if available."
category={Sections.Network} filter={filterNode}
data={selectedData} filename="weather_map_nrens_per_year">
<>
<ChartContainer>
<Table borderless className='compendium-table'>
<thead>
<tr>
<th className='nren-column'>NREN</th>
<th className='year-column'>Year</th>
<th className='blue-column'>Network Weather Map</th>
</tr>
</thead>
<tbody>
{Array.from(dataLookup.entries()).map(([nren, nrenMap]) => (
Array.from(nrenMap.entries()).map(([choice, yearMap]) => (
Array.from(yearMap.entries()).map(([year, weatherMap], yearIndex) => (
weatherMap.url && (
<tr key={nren +choice+ year} className='dotted-border'>
<td className='pt-3 nren-column text-nowrap'>{yearIndex == 0 && nren}</td>
<td className='pt-3 year-column'>{year}</td>
<td className='pt-3 blue-column'>
<ul>
<li>
<a href={weatherMap.url} target="_blank" rel="noopener noreferrer"
style={{ textDecoration: 'none' }}>
{weatherMap.url}
</a>
</li>
</ul>
</td>
</tr>
)
))
))
))
}
</tbody>
</Table>
</ChartContainer>
</>
</DataPage>
);
}
export default NetworkWeatherMapPage;
from typing import Any
from compendium_v2.db.presentation_models import PertTeam, PassiveMonitoring, AlienWave, OpsAutomation, \
NetworkAutomation, TrafficStatistics
NetworkAutomation, TrafficStatistics, WeatherMap
from compendium_v2.routes import common
from flask import Blueprint, jsonify
......@@ -110,7 +110,7 @@ NETWORK_AUTOMATION_RESPONSE_SCHEMA = {
TRAFFIC_STATISTICS_RESPONSE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'alien_wave': {
'traffic_statistics': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
......@@ -124,7 +124,27 @@ TRAFFIC_STATISTICS_RESPONSE_SCHEMA = {
}
},
'type': 'array',
'items': {'$ref': '#/definitions/alien_wave'}
'items': {'$ref': '#/definitions/traffic_statistics'}
}
WEATHER_MAP_RESPONSE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'weather_map': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
'nren_country': {'type': 'string'},
'year': {'type': 'integer'},
'weather_map': {'type': 'string'},
'url': {'type': 'string'},
},
'required': ['nren', 'nren_country', 'year'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/weather_map'}
}
......@@ -346,3 +366,39 @@ def traffic_stats_extract_data_view() -> Any:
entries.append(traffic_stats_extract_data(entry))
return jsonify(entries)
def weather_map_extract_data(weather_map: WeatherMap) -> dict:
return {
'nren': weather_map.nren.name,
'nren_country': weather_map.nren.country,
'year': int(weather_map.year),
'weather_map': str(weather_map.weather_map),
'url': weather_map.url
}
@routes.route('/weather-map', methods=['GET'])
@common.require_accepts_json
def weather_map_extract_data_view() -> Any:
"""
handler for /api/network/weather-map requests
Endpoint for getting the fibre operation models the NREN.
This endpoint retrieves fibre operation model that of the NREN.
response will be formatted as:
.. asjson::
compendium_v2.routes.network.WEATHER_MAP_RESPONSE_SCHEMA
:return:
"""
entries = []
records = common.get_data(WeatherMap)
for entry in records:
entries.append(weather_map_extract_data(entry))
return jsonify(entries)
This diff is collapsed.
......@@ -526,6 +526,28 @@ def test_traffic_statistics_data(app):
db.session.commit()
@pytest.fixture
def test_weather_map_data(app):
with app.app_context():
nrens_and_years = [('nren1', 2019), ('nren1', 2020), ('nren1', 2021), ('nren2', 2019), ('nren2', 2021)]
nren_names = set(ny[0] for ny in nrens_and_years)
nren_dict = {nren_name: presentation_models.NREN(name=nren_name, country='country') for nren_name in nren_names}
db.session.add_all(nren_dict.values())
for (nren_name, year) in nrens_and_years:
nren = nren_dict[nren_name]
db.session.add(presentation_models.WeatherMap(
nren=nren,
year=year,
weather_map=True,
url="stats.inima.al"
))
db.session.commit()
@pytest.fixture
def test_traffic_data(app):
with app.app_context():
......
......@@ -5,7 +5,7 @@ from compendium_v2.routes.fibre_light import FIBRE_LIGHT_RESPONSE_SCHEMA
from compendium_v2.routes.monitoring_tools import MONITORING_TOOLS_RESPONSE_SCHEMA
from compendium_v2.routes.network import PERT_TEAM_RESPONSE_SCHEMA, PASSIVE_MONITORING_RESPONSE_SCHEMA, \
ALIEN_WAVE_RESPONSE_SCHEMA, OPS_AUTOMATION_RESPONSE_SCHEMA, NETWORK_AUTOMATION_RESPONSE_SCHEMA, \
TRAFFIC_STATISTICS_RESPONSE_SCHEMA
TRAFFIC_STATISTICS_RESPONSE_SCHEMA, WEATHER_MAP_RESPONSE_SCHEMA
def test_pert_team_response(client, test_pert_team_data):
......@@ -86,3 +86,13 @@ def test_traffic_statistics_response(client, test_traffic_statistics_data):
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, TRAFFIC_STATISTICS_RESPONSE_SCHEMA)
assert result
def test_weather_map_response(client, test_weather_map_data):
rv = client.get(
'/api/network/weather-map',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, WEATHER_MAP_RESPONSE_SCHEMA)
assert result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment