| 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 | |
|
| 19 | |
|
| 20 | |
|
| 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 | 0 | public FileSizesPageMaker(final ReportConfig config) { |
| 30 | 0 | this.config = config; |
| 31 | 0 | this.repository = config.getRepository(); |
| 32 | 0 | } |
| 33 | |
|
| 34 | |
public NavigationNode toFile() { |
| 35 | 0 | final ChartImage fileCountChart = new TimeLineChartMaker(this.config, new FileCountTimeLineReport(this.repository.getFiles()).getTimeLine(), |
| 36 | |
"file_count.png", this.repository.getSymbolicNames()).toFile(); |
| 37 | 0 | final ChartImage fileSizeChart = new TimeLineChartMaker(this.config, new AvgFileSizeTimeLineReport(this.repository.getFiles()).getTimeLine(), |
| 38 | |
"file_size.png", this.repository.getSymbolicNames()).toFile(); |
| 39 | 0 | final TableReport largestFilesTable = new LargestFilesTableReport(this.config, this.repository.getFiles(), MAX_LARGEST_FILES); |
| 40 | 0 | final TableReport mostRevisionsTable = new FilesWithMostRevisionsTableReport(this.config, this.repository.getFiles(), MAX_FILES_WITH_MOST_REVISIONS); |
| 41 | |
|
| 42 | 0 | final Page page = this.config.createPage("file_sizes", "File Statistics", "File Sizes and File Counts"); |
| 43 | 0 | page.addAttribute("Total Files", getCurrentFileCount()); |
| 44 | 0 | page.addAttribute("Average File Size", getCurrentAverageFileSize(), 1, "lines"); |
| 45 | 0 | page.addAttribute("Average Revisions Per File", getCurrentAverageRevisionCount(), 1); |
| 46 | 0 | page.add(fileCountChart); |
| 47 | 0 | page.add(fileSizeChart); |
| 48 | 0 | page.addSection("File Types"); |
| 49 | 0 | page.add(new FileTypeReport(this.config)); |
| 50 | 0 | page.addSection("Largest Files"); |
| 51 | 0 | page.add(largestFilesTable); |
| 52 | 0 | page.addSection("Files With Most Revisions"); |
| 53 | 0 | page.add(mostRevisionsTable); |
| 54 | 0 | return page; |
| 55 | |
} |
| 56 | |
|
| 57 | |
private int getCurrentFileCount() { |
| 58 | 0 | int result = 0; |
| 59 | 0 | final Iterator it = this.repository.getFiles().iterator(); |
| 60 | 0 | while (it.hasNext()) { |
| 61 | 0 | final VersionedFile file = (VersionedFile) it.next(); |
| 62 | 0 | if (!file.isDead()) { |
| 63 | 0 | result++; |
| 64 | |
} |
| 65 | 0 | } |
| 66 | 0 | return result; |
| 67 | |
} |
| 68 | |
|
| 69 | |
private double getCurrentAverageFileSize() { |
| 70 | 0 | return ((double) this.repository.getCurrentLOC()) / getCurrentFileCount(); |
| 71 | |
} |
| 72 | |
|
| 73 | |
private double getCurrentAverageRevisionCount() { |
| 74 | 0 | int revisions = 0; |
| 75 | 0 | final Iterator it = this.repository.getFiles().iterator(); |
| 76 | 0 | while (it.hasNext()) { |
| 77 | 0 | final VersionedFile file = (VersionedFile) it.next(); |
| 78 | 0 | if (!file.isDead()) { |
| 79 | 0 | revisions += file.getRevisions().size(); |
| 80 | |
} |
| 81 | 0 | } |
| 82 | 0 | return ((double) revisions) / getCurrentFileCount(); |
| 83 | |
} |
| 84 | |
} |