139 lines
4.7 KiB
C#
139 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
public sealed class DisasterWarAuditResult
|
|
{
|
|
public bool Passed;
|
|
public string Detail = "";
|
|
public int DisasterTotal;
|
|
public int WarTypeTotal;
|
|
public int MissingDisaster;
|
|
public int OrphanDisaster;
|
|
public int MissingWarType;
|
|
public int OrphanWarType;
|
|
}
|
|
|
|
/// <summary>Live disasters + war_types library coverage audit.</summary>
|
|
public static class DisasterWarHarness
|
|
{
|
|
public static DisasterWarAuditResult RunAudit(string outputDirectory)
|
|
{
|
|
List<string> disasters = ActivityAssetCatalog.EnumerateLiveDisasterIds();
|
|
List<string> warTypes = ActivityAssetCatalog.EnumerateLiveWarTypeIds();
|
|
|
|
var authoredDisasters = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
foreach (string id in EventCatalog.Disaster.AuthoredIds)
|
|
{
|
|
authoredDisasters.Add(id);
|
|
}
|
|
|
|
var authoredWars = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
foreach (string id in EventCatalog.WarType.AuthoredIds)
|
|
{
|
|
authoredWars.Add(id);
|
|
}
|
|
|
|
int missingDisaster = 0;
|
|
int orphanDisaster = 0;
|
|
int missingWarType = 0;
|
|
int orphanWarType = 0;
|
|
var tsv = new StringBuilder();
|
|
tsv.AppendLine("kind\tid\tauthored\tevent_strength\tworld_log_id\tnotes");
|
|
|
|
var liveDisasters = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
for (int i = 0; i < disasters.Count; i++)
|
|
{
|
|
string id = disasters[i];
|
|
liveDisasters.Add(id);
|
|
DisasterInterestEntry entry = EventCatalog.Disaster.GetOrFallback(id);
|
|
bool has = EventCatalog.Disaster.HasAuthored(id) && !entry.IsFallback;
|
|
if (!has)
|
|
{
|
|
missingDisaster++;
|
|
}
|
|
|
|
tsv.Append("disaster\t").Append(id).Append('\t')
|
|
.Append(has ? "1" : "0").Append('\t')
|
|
.Append(entry.EventStrength.ToString("0.#")).Append('\t')
|
|
.Append(entry.WorldLogId ?? "").Append('\t')
|
|
.Append(has ? "ok" : "missing_authored").AppendLine();
|
|
}
|
|
|
|
foreach (string id in authoredDisasters)
|
|
{
|
|
if (!liveDisasters.Contains(id))
|
|
{
|
|
orphanDisaster++;
|
|
tsv.Append("disaster\t").Append(id).Append("\t1\t0\t\torphan_authored").AppendLine();
|
|
}
|
|
}
|
|
|
|
var liveWars = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
for (int i = 0; i < warTypes.Count; i++)
|
|
{
|
|
string id = warTypes[i];
|
|
liveWars.Add(id);
|
|
WarTypeInterestEntry entry = EventCatalog.WarType.GetOrFallback(id);
|
|
bool has = EventCatalog.WarType.HasAuthored(id) && !entry.IsFallback;
|
|
if (!has)
|
|
{
|
|
missingWarType++;
|
|
}
|
|
|
|
tsv.Append("war_type\t").Append(id).Append('\t')
|
|
.Append(has ? "1" : "0").Append('\t')
|
|
.Append(entry.EventStrength.ToString("0.#")).Append('\t')
|
|
.Append('\t')
|
|
.Append(has ? "ok" : "missing_authored").AppendLine();
|
|
}
|
|
|
|
foreach (string id in authoredWars)
|
|
{
|
|
if (!liveWars.Contains(id))
|
|
{
|
|
orphanWarType++;
|
|
tsv.Append("war_type\t").Append(id).Append("\t1\t0\t\torphan_authored").AppendLine();
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(outputDirectory))
|
|
{
|
|
Directory.CreateDirectory(outputDirectory);
|
|
File.WriteAllText(
|
|
Path.Combine(outputDirectory, "disaster-war-audit.tsv"),
|
|
tsv.ToString());
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// ignore
|
|
}
|
|
|
|
bool passed = disasters.Count > 0
|
|
&& warTypes.Count > 0
|
|
&& missingDisaster == 0
|
|
&& orphanDisaster == 0
|
|
&& missingWarType == 0
|
|
&& orphanWarType == 0;
|
|
|
|
return new DisasterWarAuditResult
|
|
{
|
|
Passed = passed,
|
|
DisasterTotal = disasters.Count,
|
|
WarTypeTotal = warTypes.Count,
|
|
MissingDisaster = missingDisaster,
|
|
OrphanDisaster = orphanDisaster,
|
|
MissingWarType = missingWarType,
|
|
OrphanWarType = orphanWarType,
|
|
Detail =
|
|
$"disasters={disasters.Count} missingDisaster={missingDisaster} orphanDisaster={orphanDisaster} "
|
|
+ $"war_types={warTypes.Count} missingWarType={missingWarType} orphanWarType={orphanWarType}"
|
|
};
|
|
}
|
|
}
|