Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / setup / SVNStats.groovy @ 1000

History | View | Annotate | Download (4.2 kB)

1
package org.txm.scripts.setup
2

    
3
File svnLog = new File("/home/mdecorde/SVN/ALLTXMSVN/txm/log.xml");
4
File outRev = new File("/home/mdecorde/TEMP/stats_rev.tsv")
5
File outPeriode = new File("/home/mdecorde/TEMP/stats_periode.tsv")
6
def periodes = [1624, 1771, 1823, 2095, 2299]
7
def SVNROOT = new File("/home/mdecorde/SVN/ALLTXMSVN/txm")
8
def composants = ["/trunk/CWB/", "/trunk/doc/", "/trunk/groovy-all/", "/trunk/RCP/", "/trunk/textometrieR/", "/trunk/Toolbox/", "/trunk/WEB/", ""]
9

    
10
def logs = new XmlParser().parse(svnLog);
11
def revisions = new LinkedHashMap<String, Object>();
12
def allPackages = new HashSet<String>();
13
def allFiles = new HashSet<String>();
14

    
15
println "Counting revisions..."
16
for (def logEntry : logs.logentry) {
17
        // SVN log.xml infos
18
        def commitAuthor = logEntry.author.text();
19
        def commitDate = logEntry.date.text();
20
        def nUpdate = 0;
21
        def nAdd = 0
22
        def nDelete = 0;
23
        def newPackages = new HashSet<String>()
24
        def newFiles = new HashSet<String>()
25

    
26
        for (def path : logEntry.paths.path) {
27
                String file = path.text();
28
                switch(path.'@action') {
29
                        case "M":
30
                                nUpdate++
31
                                break;
32
                        case "A":
33
                                nAdd++
34
                                if (file.matches(".+\\.[A-Za-z]{1,10}")) {
35
                                        newFiles << file;
36
                                } else {
37
                                        newPackages << file;
38
                                }
39
                                break;
40
                        case "D":
41
                                nDelete++;
42
                                break;
43
                        default:
44
                                break;
45
                }
46
        }
47

    
48
        // SVN file explore
49
        def nLines = 0;
50
        def authors = [commitAuthor]
51
        // count lines
52
        // get @author
53

    
54
        revisions[Integer.parseInt(logEntry.'@revision')] = [commitDate, authors, nUpdate, nAdd, nDelete, newPackages.size(), newPackages, newFiles.size(), newFiles]
55
}
56

    
57
def periodesStats = new LinkedHashMap<String, Object>()
58
int currentPeriode = 0
59
def nCommit = 0
60
def nUpdate = 0
61
def nAdd = 0
62
def nDelete = 0
63
def authors = new HashSet<String>()
64
def newPackages = new HashSet<String>()
65
def newFiles = new HashSet<String>()
66

    
67
println "Counting periodes..."
68
def revKeys = revisions.keySet().sort()
69
def previousRev = revKeys[0]
70
for( def rev : revKeys) {
71
        if (rev >= periodes[currentPeriode]) {
72
                //println "end of periode "+periodes[currentPeriode]+ " at rev "+rev
73
                periodesStats[periodes[currentPeriode]] = [revisions[previousRev][0], authors, nCommit, nUpdate, nAdd, nDelete, newPackages.size(), newFiles.size(), newPackages]
74

    
75
                currentPeriode++
76
                authors = new HashSet<String>()
77
                nCommit = 0;
78
                nUpdate = 0;
79
                nAdd = 0
80
                nDelete = 0;
81
                newPackages = new HashSet<String>()
82
                newFiles = new HashSet<String>()
83
        }
84
        def infos = revisions[rev]
85
        nCommit++
86
        authors.addAll(infos[1])
87
        nUpdate += infos[2]
88
        nAdd += infos[3]
89
        nDelete += infos[4]
90
        newPackages.addAll(infos[6])
91
        newFiles.addAll(infos[8])
92
        
93
        previousRev = rev
94
}
95
//periodesStats[2299] = [nCommit, authors, nUpdate, nAdd, nDelete, newPackages.size(), newPackages, newFiles.size(), newFiles]
96

    
97

    
98
println "Counting composants of periodes..."
99
for(def p : periodesStats.keySet()) {
100
        def infos = periodesStats[p]
101
        //println infos.size()
102
        newPackages = infos[8]
103
        def newPackagesComp = [:]
104

    
105
        for (String path : newPackages) {
106
        for (int i = 0 ; i < composants.size() ; i++) {
107
                def comp = composants[i]
108
                
109
                        if (path.startsWith(comp)) {
110
                                if (newPackagesComp[comp] == null) newPackagesComp[comp] = new HashSet<String>();
111
                                newPackagesComp[comp] << path.substring(comp.length())
112
                                break;
113
                        }
114
                }
115
        }
116
        for (int i = 0 ; i < composants.size() ; i++) {
117
                def comp = composants[i]
118
                if (newPackagesComp[comp] != null)
119
                        newPackagesComp[comp] = newPackagesComp[comp] .size()
120
        }
121
        infos[8] = newPackagesComp;
122
}
123

    
124
println "revisions stat size: "+revisions.size()
125
println "periodes stat size: "+periodesStats.size()
126

    
127
println "writing outRev"
128
outRev.withWriter("UTF-8") { writer ->
129
        writer.println "rev\tdate\tauthors\tnUpdate\tnAdd\tnDelete\tnNewPackages\tnewPackages\tnNewFiles\tnewFiles"
130
        for( def rev : revisions.keySet()) {
131
                writer.println rev+"\t"+revisions[rev].join ("\t")
132
        }
133
}
134
//[revisions[previousRev][0], authors, nCommit, nUpdate, nAdd, nDelete, newPackages.size(), newFiles.size(), newPackages]
135
println "writing outPeriode"
136
outPeriode.withWriter("UTF-8") { writer ->
137
        writer.println "periode\tdate\tauthors\tnCommit\tnUpdate\tnAdd\tnDelete\tnNewPackages\tnNewFiles\tnewPackagesPerComp"
138
        for(def p : periodesStats.keySet()) {
139
                writer.println p+"\t"+periodesStats[p].join ("\t")
140
                writer.flush()
141
        }
142
}