Coverage Report - net.sf.statcvs.pages.DeveloperPageMaker
 
Classes in this File Line Coverage Branch Coverage Complexity
DeveloperPageMaker
0%
0/57
0%
0/26
2.286
 
 1  
 package net.sf.statcvs.pages;
 2  
 
 3  
 import java.text.NumberFormat;
 4  
 import java.util.ArrayList;
 5  
 import java.util.Collection;
 6  
 import java.util.Collections;
 7  
 import java.util.Iterator;
 8  
 import java.util.List;
 9  
 
 10  
 import net.sf.statcvs.Messages;
 11  
 import net.sf.statcvs.charts.ChartImage;
 12  
 import net.sf.statcvs.charts.DirectoryPieChartMaker.CodeDistributionChartMaker;
 13  
 import net.sf.statcvs.charts.TimeBarChartMaker.HourBarChartMaker;
 14  
 import net.sf.statcvs.charts.TimeBarChartMaker.WeekdayBarChartMaker;
 15  
 import net.sf.statcvs.model.Author;
 16  
 import net.sf.statcvs.model.Commit;
 17  
 import net.sf.statcvs.model.Repository;
 18  
 import net.sf.statcvs.model.Revision;
 19  
 import net.sf.statcvs.output.ReportConfig;
 20  
 import net.sf.statcvs.reports.DirectoriesForAuthorTableReport;
 21  
 
 22  
 /**
 23  
  * @author anja
 24  
  * @author Richard Cyganiak (richard@cyganiak.de)
 25  
  * @version $Id: DeveloperPageMaker.java,v 1.11 2008/04/02 11:22:14 benoitx Exp $
 26  
  */
 27  
 public class DeveloperPageMaker {
 28  
     private final static int RECENT_COMMITS_LENGTH = 20;
 29  0
     private final static NumberFormat PERCENT_FORMAT = NumberFormat.getPercentInstance();
 30  
 
 31  
     static {
 32  0
         PERCENT_FORMAT.setMinimumFractionDigits(1);
 33  0
         PERCENT_FORMAT.setMaximumFractionDigits(1);
 34  0
     }
 35  
 
 36  
     public static String getURL(final Author developer) {
 37  0
         return getFilename(developer) + ".html";
 38  
     }
 39  
 
 40  
     private static String getFilename(final Author developer) {
 41  0
         return "user_" + HTML.escapeAuthorName(developer.getName());
 42  
     }
 43  
 
 44  
     private final ReportConfig config;
 45  
     private final Author developer;
 46  
     private final Repository repository;
 47  
 
 48  0
     public DeveloperPageMaker(final ReportConfig config, final Author developer) {
 49  0
         this.config = config;
 50  0
         this.developer = developer;
 51  0
         this.repository = config.getRepository();
 52  0
     }
 53  
 
 54  
     public Page toFile() {
 55  0
         final ChartImage hourChart = new HourBarChartMaker(this.config, this.developer.getRevisions(), Messages.getString("ACTIVITY_TIME_FOR_AUTHOR_TITLE")
 56  
                 + " " + this.developer.getRealName(), "activity_time_" + HTML.escapeAuthorName(this.developer.getName()) + ".png").toFile();
 57  0
         final ChartImage weekdayChart = new WeekdayBarChartMaker(this.config, this.developer.getRevisions(), Messages
 58  
                 .getString("ACTIVITY_DAY_FOR_AUTHOR_TITLE")
 59  
                 + " " + this.developer.getRealName(), "activity_day_" + HTML.escapeAuthorName(this.developer.getName()) + ".png").toFile();
 60  0
         final ChartImage codeDistributionChart = new CodeDistributionChartMaker(this.config, this.developer).toFile();
 61  
 
 62  
         String title;
 63  0
         if (this.config.isDeveloper(this.developer)) {
 64  0
             title = this.config.getProjectName() + " Developers: " + this.developer.getRealName();
 65  
         } else {
 66  0
             title = "Non-developer Login: " + this.developer.getRealName();
 67  
         }
 68  0
         final Page page = this.config.createPage(getFilename(this.developer), this.developer.getRealName(), title);
 69  0
         page.addAttribute("Login name", this.developer.getName());
 70  0
         if (this.developer.getRealName() != null && !this.developer.getRealName().equals(this.developer.getName())) {
 71  0
             page.addAttribute("Real name", this.developer.getRealName());
 72  
         }
 73  0
         if (this.developer.getEmail() != null && this.developer.getEmail().length() > 0) {
 74  0
             page.addRawAttribute("Email", "<a href=\"mailto:" + this.developer.getEmail() + "\">" + this.developer.getEmail() + "</a>");
 75  
         }
 76  0
         if (this.developer.getHomePageUrl() != null && this.developer.getHomePageUrl().length() > 0) {
 77  0
             page.addRawAttribute("Home Page", "<a href=\"" + this.developer.getHomePageUrl() + "\">" + this.developer.getHomePageUrl() + "</a>");
 78  
         }
 79  0
         if (this.developer.getImageUrl() != null && this.developer.getImageUrl().length() > 0) {
 80  0
             page.addRawAttribute("Image", "<img src=\"" + this.developer.getImageUrl() + "\" alt=\"" + this.developer.getRealName() + "\"/>");
 81  
         }
 82  0
         page.addAttribute("Total Commits", getNumberAndPercentage(this.developer.getRevisions().size(), this.repository.getRevisions().size()));
 83  0
         page.addAttribute("Lines of Code", getNumberAndPercentage(countContributedLines(this.developer.getRevisions()), countContributedLines(this.repository
 84  
                 .getRevisions())));
 85  0
         page.addAttribute("Most Recent Commit", ((Revision) this.developer.getRevisions().last()).getDate());
 86  0
         page.addSection(Messages.getString("ACTIVITY_TITLE"));
 87  0
         page.add(hourChart);
 88  0
         page.add(weekdayChart);
 89  0
         page.addSection("Activity in Directories");
 90  0
         page.add(new DirectoriesForAuthorTableReport(this.config, this.developer));
 91  0
         if (codeDistributionChart != null) {
 92  0
             page.add(codeDistributionChart);
 93  
         }
 94  0
         page.addSection(Messages.getString("MOST_RECENT_COMMITS"));
 95  0
         page.addRawContent(new CommitListFormatter(this.config, getRecentCommits(), Collections.EMPTY_LIST, RECENT_COMMITS_LENGTH, false).render());
 96  0
         return page;
 97  
     }
 98  
 
 99  
     private List getRecentCommits() {
 100  0
         final List results = new ArrayList();
 101  0
         final Iterator it = this.repository.getCommits().iterator();
 102  0
         while (it.hasNext()) {
 103  0
             final Commit commit = (Commit) it.next();
 104  0
             if (this.developer.equals(commit.getAuthor())) {
 105  0
                 results.add(commit);
 106  
             }
 107  0
         }
 108  0
         return results;
 109  
     }
 110  
 
 111  
     private int countContributedLines(final Collection revisions) {
 112  0
         int result = 0;
 113  0
         final Iterator it = revisions.iterator();
 114  0
         while (it.hasNext()) {
 115  0
             final Revision element = (Revision) it.next();
 116  0
             result += element.getNewLines();
 117  0
         }
 118  0
         return result;
 119  
     }
 120  
 
 121  
     /**
 122  
      * returns the percentage of a given total count and the count.
 123  
      * This will work, because division by zero is not a problem with doubles:
 124  
      * you get NaN (and the formatter will format that too).
 125  
      * @author Jan Dockx
 126  
      * @param value
 127  
      * @param total
 128  
      * @return String percentage string
 129  
      */
 130  
     private String getNumberAndPercentage(final int value, final int total) {
 131  0
         final double factor = (double) value / (double) total;
 132  0
         return value + " (" + PERCENT_FORMAT.format(factor) + ")";
 133  
     }
 134  
 }