Skip to content

Refactor toolkit to align with dynamic objects and add support for transport factors #357

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

Draft
wants to merge 61 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
ea1d8c6
Update methods to target new interface rather than EPD object to allo…
IsakNaslundBh Oct 7, 2024
f6acab8
Add Create method for EnvironmentalMetric
IsakNaslundBh Oct 7, 2024
c55e7f3
Corrections to Metric create method
IsakNaslundBh Oct 7, 2024
7886d9a
Add method for assigning A4 value explicitly
IsakNaslundBh Oct 7, 2024
3224105
fix code compliance
IsakNaslundBh Oct 7, 2024
0e0f64f
Change method name to simply be SetA4 and allow for all metric types
IsakNaslundBh Oct 15, 2024
dbdc430
Tweak input names and some method names for methods able to target ne…
IsakNaslundBh Oct 28, 2024
fea263f
Merge branch 'develop' into LifeCycleAssessment_Toolkit-#306-AddCalcu…
IsakNaslundBh Dec 4, 2024
528398f
Add toggle for SumPhaseDataValues to allow for ignoring of NaN vlaues…
IsakNaslundBh Dec 18, 2024
e5f2c0c
Update FilteredMetrics.cs
IsakNaslundBh Dec 18, 2024
fdf44a6
Method for getting out all metrics from a provider
IsakNaslundBh Dec 18, 2024
fa33318
Update ElementEnvironmentalMetric.cs
IsakNaslundBh Dec 18, 2024
97d2d76
Update QuantityType.cs
IsakNaslundBh Dec 18, 2024
b010d7d
Method for getting out a quntity from a takeoff item given a quantity…
IsakNaslundBh Dec 18, 2024
10834f3
Refactor and adding support for more metric providers
IsakNaslundBh Dec 18, 2024
e08cc36
Remove SetA4 method given new strategy for handling of transport emis…
IsakNaslundBh Dec 18, 2024
2cdcfd5
Merge branch 'develop' into LifeCycleAssessment_Toolkit-#306-AddCalcu…
IsakNaslundBh Jan 7, 2025
3e1778b
Update old copyright year for added files
IsakNaslundBh Jan 7, 2025
4f47351
Uptick previous version attributes
IsakNaslundBh Jan 13, 2025
ad423bd
fix documentation compliance issues
IsakNaslundBh Jan 13, 2025
29bca4b
Add method to help with generation of transport factors
IsakNaslundBh Jan 13, 2025
3a302e9
Align with namechange from typical to full transport scenario
IsakNaslundBh Jan 13, 2025
9b8ef13
Add create method for FullTransportScenario
IsakNaslundBh Jan 13, 2025
5dc5454
Commit containing various experiments, not finished
IsakNaslundBh May 2, 2025
bbca456
Module name change
IsakNaslundBh May 6, 2025
83d3f68
Workign general workflow for EPD evaluation Still WIP
IsakNaslundBh May 12, 2025
29846dd
Fixes for result constructors
IsakNaslundBh May 13, 2025
94f2246
remove unit input for transport factors
IsakNaslundBh May 13, 2025
1ababd3
Create method for vehicle emissions
IsakNaslundBh May 13, 2025
c05f29b
Add method for computing SingleTransportModeImpact and refactor as we…
IsakNaslundBh May 13, 2025
b10f9f3
ALign with switch from phases to Module
IsakNaslundBh May 13, 2025
e34047c
Remove old methods no longer required in current workflow
IsakNaslundBh May 13, 2025
5886ab3
Continued alignment of classes with changes in the oM. Initial update…
IsakNaslundBh May 15, 2025
e4523b4
Upgradign tests
IsakNaslundBh May 15, 2025
0c22279
Rejig tests to use TestCaseSource
IsakNaslundBh May 15, 2025
7d990ab
Add tests for total
IsakNaslundBh May 15, 2025
2f853a5
Fix bug in Total and add unit tests
IsakNaslundBh May 15, 2025
b0d6944
ModifyInsulationEPD
IsakNaslundBh May 15, 2025
eda5050
Fix descriptions for total and sumModuleValues
IsakNaslundBh May 15, 2025
d42d9e9
Make element resutl create call SumModuleDataValues
IsakNaslundBh May 15, 2025
a277822
Add more datas ources for tests
IsakNaslundBh May 16, 2025
764e87c
Add tests for MetricType
IsakNaslundBh May 16, 2025
4de28a0
Change MetricType to rely on type names to get out the metric type. A…
IsakNaslundBh May 16, 2025
4b732f6
Update all metric creation methods
IsakNaslundBh May 16, 2025
5eb2aa8
clean up leftover old/experimental material create methods
IsakNaslundBh May 16, 2025
c0b02a3
Update LifeCycleAssessment_Engine_Tests.csproj
IsakNaslundBh May 16, 2025
1c858c8
Add tests for elements
IsakNaslundBh May 16, 2025
cb8bc1b
Cleanup of usings and references to old classes
IsakNaslundBh May 16, 2025
c4afac8
Fix basic compliance
IsakNaslundBh May 16, 2025
dfde7d2
Fixing various documentation compliance issues
IsakNaslundBh May 16, 2025
e14b678
Fix descriptions for TransportResults
IsakNaslundBh May 16, 2025
e799498
Add unit tests for combined factors
IsakNaslundBh May 16, 2025
2995eac
Fix bug found in unit-testing
IsakNaslundBh May 16, 2025
a3b8064
Add more tests for combined factors, with basefactors being null
IsakNaslundBh May 19, 2025
83bc35e
Add tests for Sum
IsakNaslundBh May 19, 2025
d59c802
Versioning fixes
IsakNaslundBh May 19, 2025
5a594cb
Move createmethods for metrics to subfodler for easier navigation
IsakNaslundBh May 19, 2025
872a201
Fix adding missing return trip factor in Vehicle emissions create
IsakNaslundBh May 23, 2025
b56c689
Align with changes to element results
IsakNaslundBh May 23, 2025
73c3a1b
Improve dataset serialisation test
IsakNaslundBh May 23, 2025
1f29b71
Improve evaluation tests
IsakNaslundBh May 23, 2025
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
389 changes: 389 additions & 0 deletions .ci/unit-tests/LifeCycleAssessment_Engine_Tests/DataSource.cs

