Skip to content

Commit 1859994

Browse files
committed
nice csv outputs
1 parent b72b4a8 commit 1859994

File tree

8 files changed

+120
-5
lines changed

8 files changed

+120
-5
lines changed

ProjectPlugins/CodexPlugin/ApiChecker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace CodexPlugin
1010
public class ApiChecker
1111
{
1212
// <INSERT-OPENAPI-YAML-HASH>
13-
private const string OpenApiYamlHash = "AC-19-7F-3A-88-07-CB-43-53-60-4F-21-3D-A6-B1-53-47-65-07-3B-91-C6-88-B9-76-B2-7E-33-6A-1C-69-F4";
13+
private const string OpenApiYamlHash = "2E-7C-A2-F3-67-D9-F2-A6-4E-D5-FF-A2-EC-65-ED-59-CE-89-A8-92-57-5E-CF-40-9A-83-49-0B-49-42-5D-EC";
1414
private const string OpenApiFilePath = "/codex/openapi.yaml";
1515
private const string DisableEnvironmentVariable = "CODEXPLUGIN_DISABLE_APICHECK";
1616

ProjectPlugins/CodexPlugin/openapi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ paths:
726726
"503":
727727
description: Persistence is not enabled
728728

729-
"/node/spr":
729+
"/spr":
730730
get:
731731
summary: "Get Node's SPR"
732732
operationId: getSPR
@@ -744,7 +744,7 @@ paths:
744744
"503":
745745
description: Node SPR not ready, try again later
746746

747-
"/node/peerid":
747+
"/peerid":
748748
get:
749749
summary: "Get Node's PeerID"
750750
operationId: getPeerId

Tools/CsvCombiner/CsvCombiner.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\Framework\Logging\Logging.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

Tools/CsvCombiner/Program.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Logging;
2+
3+
public class Program
4+
{
5+
public static void Main(string[] args)
6+
{
7+
args = ["d:\\CodexTestLogs\\BlockExchange\\experiment2-fetchbatched"];
8+
var p = new Program(args[0]);
9+
p.Run();
10+
}
11+
12+
private static readonly ILog log = new ConsoleLog();
13+
private string path;
14+
15+
private readonly Dictionary<string, List<string>> combine = new Dictionary<string, List<string>>();
16+
17+
public Program(string path)
18+
{
19+
this.path = path;
20+
}
21+
22+
private void Run()
23+
{
24+
Log("Starting in " + path);
25+
26+
var files = Directory.GetFiles(path)
27+
.Where(f => f.ToLowerInvariant().EndsWith(".csv")).ToArray();
28+
29+
foreach (var file in files)
30+
{
31+
AddToMap(file);
32+
}
33+
34+
var i = 0;
35+
foreach (var pair in combine)
36+
{
37+
var list = pair.Value;
38+
list.Insert(0, pair.Key);
39+
40+
File.WriteAllLines(Path.Combine(path, "combine_" + i + ".csv"), list.ToArray());
41+
i++;
42+
}
43+
44+
Log("done");
45+
}
46+
47+
private void AddToMap(string file)
48+
{
49+
var lines = File.ReadAllLines(file);
50+
if (lines.Length > 1)
51+
{
52+
var header = lines[0];
53+
var list = GetList(header);
54+
list.AddRange(lines.Skip(1));
55+
}
56+
}
57+
58+
private List<string> GetList(string header)
59+
{
60+
if (!combine.ContainsKey(header))
61+
{
62+
combine.Add(header, new List<string>());
63+
}
64+
return combine[header];
65+
}
66+
67+
private void Log(string msg)
68+
{
69+
log.Log(msg);
70+
}
71+
}

Tools/TranscriptAnalysis/CsvWriter.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
namespace TranscriptAnalysis
1+
using Logging;
2+
3+
namespace TranscriptAnalysis
24
{
35
public class CsvWriter
46
{
7+
private readonly ILog log;
8+
9+
public CsvWriter(ILog log)
10+
{
11+
this.log = log;
12+
}
13+
514
public ICsv CreateNew()
615
{
716
return new Csv();
@@ -14,6 +23,8 @@ public void Write(ICsv csv, string filename)
1423
using var file = File.OpenWrite(filename);
1524
using var writer = new StreamWriter(file);
1625
c.CreateLines(writer.WriteLine);
26+
27+
log.Log($"CSV written to: '{filename}'");
1728
}
1829
}
1930

Tools/TranscriptAnalysis/Receivers/BaseReceiver.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ public abstract class BaseReceiver<T> : IEventReceiver<T>
88
{
99
protected ILog log { get; private set; } = new NullLog();
1010
protected OverwatchCodexHeader Header { get; private set; } = null!;
11-
protected CsvWriter CsvWriter { get; private set; } = new CsvWriter();
11+
protected CsvWriter CsvWriter { get; private set; }
1212
protected string SourceFilename { get; private set; } = string.Empty;
1313

1414
public abstract string Name { get; }
1515
public abstract void Receive(ActivateEvent<T> @event);
1616
public abstract void Finish();
1717

18+
protected BaseReceiver()
19+
{
20+
CsvWriter = new CsvWriter(log);
21+
}
22+
1823
public void Init(string sourceFilename, ILog log, OverwatchCodexHeader header)
1924
{
2025
this.log = new LogPrefixer(log, $"({Name}) ");

Tools/TranscriptAnalysis/Receivers/NodesDegree.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public Node(string peerId)
4646

4747
private readonly Dictionary<string, Node> dialingNodes = new Dictionary<string, Node>();
4848
private readonly Dictionary<string, Dial> dials = new Dictionary<string, Dial>();
49+
private long uploadSize;
4950

5051
public override string Name => "NodesDegree";
5152

@@ -57,6 +58,11 @@ public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
5758
if (peerId == null) return;
5859
AddDial(peerId, @event.Payload.DialSuccessful.TargetPeerId);
5960
}
61+
if (@event.Payload.FileUploaded != null)
62+
{
63+
var uploadEvent = @event.Payload.FileUploaded;
64+
uploadSize = uploadEvent.ByteSize;
65+
}
6066
}
6167

6268
public override void Finish()
@@ -84,6 +90,7 @@ public override void Finish()
8490

8591
float tot = numNodes;
8692
csv.GetColumn("numNodes", Header.Nodes.Length);
93+
csv.GetColumn("filesize", uploadSize.ToString());
8794
var degreeColumn = csv.GetColumn("degree", 0.0f);
8895
var occuranceColumn = csv.GetColumn("occurance", 0.0f);
8996
degreeOccurances.Print((i, count) =>

cs-codex-dist-testing.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TranscriptAnalysis", "Tools
7676
EndProject
7777
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarketInsights", "Tools\MarketInsights\MarketInsights.csproj", "{004614DF-1C65-45E3-882D-59AE44282573}"
7878
EndProject
79+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvCombiner", "Tools\CsvCombiner\CsvCombiner.csproj", "{6230347F-5045-4E25-8E7A-13D7221B7444}"
80+
EndProject
7981
Global
8082
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8183
Debug|Any CPU = Debug|Any CPU
@@ -202,6 +204,10 @@ Global
202204
{004614DF-1C65-45E3-882D-59AE44282573}.Debug|Any CPU.Build.0 = Debug|Any CPU
203205
{004614DF-1C65-45E3-882D-59AE44282573}.Release|Any CPU.ActiveCfg = Release|Any CPU
204206
{004614DF-1C65-45E3-882D-59AE44282573}.Release|Any CPU.Build.0 = Release|Any CPU
207+
{6230347F-5045-4E25-8E7A-13D7221B7444}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
208+
{6230347F-5045-4E25-8E7A-13D7221B7444}.Debug|Any CPU.Build.0 = Debug|Any CPU
209+
{6230347F-5045-4E25-8E7A-13D7221B7444}.Release|Any CPU.ActiveCfg = Release|Any CPU
210+
{6230347F-5045-4E25-8E7A-13D7221B7444}.Release|Any CPU.Build.0 = Release|Any CPU
205211
EndGlobalSection
206212
GlobalSection(SolutionProperties) = preSolution
207213
HideSolutionNode = FALSE
@@ -237,6 +243,7 @@ Global
237243
{870DDFBE-D7ED-4196-9681-13CA947BDEA6} = {81AE04BC-CBFA-4E6F-B039-8208E9AFAAE7}
238244
{C0EEBD32-23CB-45EC-A863-79FB948508C8} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3}
239245
{004614DF-1C65-45E3-882D-59AE44282573} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3}
246+
{6230347F-5045-4E25-8E7A-13D7221B7444} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3}
240247
EndGlobalSection
241248
GlobalSection(ExtensibilityGlobals) = postSolution
242249
SolutionGuid = {237BF0AA-9EC4-4659-AD9A-65DEB974250C}

0 commit comments

Comments
 (0)