Pārlūkot izejas kodu

mods to produce correct table output in gitstats

Schultz 8 gadus atpakaļ
vecāks
revīzija
6576eb9bbb

+ 0
- 1
FlaskTest/static/data/commits_by_author.dat Parādīt failu

@@ -1,4 +1,3 @@
1
-date	author1	author2	author3	author4	author5	author6	author7
2 1
 1392392111 16 0 0 0 0 0 0
3 2
 1392397527 17 0 0 0 0 0 0
4 3
 1392830779 18 0 0 0 0 0 0

FlaskTest/static/data/commits_by_author.tsv → FlaskTest/static/data/commits_by_author_copy.tsv Parādīt failu


FlaskTest/static/data/data2.tsv → FlaskTest/static/data/data2_dummy.tsv Parādīt failu


FlaskTest/static/data/data.tsv → FlaskTest/static/data/data_dummy.tsv Parādīt failu


FlaskTest/static/data/lines_of_code_by_author.tsv → FlaskTest/static/data/lines_of_code_by_author_copy.tsv Parādīt failu


+ 39
- 38
FlaskTest/static/js/script.js Parādīt failu

@@ -24,7 +24,7 @@ const margin = { top: 50, right: 0, bottom: 100, left: 30 },
24 24
 
25 25
   days = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
