Skip to content

Commit

Permalink
fix(HVACSystem): get detail info of a scenario/system
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed May 18, 2023
1 parent 28e8677 commit 499071c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
41 changes: 40 additions & 1 deletion src/Ironbug.HVAC/IB_HVACScenario.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

Expand All @@ -13,6 +14,9 @@ public class IB_HVACScenario
[DataMember]
public string Identifier { get; private set; }

[DataMember]
public string Info { get; private set; }

private IB_HVACScenario()
{
this.HVACSystems = new List<IB_HVACSystem>();
Expand All @@ -23,6 +27,7 @@ public IB_HVACScenario(string id, string name, List<IB_HVACSystem> systems )
this.Identifier = string.IsNullOrEmpty(id) ? System.Guid.NewGuid().ToString().Substring(0, 6) : id;
this.DisplayName = string.IsNullOrEmpty(name) ? this.Identifier : name;
this.HVACSystems = systems.Where(_ => _ != null).ToList();
this.Info = GetInfo();
}

public IB_HVACSystem CombineToHVACSystem()
Expand All @@ -34,5 +39,39 @@ public IB_HVACSystem CombineToHVACSystem()
return sys;

}

public string GetInfo()
{
if (HVACSystems == null || !HVACSystems.Any()) return string.Empty;

var info = new List<string>();
info.Add($"HVAC Scenario: {this.Identifier} [{this.DisplayName}]");
for (int i = 0; i < HVACSystems.Count; i++)
{
var sys = HVACSystems[i];
// system name
var sysName = $"- {i + 1}: {sys.ToString()}";
info.Add(sysName);

// zone names
//var rooms = sys.GetThermalZoneNames().Select((_,i)=> $"{i+1}: [{_}]").ToList();
//if (!rooms.Any()) rooms.Add("No zone is assigned to this system!");
//else
//{
// var zoneNames = $"- Zone names: {rooms.Count}";
// info.Add(zoneNames.PadLeft(zoneNames.Length + 2));
//}
//rooms = rooms.Select(_ => _.PadLeft(_.Length + 4)).ToList();
//info.AddRange(rooms);
}

return string.Join(Environment.NewLine, info);
}

public override string ToString()
{

return this.Info?? base.ToString();
}
}
}
28 changes: 26 additions & 2 deletions src/Ironbug.HVAC/IB_HVACSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Ironbug.HVAC
{
public class IB_HVACSystem
{
[DataMember]
public string DisplayName { get; set; }

[DataMember]
public List<IB_AirLoopHVAC> AirLoops { get; private set; }
[DataMember]
Expand Down Expand Up @@ -138,7 +141,7 @@ public static bool SaveHVAC(string osmPath, string hvacJsonFilePath)
if (!System.IO.File.Exists(osm) || !osm.ToLower().EndsWith(".osm"))
throw new ArgumentException($"Invalid osm file: {osm}");
if (!System.IO.File.Exists(hvac))
throw new ArgumentException($"Invalid hvac file: {hvac}");
throw new ArgumentException($"Invalid HVAC file: {hvac}");

var hvacJson = System.IO.File.ReadAllText(hvac);
var system = Ironbug.HVAC.IB_HVACSystem.FromJson(hvacJson);
Expand Down Expand Up @@ -328,7 +331,8 @@ private static void CheckInternalSourceConstruction(OpenStudio.Model model)

public override string ToString()
{
var s = "IB_HVACSystem";
var info = new List<string>();
var s = $"HVAC System: [{this.DisplayName ?? "Unnamed"}]";
if (AirLoops.Any())
{
var loops = this.AirLoops.GroupBy(_ => _ is HVAC.IB_NoAirLoop);
Expand All @@ -350,6 +354,26 @@ public override string ToString()
s = $"{s}{Environment.NewLine} - VRF system: {VariableRefrigerantFlows.Count}";
}

// zone names
var sys = this;
var rooms = sys.GetThermalZoneNames().Select((_, i) => $"{i + 1}: [{_}]").ToList();
if (!rooms.Any()) rooms.Add("No zone is assigned to this system!");
else
{
var zoneNames = $"- Zone names: {rooms.Count}";
s = $"{s}{Environment.NewLine} - VRF system: {VariableRefrigerantFlows.Count}";
info.Add(zoneNames.PadLeft(zoneNames.Length + 2));
}
if (rooms.Count > 3)
{
rooms = rooms.Take(3).ToList();
rooms.Add("...");
}
rooms = rooms.Select(_ => _.PadLeft(_.Length + 4)).ToList();

info.AddRange(rooms);
info.Insert(0, s);
s = string.Join(Environment.NewLine, info);
return s;
}

Expand Down

0 comments on commit 499071c

Please sign in to comment.