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
1123 markdown export #1126
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/PKSim.Infrastructure/Reporting/Markdown/Builders/CompoundMarkdownBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/PKSim.Infrastructure/Reporting/Markdown/Builders/IMarkdownBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/PKSim.Infrastructure/Reporting/Markdown/Builders/ParametersMarkdownBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/PKSim.Infrastructure/Reporting/Markdown/Elements/TitleBaseElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/PKSim.Infrastructure/Reporting/Markdown/Elements/TitleElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace PKSim.Infrastructure.Reporting.Markdown.Elements | ||
{ | ||
public class TitleElement : TitleBaseElement | ||
{ | ||
public TitleElement(string text) : base(text, 1) | ||
{ | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/PKSim.Infrastructure/Reporting/Markdown/Extensions/MarkdownElementExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/PKSim.Infrastructure/Reporting/Markdown/MarkdownBuilderRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
30
src/PKSim.Infrastructure/Reporting/Markdown/MarkdownTracker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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