Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1123 markdown export #1126

Merged
merged 3 commits into from Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/PKSim.Infrastructure/InfrastructureRegister.cs
Expand Up @@ -28,6 +28,8 @@
using PKSim.Infrastructure.ProjectConverter;
using PKSim.Infrastructure.ProjectConverter.v5_3;
using PKSim.Infrastructure.ProjectConverter.v6_2;
using PKSim.Infrastructure.Reporting.Markdown;
using PKSim.Infrastructure.Reporting.Markdown.Builders;
using PKSim.Infrastructure.Reporting.Summary;
using PKSim.Infrastructure.Reporting.TeX.Builders;
using PKSim.Infrastructure.Reporting.TeX.Reporters;
Expand Down Expand Up @@ -158,6 +160,7 @@ public override void RegisterInContainer(IContainer container)
//this type will be registered using another convention
scan.ExcludeNamespaceContainingType<IObjectConverter>(); //Converter
scan.ExcludeNamespaceContainingType<IReportBuilder>(); //report builder
scan.ExcludeNamespaceContainingType<IMarkdownBuilder>(); //Markdown builder
scan.ExcludeNamespaceContainingType<SimulationReporter>(); //tex reporter
scan.ExcludeNamespaceContainingType<IndividualTeXBuilder>(); //tex builder
scan.ExcludeNamespaceContainingType<PKSimXmlSerializerRepository>(); //Serializer
Expand Down Expand Up @@ -207,6 +210,8 @@ public override void RegisterInContainer(IContainer container)

registerTexReporters(container);

registerMarkdownBuilders(container);

container.Register<ICompression, SharpLibCompression>();
container.Register<IStringCompression, StringCompression>();
container.Register<IProjectRetriever, PKSimProjectRetriever>();
Expand Down Expand Up @@ -251,6 +256,19 @@ private static void registerReportBuilders(IContainer container)
container.Register<IReportBuilderRepository, ReportBuilderRepository>(LifeStyle.Singleton);
}


private static void registerMarkdownBuilders(IContainer container)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to our tex builder, we need to implement markdown builder. It should be much simple and I believe could potentially replace Tex in the future

{
container.AddScanner(scan =>
{
scan.AssemblyContainingType<InfrastructureRegister>();
scan.IncludeNamespaceContainingType<IMarkdownBuilder>();
scan.ExcludeType<MarkdownBuilderRepository>();
scan.WithConvention<RegisterTypeConvention<IMarkdownBuilder>>();
});
container.Register<IMarkdownBuilderRepository, MarkdownBuilderRepository>(LifeStyle.Singleton);
}