26 26
   times = ["1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12a", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p", "12p"];
27
-  datasets = ["../static/data/data.tsv", "../static/data/data2.tsv"];
27
+  datasets = ["../static/data/data_dummy.tsv", "../static/data/data2_dummy.tsv"];
28 28
 
29 29
 const svg = d3.select("#chart").append("svg")
30 30
   .attr("width", width + margin.left + margin.right)
@@ -170,7 +170,6 @@ function generateBarChart (pathToTSV,divID){
170 170
       var width=520
171 171
       var height=380
172 172
       var chartWidth, chartHeight
173
-      var margin
174 173
       var svg = d3.select(divID).append("svg")
175 174
       var axisLayer = svg.append("g").classed("axisLayer", true)
176 175
       var chartLayer = svg.append("g").classed("chartLayer", true)
@@ -183,14 +182,14 @@ function generateBarChart (pathToTSV,divID){
183 182
       .style("opacity", 0);
184 183
       
185 184
       function main(data) {
186
-          setSize(data)
187
-          drawAxis()
188
-          drawChart(data)    
185
+          setSize();
186
+          drawAxisBarChart();
187
+          drawChartBarChart();    
189 188
       }
190 189
       
191
-      function setSize(data) {
190
+      function setSize() {
192 191
 
193
-          margin = {top:50, right:0, bottom:100,  left:30}
192
+          var margin = {top:50, right:0, bottom:100,  left:30}
194 193
           chartWidth = width - margin.left - margin.right,
195 194
           chartHeight = height - margin.top - margin.bottom,        
196 195
           
@@ -215,13 +214,13 @@ function generateBarChart (pathToTSV,divID){
215 214
               
216 215
       }
217 216
       
218
-      function drawChart(data) {
217
+      function drawChartBarChart() {
219 218
          // monitor the transition
220 219
           var t = d3.transition()
221
-              .duration(1000)
220
+              .duration(1100)
222 221
               .ease(d3.easeLinear)
223
-              .on("start", function(d){ console.log("Transiton start") })
224
-              .on("end", function(d){ console.log("Transiton end") })
222
+              .on("start", function(d){ console.log("Bar Chart Transiton start") })
223
+              .on("end", function(d){ console.log("Bar Chart Transiton end") })
225 224
           
226 225
           var bar = chartLayer
227 226
             .selectAll(".bar")
@@ -229,11 +228,6 @@ function generateBarChart (pathToTSV,divID){
229 228
           
230 229
           bar.exit().remove() 
231 230
 
232
-
233
-          var labels = chartLayer
234
-            .selectAll("labels")
235
-            .data(data)
236
-
237 231
           bar
238 232
             .enter()
239 233
             .append("rect")
@@ -245,18 +239,22 @@ function generateBarChart (pathToTSV,divID){
245 239
             //setup for cool transition
246 240
             .attr("height", 0)
247 241
             .attr("transform", function(d){ return "translate("+[xScale(d.day_name), chartHeight]+")"})
248
-              
249 242
 
243
+          var labels = chartLayer
244
+            .selectAll("labels")
245
+            .data(data)
246
+              
247
+          //setup for percentage display
250 248
           var totalCommits=0
251 249
           data.forEach(function(d){
252 250
             totalCommits+=d.commits
253 251
           })   
252
+
254 253
           labels
255 254
             .enter()
256 255
             .append("text")
257 256
             .text(function(d){
258 257
               var percentage= (d.commits/totalCommits *100).toFixed(2)
259
-
260 258
               return ""+percentage+"%";
261 259
             })
262 260
             .attr("transform", function(d){
@@ -269,7 +267,7 @@ function generateBarChart (pathToTSV,divID){
269 267
               .attr("transform", function(d){ return "translate("+[xScale(d.day_name), yScale(d.commits)]+")"})
270 268
       }
271 269
       
272
-      function drawAxis(){
270
+      function drawAxisBarChart(){
273 271
           var yAxis = d3.axisLeft(yScale)
274 272
               .tickSizeInner(-chartWidth)
275 273
           
@@ -284,17 +282,17 @@ function generateBarChart (pathToTSV,divID){
284 282
               .attr("class", "axis x")
285 283
               .attr("transform", "translate("+[margin.left, (height-margin.bottom)]+")")
286 284
               .call(xAxis);
287
-          
288 285
       }  
289 286
       
290 287
       //kicks of execution of the bar chart
291
-      main(data);
292
-  }); 
288
+      main();
289
+
290
+  }); //end of tsv read in
293 291
 
294 292
 } //end of generateBarChart
295 293
 
296
-generateLineChart("../static/data/commits_by_author.tsv", "#lineChart");
297
-generateLineChart("../static/data/lines_of_code_by_author.tsv", "#lineChart2");
294
+generateLineChart("../static/data/commits_by_author_copy.tsv", "#lineChart");
295
+generateLineChart("../static/data/lines_of_code_by_author_copy.tsv", "#lineChart2");
298 296
 
299 297
 function generateLineChart(pathToTSV, divID){
300 298
 
@@ -337,12 +335,7 @@ function generateLineChart(pathToTSV, divID){
337 335
     var xScale = d3.scaleTime().range([0, width]),
338 336
         yScale = d3.scaleLinear().range([height, 0]),
339 337
         // 10 nice colors
340
-        z = d3.scaleOrdinal(d3.schemeCategory10);
341
-
342
-    var line = d3.line()
343
-      .curve(d3.curveBasis)
344
-      .x(function(d) { return xScale(d.date); })
345
-      .y(function(d) { return yScale(d.commits);});
338
+        colors = d3.scaleOrdinal(d3.schemeCategory10);
346 339
 
347 340
     xScale.domain(d3.extent(data, function(d) { return d.date; }));
348 341
 
@@ -351,7 +344,14 @@ function generateLineChart(pathToTSV, divID){
351 344
       d3.max(authors, function(c) { return d3.max(c.values, function(d) { return d.commits; }); })
352 345
     ]);
353 346
 
354
-    z.domain(authors.map(function(c) { return c.id; }));
347
+    var line = d3.line()
348
+    // different types of interpolations here
349
+    // https://bl.ocks.org/d3noob/ced1b9b18bd8192d2c898884033b5529
350
+      .curve(d3.curveBasis)
351
+      .x(function(d) { return xScale(d.date); })
352
+      .y(function(d) { return yScale(d.commits);});
353
+
354
+    colors.domain(authors.map(function(c) { return c.id; }));
355 355
 
356 356
     function main(){
357 357
       drawAxisLineChart();
@@ -372,6 +372,7 @@ function generateLineChart(pathToTSV, divID){
372 372
     }
373 373
 
374 374
     function drawAxisLineChart(){
375
+
375 376
       g.append("g")
376 377
         .attr("class", "axis axis--x")
377 378
         .attr("transform", "translate(0," + height + ")")
@@ -380,11 +381,11 @@ function generateLineChart(pathToTSV, divID){
380 381
       g.append("g")
381 382
           .attr("class", "axis axis--y")
382 383
           .call(d3.axisLeft(yScale))
383
-        .append("text")
384
-          .attr("transform", "rotate(-90)")
385
-          .attr("y", 6)
386
-          .attr("dy", "0.71em")
387
-          .attr("fill", "#000")
384
+        // .append("text")
385
+        //   .attr("transform", "rotate(-90)")
386
+        //   .attr("y", 6)
387
+        //   .attr("dy", "0.71em")
388
+        //   .attr("fill", "#000")
388 389
 
389 390
       // add the X gridlines
390 391
       g.append("g")     
@@ -414,7 +415,7 @@ function generateLineChart(pathToTSV, divID){
414 415
       author.append("path")
415 416
           .attr("class", "line")
416 417
           .attr("d", function(d) { return line(d.values); })
417
-          .style("stroke", function(d) { return z(d.id); });
418
+          .style("stroke", function(d) { return colors(d.id); });
418 419
 
419 420
       // Enable to show author at the end of the line
420 421
       // author.append("text")
@@ -441,7 +442,7 @@ function generateLineChart(pathToTSV, divID){
441 442
             .attr('width', 10)
442 443
             .attr('height', 10)
443 444
             .style('fill', function(d) {
444
-              return z(d.id);
445
+              return colors(d.id);
445 446
             });
446 447
         legend.append('text')
447 448
             .attr('x', chartWidth - 8)

+ 1
- 0
Tools_Portal_TESTING

@@ -0,0 +1 @@
1
+Subproject commit ed2cb53a85e992cebd942b39c1f7b6fc5a2eebf4

+ 30
- 3
gitstats Parādīt failu

@@ -872,6 +872,32 @@ class HTMLReportCreator(ReportCreator):
872 872
         f.write('<img src="day_of_week.png" alt="Day of Week">')
873 873
         fp.close()
874 874
 
875
+        # New function for TSV write ins, put this in a more organized place later
876
+
877
+        def writeHeaderstoNewTSV(fileName,headers):
878
+            """
879
+            Writes the headers to the first line of the .tsv file
880
+
881
+            Args:
882
+                fileName (String): Name of the destination file, ex: "data.tsv"
883
+                headers (List(String)): Headers to be written, ex: ["header1","header2"....]
884
+
885
+            """
886
+            assert fileName[-4:] ==".tsv", "fileName must be '.tsv' file not '%s'" %(fileName)
887
+
888
+            f = open (fileName,"w")
889
+            for headerIndex in range(len(headers)):
890
+                if headerIndex!=len(headers)-1:
891
+                    # write header along with\t 
892
+                    f.write(headers[headerIndex]+"\t")
893
+                else:
894
+                    # write last word along with\n
895
+                    f.write(headers[len(headers)-1]+"\n")
896
+            f.close()
897
+
898
+        writeHeaderstoNewTSV("FlaskTest/static/data/commits_by_author_TEST.tsv", ['day','hour','value'])
899
+        commits_by_author_tsv=open("FlaskTest/static/data/commits_by_author_TEST.tsv", "w")
900
+
875 901
         # Hour of Week
876 902
         f.write(html_header(2, 'Hour of Week'))
877 903
         f.write('<table>')
@@ -880,7 +906,6 @@ class HTMLReportCreator(ReportCreator):
880 906
         for hour in range(0, 24):
881 907
             f.write('<th>%d</th>' % (hour))
882 908
         f.write('</tr>')
883
-
884 909
         for weekday in range(0, 7):
885 910
             f.write('<tr><th>%s</th>' % (WEEKDAYS[weekday]))
886 911
             for hour in range(0, 24):
@@ -890,11 +915,13 @@ class HTMLReportCreator(ReportCreator):
890 915
                     commits = 0
891 916
                 if commits != 0:
892 917
                     f.write('<td')
893
-                    r = 127 + int((float(commits) / data.activity_by_hour_of_week_busiest) * 128)
894
-                    f.write(' style="background-color: rgb(%d, 0, 0)"' % r)
918
+                    value = 127 + int((float(commits) / data.activity_by_hour_of_week_busiest) * 128)
919
+                    f.write(' style="background-color: rgb(%d, 0, 0)"' % value)
895 920
                     f.write('>%d</td>' % commits)
921
+                    commits_by_author_tsv.write("%d\t%d\%d\n" %(weekday,hour,value))
896 922
                 else:
897 923
                     f.write('<td></td>')
924
+                    commits_by_author_tsv.write("%d\t%d\%d\n" %(weekday,hour,0))
898 925
             f.write('</tr>')
899 926
 
900 927
         f.write('</table>')

+ 35
- 0
toWriteTest.py Parādīt failu

@@ -0,0 +1,35 @@
1
+def writeHeaderstoNewTSV(fileName,headers):
2
+	"""
3
+	Writes the headers to the first line of the .tsv file
4
+
5
+	Args:
6
+		fileName (String): Name of the destination file, ex: "data.tsv"
7
+		headers (List(String)): Headers to be written, ex: ["header1","header2"....]
8
+
9
+	"""
10
+	assert fileName[-4:] ==".tsv", "fileName must be '.tsv' file not '%s'" %(fileName)
11
+
12
+	f = open (fileName,"w")
13
+	for headerIndex in range(len(headers)):
14
+		if headerIndex!=len(headers)-1:
15
+			# write header along with\t 
16
+			f.write(headers[headerIndex]+"\t")
17
+		else:
18
+			# write last word along with\n
19
+			f.write(headers[len(headers)-1]+"\n")
20
+	f.close()
21
+
22
+writeHeaderstoNewTSV("FlaskTest/static/data/commits_by_author.tsv",["date","author1","author2","author3","author4","author5","author6","author7"])
23
+a= open("FlaskTest/static/data/commits_by_author.tsv","r")
24
+print (a.readlines())
25
+
26
+
27
+
28
+
29
+# conversion from space to tsv for fallback if all else fails
30
+# sed 's/ /\t/g' file.dat > file.tsv
31
+
32
+
33
+
34
+
35
+# ./gitstats ~/Desktop/tony_gitstats/gitstats/Tools_Portal_TESTING/ ~/Desktop/tony_gitstats/gitstats/output_test