Skip to content

Ground_Engine: Add method that returns a unique list of suite names #3396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/Datasets/Ground_Engine/Query/DistinctSuites.json

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions Ground_Engine/Compute/ConsolidateStrata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,37 @@
public static Borehole ConsolidateStrata(Borehole borehole, string propertyCompare, int decimals)
{
if (borehole.IsValid())
return null;


Borehole consolidatedBorehole = borehole.ShallowClone();
{
Borehole consolidatedBorehole = borehole.ShallowClone();

List<Stratum> strata = consolidatedBorehole.Strata;
// Add first strata so the strings are formatted the same as the consolidated borehole
List<Stratum> consolidatedStrata = new List<Stratum>() { strata[0].RangeProperties(null, propertyCompare, true, decimals) };
List<Stratum> strata = consolidatedBorehole.Strata;
// Add first strata so the strings are formatted the same as the consolidated borehole
List<Stratum> consolidatedStrata = new List<Stratum>() { strata[0].RangeProperties(null, propertyCompare, true, decimals) };

for (int i = 1; i < strata.Count; i++)
{
Stratum consolidatedStratum = consolidatedStrata.Last();
Stratum stratum = strata[i];
// Check whether the strings are equal based on the propertyCompare
if (string.Equals(Base.Query.PropertyValue(stratum, propertyCompare), Base.Query.PropertyValue(strata[i - 1], propertyCompare)))
{
// Update ConsolidatedStratum to include next stratum
consolidatedStratum = RangeProperties(stratum, consolidatedStratum, propertyCompare, false, decimals);
consolidatedStrata[consolidatedStrata.Count - 1] = consolidatedStratum;
}
else
for (int i = 1; i < strata.Count; i++)
{
// Add new line
consolidatedStrata.Add(strata[i].RangeProperties(null, propertyCompare, true, decimals));
Stratum consolidatedStratum = consolidatedStrata.Last();
Stratum stratum = strata[i];
// Check whether the strings are equal based on the propertyCompare
if (string.Equals(Base.Query.PropertyValue(stratum, propertyCompare), Base.Query.PropertyValue(strata[i - 1], propertyCompare)))
{
// Update ConsolidatedStratum to include next stratum
consolidatedStratum = RangeProperties(stratum, consolidatedStratum, propertyCompare, false, decimals);
consolidatedStrata[consolidatedStrata.Count - 1] = consolidatedStratum;
}
else
{
// Add new line
consolidatedStrata.Add(strata[i].RangeProperties(null, propertyCompare, true, decimals));
}
}
}

consolidatedBorehole.SetPropertyValue("Strata", consolidatedStrata);
consolidatedBorehole.SetPropertyValue("Strata", consolidatedStrata);
return consolidatedBorehole;

return consolidatedBorehole;
}
else
return null;
}

/***************************************************/
Expand All @@ -91,7 +92,7 @@
double bottom = stratum.Bottom;

// Properties to skip over
List<string> skipProp = new List<string>() { "Id", "Top", "Bottom", "Properties", "BHoM_Guid", "Name", "Fragments", "Tags", "CustomData" };

Check warning on line 95 in Ground_Engine/Compute/ConsolidateStrata.cs

View check run for this annotation

BHoMBot-CI / code-compliance

Ground_Engine/Compute/ConsolidateStrata.cs#L95

The use of CustomData within the code is discouraged except in circumstances where volatile data is being used. - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsUsingCustomData
skipProp.Add(propName);

if (!initial)
Expand Down
6 changes: 6 additions & 0 deletions Ground_Engine/Ground_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</Target>
<ItemGroup>
<ProjectReference Include="..\BHoM_Engine\BHoM_Engine.csproj" />
<ProjectReference Include="..\Data_Engine\Data_Engine.csproj" />
<ProjectReference Include="..\Geometry_Engine\Geometry_Engine.csproj" />
</ItemGroup>
<ItemGroup>
Expand All @@ -25,6 +26,11 @@
<Private>false</Private>
<SpecificVersion>false</SpecificVersion>
</Reference>
<Reference Include="Data_oM">
<HintPath>$(ProgramData)\BHoM\Assemblies\Data_oM.dll</HintPath>
<Private>false</Private>
<SpecificVersion>false</SpecificVersion>
</Reference>
<Reference Include="Geometry_oM">
<HintPath>$(ProgramData)\BHoM\Assemblies\Geometry_oM.dll</HintPath>
<Private>false</Private>
Expand Down
73 changes: 73 additions & 0 deletions Ground_Engine/Query/ContaminantProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using BH.oM.Base;
using BH.oM.Base.Attributes;
using BH.oM.Data;
using BH.oM.Geometry;
using BH.oM.Ground;
using BH.oM.Quantities.Attributes;
using BH.Engine.Base;
using BH.Engine.Data;
using BH.Engine.Geometry;
using BH.oM.Data.Requests;


namespace BH.Engine.Ground
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Returns the IContaminantProperty matching the type provided..")]
[Input("sample", "The ContaminantSample to retrieve the property from.")]
[Input("type", "The type that inherits IContaminantProperty to search the ContaminantSample for.")]
[Output("property", "The IContaminantProperty found on the ContaminantSample.")]
public static IContaminantProperty ContaminantProperty(this ContaminantSample sample, Type type)
{
if (sample.IsValid())
{
List<IContaminantProperty> contaminantProperties = sample.ContaminantProperties;

if (contaminantProperties.Select(x => x.GetType()).Contains(type))
return (IContaminantProperty)Base.Query.FilterByType(contaminantProperties, type).First();
else
{
Base.Compute.RecordError($"The ContaminantSample does not contain {type}.");
return null;
}
}
else
return null;
}

