2024-08-07 09:18:40 +00:00
|
|
|
|
using CodexPlugin;
|
|
|
|
|
using CodexPlugin.OverwatchSupport;
|
|
|
|
|
using OverwatchTranscript;
|
|
|
|
|
|
|
|
|
|
namespace TranscriptAnalysis.Receivers
|
|
|
|
|
{
|
|
|
|
|
public class NodesDegree : BaseReceiver<OverwatchCodexEvent>
|
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
public class Dial
|
|
|
|
|
{
|
|
|
|
|
public Dial(Node peer, Node target)
|
|
|
|
|
{
|
|
|
|
|
Id = GetLineId(peer.Id, target.Id);
|
|
|
|
|
InitiatedBy.Add(peer);
|
|
|
|
|
Peer = peer;
|
|
|
|
|
Target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Id { get; }
|
|
|
|
|
public int RedialCount => InitiatedBy.Count - 1;
|
|
|
|
|
public List<Node> InitiatedBy { get; } = new List<Node>();
|
|
|
|
|
public Node Peer { get; }
|
|
|
|
|
public Node Target { get; }
|
|
|
|
|
|
|
|
|
|
private string GetLineId(string a, string b)
|
|
|
|
|
{
|
|
|
|
|
if (string.Compare(a, b) > 0)
|
|
|
|
|
{
|
|
|
|
|
return a + b;
|
|
|
|
|
}
|
|
|
|
|
return b + a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Node
|
|
|
|
|
{
|
|
|
|
|
public Node(string peerId)
|
|
|
|
|
{
|
|
|
|
|
Id = peerId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Id { get; }
|
|
|
|
|
public List<Dial> Dials { get; } = new List<Dial>();
|
|
|
|
|
public int Degree => Dials.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<string, Node> dialingNodes = new Dictionary<string, Node>();
|
|
|
|
|
private readonly Dictionary<string, Dial> dials = new Dictionary<string, Dial>();
|
2024-08-07 09:18:40 +00:00
|
|
|
|
|
|
|
|
|
public override string Name => "NodesDegree";
|
|
|
|
|
|
|
|
|
|
public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
|
|
|
|
|
{
|
|
|
|
|
if (@event.Payload.DialSuccessful != null)
|
|
|
|
|
{
|
2024-08-14 12:13:00 +00:00
|
|
|
|
var peerId = GetPeerId(@event.Payload.NodeIdentity);
|
|
|
|
|
AddDial(peerId, @event.Payload.DialSuccessful.TargetPeerId);
|
2024-08-07 09:18:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 07:39:20 +00:00
|
|
|
|
public override void Finish()
|
2024-08-07 09:18:40 +00:00
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
var numNodes = dialingNodes.Count;
|
|
|
|
|
var redialOccurances = new OccuranceMap();
|
|
|
|
|
foreach (var dial in dials.Values)
|
2024-08-07 09:18:40 +00:00
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
redialOccurances.Add(dial.RedialCount);
|
|
|
|
|
}
|
|
|
|
|
var degreeOccurances = new OccuranceMap();
|
|
|
|
|
foreach (var node in dialingNodes.Values)
|
|
|
|
|
{
|
|
|
|
|
degreeOccurances.Add(node.Degree);
|
2024-08-07 09:18:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 07:39:20 +00:00
|
|
|
|
Log($"Dialing nodes: {numNodes}");
|
|
|
|
|
Log("Redials:");
|
|
|
|
|
redialOccurances.PrintContinous((i, count) =>
|
2024-08-07 09:18:40 +00:00
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
Log($"{i} redials = {count}x");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
float tot = numNodes;
|
|
|
|
|
degreeOccurances.Print((i, count) =>
|
|
|
|
|
{
|
|
|
|
|
float n = count;
|
|
|
|
|
float p = 100.0f * (n / tot);
|
|
|
|
|
Log($"Degree: {i} = {count}x ({p}%)");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddDial(string peerId, string targetPeerId)
|
|
|
|
|
{
|
|
|
|
|
peerId = CodexUtils.ToShortId(peerId);
|
|
|
|
|
targetPeerId = CodexUtils.ToShortId(targetPeerId);
|
|
|
|
|
|
|
|
|
|
var peer = GetNode(peerId);
|
|
|
|
|
var target = GetNode(targetPeerId); ;
|
|
|
|
|
|
|
|
|
|
var dial = new Dial(peer, target);
|
|
|
|
|
|
|
|
|
|
if (dials.ContainsKey(dial.Id))
|
|
|
|
|
{
|
|
|
|
|
var d = dials[dial.Id];
|
|
|
|
|
d.InitiatedBy.Add(peer);
|
|
|
|
|
peer.Dials.Add(d);
|
|
|
|
|
target.Dials.Add(d);
|
2024-08-07 09:18:40 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
dials.Add(dial.Id, dial);
|
|
|
|
|
peer.Dials.Add(dial);
|
|
|
|
|
target.Dials.Add(dial);
|
2024-08-07 09:18:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 07:39:20 +00:00
|
|
|
|
private Node GetNode(string id)
|
2024-08-07 09:18:40 +00:00
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
if (!dialingNodes.ContainsKey(id))
|
|
|
|
|
{
|
|
|
|
|
dialingNodes.Add(id, new Node(id));
|
|
|
|
|
}
|
|
|
|
|
return dialingNodes[id];
|
2024-08-07 09:18:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|