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 11 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
12 changes: 12 additions & 0 deletions Ground_Engine/Ground_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
<OutputPath>..\Build\</OutputPath>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;C:\ProgramData\BHoM\Assemblies&quot; /Y" />

Check warning on line 16 in Ground_Engine/Ground_Engine.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

Ground_Engine/Ground_Engine.csproj#L16

Post Build event should be correctly set to copy the compiled DLL to the BHoM Assemblies folder
</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 All @@ -40,5 +46,11 @@
<Private>false</Private>
<SpecificVersion>false</SpecificVersion>
</Reference>
<Reference Include="Units_Engine">
<HintPath>..\..\..\..\..\..\ProgramData\BHoM\Assemblies\Units_Engine.dll</HintPath>

Check failure on line 50 in Ground_Engine/Ground_Engine.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

Ground_Engine/Ground_Engine.csproj#L50

Project reference for 'Units_Engine' should be set to '$(ProgramData)\BHoM\Assemblies\Units_Engine.dll'

Check failure on line 50 in Ground_Engine/Ground_Engine.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

Ground_Engine/Ground_Engine.csproj#L50

Project reference for 'Units_Engine' should be set to not copy local

Check failure on line 50 in Ground_Engine/Ground_Engine.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

Ground_Engine/Ground_Engine.csproj#L50

Project reference for 'Units_Engine' should set specific version as false
</Reference>
<Reference Include="Units_oM">
<HintPath>..\..\..\..\..\..\ProgramData\BHoM\Assemblies\Units_oM.dll</HintPath>

Check failure on line 53 in Ground_Engine/Ground_Engine.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

Ground_Engine/Ground_Engine.csproj#L53

Project reference for 'Units_oM' should be set to '$(ProgramData)\BHoM\Assemblies\Units_oM.dll'

Check failure on line 53 in Ground_Engine/Ground_Engine.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

Ground_Engine/Ground_Engine.csproj#L53

Project reference for 'Units_oM' should be set to not copy local

Check failure on line 53 in Ground_Engine/Ground_Engine.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

Ground_Engine/Ground_Engine.csproj#L53

Project reference for 'Units_oM' should set specific version as false
</Reference>
</ItemGroup>
</Project>
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;
}
}
}



Loading