private void VerifyStructure(ElementUsage row2Result) { var hierarchy = new CategoryDecompositionHierarchy .Builder(this.iteration, this.cat1.ShortName) .AddLevel(this.cat2.ShortName) .AddLevel(this.cat3.ShortName) .Build(); var dataSource = new DataCollectorNodesCreator <Row>(); var nestedElementTree = new NestedElementTreeGenerator().Generate(this.option).ToList(); // tabular representation built, category hierarchy considered, unneeded subtrees pruned var rows = dataSource.GetTable(hierarchy, nestedElementTree).Rows; Assert.AreEqual(2, rows.Count); ValidateRow(rows[0], this.ed1, this.eu12p1, this.eu2p31); ValidateRow(rows[1], this.ed1, row2Result, this.eu7); }
public void VerifyThatNodeIdentifiesCollectParentValueParameters() { var hierarchy = new CategoryDecompositionHierarchy .Builder(this.iteration, this.cat1.ShortName) .Build(); var dataSource = new DataCollectorNodesCreator <CollectParentValuesRow>(); var nestedElementTree = new NestedElementTreeGenerator().Generate(this.option).ToList(); var dataTable = dataSource.GetTable( hierarchy, nestedElementTree); Assert.IsTrue(dataTable.Columns.Contains($"{nameof(CollectParentValuesRow.parameter1)}")); Assert.IsTrue(dataTable.Columns.Contains($"{nameof(CollectParentValuesRow.parameter2)}")); Assert.IsTrue(dataTable.Columns.Contains($"{nameof(CollectParentValuesRow.ComputedParameter)}")); Assert.IsTrue(dataTable.Columns.Contains($"{nameof(CollectParentValuesRow.parameter1)}_{this.cat1.ShortName}")); Assert.IsTrue(dataTable.Columns.Contains($"{nameof(CollectParentValuesRow.ComputedParameter)}_{this.cat1.ShortName}")); }
public void VerifyThatCorrectColumnNameIsUsed() { var hierarchy = new CategoryDecompositionHierarchy .Builder(this.dataCollectorParameterTestFixture.iteration, this.dataCollectorParameterTestFixture.cat1.ShortName) .Build(); var dataSource = new DataCollectorNodesCreator <Row>(); var nestedElementTree = new NestedElementTreeGenerator().Generate(this.dataCollectorParameterTestFixture.option).ToList(); var node = dataSource.CreateNodes( hierarchy, nestedElementTree).First(); Assert.AreEqual(1, node.GetColumns <DataCollectorStateDependentPerRowDoubleParameter <Row> >().Count()); Assert.IsTrue(node.GetTable().Columns.Contains("ParameterName")); Assert.IsTrue(node.GetTable().Columns.Contains("ParameterState")); Assert.IsTrue(node.GetTable().Columns.Contains("ParameterValue")); Assert.AreEqual(2, node.GetTable().Rows.Count); }
public void VerifyCategorySuperCategoryAsColumn() { this.ed1.Category.Add(this.superCat); var hierarchy = new CategoryDecompositionHierarchy .Builder(this.iteration, this.cat1.ShortName) .Build(); var dataSource = new DataCollectorNodesCreator <Row2>(); var nestedElementTree = new NestedElementTreeGenerator().Generate(this.option).ToList(); var node = dataSource.CreateNodes( hierarchy, nestedElementTree).First(); var categoryColumns = node.GetColumns <DataCollectorCategory <Row2> >().ToList(); Assert.AreEqual(true, categoryColumns.Single(x => x.ShortName == this.superCat.ShortName).Value); Assert.AreEqual(this.superCat, categoryColumns.Single(x => x.ShortName == this.superCat.ShortName).MainCategory); Assert.AreEqual(false, categoryColumns.Single(x => x.ShortName == this.subCat.ShortName).Value); }
public void VerifyThatCategoryHierarchyIsCorrect() { var hierarchy = new CategoryDecompositionHierarchy .Builder(this.iteration, this.cat1.ShortName) .AddLevel(this.cat2.ShortName) .AddLevel(this.cat3.ShortName) .AddLevel(this.cat4.ShortName, "cat4FieldName") .Build(); Assert.AreEqual(this.cat1, hierarchy.Category); hierarchy = hierarchy.Child; Assert.AreEqual(this.cat2, hierarchy.Category); hierarchy = hierarchy.Child; Assert.AreEqual(this.cat3, hierarchy.Category); hierarchy = hierarchy.Child; Assert.AreEqual(this.cat4, hierarchy.Category); Assert.IsNull(hierarchy.Child); }
public void VerifyNestedParameterInitialization() { var hierarchy = new CategoryDecompositionHierarchy .Builder(this.iteration, this.cat2.ShortName) .Build(); var dataSource = new DataCollectorNodesCreator <Row>(); var nestedElementTree = new NestedElementTreeGenerator().Generate(this.option).ToList(); var node = dataSource.CreateNodes( hierarchy, nestedElementTree).First(x => x.ElementBase.Iid == this.eu2.Iid); var parameter1 = node.GetColumns <TestParameter1>().Single(); Assert.AreEqual("-21", parameter1.ValueSets.FirstOrDefault()?.ActualValue.First()); Assert.AreEqual(this.elementOwner, parameter1.Owner); var parameter2 = node.GetColumns <TestParameter2>().Single(); Assert.AreEqual("-22", parameter2.ValueSets.FirstOrDefault()?.ActualValue.First()); Assert.AreEqual(this.elementOwner, parameter2.Owner); }
/// <summary> /// A must override method that returns the actual data object. /// A data object could be anything, except a dynamic/ExpandoObject type. /// </summary> /// <returns> /// The data as an object. /// </returns> public override object CreateDataObject() { // Select an Option from the current Iteration. // this.SelectOption is a method of the OptionDependentDataCollector class // After selection the SelectedOption property will be set. this.SelectOption(); var option = this.SelectedOption; // Get the tree of NestedElements for the selected Option. var nestedElementTree = new NestedElementTreeGenerator().Generate(option).ToList(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here. // The Category hierarchy of elements in the product tree should be like: // // Missions // | Segments // | Elements [1..5 nesting levels] // | Equipment // // In case there are multiple nested Equipment levels in the model, the deepest level is selected // as the source for the parameter values. var productHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Elements", 5) .AddLevel("Equipment") .Build(); // Build a DataTable for the productHierarchy level (Product level) var resultDataSource = new DataCollectorNodesCreator<MainDataRow>() .GetTable(productHierarchy, nestedElementTree); //--------------------------------------------------- // Create distinct rows for all elements and summarize the NoOfItems //--------------------------------------------------- var resultColumnArray = resultDataSource.Columns.Cast<DataColumn>() .Select(x => x.ColumnName) .Except(new [] {"NumberOfItems", "n_items", "Equipment"}) .ToArray(); var distinctResultDataSource = new DataView(resultDataSource).ToTable(true, resultColumnArray); distinctResultDataSource.Columns.Add("NumberOfItems", typeof(double)); distinctResultDataSource.Columns.Add("Equipment", typeof(string)); foreach (DataRow distinctRow in distinctResultDataSource.Rows) { distinctRow["NumberOfItems"] = 0D; var writeElementDefinitionName = false; foreach (DataRow row in resultDataSource.Rows) { var write = true; foreach (var columnName in resultColumnArray) { if (!row[columnName].Equals(distinctRow[columnName])) { write = false; break; } } if (write) { distinctRow["NumberOfItems"] = ((double)distinctRow["NumberOfItems"]) + ((double)row["NumberOfItems"]); if (writeElementDefinitionName) { distinctRow["Equipment"] = (string)row["ElementDefinitionName"]; } else { distinctRow["Equipment"] = (string)row["Equipment"]; } writeElementDefinitionName = true; } } } resultDataSource = distinctResultDataSource; //--------------------------------------------------- // Create a DataView that contains all Distinct values in the resultDataSource's Segments column, var segmentsTable = new DataView(resultDataSource).ToTable(true, "Segments"); // Create the DataSet that will be returned by this CreateDataObject method. var dataSet = new DataSet(); // Find the data rows that contain a Segments name that is equal to the SpaceSegmentName set in the top of this file // and add that table to the DataSet. foreach (DataRow dataRow in segmentsTable.Rows) { var segment = dataRow["Segments"].ToString(); if ((segment) == Variables.SpaceSegmentName) { var newView = new DataView(resultDataSource); newView.RowFilter = "Segments = '" + segment + "'"; var newTable = newView.ToTable(); newTable.TableName = "MainData"; dataSet.Tables.Add(newTable); } } return dataSet; }
/// <summary> /// A must override method that returns the actual data object. /// A data object could be anything, except a dynamic/ExpandoObject type. /// </summary> /// <returns> /// The data as an object. /// </returns> public override object CreateDataObject() { // Select an Option from the current Iteration. // this.SelectOption is a method of the OptionDependentDataCollector class // After selection the SelectedOption property will be set. this.SelectOption(); var option = this.SelectedOption; // Get the tree of NestedElements for the selected Option. var nestedElementTree = new NestedElementTreeGenerator().Generate(option).ToList(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Equipment levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var functionHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Systems", "SystemName", 5) .AddLevel("Subsystems", "SubsystemName") .Build(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Elements levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var productHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Elements", "SystemName", 5) .AddLevel("Equipment", "SubsystemName") .Build(); // Build a DataTable for the productHierarchy level (Product level) // The third parameter in the GetTable method indicates that elements that do not contain // any wanted parameters will not be shown in the result table. var resultDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(productHierarchy, nestedElementTree, true); // Build a DataTable for the functionHierarchy level (Function level) // The third parameter in the GetTable method indicates that elements that do not contain // any wanted parameters will not be shown in the result table. var secondDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(functionHierarchy, nestedElementTree, true); // Merge the two datatables resultDataSource.Merge(secondDataSource); var newView = new DataView(resultDataSource); newView.RowFilter = "Segments = '" + Variables.SpaceSegmentName + "' And (P_on <> 0 Or P_stby <> 0)"; resultDataSource = newView.ToTable(); resultDataSource.TableName = "MainData"; //--------------------------------------------------- // Create distinct rows for all ED's and summarize the NumberOfItems //--------------------------------------------------- var resultColumnArray = resultDataSource.Columns.Cast <DataColumn>() .Select(x => x.ColumnName) .Except(new[] { "NumberOfItems", "n_items", "SubsystemName", "SystemName_3", "SystemName_4", "SystemName_5" }) .ToArray(); var distinctResultDataSource = new DataView(resultDataSource).ToTable(true, resultColumnArray); distinctResultDataSource.Columns.Add("NumberOfItems", typeof(double)); // Summarize the relevant data and write to the merged DataRow foreach (DataRow distinctRow in distinctResultDataSource.Rows) { distinctRow["NumberOfItems"] = 0D; foreach (DataRow row in resultDataSource.Rows) { var write = true; foreach (var columnName in resultColumnArray) { if (!row[columnName].Equals(distinctRow[columnName])) { write = false; break; } } if (write) { distinctRow["NumberOfItems"] = ((double)distinctRow["NumberOfItems"]) + ((double)row["NumberOfItems"]); } } } resultDataSource = distinctResultDataSource; //--------------------------------------------------- //Build dynamic tables var systemModeList = this.Iteration.ActualFiniteStateList.FirstOrDefault(x => x.ShortName == Variables.SystemModesShortName); if (systemModeList == null) { System.Windows.MessageBox.Show("Please set the correct ShortName of the System Mode ActualFiniteStateList in the Variables section of this report's code file."); } var stateList = systemModeList.ActualState.ToList().Select(x => x.ShortName); foreach (var state in stateList) { var newMeanColumn = new DataColumn("P_mean" + state, typeof(double)); newMeanColumn.DefaultValue = 0D; resultDataSource.Columns.Add(newMeanColumn); var newMaxColumn = new DataColumn("P_max" + state, typeof(double)); newMaxColumn.DefaultValue = 0D; resultDataSource.Columns.Add(newMaxColumn); this.DynamicTableCellsCollector.AddValueTableCell("dynamicDutyCycleHeaderTable", state); this.DynamicTableCellsCollector.AddValueTableCell("dynamicP_meanHeaderTable", state); this.DynamicTableCellsCollector.AddValueTableCell("dynamicP_maxHeaderTable", state); this.DynamicTableCellsCollector.AddFieldTableCell("dynamicDutyCycleTable", "P_duty_cyc" + state); this.DynamicTableCellsCollector.AddFieldTableCell("dynamicP_meanTable", "P_mean" + state); this.DynamicTableCellsCollector.AddFieldTableCell("dynamicP_maxTable", "P_max" + state); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_meanOwnerTotalsTable", "sumSum([P_mean" + state + "])"); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_meanSystemTotalsTable", "sumSum([P_mean" + state + "])"); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_meanTotalsTable", "sumSum([P_mean" + state + "])"); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_meanTotalsInclMarginTable", "sumSum([P_mean" + state + "] * (1 + ?SystemMargin / 100))"); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_maxOwnerTotalsTable", "sumSum([P_max" + state + "])"); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_maxSystemTotalsTable", "sumSum([P_max" + state + "])"); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_maxTotalsTable", "sumSum([P_max" + state + "])"); this.DynamicTableCellsCollector.AddExpressionTableCell("dynamicP_maxTotalsInclMarginTable", "sumSum([P_max" + state + "] * (1 + (?SystemMargin / 100)))"); foreach (DataRow row in resultDataSource.Rows) { var emptyValues = new [] { "", "-" }.ToList(); var P_duty_cyc = emptyValues.Contains(row["P_duty_cyc" + state].ToString()) ? -1D : double.Parse(row["P_duty_cyc" + state].ToString()); var redundancy_type = row["redundancy_type"].ToString(); var redundancy_scheme = row["redundancy_scheme"].ToString(); var redundancy_k = emptyValues.Contains(row["redundancy_k"].ToString()) ? 0D : double.Parse(row["redundancy_k"].ToString()); var redundancy_n = emptyValues.Contains(row["redundancy_n"].ToString()) ? 0D : double.Parse(row["redundancy_n"].ToString()); var P_on = emptyValues.Contains(row["P_on"].ToString()) ? 0D : double.Parse(row["P_on"].ToString()); var P_stby = emptyValues.Contains(row["P_stby"].ToString()) ? 0D : double.Parse(row["P_stby"].ToString()); var NumberOfItems = emptyValues.Contains(row["NumberOfItems"].ToString()) ? 0D : double.Parse(row["NumberOfItems"].ToString()); var maturity_margin = emptyValues.Contains(row["maturity_margin"].ToString()) ? 0D : double.Parse(row["maturity_margin"].ToString()); // -------------------------------------------------------- // Calculate P_mean // -------------------------------------------------------- var P_mean = 0D; if (P_duty_cyc != -1) { P_mean = double.NaN; if (redundancy_type == "External") { if (redundancy_scheme == "Cold") { P_mean = (redundancy_k / redundancy_n) * NumberOfItems * ((P_on * P_duty_cyc) + (P_stby * (1 - P_duty_cyc))) * (1 + maturity_margin / 100); } else if (redundancy_scheme == "Standby") { P_mean = ((redundancy_k / redundancy_n) * NumberOfItems * ((P_on * P_duty_cyc) + (P_stby * (1 - P_duty_cyc)))) + (((redundancy_n - redundancy_k) / redundancy_n) * NumberOfItems * P_stby) * (1 + maturity_margin / 100); } } if (Double.IsNaN(P_mean)) { P_mean = NumberOfItems * ((P_on * P_duty_cyc) + (P_stby * (1 - P_duty_cyc))) * (1 + maturity_margin / 100); } } row["P_mean" + state] = P_mean; // -------------------------------------------------------- // Calculate P_max // -------------------------------------------------------- var P_max = 0D; if (P_duty_cyc != -1) { P_max = double.NaN; if (P_duty_cyc == 0) { if (redundancy_type == "External") { if (redundancy_scheme == "Cold") { P_max = (redundancy_k / redundancy_n) * NumberOfItems * P_stby * (1 + maturity_margin / 100); } } if (Double.IsNaN(P_max)) { P_max = NumberOfItems * P_stby * (1 + maturity_margin / 100); } } else { if (redundancy_type == "External") { if (redundancy_scheme == "Cold") { P_max = (redundancy_k / redundancy_n) * NumberOfItems * P_on * (1 + maturity_margin / 100); } else if (redundancy_scheme == "Standby") { P_max = ((redundancy_k / redundancy_n) * NumberOfItems * P_on) + (((redundancy_n - redundancy_k) / redundancy_n) * NumberOfItems * P_stby) * (1 + maturity_margin / 100); } } if (Double.IsNaN(P_max)) { P_max = NumberOfItems * P_on * (1 + maturity_margin / 100); } } } row["P_max" + state] = P_max; } } return(resultDataSource); }
/// <summary> /// A must override method that returns the actual data object. /// A data object could be anything, except a dynamic/ExpandoObject type. /// </summary> /// <returns> /// The data as an object. /// </returns> public override object CreateDataObject() { // Select an Option from the current Iteration. // this.SelectOption is a method of the OptionDependentDataCollector class // After selection the SelectedOption property will be set. this.SelectOption(); var option = this.SelectedOption; // Get the tree of NestedElements for the selected Option. var nestedElementTree = new NestedElementTreeGenerator().Generate(option).ToList(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Equipment levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var functionHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Systems", "SystemName", 5) .AddLevel("Subsystems", "SubsystemName") .Build(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Elements levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var productHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Elements", "SystemName", 5) .AddLevel("Equipment", "SubsystemName") .Build(); // Build a DataTable for the productHierarchy level (Product level) // The third parameter in the GetTable method indicates that elements that do not contain // any wanted parameters will not be shown in the result table. var resultDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(productHierarchy, nestedElementTree, true); // Build a DataTable for the functionHierarchy level (Function level) // The third parameter in the GetTable method indicates that elements that do not contain // any wanted parameters will not be shown in the result table. var secondDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(functionHierarchy, nestedElementTree, true); // Merge the two datatables resultDataSource.Merge(secondDataSource); var newView = new DataView(resultDataSource); newView.RowFilter = "Segments = '" + Variables.SpaceSegmentName + "' And (P_on <> 0 Or P_stby <> 0)"; resultDataSource = newView.ToTable(); resultDataSource.TableName = "MainData"; //Build dynamic tables var systemModeList = this.Iteration.ActualFiniteStateList.FirstOrDefault(x => x.ShortName == Variables.SystemModesShortName); if (systemModeList == null) { System.Windows.MessageBox.Show("Please set the correct ShortName of the System Mode ActualFiniteStateList in the Variables section of this report's code file."); } var stateList = systemModeList.ActualState.ToList().Select(x => x.ShortName); foreach (var state in stateList) { this.DynamicTableCellsCollector.AddValueTableCell("dynamicDutyCycleHeaderTable", state); this.DynamicTableCellsCollector.AddFieldTableCell("dynamicDutyCycleTable", "P_duty_cyc" + state); } return(resultDataSource); }
/// <summary> /// A must override method that returns the actual data object. /// A data object could be anything, except a dynamic/ExpandoObject type. /// </summary> /// <returns> /// The data as an object. /// </returns> public override object CreateDataObject() { // Select an Option from the current Iteration. // this.SelectOption is a method of the OptionDependentDataCollector class // After selection the SelectedOption property will be set. this.SelectOption(); var option = this.SelectedOption; Variables.SetVariables(option); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Equipment levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var functionHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Systems", "SystemName", 5) .AddLevel("Subsystems", "SubsystemName") .Build(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Elements levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var productHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Elements", "SystemName", 5) .AddLevel("Equipment", "SubsystemName") .Build(); // Build a DataTable for the productHierarchy level (Product level) var resultDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(productHierarchy, Variables.NestedElements); // Build a DataTable for the functionHierarchy level (Function level) var secondDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(functionHierarchy, Variables.NestedElements); // Merge the two datatables resultDataSource.Merge(secondDataSource); // Create a DataView that contains all Distinct values in the resultDataSource's Segments column, var segmentsTable = new DataView(resultDataSource).ToTable(true, "Segments"); // Create the DataSet that will be returned by this CreateDataObject method. var dataSet = new DataSet(); resultDataSource.Columns.Add("MassWithoutExtraMargin", typeof(double)); // Set Extra Mass Margin data if found on the second Element level. foreach (DataRow dataRow in resultDataSource.Rows) { dataRow["MassWithoutExtraMargin"] = dataRow["Mass"]; if (resultDataSource.Columns.Contains("SystemName_2_MassMargin")) { if ((bool)dataRow["Products"] == true && dataRow["SystemName_2_MassMargin"] != DBNull.Value && (double)dataRow["SystemName_2_MassMargin"] != 0D) { dataRow["HasExtraMassMargin"] = true; dataRow["ExtraMassMargin"] = (double)dataRow["SystemName_2_MassMargin"] / 100; dataRow["Mass"] = (double)dataRow["Mass"] * (1D + (double)dataRow["ExtraMassMargin"]); } } } // Find the data rows that contain a Segments name that is equal to the SpaceSegmentName set in the top of this file // and add that table to the DataSet. foreach (DataRow dataRow in segmentsTable.Rows) { var segment = dataRow["Segments"].ToString(); if ((segment) == Variables.SpaceSegmentName) { var newView = new DataView(resultDataSource); newView.RowFilter = "Segments = '" + segment + "'"; newView.Sort = "SystemName_1 ASC, SystemName_2 ASC, OwnerShortName ASC, SubsystemName ASC"; var newTable = newView.ToTable(); newTable.TableName = "MainData"; dataSet.Tables.Add(newTable); } } return(dataSet); }
/// <summary> /// A must override method that returns the actual data object. /// A data object could be anything, except a dynamic/ExpandoObject type. /// </summary> /// <returns> /// The data as an object. /// </returns> public override object CreateDataObject() { // Select an Option from the current Iteration. // this.SelectOption is a method of the OptionDependentDataCollector class // After selection the SelectedOption property will be set. this.SelectOption(); var option = this.SelectedOption; // Get the tree of NestedElements for the selected Option. var nestedElementTree = new NestedElementTreeGenerator().Generate(option).ToList(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Equipment levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var functionHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Systems", "SystemName", 5) .AddLevel("Subsystems", "SubsystemName") .Build(); // Create a CategoryDecompositionHierarchy instance that reads all elements in the ProductTree that // comply to the Hierarchy of categories defined here: // // - Missions // | Segments // | Systems [1..5 nesting levels] // | Subsystems // // In case there are multiple nested Elements levels in the model, the deepest level is selected // as the source for the parameter values. // The fieldnames in the result DataSource are set explicitly (second parameter of AddLevel method). var productHierarchy = new CategoryDecompositionHierarchy .Builder(this.Iteration) .AddLevel("Missions") .AddLevel("Segments") .AddLevel("Elements", "SystemName", 5) .AddLevel("Equipment", "SubsystemName") .Build(); // Build a DataTable for the productHierarchy level (Product level) // The third parameter in the GetTable method indicates that elements that do not contain // any wanted parameters will not be shown in the result table. var resultDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(productHierarchy, nestedElementTree, true); // Build a DataTable for the functionHierarchy level (Function level) // The third parameter in the GetTable method indicates that elements that do not contain // any wanted parameters will not be shown in the result table. var secondDataSource = new DataCollectorNodesCreator <RowRepresentation>() .GetTable(functionHierarchy, nestedElementTree, true); // Merge the two datatables resultDataSource.Merge(secondDataSource); // Find the ParameterName in the Variables.ParameterOrder and set the Order property for that datarow using the Variables.ParameterOrder property. foreach (DataRow dataRow in resultDataSource.Rows) { var parameterName = dataRow["ParameterName"].ToString(); if (Variables.ParameterOrder.ContainsKey(parameterName)) { dataRow["Order"] = Variables.ParameterOrder[parameterName]; } else { System.Windows.MessageBox.Show("Unknown Parameter Name '" + parameterName + "' not found. Please add it to the Variables.ParameterOrder property in the Code Editor."); return(null); } } // Create a DataView that contains all Distinct values in the resultDataSource's Segments column, var segmentsTable = new DataView(resultDataSource).ToTable(true, "Segments"); // Find the data rows that contain a Segments name that is equal to the SpaceSegmentName set in the top of this file // and add that table to the DataSet. foreach (DataRow dataRow in segmentsTable.Rows) { var segment = dataRow["Segments"].ToString(); if ((segment) == Variables.SpaceSegmentName) { var newView = new DataView(resultDataSource); newView.RowFilter = "Segments = '" + segment + "'"; newView.Sort = "ParameterName ASC, OwnerShortName ASC, SubsystemName ASC"; var newTable = newView.ToTable(); newTable.TableName = "MainData"; // Return the table return(newTable); } } // If no table that contains the desired Variables.SpaceSegmentName was found then return null. return(null); }