/***************************************************/

}
}
131 changes: 131 additions & 0 deletions Ground_Engine/Query/DistinctSuites.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using BH.oM.Base;
using BH.oM.Base.Attributes;
using BH.oM.Data;
using BH.oM.Geometry;
using BH.oM.Ground;
using BH.oM.Quantities.Attributes;
using BH.Engine.Base;
using BH.Engine.Data;
using BH.Engine.Geometry;
using BH.oM.Data.Requests;


namespace BH.Engine.Ground
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Returns a distinct list of suites from a Borehole using the sample reference, test name or top depth (in order of priority).")]
[Input("borehole", "The Borehole from which to count the number of suites.")]
[Output("suites", "A distinct list of suites from the Borehole provided.")]
public static List<string> DistinctSuites(this Borehole borehole)
{
bool reference = true;
bool testName = false;
bool depth = false;

List<string> suites = new List<string>();
List<double> depths = new List<double>();

foreach(ContaminantSample contaminantSample in borehole.ContaminantSamples)
{
if (reference)
{
List<IContaminantProperty> contaminantProperties = contaminantSample.ContaminantProperties;
FilterRequest filterRequest = Data.Create.FilterRequest(typeof(ContaminantReference), "");
IEnumerable<IBHoMObject> contaminantReferences = Data.Compute.FilterData(filterRequest, contaminantProperties);
if (contaminantReferences.Any(x => x == null) || contaminantReferences.Count() != 0)
{
ContaminantReference contaminantReference = (ContaminantReference)contaminantReferences.First();
if (contaminantReference.Reference != "")
suites.Add(contaminantReference.Reference);
else
{
testName = true;
reference = false;
}
}
else
{
testName = true;
reference = false;
}
}

if(testName)
{
List<IContaminantProperty> contaminantProperties = contaminantSample.ContaminantProperties;
FilterRequest filterRequest = Data.Create.FilterRequest(typeof(TestProperties), "");
IEnumerable<IBHoMObject> testProperties = Data.Compute.FilterData(filterRequest, contaminantProperties);
if (!testProperties.Any(x => x == null) || testProperties.Count() != 0)
{
TestProperties testProperty = (TestProperties)testProperties.First();
if (testProperty.Name != "")
suites.Add(testProperty.Name);
else
{
testName = false;
depth = true;
}
}
else
{
testName = false;
depth = true;
}
}

if(depth)
{
depths.Add(contaminantSample.Top);
}

if(!reference && !testName && !depth)
{
Engine.Base.Compute.RecordError("Neither the ContaminantReference.Reference, TestProperties.Name or Top depth fields contain any data. \n" +
"Therefore, the number of suites cannot be counted.");
}
}

if (depth)
suites = depths.Distinct().Select(x => x.ToString()).ToList();
else
suites = suites.Distinct().ToList();

return suites;
}
}
}



46 changes: 31 additions & 15 deletions Ground_Engine/Query/IsValid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ public static bool IsValid(this Borehole borehole, string msg = "", [CallerMembe
{
if (borehole == null)
{
Base.Compute.RecordError("The borehole is null.");
return true;
Base.Compute.RecordError("The Borehole is null.");
return false;
}

if (borehole.Id == "")
{
Base.Compute.RecordError("The borehole does not contain an ID.");
return true;
Base.Compute.RecordError("The Borehole does not contain an ID.");
return false;
}

if (borehole.Top == null || borehole.Bottom == null)
{
Base.Compute.RecordError("The top or bottom of the Borehole is null.");
return true;
return false;
}

return false;
return true;
}

[Description("Checks if a Strata or its defining properties are valid and outputs relevant error message.")]
Expand All @@ -78,16 +78,32 @@ public static bool IsValid(this Stratum strata, string msg = "", [CallerMemberNa
if (strata == null)
{
Base.Compute.RecordError("The stratum is null.");
return true;
return false;
}

if (strata.LogDescription.Trim() == "")
{
Base.Compute.RecordError("The LogDescription is empty.");
return true;
return false;
}

return false;
return true;
}

[Description("Checks if a ContaminantSample or its defining properties are valid and outputs relevant error message.")]
[Input("sample", "The ContaminantSample to test for validity.")]
[Input("msg", "Optional message to be returned in addition to the generated error message.")]
[Input("methodName", "The name of the method to reference in the error message.")]
[Output("isNull", "True if the ContaminantSample or its defining properties are valid.")]
public static bool IsValid(this ContaminantSample sample, string msg = "", [CallerMemberName] string methodName = "Method")
{
if (sample == null)
{
Base.Compute.RecordError("The ContaminantSample is null.");
return false;
}

return true;
}

[Description("Checks if a IBoreholeProperty is valid and outputs relevant error message.")]
Expand All @@ -100,10 +116,10 @@ public static bool IsValid(this IBoreholeProperty property, string msg = "", [Ca
if (property == null)
{
ErrorMessage(methodName, property.GetType().ToString(), msg);
return true;
return false;
}

return false;
return true;
}

[Description("Checks if a IStratumProperties is valid and outputs relevant error message.")]
Expand All @@ -116,10 +132,10 @@ public static bool IsValid(this IStratumProperty property, string msg = "", [Cal
if (property == null)
{
ErrorMessage(methodName, property.GetType().ToString(), msg);
return true;
return false;
}

return false;
return true;
}

[Description("Checks if a IContaminantProperty is valid and outputs relevant error message.")]
Expand All @@ -132,10 +148,10 @@ public static bool IsValid(this IContaminantProperty property, string msg = "",
if (property == null)
{
ErrorMessage(methodName, property.GetType().ToString(), msg);
return true;
return false;
}

return false;
return true;
}

/***************************************************/
Expand Down
Loading