Skip to content

Commit

Permalink
add more function
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Sep 20, 2024
1 parent 3a1f896 commit db81b7f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
47 changes: 46 additions & 1 deletion APSToolkit/Database/PropDbReaderRevit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,52 @@ public Dictionary<int, string> GetAllCategories()
GetRecursiveChild(ref categories, 1, "_RC");
return categories;
}

public Dictionary<string, List<string>> GetAllCategoriesAndParameters()
{
Dictionary<string, List<string>> categories = new Dictionary<string, List<string>>();
Dictionary<int,string> allCategories = GetAllCategories();
foreach (KeyValuePair<int,string> category in allCategories)
{
List<string> parameters = new List<string>();
int[] cates = GetChildren(category.Key);
for (int i = 0; i < cates.Length; i++)
{
GetRecursiveParameters(ref parameters, cates[i]);
}
parameters = parameters.Distinct().OrderBy(x=>x).ToList();
categories[category.Value] = parameters;
}
return categories;
}
private void GetRecursiveParameters(ref List<string> parameters, int id)
{

Dictionary<string,string?> publicProperties = GetPublicProperties(id);
parameters.AddRange(publicProperties.Keys);
int[] ints = this.GetInstanceOf(id);
foreach (int @int in ints)
{
var docs = GetPublicProperties(@int);
parameters.AddRange(docs.Keys);

}
int[] children = GetChildren(id);
for (int i = 0; i < children.Length; i++)
{
GetRecursiveParameters(ref parameters,children[i]);
}
}
public List<string> GetAllParameters()
{
List<string> parameters = new List<string>();
for (int i = 0; i < this.ids!.Length; i++)
{
Dictionary<string,string?> publicProperties = GetPublicProperties(i);
parameters.AddRange(publicProperties.Keys);
}
return parameters.Distinct().OrderBy(x=>x).ToList();
}
/// <summary>
/// Retrieves a list of unique families based on the properties with the name "_RFN".
/// </summary>
Expand Down Expand Up @@ -308,7 +354,6 @@ public DataTable GetDataByCategoriesAndParameters(List<string> categories,List<s
int[] cates = GetChildren(cate.Key);
GetChildren(ref dataTable, cates,parameters);
}

return dataTable;
}
// public DataTable GetAllDataParameterByCategory(string category,List<string> parameters, bool isIncludeType = true, bool isAddUnit = true)
Expand Down
18 changes: 18 additions & 0 deletions APSToolkitUnit/ProbDbReaderRevitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ public void GetAllCategoriesTest(string urn)
}
[Test]
[TestCaseSource(typeof(Settings), nameof(Settings.RevitTestUrn))]
public void GetAllParametersTest(string urn)
{
RevitPropDbReader = new PropDbReaderRevit(urn, Settings.Token2Leg);
var parameters = RevitPropDbReader.GetAllParameters();
parameters.ExportToCsv("result.csv");
Assert.AreNotEqual(0, parameters.Count);
}
[Test]
[TestCaseSource(typeof(Settings), nameof(Settings.RevitTestUrn))]
public void GetAllCategoriesAndParameters(string urn)
{
RevitPropDbReader = new PropDbReaderRevit(urn, Settings.Token2Leg);
var parameters = RevitPropDbReader.GetAllCategoriesAndParameters();
parameters.ExportToCsv("result.csv");
Assert.AreNotEqual(0, parameters.Count);
}
[Test]
[TestCaseSource(typeof(Settings), nameof(Settings.RevitTestUrn))]
public void TestExportAllDataToExcel(string urn)
{
RevitPropDbReader = new PropDbReaderRevit(urn, Settings.Token2Leg);
Expand Down
2 changes: 1 addition & 1 deletion APSToolkitUnit/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class Settings
"dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLmZqSkFRUUx6U3BxLTR3eWRPdG9DMGc_dmVyc2lvbj0x";

public const string _RevitTestUrn =
"dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLk9kOHR4RGJLU1NlbFRvVmcxb2MxVkE_dmVyc2lvbj0yNA";
"dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkotQ2laSHpGVEd5LUEwLVJmaEVVTVE_dmVyc2lvbj04";

public const string _IfcUrn =
"dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLjEzLVdVN2NBU2kyQThVdUNqQVFmUkE_dmVyc2lvbj0x";
Expand Down

0 comments on commit db81b7f

Please sign in to comment.