1 package net.sf.statcvs.reports;
2
3 import java.util.Calendar;
4 import java.util.Collection;
5 import java.util.Date;
6 import java.util.GregorianCalendar;
7 import java.util.Iterator;
8
9 import net.sf.statcvs.model.Author;
10 import net.sf.statcvs.model.Repository;
11 import net.sf.statcvs.model.Revision;
12 import net.sf.statcvs.output.ReportConfig;
13 import net.sf.statcvs.pages.LogPageMaker;
14 import net.sf.statcvs.reportmodel.AuthorColumn;
15 import net.sf.statcvs.reportmodel.IntegerColumn;
16 import net.sf.statcvs.reportmodel.LinkColumn;
17 import net.sf.statcvs.reportmodel.Table;
18 import net.sf.statcvs.util.IntegerMap;
19
20
21
22
23
24
25
26
27
28 public class DevelopersOfTheMonthTable implements TableReport {
29 private final Repository repository;
30 private Table table;
31
32 private final static String[] MONTH_NAME = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
33 "December" };
34
35
36
37
38
39
40
41
42 public DevelopersOfTheMonthTable(final ReportConfig config) {
43 this.repository = config.getRepository();
44 }
45
46 public void calculate() {
47 final LinkColumn months = new LinkColumn("Month");
48 final AuthorColumn developers = new AuthorColumn();
49 final IntegerColumn loc = new IntegerColumn("Lines");
50 loc.setShowPercentages(false);
51
52 this.table = new Table("Repository Tags");
53 this.table.setKeysInFirstColumn(true);
54 this.table.addColumn(months);
55 this.table.addColumn(developers);
56 this.table.addColumn(loc);
57
58 final Date start = this.repository.getFirstDate();
59 final Date end = this.repository.getLastDate();
60 final Calendar calendar = new GregorianCalendar();
61 calendar.setTime(end);
62 final Calendar startCal = new GregorianCalendar();
63 startCal.setTime(start);
64 while (true) {
65 final int year = calendar.get(Calendar.YEAR);
66 final int month = calendar.get(Calendar.MONTH);
67 final String month_year = MONTH_NAME[month] + " " + year;
68 final IntegerMap developerMap = getMostActiveUserOfMonth(month, year);
69 if (developerMap.size() > 0) {
70 months.addValue(LogPageMaker.getURL(calendar.getTime()), month_year);
71 final Iterator it = developerMap.iteratorSortedByValueReverse();
72 final Author developer = (Author) it.next();
73 developers.addValue(developer);
74 loc.addValue(developerMap.get(developer));
75 }
76
77 if (calendar.get(Calendar.YEAR) == startCal.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == startCal.get(Calendar.MONTH)) {
78 break;
79 }
80 calendar.add(Calendar.MONTH, -1);
81 }
82 }
83
84 private IntegerMap getMostActiveUserOfMonth(final int month, final int year) {
85 final Collection revisions = this.repository.getRevisions();
86 final Calendar calendar = new GregorianCalendar();
87 final IntegerMap developerMap = new IntegerMap();
88 final Iterator it = revisions.iterator();
89 while (it.hasNext()) {
90 final Revision revision = (Revision) it.next();
91 calendar.setTime(revision.getDate());
92 if (calendar.get(Calendar.YEAR) != year || calendar.get(Calendar.MONTH) != month || revision.getAuthor() == null) {
93 continue;
94 }
95 if (developerMap.contains(revision.getAuthor())) {
96 final int loc = developerMap.get(revision.getAuthor());
97 developerMap.put(revision.getAuthor(), revision.getNewLines() + loc);
98 } else {
99 developerMap.put(revision.getAuthor(), revision.getNewLines());
100 }
101 }
102 return developerMap;
103 }
104
105 public Table getTable() {
106 return this.table;
107 }
108 }