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

Need a report which shows only History Graph #21

Closed
arpitgold opened this issue Jun 18, 2015 · 9 comments
Closed

Need a report which shows only History Graph #21

arpitgold opened this issue Jun 18, 2015 · 9 comments

Comments

@arpitgold
Copy link

Hi @danielpalme,

Thanks for the nice tool. It shows very pretty coverage view.
I am using this tool for n number of projects in Jenkins. And it shows very impressive and useful reports.
Now I want to collate all the project's history graph reports and want to show only History Trends as a single history monitoring UI. Can you please guide, how can i achieve this?

5

Or It will be fine even I can only show 1 project's History Trend and I will combine multiple projects later.

@danielpalme
Copy link
Owner

I think I can help you. Give me some time, I will come back to you within the next days.

@arpitgold
Copy link
Author

Thanks for your quick and supportive response. 😄
Thanks for the help.

@danielpalme
Copy link
Owner

@arpitgold:
I created a plugin for you, that renders the chart.
Please download this project, and place the compiled DLL next to ReportGenerator.exe. Then call ReportGenerator.exe with -reporttypes:HtmlChart.
This will create a single file report that contains the chart (and unfortunately the footer).

In Jenkins you can publish this file as an artifact or with the HTML Publisher Plugin.
Then you could create a simple HTML page, that embeds the charts from all of your projects as iframes.

This is the code of the plugin:

using System;
using System.Collections.Generic;
using System.Linq;
using Palmmedia.ReportGenerator.Parser.Analysis;
using Palmmedia.ReportGenerator.Properties;
using Palmmedia.ReportGenerator.Reporting;
using Palmmedia.ReportGenerator.Reporting.Rendering;

namespace MyCompany.CustomReportTypes
{
    /// <summary>
    /// Creates HTML with chart component only (no reports for classes are generated).
    /// </summary>
    [System.ComponentModel.Composition.Export(typeof(IReportBuilder))]
    public class HtmlChartReportBuilder : HtmlSummaryReportBuilder
    {
        /// <summary>
        /// Gets the report type.
        /// </summary>
        /// <value>
        /// The report type.
        /// </value>
        public override string ReportType
        {
            get { return "HtmlChart"; }
        }

        /// <summary>
        /// Creates the summary report.
        /// </summary>
        /// <param name="reportRenderer">The report renderer.</param>
        /// <param name="summaryResult">The summary result.</param>
        public override void CreateSummaryReport(IReportRenderer reportRenderer, SummaryResult summaryResult)
        {
            if (reportRenderer == null)
            {
                throw new ArgumentNullException("reportRenderer");
            }

            if (summaryResult == null)
            {
                throw new ArgumentNullException("summaryResult");
            }

            this.TargetDirectory = System.IO.Path.Combine(this.TargetDirectory, "chart");
            System.IO.Directory.CreateDirectory(this.TargetDirectory);

            reportRenderer.BeginSummaryReport(this.TargetDirectory, ReportResources.Summary);

            var historicCoverages = this.GetOverallHistoricCoverages(summaryResult.Assemblies.SelectMany(a => a.Classes));
            if (historicCoverages.Any(h => h.CoverageQuota.HasValue || h.BranchCoverageQuota.HasValue))
            {
                reportRenderer.Chart(historicCoverages);
            }

            reportRenderer.CustomSummary(summaryResult.Assemblies);

            reportRenderer.SaveSummaryReport(this.TargetDirectory);
        }

        /// <summary>
        /// Gets the overall historic coverages from all classes.
        /// </summary>
        /// <param name="classes">The classes.</param>
        /// <returns>
        /// The overall historic coverages from all classes.
        /// </returns>
        private IEnumerable<HistoricCoverage> GetOverallHistoricCoverages(IEnumerable<Class> classes)
        {
            var historicCoverages = classes
                .SelectMany(c => c.HistoricCoverages);

            var executionTimes = historicCoverages
                .Select(h => h.ExecutionTime)
                .Distinct();

            var result = new List<HistoricCoverage>();

            foreach (var executionTime in executionTimes)
            {
                var historicCoveragesOfExecutionTime = historicCoverages
                    .Where(h => h.ExecutionTime.Equals(executionTime))
                    .ToArray();

                result.Add(new HistoricCoverage(executionTime)
                {
                    CoveredLines = historicCoveragesOfExecutionTime.Sum(h => h.CoveredLines),
                    CoverableLines = historicCoveragesOfExecutionTime.Sum(h => h.CoverableLines),
                    CoveredBranches = historicCoveragesOfExecutionTime.Sum(h => h.CoveredBranches),
                    TotalBranches = historicCoveragesOfExecutionTime.Sum(h => h.TotalBranches),
                    TotalLines = historicCoveragesOfExecutionTime.Sum(h => h.TotalLines)
                });
            }

            return result;
        }
    }
}

@arpitgold
Copy link
Author

Thanks @danielpalme , 👍
A big thank for your support and fast response.
I will check it and get back to you if I need any further assistance.

@arpitgold
Copy link
Author

Hi @danielpalme,
It works as exactly as I required.
But the issue is I am calling as -reporttypes:Html;XmlSummary;HtmlChart .
Html and HtmlChart both creates index.htm. Html report's "index.htm" file get overriden.
Can we create seperate files for each report?

@danielpalme
Copy link
Owner

Easiest solution would be, to save the HtmlChart report to a different directory.
Just add the following lines to the CreateSummaryReport method:

this.TargetDirectory = System.IO.Path.Combine(this.TargetDirectory, "chart");
System.IO.Directory.CreateDirectory(this.TargetDirectory);

@arpitgold
Copy link
Author

Thanks @danielpalme, its works like a charm.
Again thanks for all your support. 👍

@gsuttie
Copy link

gsuttie commented Oct 9, 2015

I am getting unknown Report Type - I added the dll MyCompany.ReportGeneratorExtensions.dll next to the ReportGenerator.exe - can you help?

@danielpalme
Copy link
Owner

Please use latest version 2.3.2. Custom report types are only supported with version >2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants