refactor: update for testing

This commit is contained in:
Anna 2020-12-25 20:24:43 -05:00
parent b32b47397d
commit 221877cbe5
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
9 changed files with 51 additions and 39 deletions

View File

@ -11,6 +11,10 @@ namespace NoSoliciting.CursedWorkaround {
private DataViewSchema Schema { get; set; } = null!;
private PredictionEngine<MessageData, MessagePrediction> PredictionEngine { get; set; } = null!;
public override object? InitializeLifetimeService() {
return null;
}
public void Initialise(byte[] data) {
this.Context = new MLContext();
using var stream = new MemoryStream(data);

View File

@ -8,6 +8,7 @@ namespace NoSoliciting.CursedWorkaround {
private static readonly Regex WardRegex = new Regex(@"w.{0,2}\d", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex PlotRegex = new Regex(@"p.{0,2}\d", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly string[] PlotWords = {
"plot",
"apartment",
@ -17,12 +18,14 @@ namespace NoSoliciting.CursedWorkaround {
private static readonly Regex NumbersRegex = new Regex(@"\d{1,2}.{0,2}\d{1,2}", RegexOptions.Compiled);
private static readonly string[] TradeWords = {
"B>",
"S>",
"B> ",
"S> ",
"buy",
"sell",
};
private static readonly Regex SketchUrlRegex = new Regex(@"\.com-\w+\.\w+", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public string? Category { get; }
public uint Channel { get; }
@ -41,6 +44,8 @@ namespace NoSoliciting.CursedWorkaround {
public bool ContainsTradeWords => TradeWords.Any(word => this.Message.ContainsIgnoreCase(word));
public bool ContainsSketchUrl => SketchUrlRegex.IsMatch(this.Message);
public MessageData(uint channel, string message) {
this.Channel = channel;
this.Message = message;

View File

@ -18,6 +18,7 @@ namespace NoSoliciting.Tests.DefinitionsTests.Chat {
new TestMessage(ChatType.Shout, "【 PVP●K.℃ O M 、● = BAN 】5分納品ジル480-500HQセット希望の園エデン (野蛮)全部強奪!安い&安全保障【コード714、5OFF】!!!-pdonb"),
new TestMessage(ChatType.Say, "Buy Cheap gils on www,G/a/m/e/r/E/a/s/y.c0m, 8% code,FFXIV2020, 15 mins deliveryvnm15"),
new TestMessage(ChatType.TellIncoming, "You're Invited To Our Clan's Final Giveaway Of 850M Gil Starting In 45Mins! Visit Our Discord For The Location Of The Giveaway: https://discord.gg/VtqY9tFyUb"),
new TestMessage(ChatType.TellIncoming, "Quitting FFXIV, You're Invited To The Final Giveaway Of 850M Gil! Please Read The Rules And Location Of The Giveaway On The FFXIV Forum Post: https://www.squarenix.com-iy.ru/ffxiv/threads/6842918"),
});
//public static object[][] DataNegatives => DefUtils.DataFromMessages(new TestMessage[] {

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ILRepacker" AfterTargets="Build" Condition="'$(Configuration)' == 'RELEASE'">
<ItemGroup>
<!-- Include="$(OutputPath)\NoSoliciting.dll;$(OutputPath)\System.*.dll;$(OutputPath)\Microsoft.*.dll;$(OutputPath)\YamlDotNet.dll;$(OutputPath)\Newtonsoft.Json.dll" -->
<InputAssemblies
Include="$(OutputPath)\NoSoliciting.dll;$(OutputPath)\NoSoliciting.Classifier.dll;$(OutputPath)\YamlDotNet.dll;$(OutputPath)\Newtonsoft.Json.dll"
Exclude="$(OutputPath)\*Native.dll"/>
</ItemGroup>
<ILRepack
Parallel="true"
Internalize="true"
InputAssemblies="@(InputAssemblies)"
TargetKind="Dll"
TargetPlatformVersion="v4"
LibraryPath="$(OutputPath)"
OutputFile="$(OutputPath)\$(AssemblyName).dll"/>
</Target>
</Project>

View File

@ -6,6 +6,8 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Data;
using Lumina.Excel.GeneratedSheets;
namespace NoSoliciting {
public class Message {
@ -162,6 +164,22 @@ namespace NoSoliciting {
_ => (byte) type,
};
public static string Name(this ChatType type, DataManager data) {
switch (type) {
case ChatType.None:
return "Party Finder";
case ChatType.TellIncoming:
return "Tell (Incoming)";
case ChatType.TellOutgoing:
return "Tell (Outgoing)";
case ChatType.CrossParty:
return "Party (Cross-world)";
}
var lf = data.GetExcelSheet<LogFilter>().FirstOrDefault(lf => lf.LogKind == type.LogKind());
return lf?.Name?.ToString() ?? type.ToString();
}
public static ChatType FromCode(ushort code) {
return (ChatType) (code & Clear7);
}

View File

@ -15,7 +15,11 @@ namespace NoSoliciting.Ml {
private const string ManifestName = "manifest.yaml";
private const string ModelName = "model.zip";
#if DEBUG
private const string Url = "https://annaclemens.io/assets/nosol/ml/manifest.yaml";
#else
private const string Url = "http://localhost:8000/manifest.yaml";
#endif
public uint Version { get; }
private IClassifier Classifier { get; }

View File

@ -37,7 +37,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="YamlDotNet" Version="9.1.0" />
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">

View File

@ -47,6 +47,7 @@ namespace NoSoliciting {
ConfigurationFile = $"{LibraryName}.dll.config",
ApplicationBase = Path.GetDirectoryName(this.AssemblyLocation),
});
this.InnerDomain.InitializeLifetimeService();
this.Classifier = (IClassifier) this.InnerDomain.CreateInstanceAndUnwrap(LibraryName, $"{LibraryName}.CursedWorkaround");
string path = Environment.GetEnvironmentVariable("PATH")!;
@ -110,6 +111,11 @@ namespace NoSoliciting {
}
private void OnCommand(string command, string args) {
if (args == "report") {
this.Ui.OpenReporting();
return;
}
this.Ui.OpenSettings(null, null);
}

View File

@ -17,7 +17,6 @@ using NoSoliciting.Ml;
namespace NoSoliciting {
public class PluginUi {
private Plugin Plugin { get; }
private bool _resizeWindow;
private ReportStatus LastReportStatus { get; set; } = ReportStatus.None;
private bool _showSettings;
@ -42,6 +41,10 @@ namespace NoSoliciting {
this.ShowSettings = true;
}
public void OpenReporting() {
this.ShowReporting = true;
}
public void Draw() {
if (this.ShowSettings) {
this.DrawSettings();
@ -53,13 +56,6 @@ namespace NoSoliciting {
}
private void DrawSettings() {
if (this._resizeWindow) {
this._resizeWindow = false;
ImGui.SetNextWindowSize(new Vector2(this.Plugin.Config.AdvancedMode ? 650 : 0, 0));
} else {
ImGui.SetNextWindowSize(new Vector2(0, 0), ImGuiCond.FirstUseEver);
}
if (!ImGui.Begin($"{this.Plugin.Name} settings", ref this._showSettings)) {
return;
}
@ -260,6 +256,11 @@ namespace NoSoliciting {
return;
}
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(255f, 204f, 0f, 1f));
ImGui.TextUnformatted("Do not change advanced settings unless you know what you are doing.");
ImGui.TextUnformatted("The machine learning model was trained with certain channels in mind.");
ImGui.PopStyleColor();
foreach (var category in (MessageCategory[]) Enum.GetValues(typeof(MessageCategory))) {
if (category == MessageCategory.Normal) {
continue;
@ -276,13 +277,7 @@ namespace NoSoliciting {
var types = this.Plugin.Config.MlFilters[category];
void DrawTypes(ChatType type) {
string name;
if (type == ChatType.None) {
name = "Party Finder";
} else {
var lf = this.Plugin.Interface.Data.GetExcelSheet<LogFilter>().FirstOrDefault(lf => lf.LogKind == type.LogKind());
name = lf?.Name?.ToString() ?? type.ToString();
}
var name = type.Name(this.Plugin.Interface.Data);
var check = types.Contains(type);
if (!ImGui.Checkbox(name, ref check)) {
@ -451,7 +446,7 @@ namespace NoSoliciting {
.Select(payload => payload.Text)
.FirstOrDefault() ?? "";
if (AddColumn(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.ChatType.ToString(), message.FilterReason ?? "", sender, message.Content.TextValue)) {
if (AddColumn(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.ChatType.Name(this.Plugin.Interface.Data), message.FilterReason ?? "", sender, message.Content.TextValue)) {
ImGui.OpenPopup($"###modal-message-{message.Id}");
}