2
0
mirror of synced 2025-02-13 08:56:30 +00:00

Updates emoji maps

This commit is contained in:
Ben 2024-10-10 14:03:42 +02:00
parent 3ed91d7310
commit e0cbf8c84d
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
4 changed files with 111 additions and 50 deletions

View File

@ -18,6 +18,7 @@
<ProjectReference Include="..\..\Framework\OverwatchTranscript\OverwatchTranscript.csproj" /> <ProjectReference Include="..\..\Framework\OverwatchTranscript\OverwatchTranscript.csproj" />
<ProjectReference Include="..\..\Framework\Utils\Utils.csproj" /> <ProjectReference Include="..\..\Framework\Utils\Utils.csproj" />
<ProjectReference Include="..\..\ProjectPlugins\CodexContractsPlugin\CodexContractsPlugin.csproj" /> <ProjectReference Include="..\..\ProjectPlugins\CodexContractsPlugin\CodexContractsPlugin.csproj" />
<ProjectReference Include="..\..\Tools\TestNetRewarder\TestNetRewarder.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,28 @@
using NUnit.Framework;
using System.Text;
using TestNetRewarder;
namespace FrameworkTests.Utils
{
[TestFixture]
public class EmojiMapsTests
{
private readonly Random random = new Random();
private readonly EmojiMaps maps = new EmojiMaps();
[Test]
public void GeneratesConsistentStrings(
[Values(1, 5, 10, 20)] int inputLength,
[Values(1, 2, 3, 5)] int outLength)
{
var buffer = new byte[inputLength];
random.NextBytes(buffer);
var input = Encoding.ASCII.GetString(buffer);
var out1 = maps.StringToEmojis(input, outLength);
var out2 = maps.StringToEmojis(input, outLength);
Assert.That(out1, Is.EqualTo(out2));
}
}
}

View File

@ -4,50 +4,80 @@ namespace TestNetRewarder
{ {
public class EmojiMaps public class EmojiMaps
{ {
private readonly string[] create = new[] private readonly string[] emojis = new[]
{ {
// yellow
"😀",
"🌻",
"🍋",
"🧀",
"🌔",
"⭐",
"⚡",
"🏆",
// red
"💘",
"🦞",
"🌹",
"🍒",
"🫖", // teapot
"⛩",
"🚗",
"🔥",
// green
"🐊",
"🦎",
"🐛",
"🌳",
"🍀",
"🧩",
"🔋",
"♻",
// blue
"💙",
"🐳",
"🐟", "🐟",
"🔵", "🍉",
"🟦" // blue square "🧊",
}; "🌐",
private readonly string[] positive = new[] "⚓",
{ "🌀",
"🟢", // green circle
"🟩" // green square
};
private readonly string[] surprise = new[]
{
"🧐",
"🤨",
"🟡", // yellow circle
"🟨" // yellow square
};
private readonly string[] negative = new[]
{
"⛔",
"🚫",
"🔴",
"🟥" // red square
}; };
public string GetCreate() public string NewRequest => "🐟";
public string Started => "🦈";
public string SlotFilled => "🟢";
public string SlotFreed => "⭕";
public string SlotReservationsFull => "☑️";
public string Finished => "✅";
public string Cancelled => "🚫";
public string Failed => "❌";
public string StringToEmojis(string input, int outLength)
{ {
return RandomUtils.GetOneRandom(create); if (outLength < 1) outLength = 1;
var result = "";
var segmentLength = input.Length / outLength;
if (segmentLength < 1)
{
return StringToEmojis(input + input, outLength);
}
for (var i = 0; i < outLength; i++)
{
var segment = input.Substring(i * segmentLength, segmentLength);
result += SelectOne(segment);
}
return result;
} }
public string GetPositive() private string SelectOne(string segment)
{ {
return RandomUtils.GetOneRandom(positive); var index = 0;
} foreach (var c in segment) index += Convert.ToInt32(c);
index = index % emojis.Length;
public string GetSurprise() return emojis[index];
{
return RandomUtils.GetOneRandom(surprise);
}
public string GetNegative()
{
return RandomUtils.GetOneRandom(negative);
} }
} }
} }

View File

