Skip to content

Commit

Permalink
#371: Fixed order of metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Aug 27, 2020
1 parent 045b36d commit e2e55d0
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 34 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ variables:
- name: disable.coverage.autogenerate
value: 'true'
- name: version
value: '4.6.4'
value: '4.6.5'

stages:
- stage: Build
Expand Down
2 changes: 1 addition & 1 deletion src/AzureDevopsTask/ReportGenerator/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 4,
"Minor": 6,
"Patch": 4
"Patch": 5
},
"instanceNameFormat": "ReportGenerator",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion src/AzureDevopsTask/vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "reportgenerator",
"name": "ReportGenerator",
"version": "4.6.4",
"version": "4.6.5",
"publisher": "Palmmedia",
"public": true,
"targets": [
Expand Down
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ For further details take a look at LICENSE.txt.

CHANGELOG

4.6.5.0

* Fix: #371: Fixed order of metrics

4.6.4.0

* New: #366: Added custom settings to Azure DevOps task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>ReportGenerator</AssemblyName>
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
<StartupObject>Palmmedia.ReportGenerator.Console.NetCore.Program</StartupObject>
<AssemblyVersion>4.6.4.0</AssemblyVersion>
<FileVersion>4.6.4.0</FileVersion>
<AssemblyVersion>4.6.5.0</AssemblyVersion>
<FileVersion>4.6.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.6.4.0")]
[assembly: AssemblyFileVersion("4.6.4.0")]
[assembly: AssemblyVersion("4.6.5.0")]
[assembly: AssemblyFileVersion("4.6.5.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Palmmedia.ReportGenerator.Core.Test</RootNamespace>
<AssemblyVersion>4.6.4.0</AssemblyVersion>
<FileVersion>4.6.4.0</FileVersion>
<AssemblyVersion>4.6.5.0</AssemblyVersion>
<FileVersion>4.6.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 28 additions & 0 deletions src/ReportGenerator.Core/Parser/Analysis/Metric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,33 @@ public Metric(string name, Uri explanationUrl, MetricType metricType, decimal? v
/// Gets the value.
/// </summary>
public decimal? Value { get; internal set; }

/// <summary>
/// Determines whether the specified <see cref="object"/> is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="object"/> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object obj)
{
if (obj == null || !obj.GetType().Equals(typeof(Metric)))
{
return false;
}
else
{
var metric = (Metric)obj;
return metric.Name.Equals(this.Name);
}
}

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode() => this.Name.GetHashCode();
}
}
4 changes: 2 additions & 2 deletions src/ReportGenerator.Core/ReportGenerator.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyName>ReportGenerator.Core</AssemblyName>
<AssemblyVersion>4.6.4.0</AssemblyVersion>
<FileVersion>4.6.4.0</FileVersion>
<AssemblyVersion>4.6.5.0</AssemblyVersion>
<FileVersion>4.6.5.0</FileVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,18 @@ public void MetricsTable(Class @class)
throw new ArgumentNullException(nameof(@class));
}

var firstMethodMetric = @class.Files.SelectMany(f => f.MethodMetrics).First();
var metrics = @class.Files
.SelectMany(f => f.MethodMetrics)
.SelectMany(m => m.Metrics)
.Distinct()
.OrderBy(m => m.Name);

this.reportTextWriter.WriteLine("<table class=\"overview table-fixed\">");
this.reportTextWriter.Write("<thead><tr>");

this.reportTextWriter.Write("<th>{0}</th>", WebUtility.HtmlEncode(ReportResources.Method));

foreach (var met in firstMethodMetric.Metrics)
foreach (var met in metrics)
{
if (met.ExplanationUrl == null)
{
Expand Down Expand Up @@ -677,12 +681,21 @@ public void MetricsTable(Class @class)
this.reportTextWriter.Write("<td title=\"{0}\">{1}</td>", WebUtility.HtmlEncode(methodMetric.FullName), WebUtility.HtmlEncode(methodMetric.ShortName));
}

foreach (var metricValue in methodMetric.Metrics)
foreach (var metric in metrics)
{
this.reportTextWriter.Write(
var metricValue = methodMetric.Metrics.FirstOrDefault(m => m.Equals(metric));

if (metricValue != null)
{
this.reportTextWriter.Write(
"<td>{0}{1}</td>",
metricValue.Value.HasValue ? metricValue.Value.Value.ToString("0.##", CultureInfo.InvariantCulture) : "-",
metricValue.Value.HasValue && metricValue.MetricType == MetricType.CoveragePercentual ? "%" : string.Empty);
}
else
{
this.reportTextWriter.Write("<td>-</td>");
}
}

this.reportTextWriter.WriteLine("</tr>");
Expand All @@ -706,14 +719,17 @@ public void MetricsTable(IEnumerable<MethodMetric> methodMetrics)
throw new ArgumentNullException(nameof(methodMetrics));
}

var firstMethodMetric = methodMetrics.First();
var metrics = methodMetrics
.SelectMany(m => m.Metrics)
.Distinct()
.OrderBy(m => m.Name);

this.reportTextWriter.WriteLine("<table class=\"overview table-fixed\">");
this.reportTextWriter.Write("<thead><tr>");

this.reportTextWriter.Write("<th>{0}</th>", WebUtility.HtmlEncode(ReportResources.Method));

foreach (var met in firstMethodMetric.Metrics)
foreach (var met in metrics)
{
if (met.ExplanationUrl == null)
{
Expand All @@ -734,9 +750,20 @@ public void MetricsTable(IEnumerable<MethodMetric> methodMetrics)

this.reportTextWriter.Write("<td title=\"{0}\">{1}</td>", WebUtility.HtmlEncode(methodMetric.FullName), WebUtility.HtmlEncode(methodMetric.ShortName));

foreach (var metricValue in methodMetric.Metrics.Select(m => m.Value))
foreach (var metric in metrics)
{
this.reportTextWriter.Write("<td>{0}</td>", metricValue.HasValue ? metricValue.Value.ToString("0.##", CultureInfo.InvariantCulture) : "-");
var metricValue = methodMetric.Metrics.FirstOrDefault(m => m.Equals(metric));

if (metricValue != null)
{
this.reportTextWriter.Write(
"<td>{0}</td>",
metricValue.Value.HasValue ? metricValue.Value.Value.ToString("0.##", CultureInfo.InvariantCulture) : "-");
}
else
{
this.reportTextWriter.Write("<td>-</td>");
}
}

this.reportTextWriter.WriteLine("</tr>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,65 @@ public void MetricsTable(IEnumerable<MethodMetric> methodMetrics)
throw new ArgumentNullException(nameof(methodMetrics));
}

var firstMethodMetric = methodMetrics.First();
int numberOfTables = (int)Math.Ceiling((double)firstMethodMetric.Metrics.Count() / 5);
var metrics = methodMetrics
.SelectMany(m => m.Metrics)
.Distinct()
.OrderBy(m => m.Name);

int numberOfTables = (int)Math.Ceiling((double)metrics.Count() / 5);

for (int i = 0; i < numberOfTables; i++)
{
string columns = "|l|" + string.Join("|", firstMethodMetric.Metrics.Skip(i * 5).Take(5).Select(m => "r")) + "|";
string columns = "|l|" + string.Join("|", metrics.Skip(i * 5).Take(5).Select(m => "r")) + "|";

this.reportTextWriter.WriteLine(@"\begin{longtable}[l]{" + columns + "}");
this.reportTextWriter.WriteLine(@"\hline");
this.reportTextWriter.Write(@"\textbf{" + EscapeLatexChars(ReportResources.Method) + "} & " + string.Join(" & ", firstMethodMetric.Metrics.Skip(i * 5).Take(5).Select(m => @"\textbf{" + EscapeLatexChars(m.Name) + "}")));
this.reportTextWriter.Write(@"\textbf{" + EscapeLatexChars(ReportResources.Method) + "} & " + string.Join(" & ", metrics.Skip(i * 5).Take(5).Select(m => @"\textbf{" + EscapeLatexChars(m.Name) + "}")));
this.reportTextWriter.WriteLine(@"\\");
this.reportTextWriter.WriteLine(@"\hline");

foreach (var methodMetric in methodMetrics.OrderBy(c => c.Line))
{
string metrics = string.Join(" & ", methodMetric.Metrics.Skip(i * 5).Take(5).Select(m => string.Format("{0}{1}", m.Value.HasValue ? m.Value.Value.ToString(CultureInfo.InvariantCulture) : "-", m.Value.HasValue && m.MetricType == MetricType.CoveragePercentual ? "\\%" : string.Empty)));
StringBuilder sb = new StringBuilder();
int counter = 0;
foreach (var metric in metrics.Skip(i * 5).Take(5))
{
if (counter > 0)
{
sb.Append(" & ");
}

var metricValue = methodMetric.Metrics.FirstOrDefault(m => m.Equals(metric));

if (metricValue != null)
{
if (metricValue.Value.HasValue)
{
sb.Append(metricValue.Value.Value.ToString(CultureInfo.InvariantCulture));

if (metricValue.MetricType == MetricType.CoveragePercentual)
{
sb.Append("\\%");
}
}
else
{
sb.Append("-");
}
}
else
{
sb.Append("-");
}

counter++;
}

string row = string.Format(
CultureInfo.InvariantCulture,
@"\textbf{{{0}}} & {1}\\",
EscapeLatexChars(ShortenString(methodMetric.ShortName, 20)),
metrics);
sb.ToString());

this.reportTextWriter.WriteLine(row);
this.reportTextWriter.WriteLine(@"\hline");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>dotnet-reportgenerator</AssemblyName>
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
<StartupObject>Palmmedia.ReportGenerator.DotnetCliTool.Program</StartupObject>
<AssemblyVersion>4.6.4.0</AssemblyVersion>
<FileVersion>4.6.4.0</FileVersion>
<AssemblyVersion>4.6.5.0</AssemblyVersion>
<FileVersion>4.6.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RootNamespace>ReportGenerator.DotnetCorePluginLoader</RootNamespace>
<AssemblyVersion>4.6.4.0</AssemblyVersion>
<FileVersion>4.6.4.0</FileVersion>
<AssemblyVersion>4.6.5.0</AssemblyVersion>
<FileVersion>4.6.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>ReportGenerator</AssemblyName>
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
<StartupObject>Palmmedia.ReportGenerator.DotnetGlobalTool.Program</StartupObject>
<AssemblyVersion>4.6.4.0</AssemblyVersion>
<FileVersion>4.6.4.0</FileVersion>
<AssemblyVersion>4.6.5.0</AssemblyVersion>
<FileVersion>4.6.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.MSBuild/ReportGenerator.MSBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<RootNamespace>Palmmedia.ReportGenerator.MSBuild</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyVersion>4.6.4.0</AssemblyVersion>
<FileVersion>4.6.4.0</FileVersion>
<AssemblyVersion>4.6.5.0</AssemblyVersion>
<FileVersion>4.6.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!-- Version, adjust before build -->
<PropertyGroup>
<Version>4.6.4</Version>
<Version>4.6.5</Version>
</PropertyGroup>

<!-- Tools -->
Expand Down

0 comments on commit e2e55d0

Please sign in to comment.