Large diffs are not rendered by default.

55 changes: 19 additions & 36 deletions .ci/unit-tests/LifeCycleAssessment_Engine_Tests/Datasets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,37 @@
using BH.oM.Graphics;
using FluentAssertions;
using BH.oM.LifeCycleAssessment.MaterialFragments;
using BH.oM.Versioning;

namespace BH.Tests.Engine.LifeCycleAssessment
{
public class Datasets
{
[Test]
public void DatasetsAllDeserialiseing()
[TestCaseSource(nameof(DatasetFilePaths))]
public void DatasetsAllDeserialiseing(string f)
{
string folder = @"C:\ProgramData\BHoM\Datasets\LifeCycleAssessment\";
BH.Engine.Base.Compute.ClearCurrentEvents();
string json = System.IO.File.ReadAllText(f);
object back = BH.Engine.Serialiser.Convert.FromJson(json);
BH.oM.Data.Library.Dataset dataset = back as BH.oM.Data.Library.Dataset;

string[] files = Directory.GetFiles(folder, "*.json", SearchOption.AllDirectories);
Assert.That(dataset, Is.Not.Null);
Assert.That(dataset.Data, Is.Not.Null);
Assert.That(dataset.Data, Has.All.Not.Null);
Assert.That(dataset.Data, Has.All.Not.TypeOf<CustomObject>());

List<string> failures = new List<string>();
List<string> successes = new List<string>();
List<VersioningEvent> versioningEvents = BH.Engine.Base.Query.CurrentEvents().OfType<VersioningEvent>().ToList();

EnvironmentalProductDeclaration epd = new EnvironmentalProductDeclaration();
Warn.Unless(versioningEvents, Is.Empty, "Verisoning required");

foreach (string f in files)
{
try
{
string json = System.IO.File.ReadAllText(f);
object back = BH.Engine.Serialiser.Convert.FromJson(json);
BH.oM.Data.Library.Dataset dataset = back as BH.oM.Data.Library.Dataset;
if (dataset == null || dataset.Data.Any(x => x == null || x is CustomObject))
failures.Add(f);
else
successes.Add(f);
}
catch (Exception)
{
failures.Add(f);
}
}
Console.WriteLine("Fail upgrade:");
foreach (string f in failures)
{
Console.WriteLine(f);
}
}

Console.WriteLine("");
Console.WriteLine("Success upgrade:");
foreach (string s in successes)
{
Console.WriteLine(s);
}
private static IEnumerable<string> DatasetFilePaths()
{
EnvironmentalProductDeclaration epd = new EnvironmentalProductDeclaration();
string folder = @"C:\ProgramData\BHoM\Datasets\LifeCycleAssessment\";

failures.Should().BeEmpty();
return Directory.GetFiles(folder, "*.json", SearchOption.AllDirectories);
}
}
}
Expand Down
353 changes: 168 additions & 185 deletions .ci/unit-tests/LifeCycleAssessment_Engine_Tests/Evaluate.cs