@ -28,7 +28,7 @@ namespace TestNetRewarder
public void OnNewRequest(RequestEvent requestEvent) public void OnNewRequest(RequestEvent requestEvent)
{ {
var request = requestEvent.Request; var request = requestEvent.Request;
AddRequestBlock(requestEvent, $"{C} New Request", AddRequestBlock(requestEvent, $"{emojiMaps.NewRequest} New Request",
$"Client: {request.Client}", $"Client: {request.Client}",
$"Content: {request.Request.Content.Cid}", $"Content: {request.Request.Content.Cid}",
$"Duration: {BigIntToDuration(request.Request.Ask.Duration)}", $"Duration: {BigIntToDuration(request.Request.Ask.Duration)}",
@ -43,27 +43,27 @@ namespace TestNetRewarder
public void OnRequestCancelled(RequestEvent requestEvent) public void OnRequestCancelled(RequestEvent requestEvent)
{ {
AddRequestBlock(requestEvent, $"{N} Cancelled"); AddRequestBlock(requestEvent, $"{emojiMaps.Cancelled} Cancelled");
} }
public void OnRequestFailed(RequestEvent requestEvent) public void OnRequestFailed(RequestEvent requestEvent)
{ {
AddRequestBlock(requestEvent, $"{N} Failed"); AddRequestBlock(requestEvent, $"{emojiMaps.Failed} Failed");
} }
public void OnRequestFinished(RequestEvent requestEvent) public void OnRequestFinished(RequestEvent requestEvent)
{ {
AddRequestBlock(requestEvent, $"{P} Finished"); AddRequestBlock(requestEvent, $"{emojiMaps.Finished} Finished");
} }
public void OnRequestFulfilled(RequestEvent requestEvent) public void OnRequestFulfilled(RequestEvent requestEvent)
{ {
AddRequestBlock(requestEvent, $"{P} Started"); AddRequestBlock(requestEvent, $"{emojiMaps.Started} Started");
} }
public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex) public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex)
{ {
AddRequestBlock(requestEvent, $"{P} Slot Filled", AddRequestBlock(requestEvent, $"{emojiMaps.SlotFilled} Slot Filled",
$"Host: {host}", $"Host: {host}",
$"Slot Index: {slotIndex}" $"Slot Index: {slotIndex}"
); );
@ -71,14 +71,14 @@ namespace TestNetRewarder
public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex) public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
{ {
AddRequestBlock(requestEvent, $"{S} Slot Freed", AddRequestBlock(requestEvent, $"{emojiMaps.SlotFreed} Slot Freed",
$"Slot Index: {slotIndex}" $"Slot Index: {slotIndex}"
); );
} }
public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex) public void OnSlotReservationsFull(RequestEvent requestEvent, BigInteger slotIndex)
{ {
AddRequestBlock(requestEvent, $"{P} Slot Reservations Full", AddRequestBlock(requestEvent, $"{emojiMaps.SlotReservationsFull} Slot Reservations Full",
$"Slot Index: {slotIndex}" $"Slot Index: {slotIndex}"
); );
} }
@ -86,7 +86,7 @@ namespace TestNetRewarder
private void AddRequestBlock(RequestEvent requestEvent, string eventName, params string[] content) private void AddRequestBlock(RequestEvent requestEvent, string eventName, params string[] content)
{ {
var blockNumber = $"[{requestEvent.Block.BlockNumber} {FormatDateTime(requestEvent.Block.Utc)}]"; var blockNumber = $"[{requestEvent.Block.BlockNumber} {FormatDateTime(requestEvent.Block.Utc)}]";
var title = $"{blockNumber} **{eventName}** `{requestEvent.Request.Request.Id}`"; var title = $"{blockNumber} **{eventName}** {FormatRequestId(requestEvent)}";
AddBlock(title, content); AddBlock(title, content);
} }
@ -121,6 +121,13 @@ namespace TestNetRewarder
return utc.ToString("yyyy-MM-dd HH:mm:ss UTC", CultureInfo.InvariantCulture); return utc.ToString("yyyy-MM-dd HH:mm:ss UTC", CultureInfo.InvariantCulture);
} }
private string FormatRequestId(RequestEvent requestEvent)
{
return
$"({emojiMaps.StringToEmojis(requestEvent.Request.Request.Id, 3)})" +
$"`{requestEvent.Request.Request.Id}`";
}
private string BigIntToDuration(BigInteger big) private string BigIntToDuration(BigInteger big)
{ {
var span = TimeSpan.FromSeconds((int)big); var span = TimeSpan.FromSeconds((int)big);
@ -138,10 +145,5 @@ namespace TestNetRewarder
var tt = new TestToken(big); var tt = new TestToken(big);
return tt.ToString(); return tt.ToString();
} }
private string C => emojiMaps.GetCreate();
private string P => emojiMaps.GetPositive();
private string S => emojiMaps.GetSurprise();
private string N => emojiMaps.GetNegative();
} }
} }