From 2e994f31a736a77f7d7577c7cca4007e44f71379 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Wed, 24 Nov 2021 11:39:18 +0100 Subject: [PATCH 01/20] Bump package --- src/FunderMaps.Infrastructure/FunderMaps.Infrastructure.csproj | 2 +- src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/FunderMaps.Infrastructure/FunderMaps.Infrastructure.csproj b/src/FunderMaps.Infrastructure/FunderMaps.Infrastructure.csproj index 8e04764b..d0088442 100644 --- a/src/FunderMaps.Infrastructure/FunderMaps.Infrastructure.csproj +++ b/src/FunderMaps.Infrastructure/FunderMaps.Infrastructure.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs b/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs index 93edace9..3d490c1e 100644 --- a/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs +++ b/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs @@ -7,7 +7,6 @@ namespace FunderMaps.Webservice.Controllers; -// FUTURE: Split logic into analysis, risk index, statistics controller. // FUTURE: Drop the 'product' uri prefix. // FUTURE: Drop the 'v' uri version prefix. /// From a392089360116aecb0e91f73f44516fe3364dbd9 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 14:07:17 +0100 Subject: [PATCH 02/20] Geocoder parser in db --- database/fundermaps_base.sql | 110 +++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/database/fundermaps_base.sql b/database/fundermaps_base.sql index 093463b8..a744968e 100644 --- a/database/fundermaps_base.sql +++ b/database/fundermaps_base.sql @@ -373,6 +373,51 @@ ALTER DOMAIN geocoder.geocoder_id OWNER TO fundermaps; COMMENT ON DOMAIN geocoder.geocoder_id IS 'Domain for our internal geocoder identifier.'; +-- +-- Name: id_type; Type: TYPE; Schema: geocoder; Owner: postgres +-- + +CREATE TYPE geocoder.id_type AS ENUM ( + 'fundermaps', + 'nl_bag_building', + 'nl_bag_berth', + 'nl_bag_posting', + 'nl_bag_address', + 'nl_cbs_neighborhood', + 'nl_cbs_district', + 'nl_cbs_municipality', + 'nl_cbs_state' +); + + +ALTER TYPE geocoder.id_type OWNER TO postgres; + +-- +-- Name: TYPE id_type; Type: COMMENT; Schema: geocoder; Owner: postgres +-- + +COMMENT ON TYPE geocoder.id_type IS 'Geocoder identifier type.'; + + +-- +-- Name: id_parser_tuple; Type: TYPE; Schema: geocoder; Owner: postgres +-- + +CREATE TYPE geocoder.id_parser_tuple AS ( + type geocoder.id_type, + id text +); + + +ALTER TYPE geocoder.id_parser_tuple OWNER TO postgres; + +-- +-- Name: TYPE id_parser_tuple; Type: COMMENT; Schema: geocoder; Owner: postgres +-- + +COMMENT ON TYPE geocoder.id_parser_tuple IS 'Geocoder identifier parser resultset.'; + + -- -- Name: year; Type: DOMAIN; Schema: geocoder; Owner: fundermaps -- @@ -2460,6 +2505,63 @@ $$; ALTER FUNCTION data.get_restoration_cost(foundation_type report.foundation_type, surface_area numeric) OWNER TO fundermaps; +-- +-- Name: id_parser(text); Type: FUNCTION; Schema: geocoder; Owner: fundermaps +-- + +CREATE FUNCTION geocoder.id_parser(input text) RETURNS geocoder.id_parser_tuple + LANGUAGE plpgsql PARALLEL SAFE + AS $_$ +DECLARE + ret geocoder.id_parser_tuple; + id_low text := trim(lower(input)); + id_up text := trim(upper(input)); +BEGIN + CASE + -- FunderMaps internal ID + when id_low LIKE 'gfm-%' then select 'fundermaps', id_low into ret; + -- NL BAG ID + when id_up LIKE 'NL.IMBAG.PAND.%' then select 'nl_bag_building', id_up into ret; + when id_up LIKE 'NL.IMBAG.LIGPLAATS.%' then select 'nl_bag_berth', id_up into ret; + when id_up LIKE 'NL.IMBAG.STANDPLAATS.%' then select 'nl_bag_posting', id_up into ret; + when id_up LIKE 'NL.IMBAG.NUMMERAANDUIDING.%' then select 'nl_bag_address', id_up into ret; + -- NL BAG legacy ID + when id_low ~ '^\d{4}10\d{10}$' then select 'nl_bag_building', 'NL.IMBAG.PAND.' || id_low into ret; + when id_low ~ '^\d{4}02\d{10}$' then select 'nl_bag_berth', 'NL.IMBAG.LIGPLAATS.' || id_low into ret; + when id_low ~ '^\d{4}03\d{10}$' then select 'nl_bag_posting', 'NL.IMBAG.STANDPLAATS.' || id_low into ret; + when id_low ~ '^\d{4}20\d{10}$' then select 'nl_bag_address', 'NL.IMBAG.NUMMERAANDUIDING.' || id_low into ret; + -- NL BAG legacy invalid ID + when id_low ~ '^\d{3}10\d{10}$' then select 'nl_bag_building', 'NL.IMBAG.PAND.0' || id_low into ret; + when id_low ~ '^\d{3}02\d{10}$' then select 'nl_bag_berth', 'NL.IMBAG.LIGPLAATS.0' || id_low into ret; + when id_low ~ '^\d{3}03\d{10}$' then select 'nl_bag_posting', 'NL.IMBAG.STANDPLAATS.0' || id_low into ret; + when id_low ~ '^\d{3}20\d{10}$' then select 'nl_bag_address', 'NL.IMBAG.NUMMERAANDUIDING.0' || id_low into ret; + -- NL BAG legacy invalid ID + when id_low ~ '^\d{2}10\d{10}$' then select 'nl_bag_building', 'NL.IMBAG.PAND.00' || id_low into ret; + when id_low ~ '^\d{2}02\d{10}$' then select 'nl_bag_berth', 'NL.IMBAG.LIGPLAATS.00' || id_low into ret; + when id_low ~ '^\d{2}03\d{10}$' then select 'nl_bag_posting', 'NL.IMBAG.STANDPLAATS.00' || id_low into ret; + when id_low ~ '^\d{2}20\d{10}$' then select 'nl_bag_address', 'NL.IMBAG.NUMMERAANDUIDING.00' || id_low into ret; + -- NL CBS ID + when id_up ~ '^BU\d{8}$' then select 'nl_cbs_neighborhood', id_up into ret; + when id_up ~ '^WK\d{6}$' then select 'nl_cbs_district', id_up into ret; + when id_up ~ '^GM\d{4}$' then select 'nl_cbs_municipality', id_up into ret; + when id_up ~ '^PV\d{2}$' then select 'nl_cbs_state', id_up into ret; + -- Unknown ID + ELSE RAISE EXCEPTION 'unknown identifier: %', input; + end case; +RETURN ret; +END; +$_$; + + +ALTER FUNCTION geocoder.id_parser(input text) OWNER TO fundermaps; + +-- +-- Name: FUNCTION id_parser(input text); Type: COMMENT; Schema: geocoder; Owner: fundermaps +-- + +COMMENT ON FUNCTION geocoder.id_parser(input text) IS 'Attempts to parse the input as a geocoder identifier.'; + + -- -- Name: fir_generate_id(integer); Type: FUNCTION; Schema: report; Owner: fundermaps -- @@ -5716,6 +5818,14 @@ GRANT ALL ON FUNCTION data.get_foundation_category(type_indicative report.founda GRANT ALL ON FUNCTION data.get_foundation_category(type_indicative report.foundation_type, type_report report.foundation_type) TO fundermaps_portal; +-- +-- Name: FUNCTION id_parser(input text); Type: ACL; Schema: geocoder; Owner: fundermaps +-- + +GRANT ALL ON FUNCTION geocoder.id_parser(input text) TO fundermaps_webapp; +GRANT ALL ON FUNCTION geocoder.id_parser(input text) TO fundermaps_webservice; + + -- -- Name: FUNCTION fir_generate_id(client_id integer); Type: ACL; Schema: report; Owner: fundermaps -- From 409951a3ebf2edb8534565521f480fb2a66948fa Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 14:08:11 +0100 Subject: [PATCH 03/20] Reorganize projects --- FunderMaps.sln | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FunderMaps.sln b/FunderMaps.sln index 26132815..8f2fef6a 100644 --- a/FunderMaps.sln +++ b/FunderMaps.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29025.244 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31912.275 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.WebApi", "src\FunderMaps.WebApi\FunderMaps.WebApi.csproj", "{6872A2F1-EE77-4CA9-903A-B5DEC786DDE4}" EndProject @@ -27,7 +27,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2E7D6F8C-F44 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.Portal", "src\FunderMaps.Portal\FunderMaps.Portal.csproj", "{CF0E7A1A-20A8-4A15-8B57-D7218B9F33D1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunderMaps.BatchNode", "src\FunderMaps.BatchNode\FunderMaps.BatchNode.csproj", "{532227C4-BAD4-46AB-B45D-65F15317AFFA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.BatchNode", "src\FunderMaps.BatchNode\FunderMaps.BatchNode.csproj", "{532227C4-BAD4-46AB-B45D-65F15317AFFA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -82,9 +82,9 @@ Global {3BD8CCB6-82FC-4016-8D43-6814473E5796} = {0219D434-DD4F-4187-ADED-8CD4A62E90F1} {E176260E-0D9C-4374-AC49-F312C7EC23FD} = {3CCE5914-CD6D-4DFD-9FF5-E872044553DD} {278702CF-559B-4ED5-8C57-FD0E23DC4014} = {54F0529D-8DC7-4DCC-8A93-BF0B2E5F8BE2} - {8A28CFFE-2028-40AC-9CCD-81796FD360AE} = {54F0529D-8DC7-4DCC-8A93-BF0B2E5F8BE2} - {CF0E7A1A-20A8-4A15-8B57-D7218B9F33D1} = {2E7D6F8C-F448-46D2-88BA-2CA8DD7836E9} - {532227C4-BAD4-46AB-B45D-65F15317AFFA} = {2E7D6F8C-F448-46D2-88BA-2CA8DD7836E9} + {8A28CFFE-2028-40AC-9CCD-81796FD360AE} = {3CCE5914-CD6D-4DFD-9FF5-E872044553DD} + {CF0E7A1A-20A8-4A15-8B57-D7218B9F33D1} = {54F0529D-8DC7-4DCC-8A93-BF0B2E5F8BE2} + {532227C4-BAD4-46AB-B45D-65F15317AFFA} = {3CCE5914-CD6D-4DFD-9FF5-E872044553DD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CDA50611-E011-4C1E-8823-7A6943652DCE} From 5141f015ef3e931053f09fef1df98288ae4a54e8 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 14:10:58 +0100 Subject: [PATCH 04/20] Remove namespaces --- .../Types/Products/AnalysisProduct2.cs | 185 +++++++++--------- .../Types/Products/AnalysisProductType.cs | 33 ++-- .../Types/Products/StatisticsProduct.cs | 101 +++++----- .../Types/Products/StatisticsProductType.cs | 65 +++--- 4 files changed, 190 insertions(+), 194 deletions(-) diff --git a/src/FunderMaps.Core/Types/Products/AnalysisProduct2.cs b/src/FunderMaps.Core/Types/Products/AnalysisProduct2.cs index c7ddf766..87f02856 100644 --- a/src/FunderMaps.Core/Types/Products/AnalysisProduct2.cs +++ b/src/FunderMaps.Core/Types/Products/AnalysisProduct2.cs @@ -1,98 +1,97 @@ using FunderMaps.Core.DataAnnotations; -namespace FunderMaps.Core.Types.Products +namespace FunderMaps.Core.Types.Products; + +/// +/// Represents a model for the complete endpoint. +/// +public sealed record AnalysisProduct2 { /// - /// Represents a model for the complete endpoint. - /// - public sealed record AnalysisProduct2 - { - /// - /// Building identifier. - /// - [Geocoder] - public string BuildingId { get; init; } - - /// - /// Building external identifier. - /// - public string ExternalBuildingId { get; init; } - - /// - /// Address identifier. - /// - [Geocoder] - public string AddressId { get; init; } - - /// - /// Address external identifier. - /// - public string ExternalAddressId { get; init; } - - /// - /// Neighborhood identifier. - /// - [Geocoder] - public string NeighborhoodId { get; init; } - - /// - /// Built year. - /// - public int? ConstructionYear { get; init; } - - /// - /// Foundation recovery type. - /// - public RecoveryType? RecoveryType { get; init; } - - /// - /// Represents the estimated restoration costs for this building. - /// - public int? RestorationCosts { get; init; } - - /// - /// Foundation type. - /// - public FoundationType? FoundationType { get; init; } - - /// - /// Foundation type reliability. - /// - public Reliability FoundationTypeReliability { get; init; } - - /// - /// Foundation type reliability. - /// - public Reliability DrystandReliability { get; init; } - - /// - /// Represents the foundation risk for this building. - /// - public FoundationRisk? DrystandRisk { get; init; } - - /// - /// Dewatering depth reliability. - /// - public Reliability DewateringDepthReliability { get; init; } - - /// - /// Dewatering depth risk. - /// - public FoundationRisk? DewateringDepthRisk { get; init; } - - /// - /// Biological infection reliability. - /// - public Reliability BioInfectionReliability { get; init; } - - /// - /// Biological infection risk. - /// - public FoundationRisk? BioInfectionRisk { get; init; } - - /// - /// Unclassified risk. - /// - public FoundationRisk? UnclassifiedRisk { get; init; } - } + /// Building identifier. + /// + [Geocoder] + public string BuildingId { get; init; } + + /// + /// Building external identifier. + /// + public string ExternalBuildingId { get; init; } + + /// + /// Address identifier. + /// + [Geocoder] + public string AddressId { get; init; } + + /// + /// Address external identifier. + /// + public string ExternalAddressId { get; init; } + + /// + /// Neighborhood identifier. + /// + [Geocoder] + public string NeighborhoodId { get; init; } + + /// + /// Built year. + /// + public int? ConstructionYear { get; init; } + + /// + /// Foundation recovery type. + /// + public RecoveryType? RecoveryType { get; init; } + + /// + /// Represents the estimated restoration costs for this building. + /// + public int? RestorationCosts { get; init; } + + /// + /// Foundation type. + /// + public FoundationType? FoundationType { get; init; } + + /// + /// Foundation type reliability. + /// + public Reliability FoundationTypeReliability { get; init; } + + /// + /// Foundation type reliability. + /// + public Reliability DrystandReliability { get; init; } + + /// + /// Represents the foundation risk for this building. + /// + public FoundationRisk? DrystandRisk { get; init; } + + /// + /// Dewatering depth reliability. + /// + public Reliability DewateringDepthReliability { get; init; } + + /// + /// Dewatering depth risk. + /// + public FoundationRisk? DewateringDepthRisk { get; init; } + + /// + /// Biological infection reliability. + /// + public Reliability BioInfectionReliability { get; init; } + + /// + /// Biological infection risk. + /// + public FoundationRisk? BioInfectionRisk { get; init; } + + /// + /// Unclassified risk. + /// + public FoundationRisk? UnclassifiedRisk { get; init; } } diff --git a/src/FunderMaps.Core/Types/Products/AnalysisProductType.cs b/src/FunderMaps.Core/Types/Products/AnalysisProductType.cs index 6f36515a..be485441 100644 --- a/src/FunderMaps.Core/Types/Products/AnalysisProductType.cs +++ b/src/FunderMaps.Core/Types/Products/AnalysisProductType.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types.Products +namespace FunderMaps.Core.Types.Products; + +/// +/// Enum representing the different FunderMaps analysis product types. +/// +public enum AnalysisProductType { /// - /// Enum representing the different FunderMaps analysis product types. + /// Represents all data about a foundation for a given building. /// - public enum AnalysisProductType - { - /// - /// Represents all data about a foundation for a given building. - /// - Foundation = 1, + Foundation = 1, - /// - /// Represents a call with all possible data combined for a given building. - /// - Complete = 4, + /// + /// Represents a call with all possible data combined for a given building. + /// + Complete = 4, - /// - /// Represents all data about the risks for a given building including source data. - /// - RiskPlus = 7, - } + /// + /// Represents all data about the risks for a given building including source data. + /// + RiskPlus = 7, } diff --git a/src/FunderMaps.Core/Types/Products/StatisticsProduct.cs b/src/FunderMaps.Core/Types/Products/StatisticsProduct.cs index 19f3b766..cc4b1d71 100644 --- a/src/FunderMaps.Core/Types/Products/StatisticsProduct.cs +++ b/src/FunderMaps.Core/Types/Products/StatisticsProduct.cs @@ -1,56 +1,55 @@ using FunderMaps.Core.Types.Distributions; -namespace FunderMaps.Core.Types.Products +namespace FunderMaps.Core.Types.Products; + +/// +/// Model representing statistics about some region. +/// +public sealed record StatisticsProduct { /// - /// Model representing statistics about some region. - /// - public sealed record StatisticsProduct - { - /// - /// Represents the distribution of foundation types. - /// - public FoundationTypeDistribution FoundationTypeDistribution { get; set; } - - /// - /// Represents the distribution of building construction years in the - /// given region. - /// - public ConstructionYearDistribution ConstructionYearDistribution { get; set; } - - /// - /// Represents the distribution of foundation risks in the given region. - /// - public FoundationRiskDistribution FoundationRiskDistribution { get; set; } - - /// - /// Represents the percentage of collected data in the given region. - /// - public decimal DataCollectedPercentage { get; set; } - - /// - /// Total amount of restored buildings in the given area. - /// - public long TotalBuildingRestoredCount { get; set; } - - /// - /// Total amount of incidents in the given region. - /// - public IEnumerable TotalIncidentCount { get; set; } - - /// - /// Total amount of incidents in the given region. - /// - public IEnumerable MunicipalityIncidentCount { get; set; } - - /// - /// Total amount of reports in the given region. - /// - public IEnumerable TotalReportCount { get; set; } - - /// - /// Total amount of reports in the given region. - /// - public IEnumerable MunicipalityReportCount { get; set; } - } + /// Represents the distribution of foundation types. + /// + public FoundationTypeDistribution FoundationTypeDistribution { get; set; } + + /// + /// Represents the distribution of building construction years in the + /// given region. + /// + public ConstructionYearDistribution ConstructionYearDistribution { get; set; } + + /// + /// Represents the distribution of foundation risks in the given region. + /// + public FoundationRiskDistribution FoundationRiskDistribution { get; set; } + + /// + /// Represents the percentage of collected data in the given region. + /// + public decimal DataCollectedPercentage { get; set; } + + /// + /// Total amount of restored buildings in the given area. + /// + public long TotalBuildingRestoredCount { get; set; } + + /// + /// Total amount of incidents in the given region. + /// + public IEnumerable TotalIncidentCount { get; set; } + + /// + /// Total amount of incidents in the given region. + /// + public IEnumerable MunicipalityIncidentCount { get; set; } + + /// + /// Total amount of reports in the given region. + /// + public IEnumerable TotalReportCount { get; set; } + + /// + /// Total amount of reports in the given region. + /// + public IEnumerable MunicipalityReportCount { get; set; } } diff --git a/src/FunderMaps.Core/Types/Products/StatisticsProductType.cs b/src/FunderMaps.Core/Types/Products/StatisticsProductType.cs index fb287d2a..a69ee258 100644 --- a/src/FunderMaps.Core/Types/Products/StatisticsProductType.cs +++ b/src/FunderMaps.Core/Types/Products/StatisticsProductType.cs @@ -1,43 +1,42 @@ -namespace FunderMaps.Core.Types.Products +namespace FunderMaps.Core.Types.Products; + +/// +/// Enum representing the different FunderMaps statistics product types. +/// +public enum StatisticsProductType { /// - /// Enum representing the different FunderMaps statistics product types. + /// Area analysis on the ratio of foundation types. /// - public enum StatisticsProductType - { - /// - /// Area analysis on the ratio of foundation types. - /// - FoundationRatio = 0, + FoundationRatio = 0, - /// - /// Area analysis on the distribution of built years. - /// - ConstructionYears = 1, + /// + /// Area analysis on the distribution of built years. + /// + ConstructionYears = 1, - /// - /// Area analysis on building foundation risk. - /// - FoundationRisk = 2, + /// + /// Area analysis on building foundation risk. + /// + FoundationRisk = 2, - /// - /// Area analysis on the percentage of data collected. - /// - DataCollected = 3, + /// + /// Area analysis on the percentage of data collected. + /// + DataCollected = 3, - /// - /// Area analysis on the amount of restored buildings. - /// - BuildingsRestored = 4, + /// + /// Area analysis on the amount of restored buildings. + /// + BuildingsRestored = 4, - /// - /// Area analysis on the amount of incidents. - /// - Incidents = 5, + /// + /// Area analysis on the amount of incidents. + /// + Incidents = 5, - /// - /// Area analysis on the amount of reports. - /// - Reports = 6, - } + /// + /// Area analysis on the amount of reports. + /// + Reports = 6, } From 389850a08d8bfa3c2b3a7dd9d62db8b448c5eb6d Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 14:25:27 +0100 Subject: [PATCH 05/20] Add japanse_knotweed to foundation damage cause --- database/fundermaps_base.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/fundermaps_base.sql b/database/fundermaps_base.sql index a744968e..85f9de61 100644 --- a/database/fundermaps_base.sql +++ b/database/fundermaps_base.sql @@ -646,7 +646,8 @@ CREATE TYPE report.foundation_damage_cause AS ENUM ( 'vegetation', 'gas', 'vibrations', - 'partial_foundation_recovery' + 'partial_foundation_recovery', + 'japanse_knotweed' ); From c545c45694b8466a73ac56851eff0f7936477aa5 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 14:31:15 +0100 Subject: [PATCH 06/20] Skip the statistics DTO --- .../Controllers/ProductV2Controller.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs b/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs index 3d490c1e..e64a645a 100644 --- a/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs +++ b/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs @@ -7,8 +7,6 @@ namespace FunderMaps.Webservice.Controllers; -// FUTURE: Drop the 'product' uri prefix. -// FUTURE: Drop the 'v' uri version prefix. /// /// Controller for all product endpoints. /// @@ -75,15 +73,6 @@ public Task GetRiskIndexAsync([FromQuery] string id) [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task>> GetStatisticsAsync([FromQuery][Required] string id) - { - // Assign. - IAsyncEnumerable productList = _productService.GetStatisticsAsync(id); - - // Map. - ResponseWrapper result = await AsResponseWrapperAsync(productList); - - // Return. - return Ok(result); - } + public IAsyncEnumerable GetStatisticsAsync([FromQuery][Required] string id) + => _productService.GetStatisticsAsync(id); } From 320486cc0f77fe839b41e207515d217b2994711f Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 14:53:31 +0100 Subject: [PATCH 07/20] Update complete model --- database/fundermaps_base.sql | 211 +++++++++++++++++++++++++---------- 1 file changed, 155 insertions(+), 56 deletions(-) diff --git a/database/fundermaps_base.sql b/database/fundermaps_base.sql index 85f9de61..aa06a98d 100644 --- a/database/fundermaps_base.sql +++ b/database/fundermaps_base.sql @@ -291,7 +291,8 @@ COMMENT ON TYPE data.foundation_risk_indication IS 'Enum representing the founda CREATE TYPE data.reliability AS ENUM ( 'indicative', - 'established' + 'established', + 'cluster' ); @@ -3569,55 +3570,49 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS a.id AS address_id, a.external_id AS address_external_id, b.neighborhood_id, - (COALESCE(established.built_year, cluster.built_year, (construction_year.construction_year)::double precision))::integer AS construction_year, + construction_year.construction_year, CASE - WHEN (established.foundation_type IS NOT NULL) THEN established.foundation_type - WHEN (cluster.foundation_type IS NOT NULL) THEN cluster.foundation_type - ELSE indicative_foundation_type.indicative_foundation_type - END AS foundation_type, + WHEN (established.built_year IS NOT NULL) THEN 'established'::data.reliability + ELSE 'indicative'::data.reliability + END AS construction_year_reliability, + foundation_type.foundation_type, CASE WHEN (established.foundation_type IS NOT NULL) THEN 'established'::data.reliability + WHEN (cluster.foundation_type IS NOT NULL) THEN 'cluster'::data.reliability ELSE 'indicative'::data.reliability END AS foundation_type_reliability, CASE - WHEN (established.foundation_type IS NOT NULL) THEN data.get_restoration_cost(established.foundation_type, surface_area.surface_area) - WHEN (cluster.foundation_type IS NOT NULL) THEN data.get_restoration_cost(cluster.foundation_type, surface_area.surface_area) - ELSE data.get_restoration_cost(indicative_foundation_type.indicative_foundation_type, surface_area.surface_area) + WHEN ((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) THEN (round((((surface_area.surface_area)::double precision * (950)::double precision))::numeric, '-2'::integer))::integer + WHEN ((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) THEN (round((((surface_area.surface_area)::double precision * (350)::double precision))::numeric, '-2'::integer))::integer + ELSE NULL::integer END AS restoration_costs, - CASE - WHEN (established_drystand_risk.established_drystand_risk IS NOT NULL) THEN established_drystand_risk.established_drystand_risk - WHEN (cluster_drystand_risk.cluster_drystand_risk IS NOT NULL) THEN cluster_drystand_risk.cluster_drystand_risk - ELSE drystand_risk.drystand_risk - END AS drystand_risk, + NULL::double precision AS drystand, + COALESCE(established_drystand_risk.established_drystand_risk, cluster_drystand_risk.cluster_drystand_risk, drystand_risk.drystand_risk) AS drystand_risk, CASE WHEN (established_drystand_risk.established_drystand_risk IS NOT NULL) THEN 'established'::data.reliability + WHEN (cluster_drystand_risk.cluster_drystand_risk IS NOT NULL) THEN 'cluster'::data.reliability ELSE 'indicative'::data.reliability END AS drystand_risk_reliability, - CASE - WHEN (established_bio_infection_risk.established_bio_infection_risk IS NOT NULL) THEN established_bio_infection_risk.established_bio_infection_risk - WHEN (cluster_bio_infection_risk.cluster_bio_infection_risk IS NOT NULL) THEN cluster_bio_infection_risk.cluster_bio_infection_risk - ELSE bio_infection_risk.bio_infection_risk - END AS bio_infection_risk, + COALESCE(established_bio_infection_risk.established_bio_infection_risk, cluster_bio_infection_risk.cluster_bio_infection_risk, bio_infection_risk.bio_infection_risk) AS bio_infection_risk, CASE WHEN (established_bio_infection_risk.established_bio_infection_risk IS NOT NULL) THEN 'established'::data.reliability + WHEN (cluster_bio_infection_risk.cluster_bio_infection_risk IS NOT NULL) THEN 'cluster'::data.reliability ELSE 'indicative'::data.reliability END AS bio_infection_risk_reliability, - CASE - WHEN (established_dewatering_depth_risk.established_dewatering_depth_risk IS NOT NULL) THEN established_dewatering_depth_risk.established_dewatering_depth_risk - WHEN (cluster_dewatering_depth_risk.cluster_dewatering_depth_risk IS NOT NULL) THEN cluster_dewatering_depth_risk.cluster_dewatering_depth_risk - ELSE dewatering_depth_risk.dewatering_depth_risk - END AS dewatering_depth_risk, + NULL::double precision AS dewatering_depth, + COALESCE(established_dewatering_depth_risk.established_dewatering_depth_risk, cluster_dewatering_depth_risk.cluster_dewatering_depth_risk, dewatering_depth_risk.dewatering_depth_risk) AS dewatering_depth_risk, CASE WHEN (established_dewatering_depth_risk.established_dewatering_depth_risk IS NOT NULL) THEN 'established'::data.reliability + WHEN (cluster_dewatering_depth_risk.cluster_dewatering_depth_risk IS NOT NULL) THEN 'cluster'::data.reliability ELSE 'indicative'::data.reliability END AS dewatering_depth_risk_reliability, - CASE - WHEN (established_unclassified_risk.established_unclassified_risk IS NOT NULL) THEN established_unclassified_risk.established_unclassified_risk - WHEN (cluster_unclassified_risk.cluster_unclassified_risk IS NOT NULL) THEN cluster_unclassified_risk.cluster_unclassified_risk - ELSE NULL::data.foundation_risk_indication - END AS unclassified_risk, - round((bh.height)::numeric, 2) AS height, + COALESCE(established_unclassified_risk.established_unclassified_risk, cluster_unclassified_risk.cluster_unclassified_risk) AS unclassified_risk, + round((GREATEST(bh.height, (0)::real))::numeric, 2) AS height, round((s.velocity)::numeric, 2) AS velocity, + round((gwl.level)::numeric, 2) AS ground_water_level, + round((be.ground)::numeric, 2) AS ground_level, + gr.code AS soil, + surface_area.surface_area, bo.owner, established.id AS inquiry_id, established.inquiry_type, @@ -3757,37 +3752,141 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS NULL::date AS date, false AS bool) cluster_rows GROUP BY cluster_rows.group_id) cluster, - LATERAL CAST((date_part('year'::text, (b.built_year)::date))::integer AS integer) construction_year(construction_year), + LATERAL ( SELECT COALESCE((established.built_year)::integer, (date_part('year'::text, (b.built_year)::date))::integer) AS "coalesce") construction_year(construction_year), LATERAL round((public.st_area((b.geom)::public.geography, true))::numeric, 2) surface_area(surface_area), LATERAL round(((be.ground - bp.depth))::numeric, 2) pile_length(pile_length), LATERAL ( SELECT (count(a_1.id))::integer AS count FROM geocoder.address a_1 WHERE ((a_1.building_id)::text = (b.id)::text)) addresses(count), - LATERAL data.get_indicative_foundation_type(construction_year.construction_year, (bh.height)::double precision, gr.code, addresses.count) indicative_foundation_type(indicative_foundation_type), - LATERAL data.get_indicative_drystand_risk((recovery.type IS NOT NULL), ((established.foundation_type IS NULL) AND (cluster.foundation_type IS NULL)), - CASE - WHEN (established.foundation_type IS NOT NULL) THEN established.foundation_type - ELSE cluster.foundation_type - END, construction_year.construction_year, (bh.height)::double precision, gr.code, addresses.count, s.velocity, gwl.level) drystand_risk(drystand_risk), - LATERAL data.get_indicative_dewatering_depth_risk((recovery.type IS NOT NULL), ((established.foundation_type IS NULL) AND (cluster.foundation_type IS NULL)), - CASE - WHEN (established.foundation_type IS NOT NULL) THEN established.foundation_type - ELSE cluster.foundation_type - END, construction_year.construction_year, (bh.height)::double precision, gr.code, addresses.count, s.velocity, gwl.level) dewatering_depth_risk(dewatering_depth_risk), - LATERAL data.get_indicative_bio_infection_risk((recovery.type IS NOT NULL), - CASE - WHEN (established.foundation_type IS NOT NULL) THEN established.foundation_type - WHEN (cluster.foundation_type IS NOT NULL) THEN cluster.foundation_type - ELSE indicative_foundation_type.indicative_foundation_type - END, (pile_length.pile_length)::double precision, s.velocity) bio_infection_risk(bio_infection_risk), - LATERAL data.get_established_drystand_risk(false, cluster.damage_cause, cluster.enforcement_term, cluster.overall_quality, cluster.recovery_advised) cluster_drystand_risk(cluster_drystand_risk), - LATERAL data.get_established_dewatering_depth_risk(false, cluster.damage_cause, cluster.enforcement_term, cluster.overall_quality, cluster.recovery_advised) cluster_dewatering_depth_risk(cluster_dewatering_depth_risk), - LATERAL data.get_established_bio_infection_risk(false, cluster.damage_cause, cluster.enforcement_term, cluster.overall_quality, cluster.recovery_advised) cluster_bio_infection_risk(cluster_bio_infection_risk), - LATERAL data.get_established_unclassified_risk(false, cluster.recovery, cluster.damage_cause, cluster.enforcement_term, cluster.overall_quality, cluster.recovery_advised) cluster_unclassified_risk(cluster_unclassified_risk), - LATERAL data.get_established_drystand_risk(established.recovery, established.damage_cause, established.enforcement_term, established.overall_quality, established.recovery_advised) established_drystand_risk(established_drystand_risk), - LATERAL data.get_established_dewatering_depth_risk(established.recovery, established.damage_cause, established.enforcement_term, established.overall_quality, established.recovery_advised) established_dewatering_depth_risk(established_dewatering_depth_risk), - LATERAL data.get_established_bio_infection_risk(established.recovery, established.damage_cause, established.enforcement_term, established.overall_quality, established.recovery_advised) established_bio_infection_risk(established_bio_infection_risk), - LATERAL data.get_established_unclassified_risk(established.recovery, false, established.damage_cause, established.enforcement_term, established.overall_quality, established.recovery_advised) established_unclassified_risk(established_unclassified_risk) + LATERAL ( SELECT + CASE + WHEN ((construction_year.construction_year >= 1940) AND (construction_year.construction_year < 1970) AND (addresses.count >= 8)) THEN 'concrete'::report.foundation_type + WHEN ((construction_year.construction_year >= 1970) AND (gr.code <> 'hz'::text)) THEN 'concrete'::report.foundation_type + WHEN ((construction_year.construction_year >= 1970) AND (gr.code = 'hz'::text)) THEN 'no_pile'::report.foundation_type + WHEN ((construction_year.construction_year >= 1700) AND (construction_year.construction_year < 1800) AND (bh.height < (10.5)::double precision)) THEN 'no_pile'::report.foundation_type + WHEN ((construction_year.construction_year >= 1700) AND (construction_year.construction_year < 1800) AND (bh.height >= (10.5)::double precision)) THEN 'wood'::report.foundation_type + WHEN ((construction_year.construction_year >= 1700) AND (construction_year.construction_year < 1800) AND ((bh.height >= (10.5)::double precision) OR (bh.height IS NULL)) AND ((gr.code = 'hz'::text) OR (gr.code = 'ni-hz'::text) OR (gr.code = 'ni-du'::text))) THEN 'no_pile'::report.foundation_type + WHEN ((construction_year.construction_year >= 1700) AND (construction_year.construction_year < 1800) AND ((bh.height >= (10.5)::double precision) OR (bh.height IS NULL)) AND (((gr.code <> 'hz'::text) AND (gr.code <> 'ni-hz'::text) AND (gr.code <> 'ni-du'::text)) OR (gr.code IS NULL))) THEN 'wood'::report.foundation_type + WHEN ((construction_year.construction_year >= 1800) AND (construction_year.construction_year < 1970) AND (bh.height < (10.5)::double precision)) THEN 'no_pile'::report.foundation_type + WHEN ((construction_year.construction_year >= 1800) AND (construction_year.construction_year < 1970) AND ((bh.height >= (10.5)::double precision) OR (bh.height IS NULL)) AND ((gr.code = 'hz'::text) OR (gr.code = 'ni-hz'::text) OR (gr.code = 'ni-du'::text))) THEN 'wood'::report.foundation_type + WHEN ((construction_year.construction_year >= 1800) AND (construction_year.construction_year < 1920) AND ((bh.height >= (10.5)::double precision) OR (bh.height IS NULL)) AND (((gr.code <> 'hz'::text) AND (gr.code <> 'ni-hz'::text) AND (gr.code <> 'ni-du'::text)) OR (gr.code IS NULL))) THEN 'wood'::report.foundation_type + WHEN ((construction_year.construction_year >= 1920) AND (construction_year.construction_year < 1970) AND ((bh.height >= (10.5)::double precision) OR (bh.height IS NULL)) AND (((gr.code <> 'hz'::text) AND (gr.code <> 'ni-hz'::text) AND (gr.code <> 'ni-du'::text)) OR (gr.code IS NULL))) THEN 'wood_charger'::report.foundation_type + WHEN (construction_year.construction_year < 1700) THEN 'no_pile'::report.foundation_type + WHEN (bh.height >= (10.5)::double precision) THEN 'wood'::report.foundation_type + WHEN (bh.height < (10.5)::double precision) THEN 'no_pile'::report.foundation_type + ELSE 'other'::report.foundation_type + END AS "case") indicative_foundation_type(foundation_type), + LATERAL ( SELECT COALESCE(established.foundation_type, cluster.foundation_type, indicative_foundation_type.foundation_type) AS "coalesce") foundation_type(foundation_type), + LATERAL ( SELECT + CASE + WHEN (recovery.type IS NOT NULL) THEN 'a'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'concrete'::report.foundation_type) OR (foundation_type.foundation_type = 'weighted_pile'::report.foundation_type)) THEN 'a'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (s.velocity IS NULL) AND (gwl.level >= (1.5)::double precision)) THEN 'c'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (s.velocity IS NULL) AND (gwl.level < (1.5)::double precision)) THEN 'b'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (s.velocity < ('-2.0'::numeric)::double precision) AND (gwl.level >= (1.5)::double precision)) THEN 'e'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (s.velocity >= ('-2.0'::numeric)::double precision) AND (gwl.level >= (1.5)::double precision)) THEN 'd'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (s.velocity < ('-2.0'::numeric)::double precision) AND (gwl.level < (1.5)::double precision)) THEN 'd'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (s.velocity >= ('-2.0'::numeric)::double precision) AND (gwl.level < (1.5)::double precision)) THEN 'c'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'wood_charger'::report.foundation_type) AND (s.velocity IS NULL) AND (gwl.level >= (2.5)::double precision)) THEN 'c'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'wood_charger'::report.foundation_type) AND (s.velocity IS NULL) AND (gwl.level < (2.5)::double precision)) THEN 'b'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'wood_charger'::report.foundation_type) AND (s.velocity < ('-1.0'::numeric)::double precision) AND (gwl.level >= (2.5)::double precision)) THEN 'e'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'wood_charger'::report.foundation_type) AND (s.velocity < ('-1.0'::numeric)::double precision) AND (gwl.level < (2.5)::double precision)) THEN 'c'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'wood_charger'::report.foundation_type) AND (s.velocity >= ('-1.0'::numeric)::double precision) AND (gwl.level >= (2.5)::double precision)) THEN 'c'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'wood_charger'::report.foundation_type) AND (s.velocity >= ('-1.0'::numeric)::double precision) AND (gwl.level < (2.5)::double precision)) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") drystand_risk(drystand_risk), + LATERAL ( SELECT + CASE + WHEN (recovery.type IS NOT NULL) THEN 'a'::data.foundation_risk_indication + WHEN ((foundation_type.foundation_type = 'concrete'::report.foundation_type) OR (foundation_type.foundation_type = 'weighted_pile'::report.foundation_type)) THEN 'a'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) AND (s.velocity IS NULL) AND (gwl.level < (0.6)::double precision)) THEN 'c'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) AND (s.velocity IS NULL) AND (gwl.level >= (0.6)::double precision)) THEN 'b'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) AND (s.velocity < ('-1.0'::numeric)::double precision) AND (gwl.level < (0.6)::double precision)) THEN 'e'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) AND (s.velocity < ('-1.0'::numeric)::double precision) AND (gwl.level >= (0.6)::double precision)) THEN 'd'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) AND (s.velocity >= ('-1.0'::numeric)::double precision) AND (gwl.level < (0.6)::double precision)) THEN 'd'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) AND (s.velocity >= ('-1.0'::numeric)::double precision) AND (gwl.level >= (0.6)::double precision)) THEN 'c'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") dewatering_depth_risk(dewatering_depth_risk), + LATERAL ( SELECT + CASE + WHEN (recovery.type IS NOT NULL) THEN 'a'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (pile_length.pile_length <= (12)::numeric) AND (s.velocity < ('-2.0'::numeric)::double precision)) THEN 'e'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (pile_length.pile_length <= (12)::numeric)) THEN 'd'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (pile_length.pile_length > (12)::numeric) AND (pile_length.pile_length <= (15)::numeric) AND (s.velocity < ('-2.0'::numeric)::double precision)) THEN 'e'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (pile_length.pile_length > (12)::numeric) AND (pile_length.pile_length <= (15)::numeric)) THEN 'c'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (pile_length.pile_length > (15)::numeric) AND (s.velocity < ('-2.0'::numeric)::double precision)) THEN 'd'::data.foundation_risk_indication + WHEN (((foundation_type.foundation_type = 'wood'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) OR (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type)) AND (pile_length.pile_length > (15)::numeric)) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") bio_infection_risk(bio_infection_risk), + LATERAL ( SELECT + CASE + WHEN (((cluster.damage_cause = 'drystand'::report.foundation_damage_cause) OR (cluster.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (cluster.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((cluster.enforcement_term = 'term05'::report.enforcement_term) OR (cluster.enforcement_term = 'term5'::report.enforcement_term) OR cluster.recovery_advised OR (cluster.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN (((cluster.damage_cause = 'drystand'::report.foundation_damage_cause) OR (cluster.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (cluster.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((cluster.enforcement_term = 'term510'::report.enforcement_term) OR (cluster.enforcement_term = 'term10'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN (((cluster.damage_cause = 'drystand'::report.foundation_damage_cause) OR (cluster.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (cluster.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((cluster.enforcement_term = 'term1020'::report.enforcement_term) OR (cluster.enforcement_term = 'term15'::report.enforcement_term) OR (cluster.enforcement_term = 'term20'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN (((cluster.damage_cause = 'drystand'::report.foundation_damage_cause) OR (cluster.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (cluster.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") cluster_drystand_risk(cluster_drystand_risk), + LATERAL ( SELECT + CASE + WHEN ((cluster.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term05'::report.enforcement_term) OR (cluster.enforcement_term = 'term5'::report.enforcement_term) OR cluster.recovery_advised OR (cluster.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN ((cluster.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term510'::report.enforcement_term) OR (cluster.enforcement_term = 'term10'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN ((cluster.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term1020'::report.enforcement_term) OR (cluster.enforcement_term = 'term15'::report.enforcement_term) OR (cluster.enforcement_term = 'term20'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN ((cluster.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") cluster_dewatering_depth_risk(cluster_dewatering_depth_risk), + LATERAL ( SELECT + CASE + WHEN ((cluster.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term05'::report.enforcement_term) OR (cluster.enforcement_term = 'term5'::report.enforcement_term) OR cluster.recovery_advised OR (cluster.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN ((cluster.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term510'::report.enforcement_term) OR (cluster.enforcement_term = 'term10'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN ((cluster.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term1020'::report.enforcement_term) OR (cluster.enforcement_term = 'term15'::report.enforcement_term) OR (cluster.enforcement_term = 'term20'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN ((cluster.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") cluster_bio_infection_risk(cluster_bio_infection_risk), + LATERAL ( SELECT + CASE + WHEN cluster.recovery THEN 'e'::data.foundation_risk_indication + WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term05'::report.enforcement_term) OR (cluster.enforcement_term = 'term5'::report.enforcement_term) OR cluster.recovery_advised OR (cluster.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term510'::report.enforcement_term) OR (cluster.enforcement_term = 'term10'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term1020'::report.enforcement_term) OR (cluster.enforcement_term = 'term15'::report.enforcement_term) OR (cluster.enforcement_term = 'term20'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") cluster_unclassified_risk(cluster_unclassified_risk), + LATERAL ( SELECT + CASE + WHEN established.recovery THEN 'a'::data.foundation_risk_indication + WHEN (((established.damage_cause = 'drystand'::report.foundation_damage_cause) OR (established.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (established.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((established.enforcement_term = 'term05'::report.enforcement_term) OR (established.enforcement_term = 'term5'::report.enforcement_term) OR established.recovery_advised OR (established.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN (((established.damage_cause = 'drystand'::report.foundation_damage_cause) OR (established.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (established.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((established.enforcement_term = 'term510'::report.enforcement_term) OR (established.enforcement_term = 'term10'::report.enforcement_term) OR (established.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN (((established.damage_cause = 'drystand'::report.foundation_damage_cause) OR (established.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (established.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((established.enforcement_term = 'term1020'::report.enforcement_term) OR (established.enforcement_term = 'term15'::report.enforcement_term) OR (established.enforcement_term = 'term20'::report.enforcement_term) OR (established.overall_quality = 'mediocre'::report.foundation_quality) OR (established.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN (((established.damage_cause = 'drystand'::report.foundation_damage_cause) OR (established.damage_cause = 'fungus_infection'::report.foundation_damage_cause) OR (established.damage_cause = 'bio_fungus_infection'::report.foundation_damage_cause)) AND ((established.enforcement_term = 'term25'::report.enforcement_term) OR (established.enforcement_term = 'term30'::report.enforcement_term) OR (established.enforcement_term = 'term40'::report.enforcement_term) OR (established.overall_quality = 'good'::report.foundation_quality) OR (established.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") established_drystand_risk(established_drystand_risk), + LATERAL ( SELECT + CASE + WHEN established.recovery THEN 'a'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term05'::report.enforcement_term) OR (established.enforcement_term = 'term5'::report.enforcement_term) OR established.recovery_advised OR (established.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term510'::report.enforcement_term) OR (established.enforcement_term = 'term10'::report.enforcement_term) OR (established.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term1020'::report.enforcement_term) OR (established.enforcement_term = 'term15'::report.enforcement_term) OR (established.enforcement_term = 'term20'::report.enforcement_term) OR (established.overall_quality = 'mediocre'::report.foundation_quality) OR (established.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term25'::report.enforcement_term) OR (established.enforcement_term = 'term30'::report.enforcement_term) OR (established.enforcement_term = 'term40'::report.enforcement_term) OR (established.overall_quality = 'good'::report.foundation_quality) OR (established.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") established_dewatering_depth_risk(established_dewatering_depth_risk), + LATERAL ( SELECT + CASE + WHEN established.recovery THEN 'a'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term05'::report.enforcement_term) OR (established.enforcement_term = 'term5'::report.enforcement_term) OR established.recovery_advised OR (established.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term510'::report.enforcement_term) OR (established.enforcement_term = 'term10'::report.enforcement_term) OR (established.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term1020'::report.enforcement_term) OR (established.enforcement_term = 'term15'::report.enforcement_term) OR (established.enforcement_term = 'term20'::report.enforcement_term) OR (established.overall_quality = 'mediocre'::report.foundation_quality) OR (established.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN ((established.damage_cause = 'bio_infection'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term25'::report.enforcement_term) OR (established.enforcement_term = 'term30'::report.enforcement_term) OR (established.enforcement_term = 'term40'::report.enforcement_term) OR (established.overall_quality = 'good'::report.foundation_quality) OR (established.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") established_bio_infection_risk(established_bio_infection_risk), + LATERAL ( SELECT + CASE + WHEN established.recovery THEN 'a'::data.foundation_risk_indication + WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term05'::report.enforcement_term) OR (established.enforcement_term = 'term5'::report.enforcement_term) OR established.recovery_advised OR (established.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication + WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term510'::report.enforcement_term) OR (established.enforcement_term = 'term10'::report.enforcement_term) OR (established.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication + WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term1020'::report.enforcement_term) OR (established.enforcement_term = 'term15'::report.enforcement_term) OR (established.enforcement_term = 'term20'::report.enforcement_term) OR (established.overall_quality = 'mediocre'::report.foundation_quality) OR (established.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication + WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term25'::report.enforcement_term) OR (established.enforcement_term = 'term30'::report.enforcement_term) OR (established.enforcement_term = 'term40'::report.enforcement_term) OR (established.overall_quality = 'good'::report.foundation_quality) OR (established.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + ELSE NULL::data.foundation_risk_indication + END AS "case") established_unclassified_risk(established_unclassified_risk) WHERE ((addresses.count > 0) AND (b.building_type = 'house'::geocoder.building_type)) WITH NO DATA; From 1316409d7d8773a868688e1ef61ebb71a1b98bbc Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 15:00:40 +0100 Subject: [PATCH 08/20] Product v3 --- .../Interfaces/IProductService.cs | 59 ++-- .../Repositories/IAnalysisRepository.cs | 95 +++--- .../Services/ProductService.cs | 17 +- .../Types/Products/AnalysisProduct3.cs | 147 +++++++++ .../Repositories/AnalysisRepository.cs | 283 ++++++++++-------- .../Controllers/ProductV3Controller.cs | 54 ++++ 6 files changed, 439 insertions(+), 216 deletions(-) create mode 100644 src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs create mode 100644 src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs diff --git a/src/FunderMaps.Core/Interfaces/IProductService.cs b/src/FunderMaps.Core/Interfaces/IProductService.cs index 8a0b5fa3..6c6cc48e 100644 --- a/src/FunderMaps.Core/Interfaces/IProductService.cs +++ b/src/FunderMaps.Core/Interfaces/IProductService.cs @@ -1,36 +1,41 @@ using FunderMaps.Core.Types.Products; -namespace FunderMaps.Core.Interfaces +namespace FunderMaps.Core.Interfaces; + +/// +/// Service to the analysis products. +/// +public interface IProductService { /// - /// Service to the analysis products. + /// Get an analysis product. /// - public interface IProductService - { - /// - /// Get an analysis product. - /// - /// Product type. - /// Input query. - [Obsolete("GetAnalysisAsync is deprecated, please use GetAnalysis2Async instead.")] - IAsyncEnumerable GetAnalysisAsync(AnalysisProductType productType, string input); + /// Product type. + /// Input query. + [Obsolete("GetAnalysisAsync is deprecated, please use GetAnalysis2Async instead.")] + IAsyncEnumerable GetAnalysisAsync(AnalysisProductType productType, string input); - /// - /// Get the analysis product. - /// - /// Input query. - IAsyncEnumerable GetAnalysis2Async(string input); + /// + /// Get the analysis product. + /// + /// Input query. + IAsyncEnumerable GetAnalysis2Async(string input); + + /// + /// Get the analysis product. + /// + /// Input query. + Task GetAnalysis3Async(string input); - /// - /// Get statistics per region. - /// - /// Input query. - IAsyncEnumerable GetStatisticsAsync(string input); + /// + /// Get statistics per region. + /// + /// Input query. + IAsyncEnumerable GetStatisticsAsync(string input); - /// - /// Get risk index on id. - /// - /// Input query. - Task GetRiskIndexAsync(string input); - } + /// + /// Get risk index on id. + /// + /// Input query. + Task GetRiskIndexAsync(string input); } diff --git a/src/FunderMaps.Core/Interfaces/Repositories/IAnalysisRepository.cs b/src/FunderMaps.Core/Interfaces/Repositories/IAnalysisRepository.cs index 19dd71c0..fde88fe1 100644 --- a/src/FunderMaps.Core/Interfaces/Repositories/IAnalysisRepository.cs +++ b/src/FunderMaps.Core/Interfaces/Repositories/IAnalysisRepository.cs @@ -1,64 +1,57 @@ using FunderMaps.Core.Types.Products; -namespace FunderMaps.Core.Interfaces.Repositories +namespace FunderMaps.Core.Interfaces.Repositories; + +/// +/// Operations for the analysis repository. +/// +public interface IAnalysisRepository { /// - /// Operations for the analysis repository. + /// Gets an analysis product by its internal building id. /// - public interface IAnalysisRepository - { - /// - /// Gets an analysis product by its internal building id. - /// - /// Internal building id. - Task GetByIdAsync(string id); - - /// - /// Gets an analysis product by its internal building id. - /// - /// Internal building id. - Task GetById2Async(string id); + /// Internal building id. + Task GetByIdAsync(string id); - /// - /// Gets an analysis product by its external building id. - /// - /// External building id. - Task GetByExternalIdAsync(string id); + /// + /// Gets an analysis product by its internal building id. + /// + /// Internal building id. + Task GetById2Async(string id); - /// - /// Gets an analysis product by its external building id. - /// - /// External building id. - Task GetByExternalId2Async(string id); + /// + /// Gets an analysis product by its internal building id. + /// + /// Internal building id. + Task Get3Async(string id); - /// - /// Gets an analysis product by its external address id. - /// - /// External address id. - Task GetByAddressExternalIdAsync(string id); + /// + /// Gets an analysis product by its external building id. + /// + /// External building id. + Task GetByExternalIdAsync(string id); - /// - /// Gets an analysis product by its external address id. - /// - /// External address id. - Task GetByAddressExternalId2Async(string id); + /// + /// Gets an analysis product by its external building id. + /// + /// External building id. + Task GetByExternalId2Async(string id); - /// - /// Gets the risk index by its internal building id. - /// - /// Internal building id. - Task GetRiskIndexByIdAsync(string id); + /// + /// Gets an analysis product by its external address id. + /// + /// External address id. + Task GetByAddressExternalIdAsync(string id); - /// - /// Gets the risk index by its external building id and source. - /// - /// Internal building id. - Task GetRiskIndexByExternalIdAsync(string id); + /// + /// Gets an analysis product by its external address id. + /// + /// External address id. + Task GetByAddressExternalId2Async(string id); - /// - /// Gets the risk index by its external building id and source. - /// - /// Internal building id. - Task GetRiskIndexByAddressExternalIdAsync(string id); - } + /// + /// Gets the risk index by its internal building id. + /// + /// Internal building id. + Task GetRiskIndexAsync(string id); } diff --git a/src/FunderMaps.Core/Services/ProductService.cs b/src/FunderMaps.Core/Services/ProductService.cs index ea6a2d4c..ffe95eeb 100644 --- a/src/FunderMaps.Core/Services/ProductService.cs +++ b/src/FunderMaps.Core/Services/ProductService.cs @@ -170,20 +170,19 @@ public virtual async IAsyncEnumerable GetAnalysis2Async(string } } + /// + /// Get an analysis product v3. + /// + /// Input query. + public virtual Task GetAnalysis3Async(string input) + => _analysisRepository.Get3Async(input); + /// /// Get risk index on id. /// /// Input query. public virtual Task GetRiskIndexAsync(string input) - => _geocoderParser.FromIdentifier(input, out string id) switch - { - GeocoderDatasource.FunderMaps => _analysisRepository.GetRiskIndexByIdAsync(id), - GeocoderDatasource.NlBagBuilding => _analysisRepository.GetRiskIndexByExternalIdAsync(id), - GeocoderDatasource.NlBagBerth => _analysisRepository.GetRiskIndexByExternalIdAsync(id), - GeocoderDatasource.NlBagPosting => _analysisRepository.GetRiskIndexByExternalIdAsync(id), - GeocoderDatasource.NlBagAddress => _analysisRepository.GetRiskIndexByAddressExternalIdAsync(id), - _ => throw new InvalidIdentifierException(), - }; + => _analysisRepository.GetRiskIndexAsync(input); /// /// Get statistics per region. diff --git a/src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs b/src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs new file mode 100644 index 00000000..99a02b2e --- /dev/null +++ b/src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs @@ -0,0 +1,147 @@ +using FunderMaps.Core.DataAnnotations; + +namespace FunderMaps.Core.Types.Products; + +/// +/// Represents a model for the complete endpoint. +/// +public sealed record AnalysisProduct3 +{ + /// + /// Building identifier. + /// + [Geocoder] + public string BuildingId { get; init; } + + /// + /// Building external identifier. + /// + public string ExternalBuildingId { get; init; } + + /// + /// Address identifier. + /// + [Geocoder] + public string AddressId { get; init; } + + /// + /// Address external identifier. + /// + public string ExternalAddressId { get; init; } + + /// + /// Neighborhood identifier. + /// + [Geocoder] + public string NeighborhoodId { get; init; } + + /// + /// Built year. + /// + public int? ConstructionYear { get; init; } + + /// + /// Construction year reliability. + /// + public Reliability ConstructionYearReliability { get; init; } + + /// + /// Foundation recovery type. + /// + public RecoveryType? RecoveryType { get; init; } + + /// + /// Represents the estimated restoration costs for this building. + /// + public int? RestorationCosts { get; init; } + + /// + /// Represents the height of this building. + /// + public double? Height { get; init; } + + /// + /// Building subsidence velocity. + /// + public double? Velocity { get; init; } + + /// + /// Represents the ground water level. + /// + public double? GroundWaterLevel { get; init; } + + /// + /// Ground level in meters. + /// + public double? GroundLevel { get; init; } + + /// + /// Soil code. + /// + public string Soil { get; init; } + + /// + /// Building surface area in square meters. + /// + public double? SurfaceArea { get; init; } + + /// + /// Property owner. + /// + public string Owner { get; init; } + + /// + /// Foundation type. + /// + public FoundationType? FoundationType { get; init; } + + /// + /// Foundation type reliability. + /// + public Reliability FoundationTypeReliability { get; init; } + + /// + /// Represents the period of drought (droogstand) for this building. + /// + public double? Drystand { get; init; } + + /// + /// Foundation type reliability. + /// + public Reliability DrystandReliability { get; init; } + + /// + /// Represents the foundation risk for this building. + /// + public FoundationRisk? DrystandRisk { get; init; } + + /// + /// Dewatering depth. + /// + public double? DewateringDepth { get; init; } + + /// + /// Dewatering depth reliability. + /// + public Reliability DewateringDepthReliability { get; init; } + + /// + /// Dewatering depth risk. + /// + public FoundationRisk? DewateringDepthRisk { get; init; } + + /// + /// Biological infection reliability. + /// + public Reliability BioInfectionReliability { get; init; } + + /// + /// Biological infection risk. + /// + public FoundationRisk? BioInfectionRisk { get; init; } + + /// + /// Unclassified risk. + /// + public FoundationRisk? UnclassifiedRisk { get; init; } +} diff --git a/src/FunderMaps.Data/Repositories/AnalysisRepository.cs b/src/FunderMaps.Data/Repositories/AnalysisRepository.cs index db4c2a95..6da0a423 100644 --- a/src/FunderMaps.Data/Repositories/AnalysisRepository.cs +++ b/src/FunderMaps.Data/Repositories/AnalysisRepository.cs @@ -133,6 +133,79 @@ returning pt.building_id return MapFromReader2(reader); } + /// + /// Gets an analysis product by its internal building id. + /// + /// Internal building id. + public async Task Get3Async(string id) + { + var sql = @" + WITH identifier AS ( + SELECT + type, + id + FROM geocoder.id_parser(@id) + ), + tracker AS ( + INSERT INTO application.product_tracker AS pt (organization_id, product, building_id) + SELECT + @tenant, + 'analysis3', + ac.building_id + FROM data.analysis_complete ac, identifier + WHERE + CASE + WHEN identifier.type = 'fundermaps' THEN ac.building_id = identifier.id + WHEN identifier.type = 'nl_bag_address' THEN ac.address_external_id = identifier.id + WHEN identifier.type = 'nl_bag_building' THEN ac.external_building_id = identifier.id + WHEN identifier.type = 'nl_bag_berth' THEN ac.external_building_id = identifier.id + WHEN identifier.type = 'nl_bag_posting' THEN ac.external_building_id = identifier.id + END + LIMIT 1 + RETURNING pt.building_id + ) + SELECT-- AnalysisComplete + ac.building_id, + ac.external_building_id, + ac.address_id, + ac.address_external_id, + ac.neighborhood_id, + ac.construction_year, + ac.construction_year_reliability, + ac.foundation_type, + ac.foundation_type_reliability, + ac.restoration_costs, + ac.height, + ac.velocity, + ac.ground_water_level, + ac.ground_level, + ac.soil, + ac.surface_area, + ac.owner, + ac.drystand, + ac.drystand_risk, + ac.drystand_risk_reliability, + ac.bio_infection_risk, + ac.bio_infection_risk_reliability, + ac.dewatering_depth, + ac.dewatering_depth_risk, + ac.dewatering_depth_risk_reliability, + ac.unclassified_risk, + ac.recovery_type + FROM data.analysis_complete ac, tracker + WHERE ac.building_id = tracker.building_id + LIMIT 1"; + + await using var context = await DbContextFactory.CreateAsync(sql); + + context.AddParameterWithValue("id", id); + context.AddParameterWithValue("tenant", AppContext.TenantId); + + await using var reader = await context.ReaderAsync(); + + return MapFromReader3(reader); + } + /// /// Gets an analysis product by its external building id and source. /// @@ -380,41 +453,54 @@ returning pt.building_id /// Gets the risk index by its internal building id. /// /// Internal building id. - public async Task GetRiskIndexByIdAsync(string id) + public async Task GetRiskIndexAsync(string id) { var sql = @" - WITH tracker AS ( - INSERT INTO application.product_tracker AS pt (organization_id, product, building_id) - SELECT - @tenant, - 'riskindex', - ac.building_id - FROM data.analysis_complete ac - WHERE ac.building_id = @id - LIMIT 1 - returning pt.building_id - ) - SELECT -- AnalysisComplete - 'a'::data.foundation_risk_indication <> ANY (ARRAY[ - CASE - WHEN ac.drystand_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.drystand_risk - END, - CASE - WHEN ac.bio_infection_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.bio_infection_risk - END, - CASE - WHEN ac.dewatering_depth_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.dewatering_depth_risk - END, - CASE - WHEN ac.unclassified_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.unclassified_risk - END]) AS has_risk - FROM data.analysis_complete ac, tracker - WHERE ac.building_id = tracker.building_id - LIMIT 1"; + WITH identifier AS ( + SELECT + type, + id + FROM geocoder.id_parser(@id) + ), + tracker AS ( + INSERT INTO application.product_tracker AS pt (organization_id, product, building_id) + SELECT + @tenant, + 'riskindex', + ac.building_id + FROM data.analysis_complete ac, identifier + WHERE + CASE + WHEN identifier.type = 'fundermaps' THEN ac.building_id = identifier.id + WHEN identifier.type = 'nl_bag_address' THEN ac.address_external_id = identifier.id + WHEN identifier.type = 'nl_bag_building' THEN ac.external_building_id = identifier.id + WHEN identifier.type = 'nl_bag_berth' THEN ac.external_building_id = identifier.id + WHEN identifier.type = 'nl_bag_posting' THEN ac.external_building_id = identifier.id + END + LIMIT 1 + RETURNING pt.building_id + ) + SELECT -- AnalysisComplete + 'a'::data.foundation_risk_indication <> ANY (ARRAY[ + CASE + WHEN ac.drystand_risk IS NULL THEN 'a'::data.foundation_risk_indication + ELSE ac.drystand_risk + END, + CASE + WHEN ac.bio_infection_risk IS NULL THEN 'a'::data.foundation_risk_indication + ELSE ac.bio_infection_risk + END, + CASE + WHEN ac.dewatering_depth_risk IS NULL THEN 'a'::data.foundation_risk_indication + ELSE ac.dewatering_depth_risk + END, + CASE + WHEN ac.unclassified_risk IS NULL THEN 'a'::data.foundation_risk_indication + ELSE ac.unclassified_risk + END]) AS has_risk + FROM data.analysis_complete ac, tracker + WHERE ac.building_id = tracker.building_id + LIMIT 1"; await using var context = await DbContextFactory.CreateAsync(sql); @@ -424,102 +510,6 @@ ELSE ac.unclassified_risk return await context.ScalarAsync(); } - /// - /// Gets the risk index by its external building id and source. - /// - /// Internal building id. - public async Task GetRiskIndexByExternalIdAsync(string id) - { - var sql = @" - WITH tracker AS ( - INSERT INTO application.product_tracker AS pt (organization_id, product, building_id) - SELECT - @tenant, - 'riskindex', - ac.building_id - FROM data.analysis_complete ac - WHERE ac.external_building_id = upper(@external_id) - LIMIT 1 - returning pt.building_id - ) - SELECT -- AnalysisComplete - 'a'::data.foundation_risk_indication <> ANY (ARRAY[ - CASE - WHEN ac.drystand_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.drystand_risk - END, - CASE - WHEN ac.bio_infection_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.bio_infection_risk - END, - CASE - WHEN ac.dewatering_depth_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.dewatering_depth_risk - END, - CASE - WHEN ac.unclassified_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.unclassified_risk - END]) AS has_risk - FROM data.analysis_complete ac, tracker - WHERE ac.building_id = tracker.building_id - LIMIT 1"; - - await using var context = await DbContextFactory.CreateAsync(sql); - - context.AddParameterWithValue("external_id", id); - context.AddParameterWithValue("tenant", AppContext.TenantId); - - return await context.ScalarAsync(); - } - - /// - /// Gets the risk index by its external address id and source. - /// - /// Internal building id. - public async Task GetRiskIndexByAddressExternalIdAsync(string id) - { - var sql = @" - WITH tracker AS ( - INSERT INTO application.product_tracker AS pt (organization_id, product, building_id) - SELECT - @tenant, - 'riskindex', - ac.building_id - FROM data.analysis_complete ac - WHERE ac.address_external_id = upper(@external_id) - LIMIT 1 - returning pt.building_id - ) - SELECT -- AnalysisComplete - 'a'::data.foundation_risk_indication <> ANY (ARRAY[ - CASE - WHEN ac.drystand_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.drystand_risk - END, - CASE - WHEN ac.bio_infection_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.bio_infection_risk - END, - CASE - WHEN ac.dewatering_depth_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.dewatering_depth_risk - END, - CASE - WHEN ac.unclassified_risk IS NULL THEN 'a'::data.foundation_risk_indication - ELSE ac.unclassified_risk - END]) AS has_risk - FROM data.analysis_complete ac, tracker - WHERE ac.building_id = tracker.building_id - LIMIT 1"; - - await using var context = await DbContextFactory.CreateAsync(sql); - - context.AddParameterWithValue("external_id", id); - context.AddParameterWithValue("tenant", AppContext.TenantId); - - return await context.ScalarAsync(); - } - /// /// Maps a reader to an . /// @@ -590,4 +580,39 @@ public static AnalysisProduct2 MapFromReader2(DbDataReader reader, int offset = UnclassifiedRisk = reader.GetFieldValue(offset++), RecoveryType = reader.GetFieldValue(offset++), }; + + /// + /// Maps a reader to an . + /// + public static AnalysisProduct3 MapFromReader3(DbDataReader reader) + => new() + { + BuildingId = reader.GetSafeString(0), + ExternalBuildingId = reader.GetSafeString(1), + AddressId = reader.GetSafeString(2), + ExternalAddressId = reader.GetSafeString(3), + NeighborhoodId = reader.GetSafeString(4), + ConstructionYear = reader.GetSafeInt(5), + ConstructionYearReliability = reader.GetFieldValue(6), + FoundationType = reader.GetFieldValue(7), + FoundationTypeReliability = reader.GetFieldValue(8), + RestorationCosts = reader.GetSafeInt(9), + Height = reader.GetSafeDouble(10), + Velocity = reader.GetSafeDouble(11), + GroundWaterLevel = reader.GetSafeDouble(12), + GroundLevel = reader.GetSafeDouble(13), + Soil = reader.GetSafeString(14), + SurfaceArea = reader.GetSafeDouble(15), + Owner = reader.GetSafeString(16), + Drystand = reader.GetSafeDouble(17), + DrystandRisk = reader.GetFieldValue(18), + DrystandReliability = reader.GetFieldValue(19), + BioInfectionRisk = reader.GetFieldValue(20), + BioInfectionReliability = reader.GetFieldValue(21), + DewateringDepth = reader.GetSafeDouble(22), + DewateringDepthRisk = reader.GetFieldValue(23), + DewateringDepthReliability = reader.GetFieldValue(24), + UnclassifiedRisk = reader.GetFieldValue(25), + RecoveryType = reader.GetFieldValue(26), + }; } diff --git a/src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs b/src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs new file mode 100644 index 00000000..8de2f754 --- /dev/null +++ b/src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs @@ -0,0 +1,54 @@ +using FunderMaps.Core.Interfaces; +using FunderMaps.Core.Types.Products; +using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations; + +namespace FunderMaps.Webservice.Controllers; + +/// +/// Controller for all product endpoints. +/// +[Route("v3/product")] +public class ProductV3Controller : ControllerBase +{ + private readonly IProductService _productService; + + /// + /// Create new instance. + /// + public ProductV3Controller(IProductService productService) + => _productService = productService ?? throw new ArgumentNullException(nameof(productService)); + + // GET: api/v3/product/analysis + /// + /// Request the analysis product. + /// + [HttpGet("analysis")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public Task GetAnalysisAsync([FromQuery] string id) + => _productService.GetAnalysis3Async(id); + + // GET: api/v3/product/at_risk + /// + /// Request the risk index per id. + /// + [HttpGet("at_risk")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public Task GetRiskIndexAsync([FromQuery] string id) + => _productService.GetRiskIndexAsync(id); + + // GET: api/v3/product/statistics + /// + /// Request the statistics product. + /// + [HttpGet("statistics")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public IAsyncEnumerable GetStatisticsAsync([FromQuery][Required] string id) + => _productService.GetStatisticsAsync(id); +} From 21e5268d602ba4a8d7f8a58a839c93978afa730f Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 15:35:49 +0100 Subject: [PATCH 09/20] Remove old function code --- database/fundermaps_base.sql | 1082 +--------------------------------- 1 file changed, 2 insertions(+), 1080 deletions(-) diff --git a/database/fundermaps_base.sql b/database/fundermaps_base.sql index aa06a98d..c00485dd 100644 --- a/database/fundermaps_base.sql +++ b/database/fundermaps_base.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 12.8 (Debian 12.8-1.pgdg100+1) --- Dumped by pg_dump version 12.8 (Ubuntu 12.8-0ubuntu0.20.04.1) +-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-0ubuntu0.20.04.1) SET statement_timeout = 0; SET lock_timeout = 0; @@ -1395,209 +1395,6 @@ $$; ALTER PROCEDURE data.create_clusters() OWNER TO fundermaps; --- --- Name: get_established_bio_infection_risk(boolean, report.foundation_damage_cause, report.enforcement_term, report.foundation_quality, boolean); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_established_bio_infection_risk(has_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) RETURNS data.foundation_risk_indication - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN has_recovery - THEN 'a'::data.foundation_risk_indication - - WHEN damage_cause = 'bio_infection' - AND (enforcement_term = 'term05' - OR enforcement_term = 'term5' - OR recovery_advised - OR overall_quality = 'bad') - THEN 'e'::data.foundation_risk_indication - - WHEN damage_cause = 'bio_infection' - AND (enforcement_term = 'term510' - OR enforcement_term = 'term10' - OR overall_quality = 'mediocre_bad') - THEN 'd'::data.foundation_risk_indication - - WHEN damage_cause = 'bio_infection' - AND (enforcement_term = 'term1020' - OR enforcement_term = 'term15' - OR enforcement_term = 'term20' - OR overall_quality = 'mediocre' - OR overall_quality = 'tolerable') - THEN 'c'::data.foundation_risk_indication - - WHEN damage_cause = 'bio_infection' - AND (enforcement_term = 'term25' - OR enforcement_term = 'term30' - OR enforcement_term = 'term40' - OR overall_quality = 'good' - OR overall_quality = 'mediocre_good') - THEN 'b'::data.foundation_risk_indication - - ELSE NULL::data.foundation_risk_indication -END; -$$; - - -ALTER FUNCTION data.get_established_bio_infection_risk(has_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) OWNER TO fundermaps; - --- --- Name: get_established_dewatering_depth_risk(boolean, report.foundation_damage_cause, report.enforcement_term, report.foundation_quality, boolean); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_established_dewatering_depth_risk(has_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) RETURNS data.foundation_risk_indication - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN has_recovery - THEN 'a'::data.foundation_risk_indication - - WHEN damage_cause = 'drainage' - AND (enforcement_term = 'term05' - OR enforcement_term = 'term5' - OR recovery_advised - OR overall_quality = 'bad') - THEN 'e'::data.foundation_risk_indication - - WHEN damage_cause = 'drainage' - AND (enforcement_term = 'term510' - OR enforcement_term = 'term10' - OR overall_quality = 'mediocre_bad') - THEN 'd'::data.foundation_risk_indication - - WHEN damage_cause = 'drainage' - AND (enforcement_term = 'term1020' - OR enforcement_term = 'term15' - OR enforcement_term = 'term20' - OR overall_quality = 'mediocre' - OR overall_quality = 'tolerable') - THEN 'c'::data.foundation_risk_indication - - WHEN damage_cause = 'drainage' - AND (enforcement_term = 'term25' - OR enforcement_term = 'term30' - OR enforcement_term = 'term40' - OR overall_quality = 'good' - OR overall_quality = 'mediocre_good') - THEN 'b'::data.foundation_risk_indication - - ELSE NULL::data.foundation_risk_indication -END; -$$; - - -ALTER FUNCTION data.get_established_dewatering_depth_risk(has_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) OWNER TO fundermaps; - --- --- Name: get_established_drystand_risk(boolean, report.foundation_damage_cause, report.enforcement_term, report.foundation_quality, boolean); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_established_drystand_risk(has_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) RETURNS data.foundation_risk_indication - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN has_recovery - THEN 'a'::data.foundation_risk_indication - - WHEN (damage_cause = 'drystand' OR damage_cause = 'fungus_infection' OR damage_cause = 'bio_fungus_infection') - AND (enforcement_term = 'term05' - OR enforcement_term = 'term5' - OR recovery_advised - OR overall_quality = 'bad') - THEN 'e'::data.foundation_risk_indication - - WHEN (damage_cause = 'drystand' OR damage_cause = 'fungus_infection' OR damage_cause = 'bio_fungus_infection') - AND (enforcement_term = 'term510' - OR enforcement_term = 'term10' - OR overall_quality = 'mediocre_bad') - THEN 'd'::data.foundation_risk_indication - - WHEN (damage_cause = 'drystand' OR damage_cause = 'fungus_infection' OR damage_cause = 'bio_fungus_infection') - AND (enforcement_term = 'term1020' - OR enforcement_term = 'term15' - OR enforcement_term = 'term20' - OR overall_quality = 'mediocre' - OR overall_quality = 'tolerable') - THEN 'c'::data.foundation_risk_indication - - WHEN (damage_cause = 'drystand' OR damage_cause = 'fungus_infection' OR damage_cause = 'bio_fungus_infection') - AND (enforcement_term = 'term25' - OR enforcement_term = 'term30' - OR enforcement_term = 'term40' - OR overall_quality = 'good' - OR overall_quality = 'mediocre_good') - THEN 'b'::data.foundation_risk_indication - - ELSE NULL::data.foundation_risk_indication -END; -$$; - - -ALTER FUNCTION data.get_established_drystand_risk(has_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) OWNER TO fundermaps; - --- --- Name: get_established_unclassified_risk(boolean, boolean, report.foundation_damage_cause, report.enforcement_term, report.foundation_quality, boolean); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_established_unclassified_risk(has_established_recovery boolean, has_cluster_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) RETURNS data.foundation_risk_indication - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN has_established_recovery - THEN 'a'::data.foundation_risk_indication - - WHEN has_cluster_recovery - THEN 'e'::data.foundation_risk_indication - - WHEN damage_cause <> 'drystand' - AND damage_cause <> 'bio_infection' - AND damage_cause <> 'drainage' - AND (enforcement_term = 'term05' - OR enforcement_term = 'term5' - OR recovery_advised - OR overall_quality = 'bad') - THEN 'e'::data.foundation_risk_indication - - WHEN damage_cause <> 'drystand' - AND damage_cause <> 'bio_infection' - AND damage_cause <> 'drainage' - AND (enforcement_term = 'term510' - OR enforcement_term = 'term10' - OR overall_quality = 'mediocre_bad') - THEN 'd'::data.foundation_risk_indication - - WHEN damage_cause <> 'drystand' - AND damage_cause <> 'bio_infection' - AND damage_cause <> 'drainage' - AND (enforcement_term = 'term1020' - OR enforcement_term = 'term15' - OR enforcement_term = 'term20' - OR overall_quality = 'mediocre' - OR overall_quality = 'tolerable') - THEN 'c'::data.foundation_risk_indication - - WHEN damage_cause <> 'drystand' - AND damage_cause <> 'bio_infection' - AND damage_cause <> 'drainage' - AND (enforcement_term = 'term25' - OR enforcement_term = 'term30' - OR enforcement_term = 'term40' - OR overall_quality = 'good' - OR overall_quality = 'mediocre_good') - THEN 'b'::data.foundation_risk_indication - - ELSE NULL::data.foundation_risk_indication -END; -$$; - - -ALTER FUNCTION data.get_established_unclassified_risk(has_established_recovery boolean, has_cluster_recovery boolean, damage_cause report.foundation_damage_cause, enforcement_term report.enforcement_term, overall_quality report.foundation_quality, recovery_advised boolean) OWNER TO fundermaps; - -- -- Name: get_foundation_category(report.foundation_type, report.foundation_type); Type: FUNCTION; Schema: data; Owner: fundermaps -- @@ -1632,881 +1429,6 @@ $_$; ALTER FUNCTION data.get_foundation_category(type_indicative report.foundation_type, type_report report.foundation_type) OWNER TO fundermaps; --- --- Name: get_indicative_bio_infection_risk(boolean, report.foundation_type, double precision, double precision); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_indicative_bio_infection_risk(has_recovery boolean, foundation_type report.foundation_type, pile_length double precision, velocity double precision) RETURNS data.foundation_risk_indication - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN has_recovery - THEN 'a'::data.foundation_risk_indication - - WHEN (foundation_type = 'wood' OR foundation_type = 'wood_charger' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - AND pile_length <= 12 - AND velocity < -2.0 - THEN 'e'::data.foundation_risk_indication - - WHEN (foundation_type = 'wood' OR foundation_type = 'wood_charger' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - AND pile_length <= 12 - THEN 'd'::data.foundation_risk_indication - - WHEN (foundation_type = 'wood' OR foundation_type = 'wood_charger' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - AND pile_length > 12 - AND pile_length <= 15 - AND velocity < -2.0 - THEN 'e'::data.foundation_risk_indication - - WHEN (foundation_type = 'wood' OR foundation_type = 'wood_charger' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - AND pile_length > 12 - AND pile_length <= 15 - THEN 'c'::data.foundation_risk_indication - - WHEN (foundation_type = 'wood' OR foundation_type = 'wood_charger' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - AND pile_length > 15 - AND velocity < -2.0 - THEN 'd'::data.foundation_risk_indication - - WHEN (foundation_type = 'wood' OR foundation_type = 'wood_charger' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - AND pile_length > 15 - THEN 'b'::data.foundation_risk_indication - - ELSE NULL::data.foundation_risk_indication -END; -$$; - - -ALTER FUNCTION data.get_indicative_bio_infection_risk(has_recovery boolean, foundation_type report.foundation_type, pile_length double precision, velocity double precision) OWNER TO fundermaps; - --- --- Name: get_indicative_dewatering_depth_risk(boolean, boolean, report.foundation_type, integer, double precision, text, integer, double precision, double precision); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_indicative_dewatering_depth_risk(has_recovery boolean, is_indicative boolean, foundation_type report.foundation_type, construction_year integer, height double precision, geographic_region text, addresses integer, velocity double precision, ground_water double precision) RETURNS data.foundation_risk_indication - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN has_recovery - THEN 'a'::data.foundation_risk_indication - - -- "A1" - WHEN is_indicative - AND construction_year >= 1940 - AND construction_year < 1970 - AND addresses >= 8 - THEN 'a'::data.foundation_risk_indication - - -- "B2" - WHEN is_indicative - AND construction_year >= 1970 - THEN 'a'::data.foundation_risk_indication - - -- "F1" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water < 0.6 - then 'c'::data.foundation_risk_indication - - -- "F2" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water >= 0.6 - then 'b'::data.foundation_risk_indication - - -- "F3" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-2.0) - and ground_water < 0.6 - then 'e'::data.foundation_risk_indication - - -- "F4" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-2.0) - and ground_water >= 0.6 - then 'd'::data.foundation_risk_indication - - -- "F5" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-2.0) - and ground_water < 0.6 - then 'd'::data.foundation_risk_indication - - -- "F6" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-2.0) - and ground_water >= 0.6 - then 'b'::data.foundation_risk_indication - - -- "F7" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity is null - and ground_water >= 0.6 - then 'c'::data.foundation_risk_indication - - -- "F8" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity is null - and ground_water < 0.6 - then 'b'::data.foundation_risk_indication - - -- "F9" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity < (-1.0) - and ground_water >= 0.6 - then 'e'::data.foundation_risk_indication - - -- "F10" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity < (-1.0) - and ground_water < 0.6 - then 'd'::data.foundation_risk_indication - - -- "F11" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity >= (-1.0) - and ground_water >= 0.6 - then 'c'::data.foundation_risk_indication - - -- "F12" - WHEN is_indicative - AND construction_year >= 1800 - and construction_year < 1970 - AND height < 10.5 - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity >= (-1.0) - and ground_water < 0.6 - then 'b'::data.foundation_risk_indication - - -- "J1" - WHEN is_indicative - AND construction_year < 1700 - and velocity is null - and ground_water < 0.6 - then 'c'::data.foundation_risk_indication - - -- "J2" - WHEN is_indicative - AND construction_year < 1700 - and velocity is null - and ground_water >= 0.6 - then 'b'::data.foundation_risk_indication - - -- "J3" - WHEN is_indicative - AND construction_year < 1700 - and velocity < (-1.0) - and ground_water < 0.6 - then 'e'::data.foundation_risk_indication - - -- "J4" - WHEN is_indicative - AND construction_year < 1700 - and velocity < (-1.0) - and ground_water >= 0.6 - then 'd'::data.foundation_risk_indication - - -- "J5" - WHEN is_indicative - AND construction_year < 1700 - and velocity >= (-1.0) - and ground_water < 0.6 - then 'd'::data.foundation_risk_indication - - -- "J6" - WHEN is_indicative - AND construction_year < 1700 - and velocity >= (-1.0) - and ground_water >= 0.6 - then 'c'::data.foundation_risk_indication - - -- "C1" - WHEN is_indicative - AND construction_year >= 1700 - and construction_year < 1800 - and height < 10.5 - and velocity is null - and ground_water < 0.6 - then 'c'::data.foundation_risk_indication - - -- "C2" - WHEN is_indicative - AND construction_year >= 1700 - and construction_year < 1800 - and height < 10.5 - and velocity is null - and ground_water >= 0.6 - then 'b'::data.foundation_risk_indication - - -- "C3" - WHEN is_indicative - AND construction_year >= 1700 - and construction_year < 1800 - and height < 10.5 - and velocity < (-1.0) - and ground_water < 0.6 - then 'e'::data.foundation_risk_indication - - -- "C4" - WHEN is_indicative - AND construction_year >= 1700 - and construction_year < 1800 - and height < 10.5 - and velocity >= (-1.0) - and ground_water < 0.6 - then 'd'::data.foundation_risk_indication - - -- "C5" - WHEN is_indicative - AND construction_year >= 1700 - and construction_year < 1800 - and height < 10.5 - and velocity < (-1.0) - and ground_water >= 0.6 - then 'd'::data.foundation_risk_indication - - -- "C6" - WHEN is_indicative - AND construction_year >= 1700 - and construction_year < 1800 - and height < 10.5 - and velocity >= (-1.0) - and ground_water >= 0.6 - then 'c'::data.foundation_risk_indication - - -- "D1" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity is null - and ground_water < 0.6 - then 'c'::data.foundation_risk_indication - - -- "D2" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity is null - and ground_water >= 0.6 - then 'b'::data.foundation_risk_indication - - -- "D3" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity < (-1.0) - and ground_water < 0.6 - then 'e'::data.foundation_risk_indication - - -- "D4" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity < (-1.0) - and ground_water >= 0.6 - then 'd'::data.foundation_risk_indication - - -- "D5" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity >= (-1.0) - and ground_water <= 0.6 - then 'd'::data.foundation_risk_indication - - -- "D6" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity >= (-1.0) - and ground_water > 0.6 - then 'b'::data.foundation_risk_indication - - -- "M1" - WHEN NOT is_indicative - AND (foundation_type = 'no_pile' or foundation_type = 'no_pile_masonry' or foundation_type = 'no_pile_strips' or foundation_type = 'no_pile_concrete_floor' or foundation_type = 'no_pile_slit') - and velocity is null - and ground_water < 0.6 - then 'c'::data.foundation_risk_indication - - -- "M2" - WHEN NOT is_indicative - AND (foundation_type = 'no_pile' or foundation_type = 'no_pile_masonry' or foundation_type = 'no_pile_strips' or foundation_type = 'no_pile_concrete_floor' or foundation_type = 'no_pile_slit') - and velocity is null - and ground_water >= 0.6 - then 'b'::data.foundation_risk_indication - - -- "M3" - WHEN NOT is_indicative - AND (foundation_type = 'no_pile' or foundation_type = 'no_pile_masonry' or foundation_type = 'no_pile_strips' or foundation_type = 'no_pile_concrete_floor' or foundation_type = 'no_pile_slit') - and velocity < (-2.0) - and ground_water < 0.6 - then 'e'::data.foundation_risk_indication - - -- "M4" - WHEN NOT is_indicative - AND (foundation_type = 'no_pile' or foundation_type = 'no_pile_masonry' or foundation_type = 'no_pile_strips' or foundation_type = 'no_pile_concrete_floor' or foundation_type = 'no_pile_slit') - and velocity < (-2.0) - and ground_water >= 0.6 - then 'd'::data.foundation_risk_indication - - -- "M5" - WHEN NOT is_indicative - AND (foundation_type = 'no_pile' or foundation_type = 'no_pile_masonry' or foundation_type = 'no_pile_strips' or foundation_type = 'no_pile_concrete_floor' or foundation_type = 'no_pile_slit') - and velocity >= (-2.0) - and ground_water < 0.6 - then 'd'::data.foundation_risk_indication - - -- "M6" - WHEN NOT is_indicative - AND (foundation_type = 'no_pile' or foundation_type = 'no_pile_masonry' or foundation_type = 'no_pile_strips' or foundation_type = 'no_pile_concrete_floor' or foundation_type = 'no_pile_slit') - and velocity >= (-2.0) - and ground_water >= 0.6 - then 'b'::data.foundation_risk_indication - - -- "M7" - WHEN NOT is_indicative - AND (foundation_type = 'concrete' OR foundation_type = 'weighted_pile') - THEN 'a'::data.foundation_risk_indication - - ELSE NULL::data.foundation_risk_indication -END; -$$; - - -ALTER FUNCTION data.get_indicative_dewatering_depth_risk(has_recovery boolean, is_indicative boolean, foundation_type report.foundation_type, construction_year integer, height double precision, geographic_region text, addresses integer, velocity double precision, ground_water double precision) OWNER TO fundermaps; - --- --- Name: get_indicative_drystand_risk(boolean, boolean, report.foundation_type, integer, double precision, text, integer, double precision, double precision); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_indicative_drystand_risk(has_recovery boolean, is_indicative boolean, foundation_type report.foundation_type, construction_year integer, height double precision, geographic_region text, addresses integer, velocity double precision, ground_water double precision) RETURNS data.foundation_risk_indication - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN has_recovery - THEN 'a'::data.foundation_risk_indication - - -- "A1" - WHEN is_indicative - AND construction_year >= 1940 - AND construction_year < 1970 - AND addresses >= 8 - THEN 'a'::data.foundation_risk_indication - - -- "B2" - WHEN is_indicative - AND construction_year >= 1970 - THEN 'a'::data.foundation_risk_indication - - -- "E1" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - AND (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water >= 1.5 - then 'c'::data.foundation_risk_indication - - -- "E2" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water < 1.5 - then 'b'::data.foundation_risk_indication - - -- "E3" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-2.0) - and ground_water >= 1.5 - then 'e'::data.foundation_risk_indication - - -- "E4" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-2.0) - and ground_water >= 1.5 - then 'd'::data.foundation_risk_indication - - -- "E5" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-2.0) - and ground_water < 1.5 - then 'd'::data.foundation_risk_indication - - -- "E6" - WHEN is_indicative - AND (construction_year >= 1700 - and construction_year < 1800 or construction_year is null) - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-2.0) - and ground_water < 1.5 - then 'b'::data.foundation_risk_indication - - -- "G1" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1975 - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity is null - and ground_water >= 1.5 - then 'c'::data.foundation_risk_indication - - -- "G2" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1975 - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity is null - and ground_water < 1.5 - then 'b'::data.foundation_risk_indication - - -- "G3" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1975 - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity < (-2.0) - and ground_water >= 1.5 - then 'e'::data.foundation_risk_indication - - -- "G4" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1975 - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity < (-2.0) - and ground_water < 1.5 - then 'd'::data.foundation_risk_indication - - -- "G5" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1975 - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity >= (-2.0) - and ground_water >= 1.5 - then 'd'::data.foundation_risk_indication - - -- "G6" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1975 - and (height >= 10.5 or height is null) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - and velocity >= (-2.0) - and ground_water < 1.5 - then 'c'::data.foundation_risk_indication - - -- "I1" - WHEN is_indicative - and construction_year >= 1925 - and construction_year < 1970 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water >= 2.5 - then 'c'::data.foundation_risk_indication - - -- "I2" - WHEN is_indicative - and construction_year >= 1925 - and construction_year < 1970 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water < 2.5 - then 'b'::data.foundation_risk_indication - - -- "I3" - WHEN is_indicative - and construction_year >= 1925 - and construction_year < 1970 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-1.0) - and ground_water >= 2.5 - then 'e'::data.foundation_risk_indication - - -- "I4" - WHEN is_indicative - and construction_year >= 1925 - and construction_year < 1970 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-1.0) - and ground_water < 2.5 - then 'c'::data.foundation_risk_indication - - -- "I5" - WHEN is_indicative - and construction_year >= 1925 - and construction_year < 1970 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-1.0) - and ground_water >= 2.5 - then 'c'::data.foundation_risk_indication - - -- "I6" - WHEN is_indicative - and construction_year >= 1925 - and construction_year < 1970 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-1.0) - and ground_water < 2.5 - then 'b'::data.foundation_risk_indication - - -- "H1" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1925 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water >= 1.5 - then 'd'::data.foundation_risk_indication - - -- "H2" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1925 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity is null - and ground_water < 1.5 - then 'b'::data.foundation_risk_indication - - -- "H3" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1925 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-2.0) - and ground_water >= 1.5 - then 'e'::data.foundation_risk_indication - - -- "H4" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1925 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity < (-2.0) - and ground_water < 1.5 - then 'c'::data.foundation_risk_indication - - -- "H5" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1925 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-2.0) - and ground_water >= 1.5 - then 'c'::data.foundation_risk_indication - - -- "H6" - WHEN is_indicative - and construction_year >= 1800 - and construction_year < 1925 - and (height >= 10.5 or height is null) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - and velocity >= (-2.0) - and ground_water < 1.5 - then 'b'::data.foundation_risk_indication - - -- "N1" - WHEN NOT is_indicative - AND (foundation_type = 'wood' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - and velocity is null - and ground_water >= 1.5 - then 'c'::data.foundation_risk_indication - - -- "N2" - WHEN NOT is_indicative - AND (foundation_type = 'wood' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - and velocity is null - and ground_water < 1.5 - then 'b'::data.foundation_risk_indication - - -- "N3" - WHEN NOT is_indicative - AND (foundation_type = 'wood' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - and velocity < (-2.0) - and ground_water >= 1.5 - then 'e'::data.foundation_risk_indication - - -- "N4" - WHEN NOT is_indicative - AND (foundation_type = 'wood' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - and velocity >= (-2.0) - and ground_water >= 1.5 - then 'd'::data.foundation_risk_indication - - -- "N5" - WHEN NOT is_indicative - AND (foundation_type = 'wood' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - and velocity < (-2.0) - and ground_water < 1.5 - then 'd'::data.foundation_risk_indication - - -- "N6" - WHEN NOT is_indicative - AND (foundation_type = 'wood' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch') - and velocity >= (-2.0) - and ground_water < 1.5 - then 'b'::data.foundation_risk_indication - - -- "O1" - WHEN NOT is_indicative - AND foundation_type = 'wood_charger' - and velocity is null - and ground_water >= 2.5 - then 'c'::data.foundation_risk_indication - - -- "O2" - WHEN NOT is_indicative - AND foundation_type = 'wood_charger' - and velocity is null - and ground_water < 2.5 - then 'b'::data.foundation_risk_indication - - -- "O3" - WHEN NOT is_indicative - AND foundation_type = 'wood_charger' - and velocity < (-2.0) - and ground_water >= 2.5 - then 'e'::data.foundation_risk_indication - - -- "O4" - WHEN NOT is_indicative - AND foundation_type = 'wood_charger' - and velocity >= (-2.0) - and ground_water >= 2.5 - then 'd'::data.foundation_risk_indication - - -- "O5" - WHEN NOT is_indicative - AND foundation_type = 'wood_charger' - and velocity < (-2.0) - and ground_water < 2.5 - then 'd'::data.foundation_risk_indication - - -- "O6" - WHEN NOT is_indicative - AND foundation_type = 'wood_charger' - and velocity >= (-2.0) - and ground_water < 2.5 - then 'b'::data.foundation_risk_indication - - -- "O7" - WHEN NOT is_indicative - AND (foundation_type = 'concrete' OR foundation_type = 'weighted_pile') - THEN 'a'::data.foundation_risk_indication - - ELSE NULL::data.foundation_risk_indication -END; -$$; - - -ALTER FUNCTION data.get_indicative_drystand_risk(has_recovery boolean, is_indicative boolean, foundation_type report.foundation_type, construction_year integer, height double precision, geographic_region text, addresses integer, velocity double precision, ground_water double precision) OWNER TO fundermaps; - --- --- Name: get_indicative_foundation_type(integer, double precision, text, integer); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_indicative_foundation_type(construction_year integer, height double precision, geographic_region text, addresses integer) RETURNS report.foundation_type - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - -- "A" - WHEN construction_year >= 1940 - AND construction_year < 1970 - AND addresses >= 8 - THEN 'concrete'::report.foundation_type - - -- "B" - WHEN construction_year >= 1970 - THEN 'concrete'::report.foundation_type - - -- "C" - WHEN construction_year >= 1700 - AND construction_year < 1800 - AND height < 10.5 - THEN 'no_pile'::report.foundation_type - - -- "Deze is dubbel met E en D" - WHEN construction_year >= 1700 - AND construction_year < 1800 - AND height >= 10.5 - THEN 'wood'::report.foundation_type - - -- "D" - WHEN construction_year >= 1700 - AND construction_year < 1800 - AND (height >= 10.5 OR height IS NULL) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - THEN 'no_pile'::report.foundation_type - - -- "E" - WHEN construction_year >= 1700 - AND construction_year < 1800 - AND (height >= 10.5 OR height IS NULL) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - THEN 'wood'::report.foundation_type - - -- "F" - WHEN construction_year >= 1800 - AND construction_year < 1970 - AND height < 10.5 - THEN 'no_pile'::report.foundation_type - - -- "G" - WHEN construction_year >= 1800 - AND construction_year < 1970 - AND (height >= 10.5 OR height IS NULL) - AND (geographic_region = 'hz'::text OR geographic_region = 'ni-hz'::text OR geographic_region = 'ni-du'::text) - THEN 'wood'::report.foundation_type - - -- "H" - WHEN construction_year >= 1800 - AND construction_year < 1920 - AND (height >= 10.5 OR height IS NULL) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - THEN 'wood'::report.foundation_type - - -- "I" - WHEN construction_year >= 1920 - AND construction_year < 1970 - AND (height >= 10.5 OR height IS NULL) - AND ((geographic_region <> 'hz'::text AND geographic_region <> 'ni-hz'::text AND geographic_region <> 'ni-du'::text) OR geographic_region IS NULL) - THEN 'wood_charger'::report.foundation_type - - -- "J" - WHEN construction_year < 1700 - THEN 'no_pile'::report.foundation_type - - -- "K" - WHEN height >= 10.5 - THEN 'wood'::report.foundation_type - - -- "L" - WHEN height < 10.5 - THEN 'no_pile'::report.foundation_type - - ELSE 'other'::report.foundation_type -END; -$$; - - -ALTER FUNCTION data.get_indicative_foundation_type(construction_year integer, height double precision, geographic_region text, addresses integer) OWNER TO fundermaps; - --- --- Name: get_restoration_cost(report.foundation_type, numeric); Type: FUNCTION; Schema: data; Owner: fundermaps --- - -CREATE FUNCTION data.get_restoration_cost(foundation_type report.foundation_type, surface_area numeric) RETURNS integer - LANGUAGE sql IMMUTABLE PARALLEL SAFE - AS $$ -SELECT -CASE - WHEN foundation_type = 'wood' OR foundation_type = 'wood_charger' or foundation_type = 'wood_amsterdam' or foundation_type = 'wood_rotterdam' or foundation_type = 'wood_rotterdam_amsterdam' or foundation_type = 'wood_amsterdam_arch' or foundation_type = 'wood_rotterdam_arch' - THEN round((surface_area * 950::double precision)::numeric, '-2'::integer)::integer - - WHEN foundation_type = 'no_pile' or foundation_type = 'no_pile_masonry' or foundation_type = 'no_pile_strips' or foundation_type = 'no_pile_concrete_floor' or foundation_type = 'no_pile_slit' - THEN round((surface_area * 350::double precision)::numeric, '-2'::integer)::integer - - ELSE NULL::integer -END; -$$; - - -ALTER FUNCTION data.get_restoration_cost(foundation_type report.foundation_type, surface_area numeric) OWNER TO fundermaps; - -- -- Name: id_parser(text); Type: FUNCTION; Schema: geocoder; Owner: fundermaps -- @@ -2548,7 +1470,7 @@ BEGIN when id_up ~ '^GM\d{4}$' then select 'nl_cbs_municipality', id_up into ret; when id_up ~ '^PV\d{2}$' then select 'nl_cbs_state', id_up into ret; -- Unknown ID - ELSE RAISE EXCEPTION 'unknown identifier: %', input; + ELSE RAISE EXCEPTION no_data_found USING HINT = 'Unknown identifier while parsing geocoder input'; end case; RETURN ret; END; From da4c907f7a88c35a15eda844bbcab7c337a467c2 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 15:36:16 +0100 Subject: [PATCH 10/20] Catch postgres exceptions --- src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs b/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs index 1c63070e..4ccb0b17 100644 --- a/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs +++ b/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs @@ -100,11 +100,15 @@ internal override void HandleException(ExceptionDispatchInfo edi) { switch (exception.SqlState) { - case Npgsql.PostgresErrorCodes.ForeignKeyViolation: + case PostgresErrorCodes.ForeignKeyViolation: throw new ReferenceNotFoundException(exception.Message, exception); - case Npgsql.PostgresErrorCodes.AdminShutdown: + case PostgresErrorCodes.AdminShutdown: throw new ServiceUnavailableException(exception.Message, exception); + + case PostgresErrorCodes.NoDataFound: + throw new ReferenceNotFoundException(exception.Message, exception); + } } From af7dccf406ece91e4cd5377b6a64af5de1162383 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 15:44:36 +0100 Subject: [PATCH 11/20] Expect NotFound when given invalid identifier --- .../Webservice/Analysis2Tests.cs | 335 +++++++++--------- 1 file changed, 167 insertions(+), 168 deletions(-) diff --git a/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs b/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs index aed6f6ae..771cf9d1 100644 --- a/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs +++ b/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs @@ -2,177 +2,176 @@ using System.Net; using Xunit; -namespace FunderMaps.IntegrationTests.Webservice +namespace FunderMaps.IntegrationTests.Webservice; + +/// +/// Integration test for the analysis controller. +/// +public class Analysis2Tests : IClassFixture { + private WebserviceFixtureFactory Factory { get; } + /// - /// Integration test for the analysis controller. + /// Create new instance and setup the test data. /// - public class Analysis2Tests : IClassFixture + public Analysis2Tests(WebserviceFixtureFactory factory) + => Factory = factory; + + [Fact] + public async Task GetProductByIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/analysis?id=gfm-ac31bec346744745b29f8505dff8182e"); + var returnObject = await response.Content.ReadFromJsonAsync>(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(1, returnObject.Count); + Assert.Equal("NL.IMBAG.LIGPLAATS.0503020000111954", returnObject.First().ExternalBuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); + } + + [Fact] + public async Task GetProductByExternalIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/analysis?id=NL.IMBAG.LIGPLAATS.0503020000111954"); + var returnObject = await response.Content.ReadFromJsonAsync>(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(1, returnObject.Count); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); + } + + [Fact] + public async Task GetProductByExternalIdBag1ReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/analysis?id=0503020000111954"); + var returnObject = await response.Content.ReadFromJsonAsync>(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(1, returnObject.Count); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); + } + + [Fact] + public async Task GetProductByExternalAddressIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/analysis?id=NL.IMBAG.NUMMERAANDUIDING.0503200000111954"); + var returnObject = await response.Content.ReadFromJsonAsync>(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(1, returnObject.Count); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); + } + + [Fact] + public async Task GetProductByExternalAddressIdBag1ReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/analysis?id=0503200000111954"); + var returnObject = await response.Content.ReadFromJsonAsync>(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(1, returnObject.Count); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); + } + + [Fact] + public async Task GetRiskIndexByIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/at_risk?id=gfm-ac31bec346744745b29f8505dff8182e"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.False(returnObject); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); + } + + [Fact] + public async Task GetRiskIndexByExternalIdReturnProduct() { - private WebserviceFixtureFactory Factory { get; } - - /// - /// Create new instance and setup the test data. - /// - public Analysis2Tests(WebserviceFixtureFactory factory) - => Factory = factory; - - [Fact] - public async Task GetProductByIdReturnProduct() - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/analysis?id=gfm-ac31bec346744745b29f8505dff8182e"); - var returnObject = await response.Content.ReadFromJsonAsync>(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(1, returnObject.Count); - Assert.Equal("NL.IMBAG.LIGPLAATS.0503020000111954", returnObject.First().ExternalBuildingId); - - Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); - } - - [Fact] - public async Task GetProductByExternalIdReturnProduct() - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/analysis?id=NL.IMBAG.LIGPLAATS.0503020000111954"); - var returnObject = await response.Content.ReadFromJsonAsync>(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(1, returnObject.Count); - Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); - - Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); - } - - [Fact] - public async Task GetProductByExternalIdBag1ReturnProduct() - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/analysis?id=0503020000111954"); - var returnObject = await response.Content.ReadFromJsonAsync>(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(1, returnObject.Count); - Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); - - Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); - } - - [Fact] - public async Task GetProductByExternalAddressIdReturnProduct() - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/analysis?id=NL.IMBAG.NUMMERAANDUIDING.0503200000111954"); - var returnObject = await response.Content.ReadFromJsonAsync>(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(1, returnObject.Count); - Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); - - Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); - } - - [Fact] - public async Task GetProductByExternalAddressIdBag1ReturnProduct() - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/analysis?id=0503200000111954"); - var returnObject = await response.Content.ReadFromJsonAsync>(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(1, returnObject.Count); - Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.First().BuildingId); - - Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); - } - - [Fact] - public async Task GetRiskIndexByIdReturnProduct() - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/at_risk?id=gfm-ac31bec346744745b29f8505dff8182e"); - var returnObject = await response.Content.ReadFromJsonAsync(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.False(returnObject); - - Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); - } - - [Fact] - public async Task GetRiskIndexByExternalIdReturnProduct() - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/at_risk?id=NL.IMBAG.LIGPLAATS.0503020000111954"); - var returnObject = await response.Content.ReadFromJsonAsync(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.False(returnObject); - - Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); - } - - [Theory] - [InlineData("id=3kjhr834dhfjdeh")] - [InlineData("bagid=4928374hfdkjsfh")] - [InlineData("query=thisismyquerystringyes")] - [InlineData("fdshjbf438gi")] - public async Task GetRiskIndexByExternalIdInvalidAddressThrows(string address) - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/at_risk?id={address}"); - - // Assert - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } - - [Theory] - [InlineData("id=3kjhr834dhfjdeh")] - [InlineData("bagid=4928374hfdkjsfh")] - [InlineData("query=thisismyquerystringyes")] - [InlineData("fdshjbf438gi")] - public async Task GetByIdInvalidAddressThrows(string address) - { - // Arrange - using var client = Factory.CreateClient(); - - // Act - var response = await client.GetAsync($"api/v2/product/analysis?id={address}"); - - // Assert - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/at_risk?id=NL.IMBAG.LIGPLAATS.0503020000111954"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.False(returnObject); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis2") > 0); + } + + [Theory] + [InlineData("id=3kjhr834dhfjdeh")] + [InlineData("bagid=4928374hfdkjsfh")] + [InlineData("query=thisismyquerystringyes")] + [InlineData("fdshjbf438gi")] + public async Task GetRiskIndexByExternalIdInvalidAddressThrows(string address) + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/at_risk?id={address}"); + + // Assert + Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + } + + [Theory] + [InlineData("id=3kjhr834dhfjdeh")] + [InlineData("bagid=4928374hfdkjsfh")] + [InlineData("query=thisismyquerystringyes")] + [InlineData("fdshjbf438gi")] + public async Task GetByIdInvalidAddressThrows(string address) + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v2/product/analysis?id={address}"); + + // Assert + Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } } From 2fb8aaa60f90dd2945815cdfe952ed296c18b5a4 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 15:58:48 +0100 Subject: [PATCH 12/20] Custom exception --- database/fundermaps_base.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/fundermaps_base.sql b/database/fundermaps_base.sql index c00485dd..1a535de8 100644 --- a/database/fundermaps_base.sql +++ b/database/fundermaps_base.sql @@ -1470,7 +1470,7 @@ BEGIN when id_up ~ '^GM\d{4}$' then select 'nl_cbs_municipality', id_up into ret; when id_up ~ '^PV\d{2}$' then select 'nl_cbs_state', id_up into ret; -- Unknown ID - ELSE RAISE EXCEPTION no_data_found USING HINT = 'Unknown identifier while parsing geocoder input'; + ELSE RAISE EXCEPTION 'Unknown identifier: %', input USING ERRCODE = 'UX101'; end case; RETURN ret; END; From 1025a4cb5010fed9eac501302d4b25f64b91127f Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 16:01:21 +0100 Subject: [PATCH 13/20] Catch custom postgres exception --- src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs | 3 +++ .../FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs b/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs index 4ccb0b17..118a1272 100644 --- a/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs +++ b/src/FunderMaps.Data/Providers/NpgsqlDbProvider.cs @@ -109,6 +109,9 @@ internal override void HandleException(ExceptionDispatchInfo edi) case PostgresErrorCodes.NoDataFound: throw new ReferenceNotFoundException(exception.Message, exception); + case "UX101": + throw new InvalidIdentifierException(exception.Message, exception); + } } diff --git a/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs b/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs index 771cf9d1..f1dce96b 100644 --- a/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs +++ b/tests/FunderMaps.IntegrationTests/Webservice/Analysis2Tests.cs @@ -155,7 +155,7 @@ public async Task GetRiskIndexByExternalIdInvalidAddressThrows(string address) var response = await client.GetAsync($"api/v2/product/at_risk?id={address}"); // Assert - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } [Theory] @@ -172,6 +172,6 @@ public async Task GetByIdInvalidAddressThrows(string address) var response = await client.GetAsync($"api/v2/product/analysis?id={address}"); // Assert - Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } } From eca13ac3d852e0341d24f207a005d9142af89d9c Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sat, 27 Nov 2021 16:13:16 +0100 Subject: [PATCH 14/20] Improve future API --- src/FunderMaps.Core/Interfaces/IProductService.cs | 6 ++++++ src/FunderMaps.Core/Services/ProductService.cs | 14 +++++++++++++- .../Controllers/ProductController.cs | 2 +- .../Controllers/ProductV2Controller.cs | 1 + .../Controllers/ProductV3Controller.cs | 4 ++-- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/FunderMaps.Core/Interfaces/IProductService.cs b/src/FunderMaps.Core/Interfaces/IProductService.cs index 6c6cc48e..838aabb6 100644 --- a/src/FunderMaps.Core/Interfaces/IProductService.cs +++ b/src/FunderMaps.Core/Interfaces/IProductService.cs @@ -38,4 +38,10 @@ public interface IProductService /// /// Input query. Task GetRiskIndexAsync(string input); + + /// + /// Get statistics per region. + /// + /// Input query. + Task GetStatistics3Async(string input); } diff --git a/src/FunderMaps.Core/Services/ProductService.cs b/src/FunderMaps.Core/Services/ProductService.cs index ffe95eeb..be33714d 100644 --- a/src/FunderMaps.Core/Services/ProductService.cs +++ b/src/FunderMaps.Core/Services/ProductService.cs @@ -57,6 +57,7 @@ private async Task GetStatisticsByExternalIdAsync(string id) MunicipalityReportCount = await _statisticsRepository.GetMunicipalityReportCountByExternalIdAsync(id), }; + // FUTURE: Not part of newer APIs /// /// Generate drystand description text. /// @@ -80,6 +81,7 @@ var risk_low when ( _ => "Onbekend", }; + // FUTURE: Not part of newer APIs /// /// Generate dewatering depth description text. /// @@ -103,6 +105,7 @@ var risk_low when ( _ => "Onbekend", }; + // FUTURE: Not part of newer APIs /// /// Generate bioinfection description text. /// @@ -122,6 +125,7 @@ var risk_medium when _ => "Onbekend", }; + // FUTURE: Is replaced by GetAnalysis3Async /// /// Get an analysis product. /// @@ -149,7 +153,7 @@ public virtual async IAsyncEnumerable GetAnalysisAsync(Analysis } } - // TODO: Remove the foreach + // FUTURE: Is replaced by GetAnalysis3Async /// /// Get an analysis product v2. /// @@ -184,6 +188,7 @@ public virtual Task GetAnalysis3Async(string input) public virtual Task GetRiskIndexAsync(string input) => _analysisRepository.GetRiskIndexAsync(input); + // FUTURE: Has beed replaced by GetStatistics3Async /// /// Get statistics per region. /// @@ -200,4 +205,11 @@ public virtual async IAsyncEnumerable GetStatisticsAsync(stri yield return product; } } + + /// + /// Get statistics per region. + /// + /// Input query. + public virtual Task GetStatistics3Async(string input) + => GetStatisticsByIdAsync(input); } diff --git a/src/FunderMaps.Webservice/Controllers/ProductController.cs b/src/FunderMaps.Webservice/Controllers/ProductController.cs index 5a8f4c33..8598fc74 100644 --- a/src/FunderMaps.Webservice/Controllers/ProductController.cs +++ b/src/FunderMaps.Webservice/Controllers/ProductController.cs @@ -11,7 +11,7 @@ namespace FunderMaps.Webservice.Controllers; /// /// Controller for all product endpoints. /// -[Obsolete("See ProductV2Controller")] +[Obsolete("See ProductV3Controller")] [Route("product")] public sealed class ProductController : ControllerBase { diff --git a/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs b/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs index e64a645a..39fbbd65 100644 --- a/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs +++ b/src/FunderMaps.Webservice/Controllers/ProductV2Controller.cs @@ -10,6 +10,7 @@ namespace FunderMaps.Webservice.Controllers; /// /// Controller for all product endpoints. /// +[Obsolete("See ProductV3Controller")] [Route("v2/product")] public sealed class ProductV2Controller : ControllerBase { diff --git a/src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs b/src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs index 8de2f754..e5f452e0 100644 --- a/src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs +++ b/src/FunderMaps.Webservice/Controllers/ProductV3Controller.cs @@ -49,6 +49,6 @@ public Task GetRiskIndexAsync([FromQuery] string id) [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public IAsyncEnumerable GetStatisticsAsync([FromQuery][Required] string id) - => _productService.GetStatisticsAsync(id); + public Task GetStatisticsAsync([FromQuery][Required] string id) + => _productService.GetStatistics3Async(id); } From 390fc82865e86c3fb24823ba051bec50ee61b178 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sun, 28 Nov 2021 11:46:19 +0100 Subject: [PATCH 15/20] Move to .NET 6.0 namespaceless units --- src/FunderMaps.Core/Types/AccessPolicy.cs | 25 +- src/FunderMaps.Core/Types/ApplicationRole.cs | 33 +- src/FunderMaps.Core/Types/AuditStatus.cs | 59 ++- src/FunderMaps.Core/Types/BuildingType.cs | 41 +- src/FunderMaps.Core/Types/BuiltYearSource.cs | 25 +- src/FunderMaps.Core/Types/ConstructionPile.cs | 65 ++- .../Types/Control/AccessControl.cs | 39 +- .../Types/Control/AttributionControl.cs | 49 +- .../Types/Control/IAccessControl.cs | 15 +- .../Types/Control/IAttribution.cs | 15 +- .../Types/Control/IRecordControl.cs | 15 +- .../Types/Control/IStateControl.cs | 15 +- .../Types/Control/RecordControl.cs | 33 +- .../Types/Control/StateControl.cs | 197 ++++---- src/FunderMaps.Core/Types/CrackType.cs | 41 +- .../ConstructionYearDistribution.cs | 21 +- .../Distributions/ConstructionYearPair.cs | 29 +- .../FoundationRiskDistribution.cs | 49 +- .../FoundationTypeDistribution.cs | 17 +- .../Types/Distributions/FoundationTypePair.cs | 27 +- .../Types/Distributions/IncidentYearPair.cs | 27 +- .../Types/Distributions/InquiryYearPair.cs | 27 +- src/FunderMaps.Core/Types/EnforcementTerm.cs | 109 +++-- .../Types/EnvironmentDamageCharacteristics.cs | 119 +++-- .../Types/ExternalDataSource.cs | 33 +- src/FunderMaps.Core/Types/Facade.cs | 41 +- .../Types/FoundationDamageCause.cs | 179 ++++--- .../Types/FoundationDamageCharacteristics.cs | 65 ++- .../Types/FoundationQuality.cs | 57 ++- src/FunderMaps.Core/Types/FoundationRisk.cs | 49 +- src/FunderMaps.Core/Types/FoundationType.cs | 189 ++++---- .../Types/GeocoderDatasource.cs | 121 +++-- src/FunderMaps.Core/Types/GeometryFormat.cs | 49 +- .../Types/IncidentQuestionType.cs | 89 ++-- src/FunderMaps.Core/Types/InquiryType.cs | 121 +++-- src/FunderMaps.Core/Types/OrganizationRole.cs | 41 +- src/FunderMaps.Core/Types/PileType.cs | 33 +- .../Types/Products/AnalysisProduct.cs | 446 +++++++++--------- src/FunderMaps.Core/Types/Quality.cs | 41 +- .../Types/RecoveryDocumentType.cs | 49 +- src/FunderMaps.Core/Types/RecoveryStatus.cs | 33 +- src/FunderMaps.Core/Types/RecoveryType.cs | 57 ++- src/FunderMaps.Core/Types/Reliability.cs | 33 +- src/FunderMaps.Core/Types/RotationType.cs | 49 +- src/FunderMaps.Core/Types/Substructure.cs | 41 +- .../Types/WoodEncroachement.cs | 33 +- src/FunderMaps.Core/Types/WoodQuality.cs | 41 +- src/FunderMaps.Core/Types/WoodType.cs | 25 +- src/FunderMaps.Core/Types/Years.cs | 75 ++- 49 files changed, 1517 insertions(+), 1565 deletions(-) diff --git a/src/FunderMaps.Core/Types/AccessPolicy.cs b/src/FunderMaps.Core/Types/AccessPolicy.cs index 4cb6e30a..d8d197e9 100644 --- a/src/FunderMaps.Core/Types/AccessPolicy.cs +++ b/src/FunderMaps.Core/Types/AccessPolicy.cs @@ -1,18 +1,17 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Record policy. +/// +public enum AccessPolicy { /// - /// Record policy. + /// Public. /// - public enum AccessPolicy - { - /// - /// Public. - /// - Public = 0, + Public = 0, - /// - /// Private. - /// - Private = 1, - } + /// + /// Private. + /// + Private = 1, } diff --git a/src/FunderMaps.Core/Types/ApplicationRole.cs b/src/FunderMaps.Core/Types/ApplicationRole.cs index 24e2bc63..ca628625 100644 --- a/src/FunderMaps.Core/Types/ApplicationRole.cs +++ b/src/FunderMaps.Core/Types/ApplicationRole.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Application user role. +/// +public enum ApplicationRole { /// - /// Application user role. + /// Administrator. /// - public enum ApplicationRole - { - /// - /// Administrator. - /// - Administrator = 0, + Administrator = 0, - /// - /// User. - /// - User = 1, + /// + /// User. + /// + User = 1, - /// - /// Guest. - /// - Guest = 2, - } + /// + /// Guest. + /// + Guest = 2, } diff --git a/src/FunderMaps.Core/Types/AuditStatus.cs b/src/FunderMaps.Core/Types/AuditStatus.cs index c8c2c4aa..8f84eb68 100644 --- a/src/FunderMaps.Core/Types/AuditStatus.cs +++ b/src/FunderMaps.Core/Types/AuditStatus.cs @@ -1,39 +1,38 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Audit status. +/// +public enum AuditStatus { /// - /// Audit status. + /// Needs to be done. /// - public enum AuditStatus - { - /// - /// Needs to be done. - /// - Todo = 0, + Todo = 0, - /// - /// Pending. - /// - Pending = 1, + /// + /// Pending. + /// + Pending = 1, - /// - /// Done. - /// - Done = 2, + /// + /// Done. + /// + Done = 2, - // FUTURE: Remove. - /// - /// Discarded. - /// - Discarded = 3, + // FUTURE: Remove. + /// + /// Discarded. + /// + Discarded = 3, - /// - /// Pending review. - /// - PendingReview = 4, + /// + /// Pending review. + /// + PendingReview = 4, - /// - /// Rejected. - /// - Rejected = 5, - } + /// + /// Rejected. + /// + Rejected = 5, } diff --git a/src/FunderMaps.Core/Types/BuildingType.cs b/src/FunderMaps.Core/Types/BuildingType.cs index 872296ae..a107ff2e 100644 --- a/src/FunderMaps.Core/Types/BuildingType.cs +++ b/src/FunderMaps.Core/Types/BuildingType.cs @@ -1,28 +1,27 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Building type. +/// +public enum BuildingType { /// - /// Building type. + /// House. /// - public enum BuildingType - { - /// - /// House. - /// - House = 0, + House = 0, - /// - /// Shed. - /// - Shed = 1, + /// + /// Shed. + /// + Shed = 1, - /// - /// Houseboat. - /// - Houseboat = 2, + /// + /// Houseboat. + /// + Houseboat = 2, - /// - /// Mobile home. - /// - MobileHome = 3, - } + /// + /// Mobile home. + /// + MobileHome = 3, } diff --git a/src/FunderMaps.Core/Types/BuiltYearSource.cs b/src/FunderMaps.Core/Types/BuiltYearSource.cs index d8ddaf4d..a175d9ee 100644 --- a/src/FunderMaps.Core/Types/BuiltYearSource.cs +++ b/src/FunderMaps.Core/Types/BuiltYearSource.cs @@ -1,18 +1,17 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Represents an external data source. +/// +public enum BuiltYearSource { /// - /// Represents an external data source. + /// Basis Registratie Gebouwen (BAG). /// - public enum BuiltYearSource - { - /// - /// Basis Registratie Gebouwen (BAG). - /// - Bag = 0, + Bag = 0, - /// - /// FunderMaps registered data. - /// - Fundermaps = 1, - } + /// + /// FunderMaps registered data. + /// + Fundermaps = 1, } diff --git a/src/FunderMaps.Core/Types/ConstructionPile.cs b/src/FunderMaps.Core/Types/ConstructionPile.cs index a6152b9b..93e5984f 100644 --- a/src/FunderMaps.Core/Types/ConstructionPile.cs +++ b/src/FunderMaps.Core/Types/ConstructionPile.cs @@ -1,43 +1,42 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Construction pile. +/// +public enum ConstructionPile { /// - /// Construction pile. + /// Punched. /// - public enum ConstructionPile - { - /// - /// Punched. - /// - Punched = 0, + Punched = 0, - /// - /// Broken. - /// - Broken = 1, + /// + /// Broken. + /// + Broken = 1, - /// - /// Pinched. - /// - Pinched = 2, + /// + /// Pinched. + /// + Pinched = 2, - /// - /// Pressed. - /// - Pressed = 3, + /// + /// Pressed. + /// + Pressed = 3, - /// - /// Perished. - /// - Perished = 4, + /// + /// Perished. + /// + Perished = 4, - /// - /// Decay. - /// - Decay = 5, + /// + /// Decay. + /// + Decay = 5, - /// - /// Root growth. - /// - RootGrowth = 6, - } + /// + /// Root growth. + /// + RootGrowth = 6, } diff --git a/src/FunderMaps.Core/Types/Control/AccessControl.cs b/src/FunderMaps.Core/Types/Control/AccessControl.cs index f84123bd..ddd863eb 100644 --- a/src/FunderMaps.Core/Types/Control/AccessControl.cs +++ b/src/FunderMaps.Core/Types/Control/AccessControl.cs @@ -1,26 +1,25 @@ -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// Record access control. +/// +public class AccessControl { /// - /// Record access control. + /// Record access policy. /// - public class AccessControl - { - /// - /// Record access policy. - /// - /// Default to . - public AccessPolicy AccessPolicy { get; set; } = AccessPolicy.Private; + /// Default to . + public AccessPolicy AccessPolicy { get; set; } = AccessPolicy.Private; - /// - /// Is record public. - /// - /// True if public. - public bool IsPublic => AccessPolicy == AccessPolicy.Public; + /// + /// Is record public. + /// + /// True if public. + public bool IsPublic => AccessPolicy == AccessPolicy.Public; - /// - /// Is record private. - /// - /// True if private. - public bool IsPrivate => AccessPolicy == AccessPolicy.Private; - } + /// + /// Is record private. + /// + /// True if private. + public bool IsPrivate => AccessPolicy == AccessPolicy.Private; } diff --git a/src/FunderMaps.Core/Types/Control/AttributionControl.cs b/src/FunderMaps.Core/Types/Control/AttributionControl.cs index 97c671a0..ec9811c9 100644 --- a/src/FunderMaps.Core/Types/Control/AttributionControl.cs +++ b/src/FunderMaps.Core/Types/Control/AttributionControl.cs @@ -1,33 +1,32 @@ -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// Attribution represents an entity partition for user and organizational relations. +/// +public class AttributionControl { /// - /// Attribution represents an entity partition for user and organizational relations. + /// Unique identifier. /// - public class AttributionControl - { - /// - /// Unique identifier. - /// - public int Id { get; set; } + public int Id { get; set; } - /// - /// Reviewer idenitfier. - /// - public Guid? Reviewer { get; set; } + /// + /// Reviewer idenitfier. + /// + public Guid? Reviewer { get; set; } - /// - /// Creator identifier. - /// - public Guid Creator { get; set; } + /// + /// Creator identifier. + /// + public Guid Creator { get; set; } - /// - /// Owner identifier. - /// - public Guid Owner { get; set; } + /// + /// Owner identifier. + /// + public Guid Owner { get; set; } - /// - /// Contractor identifier. - /// - public Guid Contractor { get; set; } - } + /// + /// Contractor identifier. + /// + public Guid Contractor { get; set; } } diff --git a/src/FunderMaps.Core/Types/Control/IAccessControl.cs b/src/FunderMaps.Core/Types/Control/IAccessControl.cs index edd473fc..6ae5f3f6 100644 --- a/src/FunderMaps.Core/Types/Control/IAccessControl.cs +++ b/src/FunderMaps.Core/Types/Control/IAccessControl.cs @@ -1,13 +1,12 @@ -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// Access control. +/// +public interface IAccessControl { /// /// Access control. /// - public interface IAccessControl - { - /// - /// Access control. - /// - public AccessControl Access { get; set; } - } + public AccessControl Access { get; set; } } diff --git a/src/FunderMaps.Core/Types/Control/IAttribution.cs b/src/FunderMaps.Core/Types/Control/IAttribution.cs index 4112060d..21cf71cb 100644 --- a/src/FunderMaps.Core/Types/Control/IAttribution.cs +++ b/src/FunderMaps.Core/Types/Control/IAttribution.cs @@ -1,13 +1,12 @@ -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// Attribution control. +/// +public interface IAttribution { /// /// Attribution control. /// - public interface IAttribution - { - /// - /// Attribution control. - /// - public AttributionControl Attribution { get; set; } - } + public AttributionControl Attribution { get; set; } } diff --git a/src/FunderMaps.Core/Types/Control/IRecordControl.cs b/src/FunderMaps.Core/Types/Control/IRecordControl.cs index 0f67ab24..98eeaf96 100644 --- a/src/FunderMaps.Core/Types/Control/IRecordControl.cs +++ b/src/FunderMaps.Core/Types/Control/IRecordControl.cs @@ -1,13 +1,12 @@ -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// Record control. +/// +public interface IRecordControl { /// /// Record control. /// - public interface IRecordControl - { - /// - /// Record control. - /// - public RecordControl Record { get; set; } - } + public RecordControl Record { get; set; } } diff --git a/src/FunderMaps.Core/Types/Control/IStateControl.cs b/src/FunderMaps.Core/Types/Control/IStateControl.cs index 76f68a96..8feeeb20 100644 --- a/src/FunderMaps.Core/Types/Control/IStateControl.cs +++ b/src/FunderMaps.Core/Types/Control/IStateControl.cs @@ -1,13 +1,12 @@ -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// State control. +/// +public interface IStateControl { /// /// State control. /// - public interface IStateControl - { - /// - /// State control. - /// - public StateControl State { get; set; } - } + public StateControl State { get; set; } } diff --git a/src/FunderMaps.Core/Types/Control/RecordControl.cs b/src/FunderMaps.Core/Types/Control/RecordControl.cs index 38bde23a..5442d518 100644 --- a/src/FunderMaps.Core/Types/Control/RecordControl.cs +++ b/src/FunderMaps.Core/Types/Control/RecordControl.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// Record timestamps. +/// +public class RecordControl { /// - /// Record timestamps. + /// Record create date. /// - public class RecordControl - { - /// - /// Record create date. - /// - public DateTime CreateDate { get; set; } + public DateTime CreateDate { get; set; } - /// - /// Record last update. - /// - public DateTime? UpdateDate { get; set; } + /// + /// Record last update. + /// + public DateTime? UpdateDate { get; set; } - /// - /// Record delete date. - /// - public DateTime? DeleteDate { get; set; } - } + /// + /// Record delete date. + /// + public DateTime? DeleteDate { get; set; } } diff --git a/src/FunderMaps.Core/Types/Control/StateControl.cs b/src/FunderMaps.Core/Types/Control/StateControl.cs index 75f9cdb5..b307f665 100644 --- a/src/FunderMaps.Core/Types/Control/StateControl.cs +++ b/src/FunderMaps.Core/Types/Control/StateControl.cs @@ -1,123 +1,122 @@ using FunderMaps.Core.Exceptions; -namespace FunderMaps.Core.Types.Control +namespace FunderMaps.Core.Types.Control; + +/// +/// Entity state control. +/// +public class StateControl { /// - /// Entity state control. + /// Enitity status. /// - public class StateControl - { - /// - /// Enitity status. - /// - public AuditStatus AuditStatus { get; set; } = AuditStatus.Todo; + public AuditStatus AuditStatus { get; set; } = AuditStatus.Todo; - /// - /// Is write allowed in entry state. - /// - /// True if allowed. - public bool AllowWrite => AuditStatus == AuditStatus.Todo - || AuditStatus == AuditStatus.Pending - || AuditStatus == AuditStatus.Rejected; + /// + /// Is write allowed in entry state. + /// + /// True if allowed. + public bool AllowWrite => AuditStatus == AuditStatus.Todo + || AuditStatus == AuditStatus.Pending + || AuditStatus == AuditStatus.Rejected; - /// - /// Move to next state. - /// - /// - /// Not every state can transition from one state to - /// another without intervention. - /// - public void MoveNext() + /// + /// Move to next state. + /// + /// + /// Not every state can transition from one state to + /// another without intervention. + /// + public void MoveNext() + { + switch (AuditStatus) { - switch (AuditStatus) - { - case AuditStatus.Todo: - AuditStatus = AuditStatus.Pending; - break; - case AuditStatus.Pending: - AuditStatus = AuditStatus.PendingReview; - break; - } + case AuditStatus.Todo: + AuditStatus = AuditStatus.Pending; + break; + case AuditStatus.Pending: + AuditStatus = AuditStatus.PendingReview; + break; } + } - /// - /// Move state to todo. - /// - /// - /// Can move to this state from: - /// - /// Pending - /// - /// - public void TransitionToTodo() + /// + /// Move state to todo. + /// + /// + /// Can move to this state from: + /// + /// Pending + /// + /// + public void TransitionToTodo() + { + if (AuditStatus != AuditStatus.Pending) { - if (AuditStatus != AuditStatus.Pending) - { - throw new StateTransitionException(AuditStatus, AuditStatus.Todo); - } - AuditStatus = AuditStatus.Todo; + throw new StateTransitionException(AuditStatus, AuditStatus.Todo); } + AuditStatus = AuditStatus.Todo; + } - /// - /// Move state to pending. - /// - public void TransitionToPending() - { - AuditStatus = AuditStatus.Pending; - } + /// + /// Move state to pending. + /// + public void TransitionToPending() + { + AuditStatus = AuditStatus.Pending; + } - /// - /// Move state to review. - /// - /// - /// Can move to this state from: - /// - /// Pending - /// - /// - public void TransitionToReview() + /// + /// Move state to review. + /// + /// + /// Can move to this state from: + /// + /// Pending + /// + /// + public void TransitionToReview() + { + if (AuditStatus != AuditStatus.Pending) { - if (AuditStatus != AuditStatus.Pending) - { - throw new StateTransitionException(AuditStatus, AuditStatus.PendingReview); - } - AuditStatus = AuditStatus.PendingReview; + throw new StateTransitionException(AuditStatus, AuditStatus.PendingReview); } + AuditStatus = AuditStatus.PendingReview; + } - /// - /// Move state to done. - /// - /// - /// Can move to this state from: - /// - /// PendingReview - /// - /// - public void TransitionToDone() + /// + /// Move state to done. + /// + /// + /// Can move to this state from: + /// + /// PendingReview + /// + /// + public void TransitionToDone() + { + if (AuditStatus != AuditStatus.PendingReview) { - if (AuditStatus != AuditStatus.PendingReview) - { - throw new StateTransitionException(AuditStatus, AuditStatus.Done); - } - AuditStatus = AuditStatus.Done; + throw new StateTransitionException(AuditStatus, AuditStatus.Done); } + AuditStatus = AuditStatus.Done; + } - /// - /// Move state to rejected. - /// - /// - /// Can move to this state from: - /// - /// PendingReview - /// - /// - public void TransitionToRejected() + /// + /// Move state to rejected. + /// + /// + /// Can move to this state from: + /// + /// PendingReview + /// + /// + public void TransitionToRejected() + { + if (AuditStatus != AuditStatus.PendingReview) { - if (AuditStatus != AuditStatus.PendingReview) - { - throw new StateTransitionException(AuditStatus, AuditStatus.Rejected); - } - AuditStatus = AuditStatus.Rejected; + throw new StateTransitionException(AuditStatus, AuditStatus.Rejected); } + AuditStatus = AuditStatus.Rejected; } } diff --git a/src/FunderMaps.Core/Types/CrackType.cs b/src/FunderMaps.Core/Types/CrackType.cs index 3adc8342..681af3e5 100644 --- a/src/FunderMaps.Core/Types/CrackType.cs +++ b/src/FunderMaps.Core/Types/CrackType.cs @@ -1,28 +1,27 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Crack. +/// +public enum CrackType { /// - /// Crack. + /// Very mall. /// - public enum CrackType - { - /// - /// Very mall. - /// - VerySmall = 0, + VerySmall = 0, - /// - /// Small. - /// - Small = 1, + /// + /// Small. + /// + Small = 1, - /// - /// Mediocre. - /// - Mediocre = 2, + /// + /// Mediocre. + /// + Mediocre = 2, - /// - /// Big. - /// - Big = 3, - } + /// + /// Big. + /// + Big = 3, } diff --git a/src/FunderMaps.Core/Types/Distributions/ConstructionYearDistribution.cs b/src/FunderMaps.Core/Types/Distributions/ConstructionYearDistribution.cs index 7b27fce7..44f33a87 100644 --- a/src/FunderMaps.Core/Types/Distributions/ConstructionYearDistribution.cs +++ b/src/FunderMaps.Core/Types/Distributions/ConstructionYearDistribution.cs @@ -1,15 +1,14 @@ -namespace FunderMaps.Core.Types.Distributions +namespace FunderMaps.Core.Types.Distributions; + +/// +/// Represents a distribution of construction years. +/// +public sealed record ConstructionYearDistribution { /// - /// Represents a distribution of construction years. + /// Represents each decade in which the construction year of one or + /// more buildings exist, including the total amount of buildings per + /// decade. /// - public sealed record ConstructionYearDistribution - { - /// - /// Represents each decade in which the construction year of one or - /// more buildings exist, including the total amount of buildings per - /// decade. - /// - public IEnumerable Decades { get; set; } - } + public IEnumerable Decades { get; set; } } diff --git a/src/FunderMaps.Core/Types/Distributions/ConstructionYearPair.cs b/src/FunderMaps.Core/Types/Distributions/ConstructionYearPair.cs index 9d55a6dd..ef496991 100644 --- a/src/FunderMaps.Core/Types/Distributions/ConstructionYearPair.cs +++ b/src/FunderMaps.Core/Types/Distributions/ConstructionYearPair.cs @@ -1,20 +1,19 @@ -namespace FunderMaps.Core.Types.Distributions +namespace FunderMaps.Core.Types.Distributions; + +// FUTURE: Make pair a generic type. +/// +/// Represents how many buildings have their construction years in a given +/// . +/// +public sealed class ConstructionYearPair { - // FUTURE: Make pair a generic type. /// - /// Represents how many buildings have their construction years in a given - /// . + /// Decade that represents this construction year pair. /// - public sealed class ConstructionYearPair - { - /// - /// Decade that represents this construction year pair. - /// - public Years Decade { get; set; } + public Years Decade { get; set; } - /// - /// Total amount of items that fall into this decade. - /// - public int TotalCount { get; set; } - } + /// + /// Total amount of items that fall into this decade. + /// + public int TotalCount { get; set; } } diff --git a/src/FunderMaps.Core/Types/Distributions/FoundationRiskDistribution.cs b/src/FunderMaps.Core/Types/Distributions/FoundationRiskDistribution.cs index e757800a..36c5bb35 100644 --- a/src/FunderMaps.Core/Types/Distributions/FoundationRiskDistribution.cs +++ b/src/FunderMaps.Core/Types/Distributions/FoundationRiskDistribution.cs @@ -1,33 +1,32 @@ -namespace FunderMaps.Core.Types.Distributions +namespace FunderMaps.Core.Types.Distributions; + +/// +/// Represents the distribution of foundation risks. +/// +public sealed record FoundationRiskDistribution { /// - /// Represents the distribution of foundation risks. + /// Percentage of foundations having risk A. /// - public sealed record FoundationRiskDistribution - { - /// - /// Percentage of foundations having risk A. - /// - public decimal PercentageA { get; set; } + public decimal PercentageA { get; set; } - /// - /// Percentage of foundations having risk B. - /// - public decimal PercentageB { get; set; } + /// + /// Percentage of foundations having risk B. + /// + public decimal PercentageB { get; set; } - /// - /// Percentage of foundations having risk C. - /// - public decimal PercentageC { get; set; } + /// + /// Percentage of foundations having risk C. + /// + public decimal PercentageC { get; set; } - /// - /// Percentage of foundations having risk D. - /// - public decimal PercentageD { get; set; } + /// + /// Percentage of foundations having risk D. + /// + public decimal PercentageD { get; set; } - /// - /// Percentage of foundations having risk E. - /// - public decimal PercentageE { get; set; } - } + /// + /// Percentage of foundations having risk E. + /// + public decimal PercentageE { get; set; } } diff --git a/src/FunderMaps.Core/Types/Distributions/FoundationTypeDistribution.cs b/src/FunderMaps.Core/Types/Distributions/FoundationTypeDistribution.cs index 59560bb7..7e2b8865 100644 --- a/src/FunderMaps.Core/Types/Distributions/FoundationTypeDistribution.cs +++ b/src/FunderMaps.Core/Types/Distributions/FoundationTypeDistribution.cs @@ -1,13 +1,12 @@ -namespace FunderMaps.Core.Types.Distributions +namespace FunderMaps.Core.Types.Distributions; + +/// +/// Represents a distribution of foundation types. +/// +public sealed class FoundationTypeDistribution { /// - /// Represents a distribution of foundation types. + /// Contains a for each present foundation type. /// - public sealed class FoundationTypeDistribution - { - /// - /// Contains a for each present foundation type. - /// - public IEnumerable FoundationTypes { get; set; } - } + public IEnumerable FoundationTypes { get; set; } } diff --git a/src/FunderMaps.Core/Types/Distributions/FoundationTypePair.cs b/src/FunderMaps.Core/Types/Distributions/FoundationTypePair.cs index 67fd7359..08d2e5c0 100644 --- a/src/FunderMaps.Core/Types/Distributions/FoundationTypePair.cs +++ b/src/FunderMaps.Core/Types/Distributions/FoundationTypePair.cs @@ -1,19 +1,18 @@ -namespace FunderMaps.Core.Types.Distributions +namespace FunderMaps.Core.Types.Distributions; + +/// +/// Contains a pair of a and the total amount +/// of buildings having said . +/// +public record FoundationTypePair { /// - /// Contains a pair of a and the total amount - /// of buildings having said . + /// The type of foundation. /// - public record FoundationTypePair - { - /// - /// The type of foundation. - /// - public FoundationType FoundationType { get; set; } + public FoundationType FoundationType { get; set; } - /// - /// The percentage of buildings having this foundation type. - /// - public decimal Percentage { get; set; } - } + /// + /// The percentage of buildings having this foundation type. + /// + public decimal Percentage { get; set; } } diff --git a/src/FunderMaps.Core/Types/Distributions/IncidentYearPair.cs b/src/FunderMaps.Core/Types/Distributions/IncidentYearPair.cs index 1872f276..ee8d6194 100644 --- a/src/FunderMaps.Core/Types/Distributions/IncidentYearPair.cs +++ b/src/FunderMaps.Core/Types/Distributions/IncidentYearPair.cs @@ -1,19 +1,18 @@ -namespace FunderMaps.Core.Types.Distributions +namespace FunderMaps.Core.Types.Distributions; + +// FUTURE: Make pair a generic type. +/// +/// Per year incident statistics. +/// +public sealed class IncidentYearPair { - // FUTURE: Make pair a generic type. /// - /// Per year incident statistics. + /// Per year statistics. /// - public sealed class IncidentYearPair - { - /// - /// Per year statistics. - /// - public int Year { get; set; } + public int Year { get; set; } - /// - /// Total amount of items that fall into this year. - /// - public int TotalCount { get; set; } - } + /// + /// Total amount of items that fall into this year. + /// + public int TotalCount { get; set; } } diff --git a/src/FunderMaps.Core/Types/Distributions/InquiryYearPair.cs b/src/FunderMaps.Core/Types/Distributions/InquiryYearPair.cs index 31b0abe0..b72e79ca 100644 --- a/src/FunderMaps.Core/Types/Distributions/InquiryYearPair.cs +++ b/src/FunderMaps.Core/Types/Distributions/InquiryYearPair.cs @@ -1,19 +1,18 @@ -namespace FunderMaps.Core.Types.Distributions +namespace FunderMaps.Core.Types.Distributions; + +// FUTURE: Make pair a generic type. +/// +/// Per year incident statistics. +/// +public sealed class InquiryYearPair { - // FUTURE: Make pair a generic type. /// - /// Per year incident statistics. + /// Per year statistics. /// - public sealed class InquiryYearPair - { - /// - /// Per year statistics. - /// - public int Year { get; set; } + public int Year { get; set; } - /// - /// Total amount of items that fall into this year. - /// - public int TotalCount { get; set; } - } + /// + /// Total amount of items that fall into this year. + /// + public int TotalCount { get; set; } } diff --git a/src/FunderMaps.Core/Types/EnforcementTerm.cs b/src/FunderMaps.Core/Types/EnforcementTerm.cs index c79ba983..dd8bf9e1 100644 --- a/src/FunderMaps.Core/Types/EnforcementTerm.cs +++ b/src/FunderMaps.Core/Types/EnforcementTerm.cs @@ -1,58 +1,57 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Enforcement term. +/// +public enum EnforcementTerm { /// - /// Enforcement term. - /// - public enum EnforcementTerm - { - /// - /// Between 0 - 5 years. - /// - Term05 = 0, - - /// - /// Between 5 - 10 years. - /// - Term510 = 1, - - /// - /// Between 10 - 20 years. - /// - Term1020 = 2, - - /// - /// 5 years. - /// - Term5 = 3, - - /// - /// 10 years. - /// - Term10 = 4, - - /// - /// 15 years. - /// - Term15 = 5, - - /// - /// 20 years. - /// - Term20 = 6, - - /// - /// 25 years. - /// - Term25 = 7, - - /// - /// 30 years. - /// - Term30 = 8, - - /// - /// 40 years. - /// - Term40 = 9, - } + /// Between 0 - 5 years. + /// + Term05 = 0, + + /// + /// Between 5 - 10 years. + /// + Term510 = 1, + + /// + /// Between 10 - 20 years. + /// + Term1020 = 2, + + /// + /// 5 years. + /// + Term5 = 3, + + /// + /// 10 years. + /// + Term10 = 4, + + /// + /// 15 years. + /// + Term15 = 5, + + /// + /// 20 years. + /// + Term20 = 6, + + /// + /// 25 years. + /// + Term25 = 7, + + /// + /// 30 years. + /// + Term30 = 8, + + /// + /// 40 years. + /// + Term40 = 9, } diff --git a/src/FunderMaps.Core/Types/EnvironmentDamageCharacteristics.cs b/src/FunderMaps.Core/Types/EnvironmentDamageCharacteristics.cs index 3d1d6d22..cad2d243 100644 --- a/src/FunderMaps.Core/Types/EnvironmentDamageCharacteristics.cs +++ b/src/FunderMaps.Core/Types/EnvironmentDamageCharacteristics.cs @@ -1,63 +1,62 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Environment damage characteristics. +/// +public enum EnvironmentDamageCharacteristics { /// - /// Environment damage characteristics. - /// - public enum EnvironmentDamageCharacteristics - { - /// - /// Subsidence. - /// - Subsidence = 0, - - /// - /// Sagging cewer connections. - /// - SaggingSewerConnection = 1, - - /// - /// Sagging cables and pipes. - /// - SaggingCablesPipes = 2, - - /// - /// Flooding. - /// - Flooding = 3, - - /// - /// Foundation damage nearby. - /// - FoundationDamageNearby = 4, - - /// - /// Elevation. - /// - Elevation = 5, - - /// - /// Increasing traffic. - /// - IncreasingTraffic = 6, - - /// - /// Construction nearby. - /// - ConstructionNearby = 7, - - /// - /// Vegetation nearby. - /// - VegetationNearby = 8, - - /// - /// Sewage leakage. - /// - SewageLeakage = 9, - - /// - /// Low ground water. - /// - LowGroundWater = 10, - } + /// Subsidence. + /// + Subsidence = 0, + + /// + /// Sagging cewer connections. + /// + SaggingSewerConnection = 1, + + /// + /// Sagging cables and pipes. + /// + SaggingCablesPipes = 2, + + /// + /// Flooding. + /// + Flooding = 3, + + /// + /// Foundation damage nearby. + /// + FoundationDamageNearby = 4, + + /// + /// Elevation. + /// + Elevation = 5, + + /// + /// Increasing traffic. + /// + IncreasingTraffic = 6, + + /// + /// Construction nearby. + /// + ConstructionNearby = 7, + + /// + /// Vegetation nearby. + /// + VegetationNearby = 8, + + /// + /// Sewage leakage. + /// + SewageLeakage = 9, + + /// + /// Low ground water. + /// + LowGroundWater = 10, } diff --git a/src/FunderMaps.Core/Types/ExternalDataSource.cs b/src/FunderMaps.Core/Types/ExternalDataSource.cs index e835e959..4a719a47 100644 --- a/src/FunderMaps.Core/Types/ExternalDataSource.cs +++ b/src/FunderMaps.Core/Types/ExternalDataSource.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Represents an external data source. +/// +public enum ExternalDataSource { /// - /// Represents an external data source. + /// Basis Registratie Gebouwen (BAG). /// - public enum ExternalDataSource - { - /// - /// Basis Registratie Gebouwen (BAG). - /// - NlBag = 0, + NlBag = 0, - /// - /// Open Street Maps (OSM). - /// - NlOsm = 1, + /// + /// Open Street Maps (OSM). + /// + NlOsm = 1, - /// - /// Centraal Bureau Statistiek (CBS). - /// - NlCbs = 2, - } + /// + /// Centraal Bureau Statistiek (CBS). + /// + NlCbs = 2, } diff --git a/src/FunderMaps.Core/Types/Facade.cs b/src/FunderMaps.Core/Types/Facade.cs index 2c1232ca..739b6716 100644 --- a/src/FunderMaps.Core/Types/Facade.cs +++ b/src/FunderMaps.Core/Types/Facade.cs @@ -1,28 +1,27 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Facade. +/// +public enum Facade { /// - /// Facade. + /// Front. /// - public enum Facade - { - /// - /// Front. - /// - Front = 0, + Front = 0, - /// - /// Sidewall left. - /// - SidewallLeft = 1, + /// + /// Sidewall left. + /// + SidewallLeft = 1, - /// - /// Sidewall right. - /// - SidewallRight = 2, + /// + /// Sidewall right. + /// + SidewallRight = 2, - /// - /// Rear. - /// - Rear = 3, - } + /// + /// Rear. + /// + Rear = 3, } diff --git a/src/FunderMaps.Core/Types/FoundationDamageCause.cs b/src/FunderMaps.Core/Types/FoundationDamageCause.cs index 075fed81..f82745ae 100644 --- a/src/FunderMaps.Core/Types/FoundationDamageCause.cs +++ b/src/FunderMaps.Core/Types/FoundationDamageCause.cs @@ -1,93 +1,92 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Foundation damage cause. +/// +public enum FoundationDamageCause { /// - /// Foundation damage cause. - /// - public enum FoundationDamageCause - { - /// - /// Drainage. - /// - Drainage = 0, - - /// - /// Construction flaw. - /// - ConstructionFlaw = 1, - - /// - /// Drystand. - /// - Drystand = 2, - - /// - /// Overcharge. - /// - Overcharge = 3, - - /// - /// Overcharge and negative cling. - /// - OverchargeNegativeCling = 4, - - /// - /// Negative cling. - /// - NegativeCling = 5, - - /// - /// Bio infection. - /// - BioInfection = 6, - - /// - /// Fungus infection. - /// - FungusInfection = 8, - - /// - /// Bio and fungus infection. - /// - BioFungusInfection = 9, - - /// - /// Foundation flaw. - /// - FoundationFlaw = 10, - - /// - /// Construnction heave. - /// - ConstructionHeave = 11, - - /// - /// Subsidence. - /// - Subsidence = 12, - - /// - /// Vegetation. - /// - Vegetation = 13, - - /// - /// Gas. - /// - Gas = 14, - - /// - /// Vibrations. - /// - Vibrations = 15, - - /// - /// Foundation was partially recovered. - /// - PartialFoundationRecovery = 16, - - /// - /// Damage due japanese knotweed. - /// - JapanseKnotweed = 17, - } + /// Drainage. + /// + Drainage = 0, + + /// + /// Construction flaw. + /// + ConstructionFlaw = 1, + + /// + /// Drystand. + /// + Drystand = 2, + + /// + /// Overcharge. + /// + Overcharge = 3, + + /// + /// Overcharge and negative cling. + /// + OverchargeNegativeCling = 4, + + /// + /// Negative cling. + /// + NegativeCling = 5, + + /// + /// Bio infection. + /// + BioInfection = 6, + + /// + /// Fungus infection. + /// + FungusInfection = 8, + + /// + /// Bio and fungus infection. + /// + BioFungusInfection = 9, + + /// + /// Foundation flaw. + /// + FoundationFlaw = 10, + + /// + /// Construnction heave. + /// + ConstructionHeave = 11, + + /// + /// Subsidence. + /// + Subsidence = 12, + + /// + /// Vegetation. + /// + Vegetation = 13, + + /// + /// Gas. + /// + Gas = 14, + + /// + /// Vibrations. + /// + Vibrations = 15, + + /// + /// Foundation was partially recovered. + /// + PartialFoundationRecovery = 16, + + /// + /// Damage due japanese knotweed. + /// + JapanseKnotweed = 17, } diff --git a/src/FunderMaps.Core/Types/FoundationDamageCharacteristics.cs b/src/FunderMaps.Core/Types/FoundationDamageCharacteristics.cs index 65908825..0684779d 100644 --- a/src/FunderMaps.Core/Types/FoundationDamageCharacteristics.cs +++ b/src/FunderMaps.Core/Types/FoundationDamageCharacteristics.cs @@ -1,43 +1,42 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Foundation damage characteristics. +/// +public enum FoundationDamageCharacteristics { /// - /// Foundation damage characteristics. + /// Jamming door window. /// - public enum FoundationDamageCharacteristics - { - /// - /// Jamming door window. - /// - JammingDoorWindow = 0, + JammingDoorWindow = 0, - /// - /// Crack. - /// - Crack = 1, + /// + /// Crack. + /// + Crack = 1, - /// - /// Skewed. - /// - Skewed = 2, + /// + /// Skewed. + /// + Skewed = 2, - /// - /// Crawlspace flooding. - /// - CrawlspaceFlooding = 3, + /// + /// Crawlspace flooding. + /// + CrawlspaceFlooding = 3, - /// - /// Threshold above subsurface. - /// - ThresholdAboveSubsurface = 4, + /// + /// Threshold above subsurface. + /// + ThresholdAboveSubsurface = 4, - /// - /// Threshold below subsurface. - /// - ThresholdBelowSubsurface = 5, + /// + /// Threshold below subsurface. + /// + ThresholdBelowSubsurface = 5, - /// - /// Crooked floor wall. - /// - CrookedFloorWall = 6, - } + /// + /// Crooked floor wall. + /// + CrookedFloorWall = 6, } diff --git a/src/FunderMaps.Core/Types/FoundationQuality.cs b/src/FunderMaps.Core/Types/FoundationQuality.cs index f7f3fc9a..62953e13 100644 --- a/src/FunderMaps.Core/Types/FoundationQuality.cs +++ b/src/FunderMaps.Core/Types/FoundationQuality.cs @@ -1,38 +1,37 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Foundation quality. +/// +public enum FoundationQuality { /// - /// Foundation quality. + /// Bad. /// - public enum FoundationQuality - { - /// - /// Bad. - /// - Bad = 0, + Bad = 0, - /// - /// Mediocre. - /// - Mediocre = 1, + /// + /// Mediocre. + /// + Mediocre = 1, - /// - /// Tolerable. - /// - Tolerable = 2, + /// + /// Tolerable. + /// + Tolerable = 2, - /// - /// Good. - /// - Good = 3, + /// + /// Good. + /// + Good = 3, - /// - /// Mediocre good. - /// - MediocreGood = 4, + /// + /// Mediocre good. + /// + MediocreGood = 4, - /// - /// Mediocre bad. - /// - MediocreBad = 5, - } + /// + /// Mediocre bad. + /// + MediocreBad = 5, } diff --git a/src/FunderMaps.Core/Types/FoundationRisk.cs b/src/FunderMaps.Core/Types/FoundationRisk.cs index 90942f43..5d6ddd7a 100644 --- a/src/FunderMaps.Core/Types/FoundationRisk.cs +++ b/src/FunderMaps.Core/Types/FoundationRisk.cs @@ -1,33 +1,32 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Represents the foundation risk. +/// +public enum FoundationRisk { /// - /// Represents the foundation risk. + /// Risk level A. /// - public enum FoundationRisk - { - /// - /// Risk level A. - /// - A = 0, + A = 0, - /// - /// Risk level B. - /// - B = 1, + /// + /// Risk level B. + /// + B = 1, - /// - /// Risk level C. - /// - C = 2, + /// + /// Risk level C. + /// + C = 2, - /// - /// Risk level D. - /// - D = 3, + /// + /// Risk level D. + /// + D = 3, - /// - /// Risk level E. - /// - E = 4, - } + /// + /// Risk level E. + /// + E = 4, } diff --git a/src/FunderMaps.Core/Types/FoundationType.cs b/src/FunderMaps.Core/Types/FoundationType.cs index ea951dc9..d76f4038 100644 --- a/src/FunderMaps.Core/Types/FoundationType.cs +++ b/src/FunderMaps.Core/Types/FoundationType.cs @@ -1,98 +1,97 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Foundation type. +/// +public enum FoundationType { /// - /// Foundation type. - /// - public enum FoundationType - { - /// - /// Wood. - /// - Wood = 0, - - /// - /// Wood foundation accoring to Amsterdam. - /// - WoodAmsterdam = 1, - - /// - /// Wood foundation accoring to Rotterdam. - /// - WoodRotterdam = 2, - - /// - /// Concrete. - /// - Concrete = 3, - - /// - /// No pile. - /// - NoPile = 4, - - /// - /// No pile and no masonry. - /// - NoPileMasonry = 5, - - /// - /// No pile strips. - /// - NoPileStrips = 6, - - /// - /// No pile and no bearing floor. - /// - NoPileBearingFloor = 7, - - /// - /// No pile and no concrete floor. - /// - NoPileConcreteFloor = 8, - - /// - /// No pile and no slit. - /// - NoPileSlit = 9, - - /// - /// Wood charger. - /// - WoodCharger = 10, - - /// - /// Weighted pile. - /// - WeightedPile = 11, - - /// - /// Combined. - /// - Combined = 12, - - /// - /// Steel pile. - /// - SteelPile = 13, - - /// - /// Other. - /// - Other = 14, - - /// - /// Wood foundation accoring to Amsterdam or Rotterdam. - /// - WoodRotterdamAmsterdam = 15, - - /// - /// Wood foundation accoring to Rotterdam with an arch. - /// - WoodRotterdamArch = 16, - - /// - /// Wood foundation accoring to Amsterdam with an arch. - /// - WoodAmsterdamArch = 17, - } + /// Wood. + /// + Wood = 0, + + /// + /// Wood foundation accoring to Amsterdam. + /// + WoodAmsterdam = 1, + + /// + /// Wood foundation accoring to Rotterdam. + /// + WoodRotterdam = 2, + + /// + /// Concrete. + /// + Concrete = 3, + + /// + /// No pile. + /// + NoPile = 4, + + /// + /// No pile and no masonry. + /// + NoPileMasonry = 5, + + /// + /// No pile strips. + /// + NoPileStrips = 6, + + /// + /// No pile and no bearing floor. + /// + NoPileBearingFloor = 7, + + /// + /// No pile and no concrete floor. + /// + NoPileConcreteFloor = 8, + + /// + /// No pile and no slit. + /// + NoPileSlit = 9, + + /// + /// Wood charger. + /// + WoodCharger = 10, + + /// + /// Weighted pile. + /// + WeightedPile = 11, + + /// + /// Combined. + /// + Combined = 12, + + /// + /// Steel pile. + /// + SteelPile = 13, + + /// + /// Other. + /// + Other = 14, + + /// + /// Wood foundation accoring to Amsterdam or Rotterdam. + /// + WoodRotterdamAmsterdam = 15, + + /// + /// Wood foundation accoring to Rotterdam with an arch. + /// + WoodRotterdamArch = 16, + + /// + /// Wood foundation accoring to Amsterdam with an arch. + /// + WoodAmsterdamArch = 17, } diff --git a/src/FunderMaps.Core/Types/GeocoderDatasource.cs b/src/FunderMaps.Core/Types/GeocoderDatasource.cs index 3dfe03be..7ca0b8c0 100644 --- a/src/FunderMaps.Core/Types/GeocoderDatasource.cs +++ b/src/FunderMaps.Core/Types/GeocoderDatasource.cs @@ -1,78 +1,77 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Geocoder datasource identifier. +/// +public enum GeocoderDatasource { /// - /// Geocoder datasource identifier. + /// FunderMaps geocoder identifier (GFM). /// - public enum GeocoderDatasource - { - /// - /// FunderMaps geocoder identifier (GFM). - /// - FunderMaps = 0, + FunderMaps = 0, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) building identifier. - /// - NlBagBuilding = 1, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) building identifier. + /// + NlBagBuilding = 1, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) address identifier. - /// - NlBagAddress = 2, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) address identifier. + /// + NlBagAddress = 2, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) posting identifier. - /// - NlBagPosting = 3, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) posting identifier. + /// + NlBagPosting = 3, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) berth identifier. - /// - NlBagBerth = 4, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) berth identifier. + /// + NlBagBerth = 4, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) legacy building identifier. - /// - NlBagLegacyBuilding = 8, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) legacy building identifier. + /// + NlBagLegacyBuilding = 8, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) legacy address identifier. - /// - NlBagLegacyAddress = 9, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) legacy address identifier. + /// + NlBagLegacyAddress = 9, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) legacy posting identifier. - /// - NlBagLegacyPosting = 10, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) legacy posting identifier. + /// + NlBagLegacyPosting = 10, - /// - /// Basisregistratie Adressen en Gebouwen (BAG) legacy berth identifier. - /// - NlBagLegacyBerth = 11, + /// + /// Basisregistratie Adressen en Gebouwen (BAG) legacy berth identifier. + /// + NlBagLegacyBerth = 11, - /// - /// Centraal Bureau Statistiek (CBS) neighborhoor identifier. - /// - NlCbsNeighborhood = 15, + /// + /// Centraal Bureau Statistiek (CBS) neighborhoor identifier. + /// + NlCbsNeighborhood = 15, - /// - /// Centraal Bureau Statistiek (CBS) district identifier. - /// - NlCbsDistrict = 16, + /// + /// Centraal Bureau Statistiek (CBS) district identifier. + /// + NlCbsDistrict = 16, - /// - /// Centraal Bureau Statistiek (CBS) municipality identifier. - /// - NlCbsMunicipality = 17, + /// + /// Centraal Bureau Statistiek (CBS) municipality identifier. + /// + NlCbsMunicipality = 17, - /// - /// Centraal Bureau Statistiek (CBS) state identifier. - /// - NlCbsState = 18, + /// + /// Centraal Bureau Statistiek (CBS) state identifier. + /// + NlCbsState = 18, - /// - /// Unknown identifier. - /// - Unknown = 50, - } + /// + /// Unknown identifier. + /// + Unknown = 50, } diff --git a/src/FunderMaps.Core/Types/GeometryFormat.cs b/src/FunderMaps.Core/Types/GeometryFormat.cs index 35ee0a46..f4710b40 100644 --- a/src/FunderMaps.Core/Types/GeometryFormat.cs +++ b/src/FunderMaps.Core/Types/GeometryFormat.cs @@ -1,33 +1,32 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Represents a type of export format. +/// +public enum GeometryFormat { /// - /// Represents a type of export format. + /// Mapbox vector tiles. /// - public enum GeometryFormat - { - /// - /// Mapbox vector tiles. - /// - MapboxVectorTiles = 0, + MapboxVectorTiles = 0, - /// - /// GeoPackage. - /// - GeoPackage = 1, + /// + /// GeoPackage. + /// + GeoPackage = 1, - /// - /// ESRI Shapefile. - /// - ESRIShapefile = 2, + /// + /// ESRI Shapefile. + /// + ESRIShapefile = 2, - /// - /// GeoJSON. - /// - GeoJSON = 3, + /// + /// GeoJSON. + /// + GeoJSON = 3, - /// - /// GeoJSON Sequential. - /// - GeoJSONSeq = 4, - } + /// + /// GeoJSON Sequential. + /// + GeoJSONSeq = 4, } diff --git a/src/FunderMaps.Core/Types/IncidentQuestionType.cs b/src/FunderMaps.Core/Types/IncidentQuestionType.cs index 7a8e4c39..c26ecab9 100644 --- a/src/FunderMaps.Core/Types/IncidentQuestionType.cs +++ b/src/FunderMaps.Core/Types/IncidentQuestionType.cs @@ -1,48 +1,47 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Indicent question type. +/// +public enum IncidentQuestionType { /// - /// Indicent question type. - /// - public enum IncidentQuestionType - { - /// - /// Buy or sell. - /// - BuySell = 0, - - /// - /// Registration. - /// - Registration = 1, - - /// - /// Legal. - /// - Legal = 2, - - /// - /// Financial. - /// - Financial = 3, - - /// - /// Guidance. - /// - Guidance = 4, - - /// - /// Recovery. - /// - Recovery = 5, - - /// - /// Research. - /// - Research = 6, - - /// - /// Other. - /// - Other = 7, - } + /// Buy or sell. + /// + BuySell = 0, + + /// + /// Registration. + /// + Registration = 1, + + /// + /// Legal. + /// + Legal = 2, + + /// + /// Financial. + /// + Financial = 3, + + /// + /// Guidance. + /// + Guidance = 4, + + /// + /// Recovery. + /// + Recovery = 5, + + /// + /// Research. + /// + Research = 6, + + /// + /// Other. + /// + Other = 7, } diff --git a/src/FunderMaps.Core/Types/InquiryType.cs b/src/FunderMaps.Core/Types/InquiryType.cs index 2ca88915..c034563c 100644 --- a/src/FunderMaps.Core/Types/InquiryType.cs +++ b/src/FunderMaps.Core/Types/InquiryType.cs @@ -1,78 +1,77 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Inquiry type. +/// +public enum InquiryType { /// - /// Inquiry type. + /// Additional research. /// - public enum InquiryType - { - /// - /// Additional research. - /// - AdditionalResearch = 0, + AdditionalResearch = 0, - /// - /// Monitoring. - /// - Monitoring = 1, + /// + /// Monitoring. + /// + Monitoring = 1, - /// - /// Note. - /// - Note = 2, + /// + /// Note. + /// + Note = 2, - /// - /// Quickscan. - /// - Quickscan = 3, + /// + /// Quickscan. + /// + Quickscan = 3, - /// - /// Unknown. - /// - Unknown = 4, + /// + /// Unknown. + /// + Unknown = 4, - /// - /// Demolition research. - /// - DemolitionResearch = 5, + /// + /// Demolition research. + /// + DemolitionResearch = 5, - /// - /// Second opinion. - /// - SecondOpinion = 6, + /// + /// Second opinion. + /// + SecondOpinion = 6, - /// - /// Archieve research. - /// - ArchieveResearch = 7, + /// + /// Archieve research. + /// + ArchieveResearch = 7, - /// - /// Architectural research. - /// - ArchitecturalResearch = 8, + /// + /// Architectural research. + /// + ArchitecturalResearch = 8, - /// - /// Foundation advice. - /// - FoundationAdvice = 9, + /// + /// Foundation advice. + /// + FoundationAdvice = 9, - /// - /// Inspectionpit. - /// - Inspectionpit = 10, + /// + /// Inspectionpit. + /// + Inspectionpit = 10, - /// - /// Foundation research. - /// - FoundationResearch = 11, + /// + /// Foundation research. + /// + FoundationResearch = 11, - /// - /// Groundwaterlevel research. - /// - GroundWaterLevelResearch = 12, + /// + /// Groundwaterlevel research. + /// + GroundWaterLevelResearch = 12, - /// - /// Soil investigation. - /// - SoilInvestigation = 13, - } + /// + /// Soil investigation. + /// + SoilInvestigation = 13, } diff --git a/src/FunderMaps.Core/Types/OrganizationRole.cs b/src/FunderMaps.Core/Types/OrganizationRole.cs index 82b7e7ff..3acec0be 100644 --- a/src/FunderMaps.Core/Types/OrganizationRole.cs +++ b/src/FunderMaps.Core/Types/OrganizationRole.cs @@ -1,28 +1,27 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Organization user role. +/// +public enum OrganizationRole { /// - /// Organization user role. + /// Superuser. /// - public enum OrganizationRole - { - /// - /// Superuser. - /// - Superuser = 0, + Superuser = 0, - /// - /// Verifier. - /// - Verifier = 1, + /// + /// Verifier. + /// + Verifier = 1, - /// - /// Writer. - /// - Writer = 2, + /// + /// Writer. + /// + Writer = 2, - /// - /// Reader. - /// - Reader = 3, - } + /// + /// Reader. + /// + Reader = 3, } diff --git a/src/FunderMaps.Core/Types/PileType.cs b/src/FunderMaps.Core/Types/PileType.cs index 9c7d1144..a22fe41c 100644 --- a/src/FunderMaps.Core/Types/PileType.cs +++ b/src/FunderMaps.Core/Types/PileType.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Pile type. +/// +public enum PileType { /// - /// Pile type. + /// Press. /// - public enum PileType - { - /// - /// Press. - /// - Press = 0, + Press = 0, - /// - /// Intgernally driven. - /// - IntgernallyDriven = 1, + /// + /// Intgernally driven. + /// + IntgernallyDriven = 1, - /// - /// Segment. - /// - Segment = 2, - } + /// + /// Segment. + /// + Segment = 2, } diff --git a/src/FunderMaps.Core/Types/Products/AnalysisProduct.cs b/src/FunderMaps.Core/Types/Products/AnalysisProduct.cs index f4692e1d..4fc888f0 100644 --- a/src/FunderMaps.Core/Types/Products/AnalysisProduct.cs +++ b/src/FunderMaps.Core/Types/Products/AnalysisProduct.cs @@ -1,227 +1,227 @@ using FunderMaps.Core.DataAnnotations; -namespace FunderMaps.Core.Types.Products + +namespace FunderMaps.Core.Types.Products; + +/// +/// Represents a model for the complete endpoint. +/// +public sealed record AnalysisProduct { /// - /// Represents a model for the complete endpoint. - /// - public sealed record AnalysisProduct - { - /// - /// Building identifier. - /// - [Geocoder] - public string Id { get; init; } - - /// - /// Building external identifier. - /// - public string ExternalId { get; init; } - - /// - /// Postal code - /// - public string PostalCode { get; init; } - - /// - /// Represents the external data source of this building. - /// - public ExternalDataSource? ExternalSource { get; init; } - - /// - /// Built year. - /// - public DateTimeOffset ConstructionYear { get; init; } - - /// - /// Built year source. - /// - public BuiltYearSource ConstructionYearSource { get; init; } - - /// - /// Address identifier. - /// - [Geocoder] - public string AddressId { get; init; } - - /// - /// Address external identifier. - /// - public string AddressExternalId { get; init; } - - /// - /// Neighborhood identifier. - /// - [Geocoder] - public string NeighborhoodId { get; init; } - - /// - /// Represents the ground water level. - /// - public double? GroundWaterLevel { get; init; } - - /// - /// Soil code. - /// - public string Soil { get; init; } - - /// - /// Represents the height of this building. - /// - public double? BuildingHeight { get; init; } - - /// - /// Ground level in meters. - /// - public double? GroundLevel { get; init; } - - /// - /// Cone penetration test name. - /// - public string Cpt { get; init; } - - /// - /// Monitoring well. - /// - public string MonitoringWell { get; init; } - - /// - /// Recovery advised. - /// - public bool? RecoveryAdvised { get; init; } - - /// - /// Damage cause. - /// - public FoundationDamageCause? DamageCause { get; init; } - - /// - /// Substructure. - /// - public Substructure? Substructure { get; init; } - - /// - /// Client document identifier. - /// - public string DocumentName { get; init; } - - /// - /// Original document creation. - /// - public DateTime? DocumentDate { get; init; } - - /// - /// Report type. - /// - public InquiryType? InquiryType { get; init; } - - /// - /// Foundation recovery type. - /// - public RecoveryType? RecoveryType { get; init; } - - /// - /// Foundation recovery status. - /// - public RecoveryStatus? RecoveryStatus { get; init; } - - /// - /// Building surface area in square meters. - /// - public double? SurfaceArea { get; init; } - - /// - /// Address living surface area in square meters. - /// - public double? LivingArea { get; init; } - - /// - /// Foundation bearing ground layer. - /// - public double? FoundationBearingLayer { get; init; } - - /// - /// Represents the estimated restoration costs for this building. - /// - public double? RestorationCosts { get; init; } - - /// - /// Description for restoration costs. - /// - public string DescriptionRestorationCosts { get; init; } - - /// - /// Foundation type. - /// - public FoundationType? FoundationType { get; init; } - - /// - /// Foundation type reliability. - /// - public Reliability FoundationTypeReliability { get; init; } - - /// - /// Represents the period of drought (droogstand) for this building. - /// - public double? Drystand { get; init; } - - /// - /// Foundation type reliability. - /// - public Reliability DrystandReliability { get; init; } - - /// - /// Represents the foundation risk for this building. - /// - public FoundationRisk? DrystandRisk { get; init; } - - /// - /// Description for drystand. - /// - public string DescriptionDrystand { get; init; } - - /// - /// Dewatering depth. - /// - public double? DewateringDepth { get; init; } - - /// - /// Dewatering depth reliability. - /// - public Reliability DewateringDepthReliability { get; init; } - - /// - /// Dewatering depth risk. - /// - public FoundationRisk? DewateringDepthRisk { get; init; } - - /// - /// Description for dewatering depth. - /// - public string DescriptionDewateringDepth { get; init; } - - /// - /// Biological infection. - /// - public string BioInfection { get; init; } - - /// - /// Biological infection reliability. - /// - public Reliability BioInfectionReliability { get; init; } - - /// - /// Biological infection risk. - /// - public FoundationRisk? BioInfectionRisk { get; init; } - - /// - /// Description for biological infection. - /// - public string DescriptionBioInfection { get; init; } - - /// - /// Statistisch per region. - /// - public StatisticsProduct Statistics { get; init; } - } + /// Building identifier. + /// + [Geocoder] + public string Id { get; init; } + + /// + /// Building external identifier. + /// + public string ExternalId { get; init; } + + /// + /// Postal code + /// + public string PostalCode { get; init; } + + /// + /// Represents the external data source of this building. + /// + public ExternalDataSource? ExternalSource { get; init; } + + /// + /// Built year. + /// + public DateTimeOffset ConstructionYear { get; init; } + + /// + /// Built year source. + /// + public BuiltYearSource ConstructionYearSource { get; init; } + + /// + /// Address identifier. + /// + [Geocoder] + public string AddressId { get; init; } + + /// + /// Address external identifier. + /// + public string AddressExternalId { get; init; } + + /// + /// Neighborhood identifier. + /// + [Geocoder] + public string NeighborhoodId { get; init; } + + /// + /// Represents the ground water level. + /// + public double? GroundWaterLevel { get; init; } + + /// + /// Soil code. + /// + public string Soil { get; init; } + + /// + /// Represents the height of this building. + /// + public double? BuildingHeight { get; init; } + + /// + /// Ground level in meters. + /// + public double? GroundLevel { get; init; } + + /// + /// Cone penetration test name. + /// + public string Cpt { get; init; } + + /// + /// Monitoring well. + /// + public string MonitoringWell { get; init; } + + /// + /// Recovery advised. + /// + public bool? RecoveryAdvised { get; init; } + + /// + /// Damage cause. + /// + public FoundationDamageCause? DamageCause { get; init; } + + /// + /// Substructure. + /// + public Substructure? Substructure { get; init; } + + /// + /// Client document identifier. + /// + public string DocumentName { get; init; } + + /// + /// Original document creation. + /// + public DateTime? DocumentDate { get; init; } + + /// + /// Report type. + /// + public InquiryType? InquiryType { get; init; } + + /// + /// Foundation recovery type. + /// + public RecoveryType? RecoveryType { get; init; } + + /// + /// Foundation recovery status. + /// + public RecoveryStatus? RecoveryStatus { get; init; } + + /// + /// Building surface area in square meters. + /// + public double? SurfaceArea { get; init; } + + /// + /// Address living surface area in square meters. + /// + public double? LivingArea { get; init; } + + /// + /// Foundation bearing ground layer. + /// + public double? FoundationBearingLayer { get; init; } + + /// + /// Represents the estimated restoration costs for this building. + /// + public double? RestorationCosts { get; init; } + + /// + /// Description for restoration costs. + /// + public string DescriptionRestorationCosts { get; init; } + + /// + /// Foundation type. + /// + public FoundationType? FoundationType { get; init; } + + /// + /// Foundation type reliability. + /// + public Reliability FoundationTypeReliability { get; init; } + + /// + /// Represents the period of drought (droogstand) for this building. + /// + public double? Drystand { get; init; } + + /// + /// Foundation type reliability. + /// + public Reliability DrystandReliability { get; init; } + + /// + /// Represents the foundation risk for this building. + /// + public FoundationRisk? DrystandRisk { get; init; } + + /// + /// Description for drystand. + /// + public string DescriptionDrystand { get; init; } + + /// + /// Dewatering depth. + /// + public double? DewateringDepth { get; init; } + + /// + /// Dewatering depth reliability. + /// + public Reliability DewateringDepthReliability { get; init; } + + /// + /// Dewatering depth risk. + /// + public FoundationRisk? DewateringDepthRisk { get; init; } + + /// + /// Description for dewatering depth. + /// + public string DescriptionDewateringDepth { get; init; } + + /// + /// Biological infection. + /// + public string BioInfection { get; init; } + + /// + /// Biological infection reliability. + /// + public Reliability BioInfectionReliability { get; init; } + + /// + /// Biological infection risk. + /// + public FoundationRisk? BioInfectionRisk { get; init; } + + /// + /// Description for biological infection. + /// + public string DescriptionBioInfection { get; init; } + + /// + /// Statistisch per region. + /// + public StatisticsProduct Statistics { get; init; } } diff --git a/src/FunderMaps.Core/Types/Quality.cs b/src/FunderMaps.Core/Types/Quality.cs index eeb46e16..31f5241f 100644 --- a/src/FunderMaps.Core/Types/Quality.cs +++ b/src/FunderMaps.Core/Types/Quality.cs @@ -1,28 +1,27 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Quality. +/// +public enum Quality { /// - /// Quality. + /// Nil. /// - public enum Quality - { - /// - /// Nil. - /// - Nil = 0, + Nil = 0, - /// - /// Small. - /// - Small = 1, + /// + /// Small. + /// + Small = 1, - /// - /// Mediocre. - /// - Mediocre = 2, + /// + /// Mediocre. + /// + Mediocre = 2, - /// - /// Large. - /// - Large = 3, - } + /// + /// Large. + /// + Large = 3, } diff --git a/src/FunderMaps.Core/Types/RecoveryDocumentType.cs b/src/FunderMaps.Core/Types/RecoveryDocumentType.cs index 074b01e5..8935378e 100644 --- a/src/FunderMaps.Core/Types/RecoveryDocumentType.cs +++ b/src/FunderMaps.Core/Types/RecoveryDocumentType.cs @@ -1,33 +1,32 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Recovery document type. +/// +public enum RecoveryDocumentType { /// - /// Recovery document type. + /// Permit. /// - public enum RecoveryDocumentType - { - /// - /// Permit. - /// - Permit = 0, + Permit = 0, - /// - /// Foundation report - /// - FoundationReport = 1, + /// + /// Foundation report + /// + FoundationReport = 1, - /// - /// Archive report. - /// - ArchiveReport = 2, + /// + /// Archive report. + /// + ArchiveReport = 2, - /// - /// Owner evidence. - /// - OwnerEvidence = 3, + /// + /// Owner evidence. + /// + OwnerEvidence = 3, - /// - /// Unknown. - /// - Unknown = 4, - } + /// + /// Unknown. + /// + Unknown = 4, } diff --git a/src/FunderMaps.Core/Types/RecoveryStatus.cs b/src/FunderMaps.Core/Types/RecoveryStatus.cs index 2f8d32ba..2654482b 100644 --- a/src/FunderMaps.Core/Types/RecoveryStatus.cs +++ b/src/FunderMaps.Core/Types/RecoveryStatus.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Recovery status. +/// +public enum RecoveryStatus { /// - /// Recovery status. + /// Planned. /// - public enum RecoveryStatus - { - /// - /// Planned. - /// - Planned = 0, + Planned = 0, - /// - /// Requested. - /// - Requested = 1, + /// + /// Requested. + /// + Requested = 1, - /// - /// Executed. - /// - Executed = 2, - } + /// + /// Executed. + /// + Executed = 2, } diff --git a/src/FunderMaps.Core/Types/RecoveryType.cs b/src/FunderMaps.Core/Types/RecoveryType.cs index 3f7633d0..6f7abde5 100644 --- a/src/FunderMaps.Core/Types/RecoveryType.cs +++ b/src/FunderMaps.Core/Types/RecoveryType.cs @@ -1,38 +1,37 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Recovery type. +/// +public enum RecoveryType { /// - /// Recovery type. + /// Table. /// - public enum RecoveryType - { - /// - /// Table. - /// - Table = 0, + Table = 0, - /// - /// Beam on pile. - /// - BeamOnPile = 1, + /// + /// Beam on pile. + /// + BeamOnPile = 1, - /// - /// Pile lowering. - /// - PileLowering = 2, + /// + /// Pile lowering. + /// + PileLowering = 2, - /// - /// Pile in wall. - /// - PileInWall = 3, + /// + /// Pile in wall. + /// + PileInWall = 3, - /// - /// Injection. - /// - Injection = 4, + /// + /// Injection. + /// + Injection = 4, - /// - /// Unknown. - /// - Unknown = 5, - } + /// + /// Unknown. + /// + Unknown = 5, } diff --git a/src/FunderMaps.Core/Types/Reliability.cs b/src/FunderMaps.Core/Types/Reliability.cs index d87beabb..078bbb6f 100644 --- a/src/FunderMaps.Core/Types/Reliability.cs +++ b/src/FunderMaps.Core/Types/Reliability.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Indicates the reliability of a product. +/// +public enum Reliability { /// - /// Indicates the reliability of a product. + /// When our model was used. /// - public enum Reliability - { - /// - /// When our model was used. - /// - Indicative = 0, + Indicative = 0, - /// - /// When a report is present. - /// - Established = 1, + /// + /// When a report is present. + /// + Established = 1, - /// - /// When building from the same cluster was used. - /// - Cluster = 2, - } + /// + /// When building from the same cluster was used. + /// + Cluster = 2, } diff --git a/src/FunderMaps.Core/Types/RotationType.cs b/src/FunderMaps.Core/Types/RotationType.cs index 0770dbe5..a574ecd4 100644 --- a/src/FunderMaps.Core/Types/RotationType.cs +++ b/src/FunderMaps.Core/Types/RotationType.cs @@ -1,33 +1,32 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Rotation type. +/// +public enum RotationType { /// - /// Rotation type. + /// Nil. /// - public enum RotationType - { - /// - /// Nil. - /// - Nil = 0, + Nil = 0, - /// - /// Very small. - /// - VerySmall = 1, + /// + /// Very small. + /// + VerySmall = 1, - /// - /// Small. - /// - Small = 2, + /// + /// Small. + /// + Small = 2, - /// - /// Mediocre. - /// - Mediocre = 3, + /// + /// Mediocre. + /// + Mediocre = 3, - /// - /// Big. - /// - Big = 4, - } + /// + /// Big. + /// + Big = 4, } diff --git a/src/FunderMaps.Core/Types/Substructure.cs b/src/FunderMaps.Core/Types/Substructure.cs index 332584ff..1ecdd24f 100644 --- a/src/FunderMaps.Core/Types/Substructure.cs +++ b/src/FunderMaps.Core/Types/Substructure.cs @@ -1,28 +1,27 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Substructure. +/// +public enum Substructure { /// - /// Substructure. + /// Cellar. /// - public enum Substructure - { - /// - /// Cellar. - /// - Cellar = 0, + Cellar = 0, - /// - /// Basement. - /// - Basement = 1, + /// + /// Basement. + /// + Basement = 1, - /// - /// Crawlspace. - /// - Crawlspace = 2, + /// + /// Crawlspace. + /// + Crawlspace = 2, - /// - /// None. - /// - None = 3, - } + /// + /// None. + /// + None = 3, } diff --git a/src/FunderMaps.Core/Types/WoodEncroachement.cs b/src/FunderMaps.Core/Types/WoodEncroachement.cs index 8f782b63..3bc35e3d 100644 --- a/src/FunderMaps.Core/Types/WoodEncroachement.cs +++ b/src/FunderMaps.Core/Types/WoodEncroachement.cs @@ -1,23 +1,22 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Wood encroachement. +/// +public enum WoodEncroachement { /// - /// Wood encroachement. + /// Fungus infection. /// - public enum WoodEncroachement - { - /// - /// Fungus infection. - /// - FungusInfection = 0, + FungusInfection = 0, - /// - /// Bio fungus infection. - /// - BioFungusInfection = 1, + /// + /// Bio fungus infection. + /// + BioFungusInfection = 1, - /// - /// Bio infection. - /// - BioInfection = 2, - } + /// + /// Bio infection. + /// + BioInfection = 2, } diff --git a/src/FunderMaps.Core/Types/WoodQuality.cs b/src/FunderMaps.Core/Types/WoodQuality.cs index 64efd17c..b5c76b8b 100644 --- a/src/FunderMaps.Core/Types/WoodQuality.cs +++ b/src/FunderMaps.Core/Types/WoodQuality.cs @@ -1,28 +1,27 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Wood quality. +/// +public enum WoodQuality { /// - /// Wood quality. + /// Area 1. /// - public enum WoodQuality - { - /// - /// Area 1. - /// - Area1 = 0, + Area1 = 0, - /// - /// Area 2. - /// - Area2 = 1, + /// + /// Area 2. + /// + Area2 = 1, - /// - /// Area 3. - /// - Area3 = 2, + /// + /// Area 3. + /// + Area3 = 2, - /// - /// Area 4.k - /// - Area4 = 3, - } + /// + /// Area 4.k + /// + Area4 = 3, } diff --git a/src/FunderMaps.Core/Types/WoodType.cs b/src/FunderMaps.Core/Types/WoodType.cs index 02bbcff7..c0793090 100644 --- a/src/FunderMaps.Core/Types/WoodType.cs +++ b/src/FunderMaps.Core/Types/WoodType.cs @@ -1,18 +1,17 @@ -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Wood type. +/// +public enum WoodType { /// - /// Wood type. + /// Pine. /// - public enum WoodType - { - /// - /// Pine. - /// - Pine = 0, + Pine = 0, - /// - /// Spruce. - /// - Spruce = 1, - } + /// + /// Spruce. + /// + Spruce = 1, } diff --git a/src/FunderMaps.Core/Types/Years.cs b/src/FunderMaps.Core/Types/Years.cs index 0c90d13e..6cfd10be 100644 --- a/src/FunderMaps.Core/Types/Years.cs +++ b/src/FunderMaps.Core/Types/Years.cs @@ -1,51 +1,50 @@ using FunderMaps.Core.Helpers; -namespace FunderMaps.Core.Types +namespace FunderMaps.Core.Types; + +/// +/// Represents a collection of years. +/// +public sealed class Years { /// - /// Represents a collection of years. + /// Empty constructor. /// - public sealed class Years + public Years() { - /// - /// Empty constructor. - /// - public Years() + } + + /// + /// Static constructor for easy decade creation. + /// + /// + /// The must be a multiple of 10. The + /// returned will be created based on this value, + /// the will be 9 years later. + /// + /// Starting year as integer + /// + public static Years FromDecade(int decadeStart) + { + if (decadeStart % 10 != 0) { + throw new ArgumentOutOfRangeException(nameof(decadeStart)); } - /// - /// Static constructor for easy decade creation. - /// - /// - /// The must be a multiple of 10. The - /// returned will be created based on this value, - /// the will be 9 years later. - /// - /// Starting year as integer - /// - public static Years FromDecade(int decadeStart) + return new Years { - if (decadeStart % 10 != 0) - { - throw new ArgumentOutOfRangeException(nameof(decadeStart)); - } - - return new Years - { - YearFrom = DateTimeOffsetHelper.FromYear(decadeStart), - YearTo = DateTimeOffsetHelper.FromYear(decadeStart + 9), - }; - } + YearFrom = DateTimeOffsetHelper.FromYear(decadeStart), + YearTo = DateTimeOffsetHelper.FromYear(decadeStart + 9), + }; + } - /// - /// The first year for this collection of years. - /// - public DateTimeOffset YearFrom { get; set; } + /// + /// The first year for this collection of years. + /// + public DateTimeOffset YearFrom { get; set; } - /// - /// The last year in this collection of years. - /// - public DateTimeOffset YearTo { get; set; } - } + /// + /// The last year in this collection of years. + /// + public DateTimeOffset YearTo { get; set; } } From e56b6f71c52dc46a464256eee646c4abf786b811 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sun, 28 Nov 2021 13:38:27 +0100 Subject: [PATCH 16/20] Simplify code --- .../Repositories/TelemetryRepository.cs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/FunderMaps.Data/Repositories/TelemetryRepository.cs b/src/FunderMaps.Data/Repositories/TelemetryRepository.cs index b1833296..b7c66976 100644 --- a/src/FunderMaps.Data/Repositories/TelemetryRepository.cs +++ b/src/FunderMaps.Data/Repositories/TelemetryRepository.cs @@ -2,7 +2,6 @@ using FunderMaps.Core.Interfaces.Repositories; using FunderMaps.Data.Abstractions; using FunderMaps.Data.Extensions; -using System.Data.Common; namespace FunderMaps.Data.Repositories; @@ -17,12 +16,12 @@ internal class TelemetryRepository : DbServiceBase, ITelemetryRepository public async IAsyncEnumerable ListAllUsageAsync() { var sql = @" - SELECT -- ProductTracker - pt.product, - count(pt.organization_id) - FROM application.product_tracker AS pt - WHERE pt.organization_id = @tenant - GROUP BY pt.organization_id, pt.product"; + SELECT -- ProductTracker + pt.product, + count(pt.organization_id) + FROM application.product_tracker AS pt + WHERE pt.organization_id = @tenant + GROUP BY pt.organization_id, pt.product"; await using var context = await DbContextFactory.CreateAsync(sql); @@ -30,14 +29,11 @@ FROM application.product_tracker AS pt await foreach (var reader in context.EnumerableReaderAsync()) { - yield return MapFromReader(reader); + yield return new() + { + Product = reader.GetString(0), + Count = reader.GetInt(1), + }; } } - - public static ProductTelemetry MapFromReader(DbDataReader reader, int offset = 0) - => new() - { - Product = reader.GetString(offset++), - Count = reader.GetInt(offset++), - }; } From 5b7e6d6fc753d0c2374b04207c6354344540f45c Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sun, 28 Nov 2021 14:26:52 +0100 Subject: [PATCH 17/20] Testcases API v3 --- .../Webservice/Analysis3Tests.cs | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 tests/FunderMaps.IntegrationTests/Webservice/Analysis3Tests.cs diff --git a/tests/FunderMaps.IntegrationTests/Webservice/Analysis3Tests.cs b/tests/FunderMaps.IntegrationTests/Webservice/Analysis3Tests.cs new file mode 100644 index 00000000..8a326fd2 --- /dev/null +++ b/tests/FunderMaps.IntegrationTests/Webservice/Analysis3Tests.cs @@ -0,0 +1,172 @@ +using FunderMaps.Core.Types.Products; +using System.Net; +using Xunit; + +namespace FunderMaps.IntegrationTests.Webservice; + +/// +/// Integration test for the analysis controller. +/// +public class Analysis3Tests : IClassFixture +{ + private WebserviceFixtureFactory Factory { get; } + + /// + /// Create new instance and setup the test data. + /// + public Analysis3Tests(WebserviceFixtureFactory factory) + => Factory = factory; + + [Fact] + public async Task GetProductByIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/analysis?id=gfm-ac31bec346744745b29f8505dff8182e"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("NL.IMBAG.LIGPLAATS.0503020000111954", returnObject.ExternalBuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis3") > 0); + } + + [Fact] + public async Task GetProductByExternalIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/analysis?id=NL.IMBAG.LIGPLAATS.0503020000111954"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis3") > 0); + } + + [Fact] + public async Task GetProductByExternalIdBag1ReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/analysis?id=0503020000111954"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis3") > 0); + } + + [Fact] + public async Task GetProductByExternalAddressIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/analysis?id=NL.IMBAG.NUMMERAANDUIDING.0503200000111954"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis3") > 0); + } + + [Fact] + public async Task GetProductByExternalAddressIdBag1ReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/analysis?id=0503200000111954"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("gfm-ac31bec346744745b29f8505dff8182e", returnObject.BuildingId); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis3") > 0); + } + + [Fact] + public async Task GetRiskIndexByIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/at_risk?id=gfm-ac31bec346744745b29f8505dff8182e"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.False(returnObject); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis3") > 0); + } + + [Fact] + public async Task GetRiskIndexByExternalIdReturnProduct() + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/at_risk?id=NL.IMBAG.LIGPLAATS.0503020000111954"); + var returnObject = await response.Content.ReadFromJsonAsync(); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.False(returnObject); + + Assert.True(await WebserviceStub.CheckQuotaUsageAsync(Factory, "analysis3") > 0); + } + + [Theory] + [InlineData("id=3kjhr834dhfjdeh")] + [InlineData("bagid=4928374hfdkjsfh")] + [InlineData("query=thisismyquerystringyes")] + [InlineData("fdshjbf438gi")] + public async Task GetRiskIndexByExternalIdInvalidAddressThrows(string address) + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/at_risk?id={address}"); + + // Assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } + + [Theory] + [InlineData("id=3kjhr834dhfjdeh")] + [InlineData("bagid=4928374hfdkjsfh")] + [InlineData("query=thisismyquerystringyes")] + [InlineData("fdshjbf438gi")] + public async Task GetByIdInvalidAddressThrows(string address) + { + // Arrange + using var client = Factory.CreateClient(); + + // Act + var response = await client.GetAsync($"api/v3/product/analysis?id={address}"); + + // Assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } +} From 7c3188c29eec281790d5078ecd320449bd75e2b6 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sun, 28 Nov 2021 14:39:41 +0100 Subject: [PATCH 18/20] Model update --- database/fundermaps_base.sql | 63 ++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/database/fundermaps_base.sql b/database/fundermaps_base.sql index 1a535de8..a76eb16f 100644 --- a/database/fundermaps_base.sql +++ b/database/fundermaps_base.sql @@ -2508,7 +2508,22 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS WHEN ((foundation_type.foundation_type = 'no_pile'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) OR (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type)) THEN (round((((surface_area.surface_area)::double precision * (350)::double precision))::numeric, '-2'::integer))::integer ELSE NULL::integer END AS restoration_costs, - NULL::double precision AS drystand, + CASE + WHEN ((established.wood_level IS NOT NULL) AND (established.groundwater_level IS NOT NULL)) THEN (((established.wood_level)::numeric - (established.groundwater_level)::numeric))::double precision + WHEN ((cluster.wood_level IS NOT NULL) AND (cluster.groundwater_level IS NOT NULL)) THEN (((cluster.wood_level)::numeric - (cluster.groundwater_level)::numeric))::double precision + ELSE + CASE + WHEN (foundation_type.foundation_type = 'wood_charger'::report.foundation_type) THEN (gwl.level - (2.5)::double precision) + WHEN (foundation_type.foundation_type = 'wood'::report.foundation_type) THEN (gwl.level - (1.5)::double precision) + WHEN (foundation_type.foundation_type = 'wood_amsterdam'::report.foundation_type) THEN (gwl.level - (1.5)::double precision) + WHEN (foundation_type.foundation_type = 'wood_rotterdam'::report.foundation_type) THEN (gwl.level - (1.5)::double precision) + WHEN (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) THEN (gwl.level - (1.5)::double precision) + WHEN (foundation_type.foundation_type = 'wood_amsterdam_arch'::report.foundation_type) THEN (gwl.level - (1.5)::double precision) + WHEN (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type) THEN (gwl.level - (1.5)::double precision) + WHEN (foundation_type.foundation_type = 'wood_rotterdam_arch'::report.foundation_type) THEN (gwl.level - (1.5)::double precision) + ELSE NULL::double precision + END + END AS drystand, COALESCE(established_drystand_risk.established_drystand_risk, cluster_drystand_risk.cluster_drystand_risk, drystand_risk.drystand_risk) AS drystand_risk, CASE WHEN (established_drystand_risk.established_drystand_risk IS NOT NULL) THEN 'established'::data.reliability @@ -2521,7 +2536,21 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS WHEN (cluster_bio_infection_risk.cluster_bio_infection_risk IS NOT NULL) THEN 'cluster'::data.reliability ELSE 'indicative'::data.reliability END AS bio_infection_risk_reliability, - NULL::double precision AS dewatering_depth, + CASE + WHEN ((established.foundation_depth IS NOT NULL) AND (established.groundwater_level IS NOT NULL)) THEN ((((established.foundation_depth)::numeric - (established.groundwater_level)::numeric) - 0.6))::double precision + WHEN ((cluster.wood_level IS NOT NULL) AND (cluster.groundwater_level IS NOT NULL)) THEN ((((cluster.foundation_depth)::numeric - (cluster.groundwater_level)::numeric) - 0.6))::double precision + ELSE + CASE + WHEN (foundation_type.foundation_type = 'no_pile'::report.foundation_type) THEN (gwl.level - (0.6)::double precision) + WHEN (foundation_type.foundation_type = 'no_pile_masonry'::report.foundation_type) THEN (gwl.level - (0.6)::double precision) + WHEN (foundation_type.foundation_type = 'no_pile_strips'::report.foundation_type) THEN (gwl.level - (0.6)::double precision) + WHEN (foundation_type.foundation_type = 'no_pile_concrete_floor'::report.foundation_type) THEN (gwl.level - (0.6)::double precision) + WHEN (foundation_type.foundation_type = 'wood_rotterdam_amsterdam'::report.foundation_type) THEN (gwl.level - (0.6)::double precision) + WHEN (foundation_type.foundation_type = 'no_pile_slit'::report.foundation_type) THEN (gwl.level - (0.6)::double precision) + WHEN (foundation_type.foundation_type = 'no_pile_bearing_floor'::report.foundation_type) THEN (gwl.level - (0.6)::double precision) + ELSE NULL::double precision + END + END AS dewatering_depth, COALESCE(established_dewatering_depth_risk.established_dewatering_depth_risk, cluster_dewatering_depth_risk.cluster_dewatering_depth_risk, dewatering_depth_risk.dewatering_depth_risk) AS dewatering_depth_risk, CASE WHEN (established_dewatering_depth_risk.established_dewatering_depth_risk IS NOT NULL) THEN 'established'::data.reliability @@ -2578,6 +2607,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS (array_agg(established_rows.overall_quality) FILTER (WHERE (established_rows.overall_quality IS NOT NULL)))[1] AS overall_quality, (array_agg(established_rows.recovery_advised) FILTER (WHERE (established_rows.recovery_advised IS NOT NULL)))[1] AS recovery_advised, (array_agg(date_part('year'::text, established_rows.built_year)) FILTER (WHERE (established_rows.recovery_advised IS NOT NULL)))[1] AS built_year, + (array_agg(established_rows.groundwater_level_temp) FILTER (WHERE (established_rows.groundwater_level_temp IS NOT NULL)))[1] AS groundwater_level, + (array_agg(established_rows.wood_level) FILTER (WHERE (established_rows.wood_level IS NOT NULL)))[1] AS wood_level, + (array_agg(established_rows.foundation_depth) FILTER (WHERE (established_rows.foundation_depth IS NOT NULL)))[1] AS foundation_depth, (array_agg(established_rows.type) FILTER (WHERE (established_rows.type IS NOT NULL)))[1] AS inquiry_type, (array_agg(established_rows.document_date) FILTER (WHERE (established_rows.document_date IS NOT NULL)))[1] AS document_date, (array_agg(established_rows.id) FILTER (WHERE (established_rows.document_date IS NOT NULL)))[1] AS id, @@ -2589,6 +2621,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS is2.overall_quality, is2.recovery_advised, is2.built_year, + is2.groundwater_level_temp, + is2.wood_level, + is2.foundation_depth, i.type, i.document_date, i.id, @@ -2622,6 +2657,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS NULL::report.foundation_quality AS foundation_quality, false AS bool, NULL::date AS date, + (NULL::numeric)::report.height AS height, + (NULL::numeric)::report.height AS height, + (NULL::numeric)::report.height AS height, NULL::report.inquiry_type AS inquiry_type, NULL::date AS date, NULL::integer AS int4, @@ -2633,6 +2671,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS (array_agg(cluster_rows.overall_quality) FILTER (WHERE (cluster_rows.overall_quality IS NOT NULL)))[1] AS overall_quality, (array_agg(cluster_rows.recovery_advised) FILTER (WHERE (cluster_rows.recovery_advised IS NOT NULL)))[1] AS recovery_advised, (array_agg(date_part('year'::text, cluster_rows.built_year)) FILTER (WHERE (cluster_rows.recovery_advised IS NOT NULL)))[1] AS built_year, + (array_agg(cluster_rows.groundwater_level_temp) FILTER (WHERE (cluster_rows.groundwater_level_temp IS NOT NULL)))[1] AS groundwater_level, + (array_agg(cluster_rows.wood_level) FILTER (WHERE (cluster_rows.wood_level IS NOT NULL)))[1] AS wood_level, + (array_agg(cluster_rows.foundation_depth) FILTER (WHERE (cluster_rows.foundation_depth IS NOT NULL)))[1] AS foundation_depth, (array_agg(cluster_rows.recovery) FILTER (WHERE (cluster_rows.recovery IS NOT NULL)))[1] AS recovery FROM (( SELECT 1 AS group_id, is2.foundation_type, @@ -2641,6 +2682,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS is2.overall_quality, is2.recovery_advised, is2.built_year, + is2.groundwater_level_temp, + is2.wood_level, + is2.foundation_depth, ( SELECT (EXISTS ( SELECT 1 FROM report.recovery_sample WHERE ((recovery_sample.address)::text = (ab.address_id)::text) @@ -2672,6 +2716,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS NULL::report.foundation_quality AS foundation_quality, false AS bool, NULL::date AS date, + (NULL::numeric)::report.height AS height, + (NULL::numeric)::report.height AS height, + (NULL::numeric)::report.height AS height, false AS bool) cluster_rows GROUP BY cluster_rows.group_id) cluster, LATERAL ( SELECT COALESCE((established.built_year)::integer, (date_part('year'::text, (b.built_year)::date))::integer) AS "coalesce") construction_year(construction_year), @@ -2767,10 +2814,8 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS LATERAL ( SELECT CASE WHEN cluster.recovery THEN 'e'::data.foundation_risk_indication - WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term05'::report.enforcement_term) OR (cluster.enforcement_term = 'term5'::report.enforcement_term) OR cluster.recovery_advised OR (cluster.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication - WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term510'::report.enforcement_term) OR (cluster.enforcement_term = 'term10'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication - WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term1020'::report.enforcement_term) OR (cluster.enforcement_term = 'term15'::report.enforcement_term) OR (cluster.enforcement_term = 'term20'::report.enforcement_term) OR (cluster.overall_quality = 'mediocre'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication - WHEN ((cluster.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (cluster.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + WHEN ((cluster.enforcement_term = 'term05'::report.enforcement_term) OR (cluster.enforcement_term = 'term5'::report.enforcement_term) OR (cluster.enforcement_term = 'term510'::report.enforcement_term) OR (cluster.enforcement_term = 'term10'::report.enforcement_term) OR (cluster.enforcement_term = 'term15'::report.enforcement_term) OR (cluster.enforcement_term = 'term1020'::report.enforcement_term) OR (cluster.enforcement_term = 'term20'::report.enforcement_term) OR cluster.recovery_advised OR (cluster.overall_quality = 'bad'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_bad'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre'::report.foundation_quality) OR (cluster.damage_cause IS NOT NULL)) THEN 'd'::data.foundation_risk_indication + WHEN ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality)) THEN 'c'::data.foundation_risk_indication ELSE NULL::data.foundation_risk_indication END AS "case") cluster_unclassified_risk(cluster_unclassified_risk), LATERAL ( SELECT @@ -2803,10 +2848,8 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS LATERAL ( SELECT CASE WHEN established.recovery THEN 'a'::data.foundation_risk_indication - WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term05'::report.enforcement_term) OR (established.enforcement_term = 'term5'::report.enforcement_term) OR established.recovery_advised OR (established.overall_quality = 'bad'::report.foundation_quality))) THEN 'e'::data.foundation_risk_indication - WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term510'::report.enforcement_term) OR (established.enforcement_term = 'term10'::report.enforcement_term) OR (established.overall_quality = 'mediocre_bad'::report.foundation_quality))) THEN 'd'::data.foundation_risk_indication - WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term1020'::report.enforcement_term) OR (established.enforcement_term = 'term15'::report.enforcement_term) OR (established.enforcement_term = 'term20'::report.enforcement_term) OR (established.overall_quality = 'mediocre'::report.foundation_quality) OR (established.overall_quality = 'tolerable'::report.foundation_quality))) THEN 'c'::data.foundation_risk_indication - WHEN ((established.damage_cause <> 'drystand'::report.foundation_damage_cause) AND (established.damage_cause <> 'bio_infection'::report.foundation_damage_cause) AND (established.damage_cause <> 'drainage'::report.foundation_damage_cause) AND ((established.enforcement_term = 'term25'::report.enforcement_term) OR (established.enforcement_term = 'term30'::report.enforcement_term) OR (established.enforcement_term = 'term40'::report.enforcement_term) OR (established.overall_quality = 'good'::report.foundation_quality) OR (established.overall_quality = 'mediocre_good'::report.foundation_quality))) THEN 'b'::data.foundation_risk_indication + WHEN ((established.enforcement_term = 'term05'::report.enforcement_term) OR (established.enforcement_term = 'term5'::report.enforcement_term) OR (established.enforcement_term = 'term510'::report.enforcement_term) OR (established.enforcement_term = 'term10'::report.enforcement_term) OR (established.enforcement_term = 'term15'::report.enforcement_term) OR (established.enforcement_term = 'term1020'::report.enforcement_term) OR (established.enforcement_term = 'term20'::report.enforcement_term) OR established.recovery_advised OR (established.overall_quality = 'bad'::report.foundation_quality) OR (established.overall_quality = 'mediocre_bad'::report.foundation_quality) OR (established.overall_quality = 'mediocre'::report.foundation_quality) OR (established.damage_cause IS NOT NULL)) THEN 'e'::data.foundation_risk_indication + WHEN ((established.enforcement_term = 'term25'::report.enforcement_term) OR (established.enforcement_term = 'term30'::report.enforcement_term) OR (established.enforcement_term = 'term40'::report.enforcement_term) OR (established.overall_quality = 'good'::report.foundation_quality) OR (established.overall_quality = 'mediocre_good'::report.foundation_quality) OR (established.overall_quality = 'tolerable'::report.foundation_quality)) THEN 'b'::data.foundation_risk_indication ELSE NULL::data.foundation_risk_indication END AS "case") established_unclassified_risk(established_unclassified_risk) WHERE ((addresses.count > 0) AND (b.building_type = 'house'::geocoder.building_type)) From 1e426e76e74e3852d7ecdb78592c6bbf3c354a10 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sun, 28 Nov 2021 15:00:24 +0100 Subject: [PATCH 19/20] Model update --- database/fundermaps_base.sql | 41 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/database/fundermaps_base.sql b/database/fundermaps_base.sql index a76eb16f..ad8af862 100644 --- a/database/fundermaps_base.sql +++ b/database/fundermaps_base.sql @@ -2565,24 +2565,24 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS gr.code AS soil, surface_area.surface_area, bo.owner, - established.id AS inquiry_id, - established.inquiry_type, - established.damage_cause, + COALESCE(established.id, cluster.id) AS inquiry_id, + COALESCE(established.inquiry_type, cluster.inquiry_type) AS inquiry_type, + COALESCE(established.damage_cause, cluster.damage_cause) AS damage_cause, date_part('years'::text, age(( - CASE established.enforcement_term - WHEN 'term05'::report.enforcement_term THEN (established.document_date + '5 years'::interval) - WHEN 'term510'::report.enforcement_term THEN (established.document_date + '10 years'::interval) - WHEN 'term1020'::report.enforcement_term THEN (established.document_date + '20 years'::interval) - WHEN 'term5'::report.enforcement_term THEN (established.document_date + '5 years'::interval) - WHEN 'term10'::report.enforcement_term THEN (established.document_date + '10 years'::interval) - WHEN 'term15'::report.enforcement_term THEN (established.document_date + '15 years'::interval) - WHEN 'term20'::report.enforcement_term THEN (established.document_date + '20 years'::interval) - WHEN 'term25'::report.enforcement_term THEN (established.document_date + '25 years'::interval) - WHEN 'term30'::report.enforcement_term THEN (established.document_date + '30 years'::interval) - WHEN 'term40'::report.enforcement_term THEN (established.document_date + '40 years'::interval) + CASE COALESCE(established.enforcement_term, cluster.enforcement_term) + WHEN 'term05'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '5 years'::interval) + WHEN 'term510'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '10 years'::interval) + WHEN 'term1020'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '20 years'::interval) + WHEN 'term5'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '5 years'::interval) + WHEN 'term10'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '10 years'::interval) + WHEN 'term15'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '15 years'::interval) + WHEN 'term20'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '20 years'::interval) + WHEN 'term25'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '25 years'::interval) + WHEN 'term30'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '30 years'::interval) + WHEN 'term40'::report.enforcement_term THEN (COALESCE(established.document_date, cluster.document_date) + '40 years'::interval) ELSE NULL::timestamp without time zone END)::timestamp with time zone, CURRENT_TIMESTAMP)) AS enforcement_term, - established.overall_quality, + COALESCE(established.overall_quality, cluster.overall_quality) AS overall_quality, recovery.type AS recovery_type, b.geom FROM (((((((((geocoder.building_active b @@ -2674,6 +2674,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS (array_agg(cluster_rows.groundwater_level_temp) FILTER (WHERE (cluster_rows.groundwater_level_temp IS NOT NULL)))[1] AS groundwater_level, (array_agg(cluster_rows.wood_level) FILTER (WHERE (cluster_rows.wood_level IS NOT NULL)))[1] AS wood_level, (array_agg(cluster_rows.foundation_depth) FILTER (WHERE (cluster_rows.foundation_depth IS NOT NULL)))[1] AS foundation_depth, + (array_agg(cluster_rows.type) FILTER (WHERE (cluster_rows.type IS NOT NULL)))[1] AS inquiry_type, + (array_agg(cluster_rows.document_date) FILTER (WHERE (cluster_rows.document_date IS NOT NULL)))[1] AS document_date, + (array_agg(cluster_rows.id) FILTER (WHERE (cluster_rows.document_date IS NOT NULL)))[1] AS id, (array_agg(cluster_rows.recovery) FILTER (WHERE (cluster_rows.recovery IS NOT NULL)))[1] AS recovery FROM (( SELECT 1 AS group_id, is2.foundation_type, @@ -2685,6 +2688,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS is2.groundwater_level_temp, is2.wood_level, is2.foundation_depth, + i.type, + i.document_date, + i.id, ( SELECT (EXISTS ( SELECT 1 FROM report.recovery_sample WHERE ((recovery_sample.address)::text = (ab.address_id)::text) @@ -2719,6 +2725,9 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS (NULL::numeric)::report.height AS height, (NULL::numeric)::report.height AS height, (NULL::numeric)::report.height AS height, + NULL::report.inquiry_type AS inquiry_type, + NULL::date AS date, + NULL::integer AS int4, false AS bool) cluster_rows GROUP BY cluster_rows.group_id) cluster, LATERAL ( SELECT COALESCE((established.built_year)::integer, (date_part('year'::text, (b.built_year)::date))::integer) AS "coalesce") construction_year(construction_year), @@ -2815,7 +2824,7 @@ CREATE MATERIALIZED VIEW data.analysis_complete AS CASE WHEN cluster.recovery THEN 'e'::data.foundation_risk_indication WHEN ((cluster.enforcement_term = 'term05'::report.enforcement_term) OR (cluster.enforcement_term = 'term5'::report.enforcement_term) OR (cluster.enforcement_term = 'term510'::report.enforcement_term) OR (cluster.enforcement_term = 'term10'::report.enforcement_term) OR (cluster.enforcement_term = 'term15'::report.enforcement_term) OR (cluster.enforcement_term = 'term1020'::report.enforcement_term) OR (cluster.enforcement_term = 'term20'::report.enforcement_term) OR cluster.recovery_advised OR (cluster.overall_quality = 'bad'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_bad'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre'::report.foundation_quality) OR (cluster.damage_cause IS NOT NULL)) THEN 'd'::data.foundation_risk_indication - WHEN ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality)) THEN 'c'::data.foundation_risk_indication + WHEN ((cluster.enforcement_term = 'term25'::report.enforcement_term) OR (cluster.enforcement_term = 'term30'::report.enforcement_term) OR (cluster.enforcement_term = 'term40'::report.enforcement_term) OR (cluster.overall_quality = 'good'::report.foundation_quality) OR (cluster.overall_quality = 'mediocre_good'::report.foundation_quality) OR (cluster.overall_quality = 'tolerable'::report.foundation_quality)) THEN 'b'::data.foundation_risk_indication ELSE NULL::data.foundation_risk_indication END AS "case") cluster_unclassified_risk(cluster_unclassified_risk), LATERAL ( SELECT From 06ee309bf4dd869cdd4ce8fed408d065c5abf978 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Sun, 28 Nov 2021 15:12:25 +0100 Subject: [PATCH 20/20] More fields for the APIv3 product --- .../Types/Products/AnalysisProduct3.cs | 19 ++++++++++-- .../Repositories/AnalysisRepository.cs | 30 +++++++++++-------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs b/src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs index 99a02b2e..59823360 100644 --- a/src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs +++ b/src/FunderMaps.Core/Types/Products/AnalysisProduct3.cs @@ -86,9 +86,24 @@ public sealed record AnalysisProduct3 public double? SurfaceArea { get; init; } /// - /// Property owner. + /// Damage cause. /// - public string Owner { get; init; } + public FoundationDamageCause? DamageCause { get; init; } + + /// + /// Enforcement term. + /// + public EnforcementTerm? EnforcementTerm { get; init; } + + /// + /// Enforcement term. + /// + public Quality? OverallQuality { get; init; } + + /// + /// Report type. + /// + public InquiryType? InquiryType { get; init; } /// /// Foundation type. diff --git a/src/FunderMaps.Data/Repositories/AnalysisRepository.cs b/src/FunderMaps.Data/Repositories/AnalysisRepository.cs index 6da0a423..44188639 100644 --- a/src/FunderMaps.Data/Repositories/AnalysisRepository.cs +++ b/src/FunderMaps.Data/Repositories/AnalysisRepository.cs @@ -181,7 +181,10 @@ RETURNING pt.building_id ac.ground_level, ac.soil, ac.surface_area, - ac.owner, + ac.damage_cause, + ac.enforcement_term, + ac.overall_quality, + ac.inquiry_type, ac.drystand, ac.drystand_risk, ac.drystand_risk_reliability, @@ -603,16 +606,19 @@ public static AnalysisProduct3 MapFromReader3(DbDataReader reader) GroundLevel = reader.GetSafeDouble(13), Soil = reader.GetSafeString(14), SurfaceArea = reader.GetSafeDouble(15), - Owner = reader.GetSafeString(16), - Drystand = reader.GetSafeDouble(17), - DrystandRisk = reader.GetFieldValue(18), - DrystandReliability = reader.GetFieldValue(19), - BioInfectionRisk = reader.GetFieldValue(20), - BioInfectionReliability = reader.GetFieldValue(21), - DewateringDepth = reader.GetSafeDouble(22), - DewateringDepthRisk = reader.GetFieldValue(23), - DewateringDepthReliability = reader.GetFieldValue(24), - UnclassifiedRisk = reader.GetFieldValue(25), - RecoveryType = reader.GetFieldValue(26), + DamageCause = reader.GetFieldValue(16), + EnforcementTerm = reader.GetFieldValue(17), + OverallQuality = reader.GetFieldValue(18), + InquiryType = reader.GetFieldValue(19), + Drystand = reader.GetSafeDouble(20), + DrystandRisk = reader.GetFieldValue(21), + DrystandReliability = reader.GetFieldValue(22), + BioInfectionRisk = reader.GetFieldValue(23), + BioInfectionReliability = reader.GetFieldValue(24), + DewateringDepth = reader.GetSafeDouble(25), + DewateringDepthRisk = reader.GetFieldValue(26), + DewateringDepthReliability = reader.GetFieldValue(27), + UnclassifiedRisk = reader.GetFieldValue(28), + RecoveryType = reader.GetFieldValue(29), }; }