Large diffs are not rendered by default.

355 changes: 177 additions & 178 deletions .ci/unit-tests/LifeCycleAssessment_Engine_Tests/EvaluateIStructE.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<FileVersion>8.1.0.0</FileVersion>
<FileVersion>8.2.0.0</FileVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<Description>https://github.com/BHoM/LifeCycleAssessment_Toolkit</Description>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down Expand Up @@ -82,11 +82,21 @@
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Physical_Engine">
<HintPath>$(ProgramData)\BHoM\Assemblies\Physical_Engine.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Physical_oM">
<HintPath>$(ProgramData)\BHoM\Assemblies\Physical_oM.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Quantities_oM">
<HintPath>$(ProgramData)\BHoM\Assemblies\Quantities_oM.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Serialiser_Engine">
<HintPath>$(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -117,6 +127,11 @@
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Versioning_oM">
<HintPath>$(ProgramData)\BHoM\Assemblies\Versioning_oM.dll</HintPath>
<Private>True</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,51 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using AutoBogus;
using BH.Engine.LifeCycleAssessment;
using BH.oM.LifeCycleAssessment;
using BH.oM.LifeCycleAssessment.Interfaces;
using BH.oM.LifeCycleAssessment.MaterialFragments;
using BH.oM.Base.Attributes;
using System.ComponentModel;
using BH.oM.Dimensional;
using BH.oM.LifeCycleAssessment.Results;
using BH.oM.Physical.Materials;
using FluentAssertions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using BH.Engine.Matter;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace BH.Engine.LifeCycleAssessment
namespace BH.Tests.Engine.LifeCycleAssessment
{
public static partial class Query
public class MetricTypeTests
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Query the QuantityType values from any IElementM object's MaterialComposition.")]
[Input("elementM", "The IElementM object from which to query the EPD's QuantityType values.")]
[Output("quantityType", "The quantityType values from the IEnvironmentalProductDeclarationData objects found within the Element's MaterialComposition.")]
public static List<QuantityType> QuantityTypes(this IElementM elementM)
[TestCaseSource(typeof(DataSource), nameof(DataSource.DummyFactors), new object[] { 1, 0 })]
[TestCaseSource(typeof(DataSource), nameof(DataSource.DummyMetrics), new object[] { 1, 0, false })]
public void MetricTypeNotUndefined(ILifeCycleAssemsmentIndicator metricFactors)
{
List<QuantityType> qt = new List<QuantityType>();

if (elementM == null)
{
Base.Compute.RecordError("Cannot get the QuantityType from a null element.");
return new List<QuantityType> { oM.LifeCycleAssessment.QuantityType.Undefined };
}

return elementM.ElementEpds().Select(x => x == null ? oM.LifeCycleAssessment.QuantityType.Undefined : x.QuantityType).ToList();
MetricType metricType = metricFactors.IMetricType();
metricType.Should().NotBe(MetricType.Undefined);
}

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

[TestCaseSource(typeof(DataSource), nameof(DataSource.DummyFactorsList), new object[] { 1, 0 })]
[TestCaseSource(typeof(DataSource), nameof(DataSource.DummyMetricsList), new object[] { 1, 0, false })]
public void MetricTypesAllUnique(IEnumerable<ILifeCycleAssemsmentIndicator> metricFactors)
{
List<MetricType> metricTypes = metricFactors.Select(x => x.IMetricType()).ToList();
metricTypes.Should().OnlyHaveUniqueItems();
}

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

}
}




