Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/Services/ReportGeneratorService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using GeneralUpdate.Tools.Models;

namespace GeneralUpdate.Tools.Services;

/// <summary>
/// Generates simulation_report.md after a simulation run.
/// </summary>
public class ReportGeneratorService
{
public async Task<string> GenerateAsync(
SimulateConfigModel config,
SimulationResult result,
string outputDir)
{
var sb = new StringBuilder();

sb.AppendLine("# Update Simulation Report");
sb.AppendLine();
sb.AppendLine("## Configuration");
sb.AppendLine();
sb.AppendLine("| Field | Value |");
sb.AppendLine("|-------|-------|");
sb.AppendLine($"| Patch | {EscapeMd(config.PatchFilePath)} |");
sb.AppendLine($"| App Directory | {EscapeMd(config.AppDirectory)} |");
sb.AppendLine($"| Platform | {config.Platform} |");
sb.AppendLine($"| AppType | {config.AppType} |");
sb.AppendLine($"| Version | {config.CurrentVersion} → {config.TargetVersion} |");
sb.AppendLine($"| Server Port | {config.ServerPort} |");
sb.AppendLine($"| Simulation Time | {DateTime.Now:yyyy-MM-dd HH:mm:ss} |");
Comment on lines +25 to +33
sb.AppendLine();

sb.AppendLine("## Result");
sb.AppendLine();
sb.AppendLine($"**{(result.Success ? "✅ PASS" : "❌ FAIL")}** — {result.Elapsed.TotalSeconds:F1}s");
if (!string.IsNullOrEmpty(result.ErrorMessage))
sb.AppendLine($"\nError: `{result.ErrorMessage}`");
sb.AppendLine();
Comment on lines +38 to +41

if (result.Notes.Count > 0)
{
sb.AppendLine("## Notes");
sb.AppendLine();
foreach (var note in result.Notes)
sb.AppendLine($"- {note}");
sb.AppendLine();
}

sb.AppendLine("## Timeline");
sb.AppendLine();
sb.AppendLine("```");
sb.Append(result.FullLog);
sb.AppendLine("```");

var reportPath = Path.Combine(outputDir, "simulation_report.md");
await File.WriteAllTextAsync(reportPath, sb.ToString(), Encoding.UTF8);
return reportPath;
}

Comment on lines +54 to +62
private static string EscapeMd(string s) => s.Replace(@"\", @"\\").Replace("|", "\\|");
}
5 changes: 3 additions & 2 deletions src/ViewModels/SimulateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class SimulateViewModel : ViewModelBase
{
private readonly LocalizationService _loc = LocalizationService.Instance;
private readonly SimulationService _sim = new();
private readonly ReportGeneratorService _report = new();

public SimulateConfigModel Config { get; } = new();

Expand Down Expand Up @@ -85,8 +86,8 @@ async Task StartSimulation()
L($" Note: {note}");

// Generate report
var reportPath = Path.Combine(Config.OutputDirectory, "simulation_report.md");
// report generation will be in next PR
var reportPath = await _report.GenerateAsync(Config, result, Config.OutputDirectory);
L($"Report: {reportPath}");
}
else
{
Expand Down