1 package net.sf.statcvs.pages; 2 3 import java.util.Iterator; 4 5 import net.sf.statcvs.charts.ChartImage; 6 import net.sf.statcvs.charts.TimeLineChartMaker; 7 import net.sf.statcvs.model.Repository; 8 import net.sf.statcvs.model.VersionedFile; 9 import net.sf.statcvs.output.ReportConfig; 10 import net.sf.statcvs.reports.AvgFileSizeTimeLineReport; 11 import net.sf.statcvs.reports.FileCountTimeLineReport; 12 import net.sf.statcvs.reports.FileTypeReport; 13 import net.sf.statcvs.reports.FilesWithMostRevisionsTableReport; 14 import net.sf.statcvs.reports.LargestFilesTableReport; 15 import net.sf.statcvs.reports.TableReport; 16 17 /** 18 * @author anja 19 * @author Richard Cyganiak (richard@cyganiak.de) 20 * @version $Id: FileSizesPageMaker.java,v 1.8 2009/03/13 23:04:28 benoitx Exp $ 21 */ 22 public class FileSizesPageMaker { 23 private static final int MAX_LARGEST_FILES = 20; 24 private static final int MAX_FILES_WITH_MOST_REVISIONS = 20; 25 26 private final ReportConfig config; 27 private final Repository repository; 28 29 public FileSizesPageMaker(final ReportConfig config) { 30 this.config = config; 31 this.repository = config.getRepository(); 32 } 33 34 public NavigationNode toFile() { 35 final ChartImage fileCountChart = new TimeLineChartMaker("file_count", this.config, new FileCountTimeLineReport(this.repository.getFiles()) 36 .getTimeLine(), "file_count.png", this.repository.getSymbolicNames()).toFile(); 37 final ChartImage fileSizeChart = new TimeLineChartMaker("file_size", this.config, new AvgFileSizeTimeLineReport(this.repository.getFiles()) 38 .getTimeLine(), "file_size.png", this.repository.getSymbolicNames()).toFile(); 39 final TableReport largestFilesTable = new LargestFilesTableReport(this.config, this.repository.getFiles(), MAX_LARGEST_FILES); 40 final TableReport mostRevisionsTable = new FilesWithMostRevisionsTableReport(this.config, this.repository.getFiles(), MAX_FILES_WITH_MOST_REVISIONS); 41 42 final Page page = this.config.createPage("file_sizes", "File Statistics", "File Sizes and File Counts"); 43 page.addAttribute("Total Files", getCurrentFileCount()); 44 page.addAttribute("Average File Size", getCurrentAverageFileSize(), 1, "lines"); 45 page.addAttribute("Average Revisions Per File", getCurrentAverageRevisionCount(), 1); 46 page.add(fileCountChart); 47 page.add(fileSizeChart); 48 page.addSection("File Types"); 49 page.add(new FileTypeReport(this.config)); 50 page.addSection("Largest Files"); 51 page.add(largestFilesTable); 52 page.addSection("Files With Most Revisions"); 53 page.add(mostRevisionsTable); 54 return page; 55 } 56 57 private int getCurrentFileCount() { 58 int result = 0; 59 final Iterator it = this.repository.getFiles().iterator(); 60 while (it.hasNext()) { 61 final VersionedFile file = (VersionedFile) it.next(); 62 if (!file.isDead()) { 63 result++; 64 } 65 } 66 return result; 67 } 68 69 private double getCurrentAverageFileSize() { 70 return ((double) this.repository.getCurrentLOC()) / getCurrentFileCount(); 71 } 72 73 private double getCurrentAverageRevisionCount() { 74 int revisions = 0; 75 final Iterator it = this.repository.getFiles().iterator(); 76 while (it.hasNext()) { 77 final VersionedFile file = (VersionedFile) it.next(); 78 if (!file.isDead()) { 79 revisions += file.getRevisions().size(); 80 } 81 } 82 return ((double) revisions) / getCurrentFileCount(); 83 } 84 }