改进模型统计信息准确性,实现真实元素分类统计
- 添加递归元素统计方法CountElementsByType(),使用GetActualType()获取准确元素类型 - 实现Zone专门统计方法CountZones(),统计SITE下的ZONE元素及其名称 - 替换硬编码统计逻辑,支持SITE、ZONE、PIPE、EQUI、STRU、VALVE、FITT、NOZZ等类型 - 修复GetValidString API调用,使用正确的两参数方式 - 移除所有硬编码的0值,返回真实的模型统计数据 现在/api/status/model接口将返回准确的模型元素统计信息。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3082148d7e
commit
69f32020fa
@ -131,36 +131,28 @@ namespace TellmePdmsPluging.Core
|
|||||||
var designDb = currentMdb.GetFirstDB(DbType.Design);
|
var designDb = currentMdb.GetFirstDB(DbType.Design);
|
||||||
if (designDb?.World != null)
|
if (designDb?.World != null)
|
||||||
{
|
{
|
||||||
// 获取真实的元素统计信息
|
// 初始化统计计数器
|
||||||
var worldMembers = designDb.WorldMembers();
|
|
||||||
var elementCounts = new Dictionary<string, int>
|
var elementCounts = new Dictionary<string, int>
|
||||||
{
|
{
|
||||||
{"PIPE", 0}, {"EQUI", 0}, {"STRU", 0},
|
{"SITE", 0}, {"ZONE", 0}, {"PIPE", 0}, {"EQUI", 0},
|
||||||
{"VALVE", 0}, {"FITT", 0}, {"NOZZ", 0}
|
{"STRU", 0}, {"VALVE", 0}, {"FITT", 0}, {"NOZZ", 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int totalElements = 0;
|
int totalElements = 0;
|
||||||
var activeZones = new List<string>();
|
var activeZones = new List<string>();
|
||||||
|
int zoneCount = 0;
|
||||||
|
|
||||||
// 遍历World的直接子元素进行统计
|
// 递归统计所有元素
|
||||||
if (worldMembers != null)
|
CountElementsByType(designDb.World, elementCounts, ref totalElements);
|
||||||
{
|
|
||||||
foreach (var element in worldMembers)
|
// 专门统计Zone信息
|
||||||
{
|
CountZones(designDb.World, ref zoneCount, activeZones);
|
||||||
if (element != null && !element.IsNull && element.IsValid)
|
|
||||||
{
|
|
||||||
totalElements++;
|
|
||||||
// 这里需要获取元素类型,可能需要进一步的API调用来判断具体类型
|
|
||||||
// 暂时先统计总数
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ModelStatistics
|
return new ModelStatistics
|
||||||
{
|
{
|
||||||
TotalElements = totalElements,
|
TotalElements = totalElements,
|
||||||
ElementCounts = elementCounts,
|
ElementCounts = elementCounts,
|
||||||
ZoneCount = 0, // Zone统计需要额外的API
|
ZoneCount = zoneCount,
|
||||||
ActiveZones = activeZones
|
ActiveZones = activeZones
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -187,6 +179,108 @@ namespace TellmePdmsPluging.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CountElementsByType(DbElement parentElement, Dictionary<string, int> elementCounts, ref int totalElements)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (parentElement == null || parentElement.IsNull || !parentElement.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 获取所有子元素
|
||||||
|
var members = parentElement.Members();
|
||||||
|
if (members != null)
|
||||||
|
{
|
||||||
|
foreach (var element in members)
|
||||||
|
{
|
||||||
|
if (element != null && !element.IsNull && element.IsValid)
|
||||||
|
{
|
||||||
|
totalElements++;
|
||||||
|
|
||||||
|
// 获取元素的实际类型
|
||||||
|
var elementType = element.GetActualType();
|
||||||
|
if (elementType != null)
|
||||||
|
{
|
||||||
|
string typeName = elementType.Name;
|
||||||
|
if (elementCounts.ContainsKey(typeName))
|
||||||
|
{
|
||||||
|
elementCounts[typeName]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归统计子元素
|
||||||
|
CountElementsByType(element, elementCounts, ref totalElements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"统计元素类型时出错: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CountZones(DbElement worldElement, ref int zoneCount, List<string> activeZones)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (worldElement == null || worldElement.IsNull || !worldElement.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 查找SITE元素
|
||||||
|
var sites = worldElement.Members();
|
||||||
|
if (sites != null)
|
||||||
|
{
|
||||||
|
foreach (var site in sites)
|
||||||
|
{
|
||||||
|
if (site != null && !site.IsNull && site.IsValid)
|
||||||
|
{
|
||||||
|
var siteType = site.GetActualType();
|
||||||
|
if (siteType != null && siteType.Name == "SITE")
|
||||||
|
{
|
||||||
|
// 在SITE下查找ZONE元素
|
||||||
|
var zones = site.Members();
|
||||||
|
if (zones != null)
|
||||||
|
{
|
||||||
|
foreach (var zone in zones)
|
||||||
|
{
|
||||||
|
if (zone != null && !zone.IsNull && zone.IsValid)
|
||||||
|
{
|
||||||
|
var zoneType = zone.GetActualType();
|
||||||
|
if (zoneType != null && zoneType.Name == "ZONE")
|
||||||
|
{
|
||||||
|
zoneCount++;
|
||||||
|
|
||||||
|
// 获取Zone名称
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string zoneName = "";
|
||||||
|
if (zone.GetValidString(DbAttributeInstance.NAME, ref zoneName))
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(zoneName))
|
||||||
|
{
|
||||||
|
activeZones.Add(zoneName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// 如果无法获取名称,跳过
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"统计Zone信息时出错: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SessionInfo GetSessionInfo()
|
private SessionInfo GetSessionInfo()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user