From 793838a07c390f166c097df7968b8538ab3e5b13 Mon Sep 17 00:00:00 2001 From: Darius Williams <dswilliams@contractor.usgs.gov> Date: Wed, 11 Jan 2023 13:48:23 -0600 Subject: [PATCH 1/3] Adding temporary page with feature toggle --- CHANGELOG.md | 1 + wdfn-server/config.py | 1 + .../waterdata/templates/temporary_mlp.html | 410 ++++++++++++++++++ wdfn-server/waterdata/views.py | 146 +++++++ 4 files changed, 558 insertions(+) create mode 100644 wdfn-server/waterdata/templates/temporary_mlp.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 56871cea6..414925763 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - The Data Details View now has a reformatted statistics table. - Reusable ExpansionSection component which contains a toggle that will show/hide a section defined with a slot. The toggle labels are configurable as is the initial state. - Route and template for work starting on Search and Filter. +- There is now a feature-toggled page for interpage navigation testing. ### Changed - The IV Hydrograph Legend and the DV Hydrograph legend no longer used D3 rendering code to render the various legend markers. diff --git a/wdfn-server/config.py b/wdfn-server/config.py index 04b6a791a..40761c07b 100644 --- a/wdfn-server/config.py +++ b/wdfn-server/config.py @@ -17,6 +17,7 @@ AFFILIATED_NETWORKS_ENABLED = True DAILY_VALUE_HYDROGRAPH_ENABLED = True MULTI_SITE_HYDROGRAPH_PAGE_ENABLED = True SEARCH_AND_FILTER_PAGE_ENABLED = False +INTERPAGE_NAVIGATION_TEST_PAGE_ENABLED = True DEBUG = False diff --git a/wdfn-server/waterdata/templates/temporary_mlp.html b/wdfn-server/waterdata/templates/temporary_mlp.html new file mode 100644 index 000000000..cf15775e7 --- /dev/null +++ b/wdfn-server/waterdata/templates/temporary_mlp.html @@ -0,0 +1,410 @@ +{% extends 'base.html' %} + +{% import 'macros/components.html' as components %} + +{% if stations|length == 1 %}{% set page_title = stations[0].station_nm | title_case_place_name %}{% endif %} + +{% block extra_head_tags %} + {% if status_code == 200 %} + {% if stations|length == 1 %} + <meta name="description" content="{{ components.Description(stations[0].site_no, location_with_values, parm_grp_summary) }}"> + <!-- tags for Facebook Open Graph --> + <meta property="og:url" content="{{ url_for('monitoring_location', site_no=stations[0].site_no, _external=True) }}"> + <meta property="og:type" content="website"> + <meta property="og:title" content="{{ page_title }}"> + <meta property="og:description" content="{{ components.Description(stations[0].site_no, location_with_values, parm_grp_summary) }}"> + <meta property="og:image" content="{{ config.GRAPH_SERVER_ENDPOINT }}/monitoring-location/{{ stations[0].site_no }}/?parameterCode={{ default_parameter_code }}&width=1000"> + <meta property="og:image:width" content="936"> + <meta property="og:image:height" content="617"> + <meta property="og:image:alt" content="hydrograph for location: {{ stations[0].site_no }}"> + <!-- tags for Twitter Cards --> + <meta name="twitter:card" content="summary_large_image"> + <meta name="twitter:image" content="{{ config.GRAPH_SERVER_ENDPOINT }}/monitoring-location/{{ stations[0].site_no }}/?parameterCode={{ default_parameter_code }}&width=500"> + <meta name="twitter:site" content="@USGS_Water"> + <meta name="twitter:creator" content="@USGS_Water"> + {% endif %} + {% endif %} +{% endblock %} + + +{% block page_css %} + {% if stations|length == 1 %} + {% for css_link in vue_css_links %} + <link rel="stylesheet" href="{{ css_link | asset_url }}" /> + {% endfor %} + {% else %} + {{ super() }} + {% endif %} +{% endblock %} + +{% block page_head_script %} + <script type="application/javascript"> + window.CONFIG = { + 'IV_DATA_ENDPOINT': '{{ config.IV_DATA_ENDPOINT }}', + 'HISTORICAL_IV_DATA_ENDPOINT': '{{ config.HISTORICAL_IV_DATA_ENDPOINT }}', + 'SITE_DATA_ENDPOINT': '{{ config.PUBLIC_SITE_DATA_ENDPOINT }}', + 'STATISTICS_ENDPOINT': '{{ config.STATISTICS_ENDPOINT }}', + 'NWISWEB_INVENTORY_ENDPOINT': '{{ config.NWISWEB_ENDPOINTS.INVENTORY }}', + 'MONITORING_LOCATIONS_OBSERVATIONS_ENDPOINT': '{{ config.MONITORING_LOCATIONS_OBSERVATIONS_ENDPOINT }}', + 'GROUNDWATER_LEVELS_ENDPOINT': '{{ config.GROUNDWATER_LEVELS_ENDPOINT }}', + 'HYDRO_ENDPOINT': '{{ config.HYDRO_ENDPOINT }}', + 'TNM_USGS_TOPO_ENDPOINT': '{{ config.TNM_USGS_TOPO_ENDPOINT }}', + 'TNM_USGS_IMAGERY_ONLY_ENDPOINT': '{{ config.TNM_USGS_IMAGERY_ONLY_ENDPOINT }}', + 'TNM_USGS_IMAGERY_TOPO_ENDPOINT': '{{ config.TNM_USGS_IMAGERY_TOPO_ENDPOINT }}', + 'TNM_HYDRO_ENDPOINT': '{{ config.TNM_HYDRO_ENDPOINT }}', + 'FIM_GIS_ENDPOINT': '{{ config.FIM_GIS_ENDPOINT }}', + 'FIM_ENDPOINT': '{{ config.FIM_ENDPOINT }}', + 'CITIES_ENDPOINT': '{{ config.CITIES_ENDPOINT }}', + 'NLDI_SERVICES_ENDPOINT': '{{ config.NLDI_SERVICES_ENDPOINT }}', + 'NLDI_SERVICES_DISTANCE': '{{ config.NLDI_SERVICES_DISTANCE }}', + 'WATERWATCH_ENDPOINT': '{{ config.WATERWATCH_ENDPOINT }}', + 'GRAPH_SERVER_ENDPOINT': '{{ config.GRAPH_SERVER_ENDPOINT }}', + 'HIVIS_API_CAMERA_ENDPOINT': '{{ config.HIVIS_API_CAMERA_ENDPOINT }}', + 'HIVIS_APPLICATION_ENDPOINT': '{{ config.HIVIS_APPLICATION_ENDPOINT }}', + 'STATIC_URL': '{{ config.STATIC_ROOT }}', + 'WATERALERT_SUBSCRIPTION': '{{ config.WATERALERT_SUBSCRIPTION }}', + 'SENSOR_THINGS_ENDPOINT': '{{ config.SENSOR_THINGS_ENDPOINT }}', + 'DISCRETE_SUMMARY_ENDPOINT': '{{ url_for("discrete_summary", monitoring_location_id="ID") }}', + 'locationTimeZone': '{{ time_zone }}', + 'PROVISIONAL_DATA_STATEMENT_PAGE': '{{ url_for("provisional_data_statement") }}', + 'DATA_DETAILS_VIEW_ENABLED': '{{ config.DATA_DETAILS_VIEW_ENABLED }}' + } + {% if iv_period_of_record %} + window.CONFIG.ivPeriodOfRecord = {{ iv_period_of_record | tojson }}; + {% endif %} + {% if gw_period_of_record %} + window.CONFIG.gwPeriodOfRecord = {{ gw_period_of_record | tojson }}; + {% endif %} + </script> + {% if stations|length == 1 %} + {% with site=stations[0] %} + <script type="application/ld+json"> + {% include 'monitoring_location_jsonld.txt' %} + </script> + {% endwith %} + {% endif %} +{% endblock page_head_script %} + +{% block page_header %} + {% include 'partials/monitoring_location_header.html' %} +{% endblock %} + +{% block content %} + <div id="monitoring-location-page-container" class="grid-container content-container usa-prose"> + {% if status_code == 200 %} + {% if stations|length > 1 %} + <h1>Multiple sites found</h1> + <h3>Please pick a site:</h3> + <table class="usa-table usa-table--borderless"> + <thead> + <tr> + <th scope="col">Agency</th> + <th scope="col">Site number</th> + <th scope="col">Site name</th> + </tr> + </thead> + <tbody> + {% for site in stations %} + <tr> + <td><a class="usa-link" href="{{ url_for('monitoring_location', site_no=site.site_no, agency_cd=site.agency_cd) }}">{{ site.agency_cd }}</a></td> + <td> {{ site.site_no }} </td> + <td> {{ site.station_nm }} </td> + </tr> + {% endfor %} + </tbody> + </table> + + {% else %} + <div class="site-header"> + {% with site_no=stations[0].site_no %}{% include 'partials/social_share.html' %}{% endwith %} + + {% if sims_data and sims_data['alert'] != None %} + {% if sims_data['alert']['alert_type_id'] == 10 %} + {% with alert_class='usa-alert usa-alert--error usa-alert--slim', alert_text=sims_data['alert']['alert_text'] %} + {% include 'partials/uswds-alert.html' %} + {% endwith %} + {% else %} + {% with alert_class='usa-alert usa-alert--warning usa-alert--slim', alert_text=sims_data['alert']['alert_text'] %} + {% include 'partials/uswds-alert.html' %} + {% endwith %} + {% endif %} + {% endif %} + + {% if sims_data and sims_data['endangermentStatus'] != None %} + {% if sims_data['endangermentStatus']['fundingStatus'] == 'Discontinued' %} + {% with alert_class='usa-alert usa-alert--error usa-alert--slim', alert_text=sims_data['endangermentStatus']['alertMessageText'] %} + {% include 'partials/uswds-alert.html' %} + {% endwith %} + {% elif sims_data['endangermentStatus']['fundingStatus'] == 'Rescued'%} + {% with alert_class='usa-alert usa-alert--success usa-alert--slim', alert_text=sims_data['endangermentStatus']['alertMessageText'] %} + {% include 'partials/uswds-alert.html' %} + {% endwith %} + {% else %} + {% with alert_class='usa-alert usa-alert--warning usa-alert--slim', alert_text=sims_data['endangermentStatus']['alertMessageText'] %} + {% include 'partials/uswds-alert.html' %} + {% endwith %} + {% endif %} + {% endif %} + + <div> + <span class="usa-tag">Important</span> + {% if iv_period_of_record %} + <a id="legacy-page-link" + class="usa-link" + aria-describedby="legacy-page-link-help" + href="{{ config.NWISWEB_ENDPOINTS.UV }}?site_no={{ stations[0].site_no }}&legacy=1" target="_blank" rel="noopener"> + Legacy real-time page + </a> + {{ components.QuestionTooltip('legacy-current-conditions-help', 'top', 'If you need the legacy system, click here. Over the next few years, the legacy pages will be completely replaced with new pages like this one.') }} + {% else %} + <a id="legacy-inventory-link" + class="usa-link" + aria-describedby="legacy-inventory-link-help" + href="{{ config.NWISWEB_ENDPOINTS.INVENTORY }}?site_no={{ stations[0].site_no }}&agency_cd={{ stations[0].agency_cd }}" target="_blank" rel="noopener"> + Inventory Page + </a> + {{ components.QuestionTooltip('legacy-inventory-link-help', 'top', 'View the Water Data for the Nation site inventory.') }} + {% endif %} + </div> + + </div> + {% if browser == 'IE' %} + <div id="static-graph-div"></div> + <div class="usa-alert usa-alert--warning"> + <div class="usa-alert__body"> + <h3 class="usa-alert__heading">Please switch from Internet Explorer</h3> + <p class="usa-alert__text"> + Internet Explorer is only minimally supported on this website and many features are disabled. + This page is best viewed in recent versions of Edge, Firefox, Chrome or Safari. + </p> + </div> + </div> + {% endif %} + {% if browser != 'IE' %} + {{ components.TimeSeriesComponent(stations[0], default_parameter_code, iv_period_of_record, gw_period_of_record) }} + + <div class="wdfn-component" data-component="cameras" data-siteno="{{ stations[0].site_no }}"></div> + + {% if config.DAILY_VALUE_HYDROGRAPH_ENABLED and is_groundwater_location %} + <div id="dv-accordion" class="wdfn-accordion usa-accordion"> + <div> + <h3 class="usa-accordion__heading"> + <button type="button" + class="usa-accordion__button" + aria-expanded="true" aria-controls="dv-graph-container" + ga-on="click" ga-event-category="accordion" ga-event-action="interactionWithDVAccordion"> + Groundwater data {{ components.BetaTag() }} + </button> + </h3> + <div id="dv-graph-container"> + {{ components.DailyValueTimeSeriesComponent(stations[0].site_no, stations[0].agency_cd) }} + </div> + </div> + </div> + {% endif %} + + {% if stations[0].dec_lat_va and stations[0].dec_long_va %} + {{ components.MapComponent(stations[0].site_no, stations[0].dec_lat_va, stations[0].dec_long_va) }} + {% endif %} + + {% if config.MULTI_SITE_HYDROGRAPH_PAGE_ENABLED %} + <div class="wdfn-component" + data-component="discrete-samples" + data-site-no="{{ stations[0].site_no }}" + data-agency-cd="{{ stations[0].agency_cd }}"> + </div> + {% endif %} + + {% if affiliated_networks_enabled %} + <div class="wdfn-accordion usa-accordion"> + <h3 class="usa-accordion__heading"> + <button type="button" + class="usa-accordion__button" + aria-expanded="true" aria-controls="network-list" + ga-on="click" ga-event-category="accordion" ga-event-action="interactionWithAffiliatedNetworkAccordion"> + Affiliated networks {{ components.BetaTag() }} + </button> + </h3> + <div id="network-list" class="usa-accordion__content"> + {{ components.NetworkListComponent(stations[0].site_no) }} + </div> + </div> + {% endif %} + + {% if parm_grp_summary %} + <div class="wdfn-accordion usa-accordion"> + <h2 class="usa-accordion__heading"> + <button type="button" + class="usa-accordion__button" + aria-expanded="false" aria-controls="site-data-summary-container" + ga-on="click" ga-event-category="accordion" ga-event-action="interactionWithDataSummaryAccordion"> + Summary of all available data + </button> + </h2> + <div id="site-data-summary-container" class="usa-accordion__content"> + <table class="usa-table" id="site-data-summary"> + <thead> + <tr> + <th scope="col">USGS Parameter Group</th> + <th scope="col">Data Types</th> + <th scope="col">Start Date</th> + <th scope="col">End Date</th> + </tr> + </thead> + <tbody> + {% for grp in parm_grp_summary %} + <tr> + <th scope="row">{% if grp.name %}{{ grp.name }}{% else %}<sub>n/a</sub>{% endif %}</th> + <td>{{ grp.data_types }}</td> + <td>{{ grp.start_date|date_to_string }}</td> + <td>{{ grp.end_date|date_to_string }}</td> + </tr> + {% endfor %} + </tbody> + </table> + <a class="usa-link" href="{{ config.NWISWEB_ENDPOINTS.INVENTORY}}?site_no={{ stations[0].site_no }}&agency_cd={{ stations[0].agency_cd }}" target="_blank" rel="noopener">Water Data for the Nation inventory</a> + </div> + </div> + {% endif %} + + <div class="wdfn-accordion usa-accordion"> + <h2 class="usa-accordion__heading"> + <button type="button" + class="usa-accordion__button" + aria-expanded="false" aria-controls="site-summary-container" + ga-on="click" ga-event-category="accordion" ga-event-action="interactionWithMetadataAccordion"> + Location metadata + </button> + </h2> + <div id="site-summary-container" class="usa-accordion__content"> + <p id="site-description">{{ components.Description(stations[0].site_no, location_with_values, parm_grp_summary) }} + {% if browser == 'IE' %} + {{ components.DescriptionInternetExplorerLinks(stations[0].site_no, location_with_values, parm_grp_summary) }} + {% endif %} + </p> + <div id="sims-data-observations"> + {% if sims_data and sims_data['dataObservationContext'] != None %} + {{ sims_data['dataObservationContext']['observation_text'] | safe }} + {% endif %} + </div> + <table class="usa-table" id="site-summary"> + <thead> + <tr> + <th scope="col">Metadata Element</th> + <th scope="col">Location Metadata</th> + <th scope="col">Metadata Code</th> + </tr> + </thead> + <tbody> + {% for key, value in location_with_values.items() %} + <tr> + <th + {% if STATION_FIELDS_D[key].description %}aria-describedby="{{ key }}"{% endif %} + scope="row"> + {{ STATION_FIELDS_D[key].name }} + {% if STATION_FIELDS_D[key].description %} + {{ components.QuestionTooltip(key, 'right', STATION_FIELDS_D[key].description) }} + {% endif %} + </th> + <td class="loc-metadata"> + {% if value.url %} + <a href="{{ value.url }}">{{ value.name }}</a> + {% else %} + {{ value.name }} + {% endif %} + {% if value.desc %} + {{ components.QuestionTooltip(value.code, 'right', value.desc) }} + {% endif %} + </td> + <td>{% if value.code != value.name %}{{ value.code }}{% else %}<sub>n/a</sub>{% endif %}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + </div> + {% endif %} + + {% if cooperators.has_service_error %} + <p>Sorry, the cooperator service isn't returning the needed information. + Please try refreshing the page. + </p> + {% elif cooperators.customers %} + <div> + <p>Operated in cooperation with:</p> + {% for cooperator in cooperators.customers | sort(attribute='Name') %} + <figure class="cooperator-logo"> + <a class="usa-link" href="{{ cooperator.URL }}"> + <img src="{{ cooperator.IconURL | https_url }}" alt="logo for {{ cooperator.Name }}" height="50"> + </a> + <figcaption><a class="usa-link"href="{{ cooperator.URL }}">{{ cooperator.Name }}</a></figcaption> + </figure> + {% endfor %} + </div> + {% endif %} + {% endif %} + + {% else %} + <h1>Error: HTTP {{ status_code }} -- {{ reason }}</h1> + {% endif %} + </div> +{% endblock %} + +{% block javascript_bundle %} + {% if browser == 'IE' %} + <script src="{{ 'scripts/wdfnviz.js' | asset_url }}"></script> + <script type="application/javascript"> + document.addEventListener('DOMContentLoaded', function() { + // This script inserts a PNG image generated by the WDFN Graph Server for the Internet Explorer Browser + // which cannot render the interactive hydrograph. + // The code needs to be in the Flask application, because Internet Explorer errors out immediately + // when attempting to run the JavaScript of the Redux application. Since we have no JS post pre/post processing + // in the Flask application, we need to use Plain Old JavaScript. The Graph Server requires + // a URL with the general format https://labs.waterdata.usgs.gov/api/graph-images/monitoring-location/{site number}/?parameterCode={parameter code}. + // However, other permutations are possible. For more information see https://labs.waterdata.usgs.gov/api/graph-images/api-docs + var urlString = window.location.href; + var staticGraphContainer = document.getElementById('static-graph-div'); + + if (!CONFIG.ivPeriodOfRecord) { + var incompatibleURLMessageTag = document.createElement('H2'); + var message = document.createTextNode('Sorry, the graph cannot be displayed.'); + var subMessageTag = document.createElement('p'); + var subMessage = document.createTextNode('Please check the URL used. The URL must have the form of ' + + 'https://waterdata.usgs.gov/monitoring-location/{site number}/#parameterCode={the desired parameter code}') + incompatibleURLMessageTag.appendChild(message); + staticGraphContainer.appendChild(incompatibleURLMessageTag); + subMessageTag.appendChild(subMessage) + staticGraphContainer.appendChild(subMessage) + } else { + var splitUrl = urlString.split('#'); + var splitUrlOnLocation = splitUrl[0].split('/monitoring-location/') + var siteNumber = splitUrlOnLocation[1].slice(0, -1); + var paramString = splitUrl[1]; + var allParameterCodes = Object.keys(CONFIG.ivPeriodOfRecord); + var defaultParameterCode; + + if (allParameterCodes.indexOf('00065') !== -1) { + defaultParameterCode = '00065'; + } else if (allParameterCodes.indexOf('00060') !== -1) { + defaultParameterCode = '00060'; + } else { + defaultParameterCode = allParameterCodes[0]; + } + + if (typeof (paramString) === 'undefined') { + paramString = 'parameterCode=' + defaultParameterCode; + } + + var graphServerURL = '{{ config.GRAPH_SERVER_ENDPOINT }}/monitoring-location/' + siteNumber + '/?' + paramString; + var altText = 'hydrograph for monitoring location ' + siteNumber; + var staticGraphImage = document.createElement('img'); + staticGraphImage.setAttribute('src', graphServerURL); + staticGraphImage.setAttribute('alt', altText); + staticGraphContainer.appendChild(staticGraphImage); + } + }); + </script> + {% else %} + <script type="module" crossorigin="" src="{{ 'monitoringLocation.js' | asset_url }}"></script> + {% endif %} +{% endblock %} diff --git a/wdfn-server/waterdata/views.py b/wdfn-server/waterdata/views.py index 6a1caa0a3..8447479c6 100644 --- a/wdfn-server/waterdata/views.py +++ b/wdfn-server/waterdata/views.py @@ -296,6 +296,152 @@ async def monitoring_location(site_no): return make_response(render_template(template, **context), http_code) +@app.route('/temporary-mlp/<site_no>/', methods=['GET']) +async def temporary_mlp(site_no): + # pylint: disable=too-many-locals + # pylint: disable=too-many-statements + # TODO: refactor to use more utility functions so that this doesn't have too many locals + """ + Monitoring Location view + :param site_no: USGS site number + """ + agency_cd = request.args.get('agency_cd', '') + + async with aiohttp.ClientSession() as session, aiohttp.ClientSession(timeout=client_timeout) as timeout_session: + site_data_task = asyncio.create_task(get_site_data(session, site_no, agency_cd)) + period_of_record_task = asyncio.create_task(get_period_of_record(session, site_no, agency_cd)) + cooperators_task = asyncio.create_task(get_cooperators(timeout_session, site_no)) + + try: + site_data_resp, period_of_record_resp, sifta_resp = \ + await asyncio.gather(site_data_task, period_of_record_task, cooperators_task) + except asyncio.exceptions.TimeoutError: + sifta_resp = (True, []) + site_data_resp, period_of_record_resp, = \ + await asyncio.gather(site_data_task, period_of_record_task) + site_status, site_status_reason, site_data = site_data_resp + cooperators = { + 'has_service_error': sifta_resp[0], + 'customers': sifta_resp[1] + } + + if site_status == 200: + template = 'temporary_mlp.html' + context = { + 'status_code': 200, + 'stations': site_data, + 'STATION_FIELDS_D': STATION_FIELDS_D + } + + if len(site_data) == 1: + unique_site = site_data[0] + + _, _, period_of_record = period_of_record_resp + iv_period_of_record = get_period_of_record_by_parm_cd(period_of_record, 'uv') + gw_period_of_record = get_period_of_record_by_parm_cd(period_of_record, 'gw') + + # Some Alaskan HUC numbers are non-standard so check that the HUC of the location + # has an official HUC (Hydrologic Unit Code) + is_huc_in_lookup_file = unique_site.get('huc_cd') in app.config['HUC_LOOKUP']['hucs'] + + site_dataseries = [ + get_disambiguated_values( + param_datum, + app.config['NWIS_CODE_LOOKUP'], + {}, + app.config['HUC_LOOKUP'], + is_huc_in_lookup_file + ) + for param_datum in period_of_record + ] + grouped_dataseries = rollup_dataseries(site_dataseries) + available_data_types = set(param_datum['data_type_cd'] for param_datum in period_of_record) + + location_with_values = get_disambiguated_values( + unique_site, + app.config['NWIS_CODE_LOOKUP'], + app.config['COUNTRY_STATE_COUNTY_LOOKUP'], + app.config['HUC_LOOKUP'], + is_huc_in_lookup_file + ) + + try: + site_owner_state = ( + location_with_values['district_cd']['abbreviation'] + if location_with_values['district_cd']['abbreviation'] + else location_with_values['state_cd']['abbreviation'] + ) + except KeyError: + site_owner_state = None + + if site_owner_state is not None: + email_for_data_questions = \ + app.config['EMAIL_TARGET']['contact'].format(state_district_code=site_owner_state.lower()) + else: + email_for_data_questions = app.config['EMAIL_TARGET']['report'] + + # Get the time zone for the location + time_zone = time_zone_service.get_iana_time_zone(unique_site.get('dec_lat_va', ''), + unique_site.get('dec_long_va', '')) + + location_identifier = f"{unique_site.get('agency_cd')}-{site_no}" + + sims_data = system_information_management_service.get_sims_data(location_identifier) + + is_groundwater_location = site_data[0]['site_tp_cd'] in app.config['GROUNDWATER_CODES'] + + context = { + 'browser': user_agent_parser.Parse(request.user_agent.string)['user_agent']['family'], + 'status_code': site_status, + 'stations': site_data, + 'location_with_values': location_with_values, + 'STATION_FIELDS_D': STATION_FIELDS_D, + 'sims_data': sims_data, + 'available_data_types': available_data_types, + 'time_zone': time_zone if time_zone else 'local', + 'iv_period_of_record': iv_period_of_record, + 'gw_period_of_record': gw_period_of_record, + 'default_parameter_code': get_default_parameter_code(iv_period_of_record, gw_period_of_record), + 'parm_grp_summary': grouped_dataseries, + 'cooperators': cooperators, + 'email_for_data_questions': email_for_data_questions, + 'referring_page_type': 'monitoring', + 'is_groundwater_location': is_groundwater_location, + 'affiliated_networks_enabled': app.config['AFFILIATED_NETWORKS_ENABLED'], + 'vue_css_links': stylesheet_links('src/scripts/monitoring-location/index.js') + } + + http_code = 200 + elif 400 <= site_status < 500: + template = 'monitoring_location.html' + context = {'status_code': site_status, 'reason': site_status_reason} + http_code = 200 + elif 500 <= site_status <= 511: + template = 'errors/500.html' + context = {} + http_code = 503 + else: + template = 'errors/500.html' + context = {} + http_code = 500 + + if request.headers.get('Accept', '').lower() == 'application/ld+json': + if site_status == 200 and len(site_data) == 1: + json_ld = render_template('monitoring_location_jsonld.txt', + site=context['stations'][0], + location_with_values=context['location_with_values'], + parm_grp_summary=context['parm_grp_summary'], + default_parameter_code=context['default_parameter_code'] + ) + else: + json_ld = '{}' + return app.response_class(json_ld, status=site_status, mimetype='application/ld+json') + if app.config['INTERPAGE_NAVIGATION_TEST_PAGE_ENABLED']: + return make_response(render_template(template, **context), http_code) + + return abort(404) + + @app.route('/multi-site-hydrograph/') def multi_site_hydrograph(): """Render the IV data availability statement page.""" -- GitLab From 78cd5ab85ba62ffa07f22bc5cb868f4fe17dbeb6 Mon Sep 17 00:00:00 2001 From: Darius Williams <dswilliams@contractor.usgs.gov> Date: Wed, 11 Jan 2023 14:03:36 -0600 Subject: [PATCH 2/3] Removing some error handling to lower complexity --- wdfn-server/waterdata/views.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/wdfn-server/waterdata/views.py b/wdfn-server/waterdata/views.py index 8447479c6..827820269 100644 --- a/wdfn-server/waterdata/views.py +++ b/wdfn-server/waterdata/views.py @@ -412,18 +412,6 @@ async def temporary_mlp(site_no): } http_code = 200 - elif 400 <= site_status < 500: - template = 'monitoring_location.html' - context = {'status_code': site_status, 'reason': site_status_reason} - http_code = 200 - elif 500 <= site_status <= 511: - template = 'errors/500.html' - context = {} - http_code = 503 - else: - template = 'errors/500.html' - context = {} - http_code = 500 if request.headers.get('Accept', '').lower() == 'application/ld+json': if site_status == 200 and len(site_data) == 1: @@ -438,7 +426,7 @@ async def temporary_mlp(site_no): return app.response_class(json_ld, status=site_status, mimetype='application/ld+json') if app.config['INTERPAGE_NAVIGATION_TEST_PAGE_ENABLED']: return make_response(render_template(template, **context), http_code) - + return abort(404) -- GitLab From ed3ed9ecc0d841145ac12f2de296eae9b3dfaedc Mon Sep 17 00:00:00 2001 From: Darius Williams <dswilliams@contractor.usgs.gov> Date: Wed, 11 Jan 2023 14:16:45 -0600 Subject: [PATCH 3/3] Lint --- wdfn-server/waterdata/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wdfn-server/waterdata/views.py b/wdfn-server/waterdata/views.py index 827820269..12859a221 100644 --- a/wdfn-server/waterdata/views.py +++ b/wdfn-server/waterdata/views.py @@ -299,7 +299,6 @@ async def monitoring_location(site_no): @app.route('/temporary-mlp/<site_no>/', methods=['GET']) async def temporary_mlp(site_no): # pylint: disable=too-many-locals - # pylint: disable=too-many-statements # TODO: refactor to use more utility functions so that this doesn't have too many locals """ Monitoring Location view @@ -319,7 +318,7 @@ async def temporary_mlp(site_no): sifta_resp = (True, []) site_data_resp, period_of_record_resp, = \ await asyncio.gather(site_data_task, period_of_record_task) - site_status, site_status_reason, site_data = site_data_resp + site_status, site_data = site_data_resp cooperators = { 'has_service_error': sifta_resp[0], 'customers': sifta_resp[1] -- GitLab