-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch5.diff
More file actions
108 lines (106 loc) · 5.25 KB
/
patch5.diff
File metadata and controls
108 lines (106 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--- src/MedWNetworkSim.App/Services/ReportExportService.cs
+++ src/MedWNetworkSim.App/Services/ReportExportService.cs
@@ -41,6 +41,27 @@
File.WriteAllText(path, contents, Encoding.UTF8);
}
+ public void SaveAgentReport(
+ NetworkModel network,
+ SimulationActorRunResult runResult,
+ string path,
+ ReportExportFormat format)
+ {
+ ArgumentNullException.ThrowIfNull(network);
+ ArgumentNullException.ThrowIfNull(runResult);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
+
+ var contents = format switch
+ {
+ ReportExportFormat.Csv => BuildAgentCsvReport(network, runResult),
+ ReportExportFormat.Json => BuildAgentJsonReport(network, runResult),
+ _ => BuildAgentHtmlReport(network, runResult)
+ };
+
+ File.WriteAllText(path, contents, Encoding.UTF8);
+ }
+
private static string BuildCurrentHtmlReport(
NetworkModel network,
IReadOnlyList<TrafficSimulationOutcome> outcomes,
@@ -754,6 +775,78 @@
return builder.ToString();
}
+ private static string BuildAgentHtmlReport(NetworkModel network, SimulationActorRunResult runResult)
+ {
+ var builder = new StringBuilder();
+ builder.AppendLine("<!DOCTYPE html>");
+ builder.AppendLine("<html><head><meta charset=\"utf-8\"><title>Agent Run Report</title>");
+ builder.AppendLine("<style>");
+ builder.AppendLine("body { font-family: sans-serif; line-height: 1.6; color: #333; max-width: 1200px; margin: 0 auto; padding: 20px; }");
+ builder.AppendLine("h1, h2, h3 { color: #0056b3; border-bottom: 1px solid #eee; padding-bottom: 0.3em; }");
+ builder.AppendLine("table { border-collapse: collapse; width: 100%; margin-bottom: 2em; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }");
+ builder.AppendLine("th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; }");
+ builder.AppendLine("th { background-color: #f8f9fa; font-weight: 600; }");
+ builder.AppendLine("tr:hover { background-color: #f5f5f5; }");
+ builder.AppendLine(".meta { background: #f8f9fa; padding: 15px; border-radius: 5px; margin-bottom: 2em; border-left: 4px solid #0056b3; }");
+ builder.AppendLine("</style></head><body>");
+
+ builder.AppendLine($"<h1>Agent Run Report: {HtmlEncode(network.Name)}</h1>");
+ if (!string.IsNullOrWhiteSpace(network.Description))
+ {
+ builder.AppendLine($"<p>{HtmlEncode(network.Description)}</p>");
+ }
+ builder.AppendLine($"<p class=\"meta\"><strong>Agent Mode:</strong> {HtmlEncode(FormatAgentMode(network.AgentMode))}</p>");
+
+ builder.AppendLine("<h2>Agent Actions</h2>");
+ builder.AppendLine(BuildHtmlTable(
+ ["Simulation Tick", "Agent", "Action", "Target", "Decision Summary", "Outcome", "Utility", "Factors", "Alternatives", "State Metrics"],
+ BuildAgentActionRows(network, network.AgentActionLogs)));
+
+ builder.AppendLine("</body></html>");
+ return builder.ToString();
+ }
+
+ private static string BuildAgentCsvReport(NetworkModel network, SimulationActorRunResult runResult)
+ {
+ var builder = new StringBuilder();
+ builder.AppendLine(CsvBrandHeader);
+ builder.AppendLine(BuildCsvRow(["Report Type", "Agent Run"]));
+ builder.AppendLine(BuildCsvRow(["Network Name", network.Name]));
+ builder.AppendLine(BuildCsvRow(["Agent Mode", FormatAgentMode(network.AgentMode)]));
+ builder.AppendLine();
+
+ builder.AppendLine("Agent Actions");
+ builder.AppendLine(BuildCsvRow(["Simulation Tick", "Agent", "Action", "Target", "Decision Summary", "Outcome", "Utility", "Factors", "Alternatives", "State Metrics"]));
+ foreach (var row in BuildAgentActionRows(network, network.AgentActionLogs))
+ {
+ builder.AppendLine(BuildCsvRow(row));
+ }
+
+ return builder.ToString();
+ }
+
+ private static string BuildAgentJsonReport(NetworkModel network, SimulationActorRunResult runResult)
+ {
+ var payload = new
+ {
+ reportType = "AgentRun",
+ network = new { network.Name, network.Description, nodes = network.Nodes.Count, edges = network.Edges.Count, agentMode = FormatAgentMode(network.AgentMode), limitMeetingNodeDemandBySellLocalPermission = network.LimitMeetingNodeDemandBySellLocalPermission },
+ agentActions = network.AgentActionLogs
+ .Select(entry => new
+ {
+ tick = entry.Tick,
+ agent = FormatAgentReference(network, entry),
+ action = entry.ActionKind,
+ target = FormatActionTarget(entry),
+ summary = entry.DecisionSummary,
+ outcome = entry.Outcome,
+ utility = entry.EvaluatedUtility,
+ stateMetrics = entry.StateMetrics
+ })
+ };
+ return System.Text.Json.JsonSerializer.Serialize(payload, new System.Text.Json.JsonSerializerOptions { WriteIndented = true });
+ }
+
private static string BuildTimelineJsonReport(
NetworkModel network,
IReadOnlyList<TemporalNetworkSimulationEngine.TemporalSimulationStepResult> periodResults)