Skip to content
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
6 changes: 3 additions & 3 deletions ifrs17-template/Test/ScenarioDataImportTest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{
"cell_type": "code",
"source": [
"var EnableScenarioBackup = EnableScenario;"
"var EnableScenarioBackup = Scenarios.EnableScenario;"
],
"metadata": {},
"execution_count": 0,
Expand All @@ -64,7 +64,7 @@
{
"cell_type": "code",
"source": [
"EnableScenario = true;"
"Scenarios.EnableScenario = true;"
],
"metadata": {},
"execution_count": 0,
Expand Down Expand Up @@ -952,7 +952,7 @@
{
"cell_type": "code",
"source": [
"EnableScenario = EnableScenarioBackup;"
"Scenarios.EnableScenario = EnableScenarioBackup;"
],
"metadata": {},
"execution_count": 0,
Expand Down
6 changes: 3 additions & 3 deletions ifrs17-template/Test/ScenarioYieldCurveImportTest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{
"cell_type": "code",
"source": [
"var EnableScenarioBackup = EnableScenario;"
"var EnableScenarioBackup = Scenarios.EnableScenario;"
],
"metadata": {},
"execution_count": 0,
Expand All @@ -64,7 +64,7 @@
{
"cell_type": "code",
"source": [
"EnableScenario = true;"
"Scenarios.EnableScenario = true;"
],
"metadata": {},
"execution_count": 0,
Expand Down Expand Up @@ -734,7 +734,7 @@
{
"cell_type": "code",
"source": [
"EnableScenario = EnableScenarioBackup;"
"Scenarios.EnableScenario = EnableScenarioBackup;"
],
"metadata": {},
"execution_count": 0,
Expand Down
34 changes: 6 additions & 28 deletions ifrs17/Constants/Consts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -383,34 +383,12 @@
{
"cell_type": "code",
"source": [
"public bool EnableScenario = false;"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public const string ScenarioDefault = \"Best Estimate\";"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public const string ScenariosAll = \"All\";"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"public const string ScenariosDelta = \"Delta\";"
"public static class Scenarios{",
"\n public static bool EnableScenario = false;",
"\n public const string Default = \"Best Estimate\";",
"\n public const string All = nameof(All);",
"\n public const string Delta = nameof(Delta);",
"\n}"
],
"metadata": {},
"execution_count": 0,
Expand Down
7 changes: 3 additions & 4 deletions ifrs17/Import/Importers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@
"\n break;",
"\n }",
"\n }",
"\n return allArgs.Where(x => (!EnableScenario && x.Scenario == null) || EnableScenario).ToArray();",
"\n return allArgs.Where(x => (!Scenarios.EnableScenario && x.Scenario == null) || Scenarios.EnableScenario).ToArray();",
"\n}"
],
"metadata": {},
Expand Down Expand Up @@ -669,10 +669,9 @@
"using static Systemorph.Vertex.Equality.IdentityPropertyExtensions;",
"\npublic async static Task ValidateForMandatoryAocSteps(this IWorkspace workspace, IDataSet dataSet, HashSet<AocStep> mandatoryAocSteps)",
"\n{ ",
"\n var excludedProperties = new[]{nameof(AocType), nameof(Novelty)};",
"\n var includingProperties = typeof(RawVariable).GetIdentityProperties().Select(x=>x.Name).Except(excludedProperties).ToArray();",
"\n var ignoreProperties = new[]{nameof(AocType), nameof(Novelty)};",
"\n var missingAocStepsByIdentityProperties = (await workspace.Query<RawVariable>().ToListAsync())",
"\n .GroupBy(x => x.ToStringWith(properties: includingProperties),",
"\n .GroupBy(x => x.ToIdentityString(ignoreProperties),",
"\n x => new AocStep(x.AocType, x.Novelty),",
"\n (properties, parsedAocSteps) => (properties, mandatoryAocSteps.Except(parsedAocSteps))",
"\n );",
Expand Down
6 changes: 3 additions & 3 deletions ifrs17/Report/ReportMutableScopes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@
"\n IDataCube<ReportVariable> Cube { get{",
"\n var data = GetScope<IIfrs17Report>(Identity.reportType).GetDataCube();",
"\n // TODO: suggestion to place the filter here instead of having it in every applicability scope",
"\n if(Identity.scenario != ScenariosAll && Identity.scenario != ScenariosDelta) return data;",
"\n if(Identity.scenario == ScenariosAll) return data.Select(x => x.Scenario == null? x with {Scenario = ScenarioDefault } : x).ToDataCube();",
"\n if(Identity.scenario != Scenarios.All && Identity.scenario != Scenarios.Delta) return data;",
"\n if(Identity.scenario == Scenarios.All) return data.Select(x => x.Scenario == null? x with {Scenario = Scenarios.Default } : x).ToDataCube();",
"\n var bestEstimateById = data.Where(x => x.Scenario == null).ToDictionary(x => x.ToIdentityString());",
"\n return data.Select(x => x.Scenario == null ? x with { Scenario = ScenarioDefault } ",
"\n return data.Select(x => x.Scenario == null ? x with { Scenario = Scenarios.Default } ",
"\n : x with { Value = x.Value - (bestEstimateById.TryGetValue((x with {Scenario = null}).ToIdentityString(), out var be)? be.Value : 0.0) }).ToDataCube();",
"\n }}",
"\n} "
Expand Down
45 changes: 29 additions & 16 deletions ifrs17/Utils/Extensions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
{
"cell_type": "markdown",
"source": [
"# ToIdentityString"
"# Identity property reader"
],
"metadata": {},
"execution_count": 0,
Expand All @@ -208,16 +208,30 @@
{
"cell_type": "code",
"source": [
"using System.Text;",
"\npublic static string ToIdentityString<T>(this T v, params string[] excludingProperties) where T : class",
"\n{",
"\n StringBuilder sb = new StringBuilder();",
"\n var propertyInfos = v.GetType()",
"\n .GetProperties()",
"\n .Where(x => Attribute.IsDefined(x, typeof(IdentityPropertyAttribute)) && !excludingProperties.Contains(x.Name))",
"\n .OrderByDescending(x => x.PropertyType.Name).ThenByDescending(x => x.Name)",
"\n .Select(x => sb.Append(x.Name).Append(\":\").Append(v.GetType().GetProperty(x.Name)?.GetValue(v, null)).Append(\", \")).ToArray();",
"\n return propertyInfos.Count() == 0? v.ToString() : propertyInfos.Select(p => p.ToString()).ToArray().Last();",
"using static Systemorph.Vertex.Equality.IdentityPropertyExtensions;",
"\nusing System.Linq.Expressions;",
"\npublic static class IdentityReader<T> where T : class {",
"\n private static Dictionary<string, Func<T, string>> ExpressionsByExcludedProperties = new();",
"\n public static string Concat(string first, string second) => first + \" \" + second;",
"\n public static string GetString(Object item) => (item == null) ? \"\" : item.ToString();",
"\n",
"\n private static Func<T, string> GetToIdentityExpression(string[] excludedProperties) {",
"\n var pm = Expression.Parameter(typeof(T));",
"\n var expression = typeof(T).GetIdentityProperties().Where(x => !excludedProperties.Contains(x.Name))",
"\n .SelectMany(x => new Expression[]{ Expression.Constant(x.Name.ToString()+\":\"),",
"\n Expression.Call(typeof(IdentityReader<T>).GetMethod(nameof(GetString)), Expression.Convert(Expression.Property(pm, x.Name), typeof(Object))) }",
"\n ).Aggregate((x, y) => Expression.Call(typeof(IdentityReader<T>).GetMethod(nameof(IdentityReader<T>.Concat)), x, y));",
"\n return Expression.Lambda<Func<T,string>>(expression, pm).Compile();",
"\n }",
"\n",
"\n public static string ToString(T x, string[] excludedProperties) {",
"\n var key = string.Join(\",\", excludedProperties.OrderBy(x => x));",
"\n if(!ExpressionsByExcludedProperties.TryGetValue(key, out var expression)) {",
"\n ExpressionsByExcludedProperties[key] = GetToIdentityExpression(excludedProperties);",
"\n return ExpressionsByExcludedProperties[key](x);",
"\n }",
"\n return expression(x);",
"\n }",
"\n}"
],
"metadata": {},
Expand All @@ -227,7 +241,7 @@
{
"cell_type": "markdown",
"source": [
"# ToString with including properties"
"# ToString with excluding properties"
],
"metadata": {},
"execution_count": 0,
Expand All @@ -236,11 +250,10 @@
{
"cell_type": "code",
"source": [
"public static string ToStringWith<T>(this T variable, string[] properties) where T : BaseVariableIdentity",
"public static string ToIdentityString<T>(this T variable, string[] ignoreProperties = null) where T : class",
"\n{",
"\n var propertiesRead = variable.ToString().Split('{', '}')[1].Split(',');",
"\n var propertiesFiltered = propertiesRead.Where(x=> properties.Contains(x.Split('=')[0].Trim()));",
"\n return string.Join(\", \", propertiesFiltered).Trim();",
"\n if (ignoreProperties == null) ignoreProperties = new string[0];",
"\n return IdentityReader<T>.ToString(variable, ignoreProperties);",
"\n}"
],
"metadata": {},
Expand Down