PlotDirector/PlotLine/Services/Investigations/EditorialConclusion.cs

21 lines
1.7 KiB
C#

using PlotLine.Models.Investigations;
namespace PlotLine.Services.Investigations;
public sealed record EditorialConclusion(string Kind,string Title,string Explanation,string Qualification,IReadOnlyList<EditorialResult> Findings,string Action)
{
public static EditorialConclusion From(Catalogue c,Evaluation e)
{
var ed=c.Editorial!;
var positive=e.Hypotheses.Where(h=>h.Support+h.Opposition>=2).ToArray();
var supported=e.Hypotheses.Where(h=>h.Supported).ToArray();
var conflicts=e.Hypotheses.Where(h=>h.Conflicts.Length>0).ToArray();
var mixed=e.Hypotheses.Where(h=>h.Support>=2&&h.Opposition<=-2).ToArray();
var kind=e.Recommendations.Count>0?"supported":supported.Any(h=>!h.Eligible)&&!supported.Any(h=>h.Eligible)?"unavailable":conflicts.Length>0?"conflicting":positive.Length>1&&positive[1].Score>=positive[0].Score-2?"ambiguous":positive.Length>0?"tentative":mixed.Length>0?"ambiguous":e.Evidence.Any(v=>v.Raw<=-2&&!v.Uncertain)?"healthy":"uncertain";
var relevant=(kind=="supported"?e.Hypotheses.Where(h=>e.Recommendations.Contains(h.Id)):kind=="unavailable"?supported:kind=="conflicting"?conflicts:positive.Length>0?positive.AsEnumerable():mixed).Take(2).ToArray();
var findings=relevant.Select(h=>ed.Results.Single(r=>r.Hypothesis==h.Id)).Where(r=>r.States.Contains(kind)).ToArray();
var state=ed.States[kind];
var title=(kind is "supported" or "tentative")&&findings.Length>0?findings[0].Title:state.Title;
var action=findings.Length>0?findings[0].Action:kind=="healthy"?state.Action:ed.Results.Single(r=>c.Hypotheses.Single(h=>h.Id==r.Hypothesis).Capabilities.Count==0).Action;
return new(kind,title,state.Explanation,state.Qualification,findings,action);
}
}