Skip to content

Commit

Permalink
optional asynchronous pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jsboige committed Feb 14, 2024
1 parent cf1914e commit 9c658fb
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AssetConverterConfig

public bool SkipConfigFile { get; set; } = false;

public ConverterMode Mode { get; set; } = ConverterMode.OwlGenerator;// | ConverterMode.WebBasedImageGeneration;
public ConverterMode Mode { get; set; } = ConverterMode.Mindmapper | ConverterMode.OwlGenerator;// | ConverterMode.WebBasedImageGeneration;

public bool ForceDebugParams { get; set; }

Expand Down Expand Up @@ -313,8 +313,8 @@ public string GetBaseTargetDirectory(string language)

public bool EnableSVGPrompt { get; set; } = true;



public bool AsynchronousPipeline { get; set; }



Expand Down Expand Up @@ -384,41 +384,94 @@ public async Task<bool> Apply()

if (Mode.HasFlag(ConverterMode.BatchImageProcessor))
{
if (AsynchronousPipeline)
{
tasks.Add(Task.Run(() => BatchImageConverterConfig.Apply()));
}
else
{
await BatchImageConverterConfig.Apply();
}

tasks.Add(Task.Run(() => BatchImageConverterConfig.Apply()));


}

if (Mode.HasFlag(ConverterMode.DatasetUpdater))
{
tasks.Add(DatasetUpdaterRootConfig.Apply(this));
if (AsynchronousPipeline)
{
tasks.Add(Task.Run(() => DatasetUpdaterRootConfig.Apply(this)));
}
else
{
await DatasetUpdaterRootConfig.Apply(this);
}


}

if (Mode.HasFlag(ConverterMode.WebBasedImageGeneration))
{

tasks.Add(WebBasedGeneratorConfig.Apply(this));
if (AsynchronousPipeline)
{
tasks.Add(Task.Run(() => WebBasedGeneratorConfig.Apply(this)));
}
else
{
await WebBasedGeneratorConfig.Apply(this);
}



}

if (Mode.HasFlag(ConverterMode.Mindmapper))
{
tasks.Add(MindMapCreatorConfig.Apply(this));
if (AsynchronousPipeline)
{
tasks.Add(Task.Run(() => MindMapCreatorConfig.Apply(this)));
}
else
{
await MindMapCreatorConfig.Apply(this);
}


}


if (Mode.HasFlag(ConverterMode.Dnn2sxc))
{
tasks.Add(Task.Run(() => Dnn2sxcConfig.Apply()));
if (AsynchronousPipeline)
{
tasks.Add(Task.Run(() => Dnn2sxcConfig.Apply()));
}
else
{
Dnn2sxcConfig.Apply();
}


}

if (Mode.HasFlag(ConverterMode.OwlGenerator))
{
tasks.Add(OwlGeneratorConfig.Apply(this));
if (AsynchronousPipeline)
{
tasks.Add(Task.Run(() => OwlGeneratorConfig.Apply(this)));
}
else
{
await OwlGeneratorConfig.Apply(this);
}
}

if (AsynchronousPipeline)
{
await Task.WhenAll(tasks);
}

await Task.WhenAll(tasks);


// Handling for None or unrecognized values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public Func<Fallacy, string> ThumbnailsPathFunc
public List<int> FontSizes { get; set; } = new List<int>(new[] { 60, 60, 50, 40, 30, 30, 25, 23, 23, 23, 23 });


public List<int> EdgeSizes { get; set; } = new List<int>(new[] { 50, 20, 5, 1 });
public List<int> EdgeSizes { get; set; } = new List<int>(new[] { 20, 10, 5, 1});


public bool InsertCardsThumbnails { get; set; }
Expand Down Expand Up @@ -425,10 +425,12 @@ private void SetNodeStyle(Node fallacyNode, Fallacy fallacy, int familyNb)

if (fallacy.Depth < EdgeSizes.Count)
{
fallacyNode.Edge = new Edge() { WIDTH = EdgeSizes[fallacy.Depth].ToString(CultureInfo.InvariantCulture) };



if (familyNb > 0)
{
fallacyNode.Edge = new Edge() { WIDTH = EdgeSizes[fallacy.Depth - 1].ToString(CultureInfo.InvariantCulture) };
fallacyNode.Edge.COLOR = Colors[familyNb];
fallacyNode.BACKGROUND_COLOR = HLSColor.GetLighterColor(Colors[familyNb]);
}
Expand All @@ -438,6 +440,10 @@ private void SetNodeStyle(Node fallacyNode, Fallacy fallacy, int familyNb)
else
{
fallacyNode.STYLE = "fork";
if (fallacy.Depth == EdgeSizes.Count)
{
fallacyNode.Edge = new Edge() { WIDTH = EdgeSizes[fallacy.Depth - 1].ToString(CultureInfo.InvariantCulture) };
}
}

if (fallacy.Depth <= EdgeSizes.Count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,27 @@ public override async Task GenerateFallacyFile(IList<Fallacy> fallacies, AssetCo
fileName = Path.Combine(targetDirectory, fileName);

}
var documentPath = Path.Combine(targetDirectory, DocumentName);
//var documentPath = Path.Combine(targetDirectory, DocumentName);

CreateOwlDocument(fallacies, config, language, documentPath, fileName);

if (File.Exists(fileName) && !config.OverwriteExistingDocs)
{
Logger.Log($"Skip existing Owl document: {fileName}");
}
else
{
Logger.Log($"Creating Owl document {DocumentName}");
CreateOwlDocument(fallacies, config, language, fileName);
}



}

private void CreateOwlDocument(IList<Fallacy> fallacies, AssetConverterConfig config, string language, string documentPath, string fileName)
private void CreateOwlDocument(IList<Fallacy> fallacies, AssetConverterConfig config, string language, string fileName)
{

var fallaciesByPath = fallacies.ToDictionary(f => f.Path, f => f);
var fallaciesByPath = fallacies.ToDictionary(f => f.Path, f => f);
Fallacy GetParent(Fallacy f)
{
if (f.Depth <= 1)
Expand Down Expand Up @@ -307,6 +319,8 @@ Fallacy GetParent(Fallacy f)
// WRITE OWL2/XML FILE
ontology.ToFile(xmlFormat, fileName);

Logger.LogSuccess($"Owl document {fileName} successfully saved");

}

private RDFResource GetFallacyConcept(Fallacy targetFallacy,
Expand Down

0 comments on commit 9c658fb

Please sign in to comment.