private static void registerTexReporters(IContainer container)
{
container.AddScanner(scan =>
Expand Down
12 changes: 11 additions & 1 deletion src/PKSim.Infrastructure/PKSim.Infrastructure.csproj
Expand Up @@ -93,6 +93,9 @@
<Reference Include="LumenWorks.Framework.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5ad3ea2f85776344, processorArchitecture=MSIL">
<HintPath>..\..\packages\LumenWorksCsvReader.4.0.0\lib\net461\LumenWorks.Framework.IO.dll</HintPath>
</Reference>
<Reference Include="MarkdownLog, Version=0.10.1.0, Culture=neutral, PublicKeyToken=2b6c562c5dd991ab, processorArchitecture=MSIL">
<HintPath>..\..\packages\MarkdownLog.NS20.0.10.1\lib\netstandard2.0\MarkdownLog.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics, Version=4.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\MathNet.Numerics.4.7.0\lib\net461\MathNet.Numerics.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -279,6 +282,14 @@
<Compile Include="ProjectConverter\v7_4\Converter730To740.cs" />
<Compile Include="Reporting\Extensions\DataTableExtensions.cs" />
<Compile Include="Reporting\Extensions\SimpleProtocolExtensions.cs" />
<Compile Include="Reporting\Markdown\Builders\CompoundMarkdownBuilder.cs" />
<Compile Include="Reporting\Markdown\Builders\IMarkdownBuilder.cs" />
<Compile Include="Reporting\Markdown\Builders\ParametersMarkdownBuilder.cs" />
<Compile Include="Reporting\Markdown\Elements\TitleBaseElement.cs" />
<Compile Include="Reporting\Markdown\Elements\TitleElement.cs" />
<Compile Include="Reporting\Markdown\Extensions\MarkdownElementExtensions.cs" />
<Compile Include="Reporting\Markdown\MarkdownBuilderRepository.cs" />
<Compile Include="Reporting\Markdown\MarkdownTracker.cs" />
<Compile Include="Reporting\Summary\AdvancedProtocolReportBuilder.cs" />
<Compile Include="Reporting\Summary\CreationMetaDataReportBuilder.cs" />
<Compile Include="Reporting\Summary\GroupingDefinitionReportBuilder.cs" />
Expand Down Expand Up @@ -811,7 +822,6 @@
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Reporting\TeX\ReportingTEX.cd" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
@@ -0,0 +1,26 @@
using System.Linq;
using OSPSuite.Core.Domain;
using PKSim.Core.Model;
using PKSim.Infrastructure.Reporting.Markdown.Extensions;

namespace PKSim.Infrastructure.Reporting.Markdown.Builders
{
public class CompoundMarkdownBuilder : MarkdownBuilder<Compound>
{
private readonly IMarkdownBuilderRepository _markdownBuilderRepository;

public CompoundMarkdownBuilder(IMarkdownBuilderRepository markdownBuilderRepository)
{
_markdownBuilderRepository = markdownBuilderRepository;
}

public override void Report(Compound compound, MarkdownTracker tracker)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of (too simple until specified) markdown export for compound

{
tracker.Add(compound.Name.ToMarkdownTitle());

var allDefaultAlternatives = compound.AllParameterAlternativeGroups().Select(x => x.DefaultAlternative).SelectMany(x => x.AllParameters()).Where(x => !x.IsDefault);

_markdownBuilderRepository.Report(allDefaultAlternatives, tracker);
}
}
}
@@ -0,0 +1,28 @@
using System;
using OSPSuite.Utility;
using OSPSuite.Utility.Extensions;

namespace PKSim.Infrastructure.Reporting.Markdown.Builders
{
public interface IMarkdownBuilder : ISpecification<Type>
{
void Report(object objectToReport, MarkdownTracker tracker);
}

public interface IMarkdownBuilder<T> : IMarkdownBuilder
{
void Report(T objectToReport, MarkdownTracker tracker);
}

public abstract class MarkdownBuilder<T> : IMarkdownBuilder<T>
{
public void Report(object objectToReport, MarkdownTracker tracker)
{
Report(objectToReport.DowncastTo<T>(), tracker);
}

public abstract void Report(T objectToReport, MarkdownTracker tracker);

public bool IsSatisfiedBy(Type type) => type.IsAnImplementationOf<T>();
}
}
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Linq;
using MarkdownLog;
using OSPSuite.Core.Domain;

namespace PKSim.Infrastructure.Reporting.Markdown.Builders
{
public class ParametersMarkdownBuilder : MarkdownBuilder<IEnumerable<IParameter>>
{
public override void Report(IEnumerable<IParameter> parameters, MarkdownTracker tracker)
{
var table = parameters.Select(x => new
{
Name = x.Name,
Value = x.ValueInDisplayUnit,
Unit = x.DisplayUnit.ToString(),
});

tracker.Add(table.ToMarkdownTable());
}
}
}
@@ -0,0 +1,19 @@
using System;
using MarkdownLog;

namespace PKSim.Infrastructure.Reporting.Markdown.Elements
{
public class TitleBaseElement : MarkdownElement
{
private readonly string _text;
private readonly int _level;

public TitleBaseElement(string text, int level)
{
_text = text;
_level = level;
}

public override string ToMarkdown() => $"{new string('#', _level)} {_text}\n\n";
}
}
@@ -0,0 +1,9 @@
namespace PKSim.Infrastructure.Reporting.Markdown.Elements
{
public class TitleElement : TitleBaseElement
{
public TitleElement(string text) : base(text, 1)
{
}
}
}
@@ -0,0 +1,9 @@
using PKSim.Infrastructure.Reporting.Markdown.Elements;

namespace PKSim.Infrastructure.Reporting.Markdown.Extensions
{
public static class MarkdownElementExtensions
{
public static TitleElement ToMarkdownTitle(this string text) => new TitleElement(text);
}
}
@@ -0,0 +1,24 @@
using OSPSuite.Utility;
using OSPSuite.Utility.Container;
using PKSim.Infrastructure.Reporting.Markdown.Builders;

namespace PKSim.Infrastructure.Reporting.Markdown
{
public interface IMarkdownBuilderRepository : IBuilderRepository<IMarkdownBuilder>
{
void Report<T>(T objectToReport, MarkdownTracker tracker);
}

public class MarkdownBuilderRepository : BuilderRepository<IMarkdownBuilder>, IMarkdownBuilderRepository
{
public MarkdownBuilderRepository(IContainer container) : base(container, typeof(IMarkdownBuilder<>))
{
}

public void Report<T>(T objectToReport, MarkdownTracker tracker)
{
var builder = BuilderFor(objectToReport);
builder.Report(objectToReport, tracker);
}
}
}
30 changes: 30 additions & 0 deletions src/PKSim.Infrastructure/Reporting/Markdown/MarkdownTracker.cs
@@ -0,0 +1,30 @@
using System.Text;
using MarkdownLog;

namespace PKSim.Infrastructure.Reporting.Markdown
{
public class MarkdownTracker
{

/// <summary>
/// The string builder containing the actual Markdown being generated
/// </summary>
///
public StringBuilder Markdown { get; } = new StringBuilder();

public MarkdownTracker()
{
}

public override string ToString()
{
return Markdown.ToString();
}

public MarkdownTracker Add(IMarkdownElement markdown)
{
Markdown.Append(markdown.ToMarkdown());
return this;
}
}
}