131 changes: 131 additions & 0 deletions .ci/unit-tests/LifeCycleAssessment_Engine_Tests/SumModuleDataValues.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 - 2025, 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 AutoBogus;
using BH.Engine.LifeCycleAssessment;
using BH.oM.LifeCycleAssessment;
using BH.oM.LifeCycleAssessment.Interfaces;
using BH.oM.LifeCycleAssessment.MaterialFragments;
using BH.oM.LifeCycleAssessment.Results;
using BH.oM.Physical.Materials;
using FluentAssertions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BH.Tests.Engine.LifeCycleAssessment
{
public class SumTests
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[TestCaseSource(nameof(SumTestCases))]
public void SumTest(IReadOnlyList<ILifeCycleAssessmentModuleData<IDictionary<Module, double>>> moduleData, bool onlyIncludeIfAllAvailable, Dictionary<Module, double> assumedSum)
{
Dictionary<Module, double> sum = moduleData.SumModuleDataValues(onlyIncludeIfAllAvailable);

sum.Count.Should().Be(assumedSum.Count);
double tol = 1e-12;
foreach (var sumItem in sum)
{
sumItem.Value.Should().Be(assumedSum[sumItem.Key], sumItem.Key.ToString());
}

}

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

private static IEnumerable<object[]> SumTestCases()
{
Dictionary<Module, double> dict1 = new Dictionary<Module, double>();
dict1[Module.A1] = 1;
dict1[Module.A2] = 2;
dict1[Module.A3] = 3;

dict1[Module.B1toB7] = 6;

dict1[Module.C2] = 2;
dict1[Module.C3] = 3;
dict1[Module.C4] = 4;
dict1[Module.D] = 0;

Dictionary<Module, double> dict2 = new Dictionary<Module, double>();
foreach (var item in dict1)
{
dict2[item.Key] = item.Value + 10;
}

dict1[Module.C1] = 1;
dict1[Module.A4] = 4;
dict1[Module.A5] = 5;


Dictionary<Module, double> sum1 = new Dictionary<Module, double>();
sum1[Module.A1] = 12;
sum1[Module.A2] = 14;
sum1[Module.A3] = 16;

sum1[Module.B1toB7] = 22;

sum1[Module.C2] = 14;
sum1[Module.C3] = 16;
sum1[Module.C4] = 18;
sum1[Module.D] = 10;

ClimateChangeFossilMetric metric1 = new ClimateChangeFossilMetric() { Indicators = dict1 };
ClimateChangeFossilMetric metric2 = new ClimateChangeFossilMetric(){ Indicators = dict2 };

yield return new object[] { new List<IEnvironmentalMetricFactors> { metric1, metric2 }, true, sum1 }; //Check for only including modules present in both results

Dictionary<Module, double> sum2 = new Dictionary<Module, double>(sum1);
sum2[Module.C1] = 1;
sum2[Module.A4] = 4;
sum2[Module.A5] = 5;

yield return new object[] { new List<IEnvironmentalMetricFactors> { metric1, metric2 }, false, sum2 }; //Check for including all

ClimateChangeFossilMaterialResult res1 = new ClimateChangeFossilMaterialResult("", "", dict1);
ClimateChangeFossilMaterialResult res2 = new ClimateChangeFossilMaterialResult("", "", dict2);

//Test that works for material results
yield return new object[] { new List<MaterialResult> { res1, res2 }, true, sum1 };
yield return new object[] { new List<MaterialResult> { res1, res2 }, false, sum2 };


ClimateChangeBiogenicMetric metricOtherType = new ClimateChangeBiogenicMetric() { Indicators = dict2 };

//Check that differing types give no results
yield return new object[] { new List<IEnvironmentalMetricFactors> { metric1, metricOtherType }, true, new Dictionary<Module, double>() };
yield return new object[] { new List<IEnvironmentalMetricFactors> { metric1, metricOtherType }, false, new Dictionary<Module, double>() };
}

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

}
}


Loading
Loading