mirror of
https://github.com/cosyneco/MediaPipe.NET.git
synced 2025-08-06 15:08:53 +08:00
Useless changes or something idk
This commit is contained in:
@ -27,12 +27,10 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
public static string GetUnusedNodeName(CalculatorGraphConfig config, string nodeNameBase)
|
public static string GetUnusedNodeName(CalculatorGraphConfig config, string nodeNameBase)
|
||||||
{
|
{
|
||||||
var nodeNames = new HashSet<string>(config.Node.Select(node => node.Name).Where(name => name.Length > 0));
|
var nodeNames = new HashSet<string>(config.Node.Select(node => node.Name).Where(name => name.Length > 0));
|
||||||
|
|
||||||
var candidate = nodeNameBase;
|
var candidate = nodeNameBase;
|
||||||
var iter = 1;
|
|
||||||
|
|
||||||
while (nodeNames.Contains(candidate))
|
for (int i = 2; nodeNames.Contains(candidate); i++)
|
||||||
candidate = $"{nodeNameBase}_{++iter:D2}";
|
candidate = $"{nodeNameBase}_{i:D2}";
|
||||||
|
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
@ -48,39 +46,34 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
var candidate = inputSidePacketNameBase;
|
var candidate = inputSidePacketNameBase;
|
||||||
var iter = 1;
|
|
||||||
|
|
||||||
while (inputSidePackets.Contains(candidate))
|
for (int i = 2; inputSidePackets.Contains(candidate); i++)
|
||||||
{
|
candidate = $"{inputSidePacketNameBase}_{i:D2}";
|
||||||
candidate = $"{inputSidePacketNameBase}_{++iter:D2}";
|
|
||||||
}
|
|
||||||
|
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="ArgumentOutOfRangeException">
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
/// Thrown when <paramref name="nodeId" /> is invalid
|
/// Thrown when <paramref name="nodeId" /> is invalid
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public static string CanonicalNodeName(CalculatorGraphConfig graphConfig, int nodeId)
|
public static string CanonicalNodeName(CalculatorGraphConfig graphConfig, int nodeId)
|
||||||
{
|
{
|
||||||
var nodeConfig = graphConfig.Node[nodeId];
|
CalculatorGraphConfig.Types.Node nodeConfig = graphConfig.Node[nodeId];
|
||||||
var nodeName = nodeConfig.Name.Length == 0 ? nodeConfig.Calculator : nodeConfig.Name;
|
string nodeName = nodeConfig.Name.Length == 0 ? nodeConfig.Calculator : nodeConfig.Name;
|
||||||
|
|
||||||
var nodesWithSameName = graphConfig.Node
|
var nodesWithSameName = graphConfig.Node
|
||||||
.Select((node, i) => (node.Name.Length == 0 ? node.Calculator : node.Name, i))
|
.Select((node, i) => (node.Name.Length == 0 ? node.Calculator : node.Name, i))
|
||||||
.Where(pair => pair.Item1 == nodeName);
|
.Where(pair => pair.Item1 == nodeName);
|
||||||
|
|
||||||
if (nodesWithSameName.Count() <= 1)
|
if (nodesWithSameName.Count() <= 1)
|
||||||
{
|
|
||||||
return nodeName;
|
return nodeName;
|
||||||
}
|
|
||||||
|
|
||||||
var seq = nodesWithSameName.Count(pair => pair.i <= nodeId);
|
var seq = nodesWithSameName.Count(pair => pair.i <= nodeId);
|
||||||
return $"{nodeName}_{seq}";
|
return $"{nodeName}_{seq}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="ArgumentException">
|
/// <exception cref="ArgumentException">
|
||||||
/// Thrown when the format of <paramref cref="stream" /> is invalid
|
/// Thrown when the format of <paramref cref="stream" /> is invalid
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public static string ParseNameFromStream(string stream)
|
public static string ParseNameFromStream(string stream)
|
||||||
{
|
{
|
||||||
@ -89,7 +82,7 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="ArgumentException">
|
/// <exception cref="ArgumentException">
|
||||||
/// Thrown when the format of <paramref cref="tagIndex" /> is invalid
|
/// Thrown when the format of <paramref cref="tagIndex" /> is invalid
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public static (string, int) ParseTagIndex(string tagIndex)
|
public static (string, int) ParseTagIndex(string tagIndex)
|
||||||
{
|
{
|
||||||
@ -98,7 +91,7 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="ArgumentException">
|
/// <exception cref="ArgumentException">
|
||||||
/// Thrown when the format of <paramref cref="stream" /> is invalid
|
/// Thrown when the format of <paramref cref="stream" /> is invalid
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public static (string, int) ParseTagIndexFromStream(string stream)
|
public static (string, int) ParseTagIndexFromStream(string stream)
|
||||||
{
|
{
|
||||||
@ -108,14 +101,13 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
|
|
||||||
public static string CatTag(string tag, int index)
|
public static string CatTag(string tag, int index)
|
||||||
{
|
{
|
||||||
var colonIndex = index <= 0 || tag.Length == 0 ? "" : $":{index}";
|
string colonIndex = index <= 0 || tag.Length == 0 ? "" : $":{index}";
|
||||||
return $"{tag}{colonIndex}";
|
return $"{tag}{colonIndex}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CatStream((string, int) tagIndex, string name)
|
public static string CatStream((string, int) tagIndex, string name)
|
||||||
{
|
{
|
||||||
var tag = CatTag(tagIndex.Item1, tagIndex.Item2);
|
string tag = CatTag(tagIndex.Item1, tagIndex.Item2);
|
||||||
|
|
||||||
return tag.Length == 0 ? name : $"{tag}:{name}";
|
return tag.Length == 0 ? name : $"{tag}:{name}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,8 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
|
|
||||||
public static void ParseTagAndName(string tagAndName, out string tag, out string name)
|
public static void ParseTagAndName(string tagAndName, out string tag, out string name)
|
||||||
{
|
{
|
||||||
var nameIndex = -1;
|
int nameIndex;
|
||||||
var v = tagAndName.Split(':');
|
string[] v = tagAndName.Split(':');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -77,10 +77,11 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
ValidateName(v[1]);
|
ValidateName(v[1]);
|
||||||
nameIndex = 1;
|
nameIndex = 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ArgumentException("nope");
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: what do we put inside of this ArgumentException?
|
|
||||||
if (nameIndex == -1)
|
|
||||||
throw new ArgumentException();
|
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
@ -93,9 +94,9 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
|
|
||||||
public static void ParseTagIndexName(string tagIndexName, out string tag, out int index, out string name)
|
public static void ParseTagIndexName(string tagIndexName, out string tag, out int index, out string name)
|
||||||
{
|
{
|
||||||
var nameIndex = -1;
|
int nameIndex;
|
||||||
var theIndex = 0;
|
int theIndex = 0;
|
||||||
var v = tagIndexName.Split(':');
|
string[] v = tagIndexName.Split(':');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -116,13 +117,18 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
ValidateTag(v[0]);
|
ValidateTag(v[0]);
|
||||||
ValidateNumber(v[1]);
|
ValidateNumber(v[1]);
|
||||||
|
|
||||||
theIndex = int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId ? result : throw new ArgumentException();
|
if (int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId)
|
||||||
|
theIndex = result;
|
||||||
|
else
|
||||||
|
throw new ArgumentException("nope");
|
||||||
|
|
||||||
ValidateName(v[2]);
|
ValidateName(v[2]);
|
||||||
nameIndex = 2;
|
nameIndex = 2;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (nameIndex == -1)
|
{
|
||||||
throw new ArgumentException();
|
throw new ArgumentException("nope");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
@ -136,32 +142,32 @@ namespace Mediapipe.Net.Framework.Tool
|
|||||||
|
|
||||||
public static void ParseTagIndex(string tagIndex, out string tag, out int index)
|
public static void ParseTagIndex(string tagIndex, out string tag, out int index)
|
||||||
{
|
{
|
||||||
var theIndex = -1;
|
int theIndex;
|
||||||
var v = tagIndex.Split(':');
|
string[] v = tagIndex.Split(':');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (v.Length == 1)
|
if (v.Length == 1)
|
||||||
{
|
{
|
||||||
if (v[0].Length != 0)
|
if (v[0].Length != 0)
|
||||||
{
|
|
||||||
ValidateTag(v[0]);
|
ValidateTag(v[0]);
|
||||||
}
|
|
||||||
theIndex = 0;
|
theIndex = 0;
|
||||||
}
|
}
|
||||||
else if (v.Length == 2)
|
else if (v.Length == 2)
|
||||||
{
|
{
|
||||||
if (v[0].Length != 0)
|
if (v[0].Length != 0)
|
||||||
{
|
|
||||||
ValidateTag(v[0]);
|
ValidateTag(v[0]);
|
||||||
}
|
|
||||||
ValidateNumber(v[1]);
|
ValidateNumber(v[1]);
|
||||||
|
|
||||||
theIndex = int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId ? result : throw new ArgumentException();
|
if (int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId)
|
||||||
|
theIndex = result;
|
||||||
|
else
|
||||||
|
throw new ArgumentException("nope");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ArgumentException("nope");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theIndex == -1)
|
|
||||||
throw new ArgumentException();
|
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user