ソースを参照

mods to produce correct table output in gitstats

Schultz 8 年 前
コミット
6576eb9bbb

+ 0
- 1
FlaskTest/static/data/commits_by_author.dat ファイルの表示

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

FlaskTest/static/data/commits_by_author.tsv → FlaskTest/static/data/commits_by_author_copy.tsv ファイルの表示


FlaskTest/static/data/data2.tsv → FlaskTest/static/data/data2_dummy.tsv ファイルの表示


FlaskTest/static/data/data.tsv → FlaskTest/static/data/data_dummy.tsv ファイルの表示


FlaskTest/static/data/lines_of_code_by_author.tsv → FlaskTest/static/data/lines_of_code_by_author_copy.tsv ファイルの表示


+ 39
- 38
FlaskTest/static/js/script.js ファイルの表示

24
 
24
 
25
   days = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
25
   days = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
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"];
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
 const svg = d3.select("#chart").append("svg")
29
 const svg = d3.select("#chart").append("svg")
30
   .attr("width", width + margin.left + margin.right)
30
   .attr("width", width + margin.left + margin.right)
170
       var width=520
170
       var width=520
171
       var height=380
171
       var height=380
172
       var chartWidth, chartHeight
172
       var chartWidth, chartHeight
173
-      var margin
174
       var svg = d3.select(divID).append("svg")
173
       var svg = d3.select(divID).append("svg")
175
       var axisLayer = svg.append("g").classed("axisLayer", true)
174
       var axisLayer = svg.append("g").classed("axisLayer", true)
176
       var chartLayer = svg.append("g").classed("chartLayer", true)
175
       var chartLayer = svg.append("g").classed("chartLayer", true)
183
       .style("opacity", 0);
182
       .style("opacity", 0);
184
       
183
       
185
       function main(data) {
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
           chartWidth = width - margin.left - margin.right,
193
           chartWidth = width - margin.left - margin.right,
195
           chartHeight = height - margin.top - margin.bottom,        
194
           chartHeight = height - margin.top - margin.bottom,        
196
           
195
           
215
               
214
               
216
       }
215
       }
217
       
216
       
218
-      function drawChart(data) {
217
+      function drawChartBarChart() {
219
          // monitor the transition
218
          // monitor the transition
220
           var t = d3.transition()
219
           var t = d3.transition()
221
-              .duration(1000)
220
+              .duration(1100)
222
               .ease(d3.easeLinear)
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
           var bar = chartLayer
225
           var bar = chartLayer
227
             .selectAll(".bar")
226
             .selectAll(".bar")
229
           
228
           
230
           bar.exit().remove() 
229
           bar.exit().remove() 
231
 
230
 
232
-
233
-          var labels = chartLayer
234
-            .selectAll("labels")
235
-            .data(data)
236
-
237
           bar
231
           bar
238
             .enter()
232
             .enter()
239
             .append("rect")
233
             .append("rect")
245
             //setup for cool transition
239
             //setup for cool transition
246
             .attr("height", 0)
240
             .attr("height", 0)
247
             .attr("transform", function(d){ return "translate("+[xScale(d.day_name), chartHeight]+")"})
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
           var totalCommits=0
248
           var totalCommits=0
251
           data.forEach(function(d){
249
           data.forEach(function(d){
252
             totalCommits+=d.commits
250
             totalCommits+=d.commits
253
           })   
251
           })   
252
+
254
           labels
253
           labels
255
             .enter()
254
             .enter()
256
             .append("text")
255
             .append("text")
257
             .text(function(d){
256
             .text(function(d){
258
               var percentage= (d.commits/totalCommits *100).toFixed(2)
257
               var percentage= (d.commits/totalCommits *100).toFixed(2)
259
-
260
               return ""+percentage+"%";
258
               return ""+percentage+"%";
261
             })
259
             })
262
             .attr("transform", function(d){
260
             .attr("transform", function(d){
269
               .attr("transform", function(d){ return "translate("+[xScale(d.day_name), yScale(d.commits)]+")"})
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
           var yAxis = d3.axisLeft(yScale)
271
           var yAxis = d3.axisLeft(yScale)
274
               .tickSizeInner(-chartWidth)
272
               .tickSizeInner(-chartWidth)
275
           
273
           
284
               .attr("class", "axis x")
282
               .attr("class", "axis x")
285
               .attr("transform", "translate("+[margin.left, (height-margin.bottom)]+")")
283
               .attr("transform", "translate("+[margin.left, (height-margin.bottom)]+")")
286
               .call(xAxis);
284
               .call(xAxis);
287
-          
288
       }  
285
       }  
289
       
286
       
290
       //kicks of execution of the bar chart
287
       //kicks of execution of the bar chart
291
-      main(data);
292
-  }); 
288
+      main();
289
+
290
+  }); //end of tsv read in
293
 
291
 
294
 } //end of generateBarChart
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
 function generateLineChart(pathToTSV, divID){
297
 function generateLineChart(pathToTSV, divID){
300
 
298
 
337
     var xScale = d3.scaleTime().range([0, width]),
335
     var xScale = d3.scaleTime().range([0, width]),
338
         yScale = d3.scaleLinear().range([height, 0]),
336
         yScale = d3.scaleLinear().range([height, 0]),
339
         // 10 nice colors
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
     xScale.domain(d3.extent(data, function(d) { return d.date; }));
340
     xScale.domain(d3.extent(data, function(d) { return d.date; }));
348
 
341
 
351
       d3.max(authors, function(c) { return d3.max(c.values, function(d) { return d.commits; }); })
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
     function main(){
356
     function main(){
357
       drawAxisLineChart();
357
       drawAxisLineChart();
372
     }
372
     }
373
 
373
 
374
     function drawAxisLineChart(){
374
     function drawAxisLineChart(){
375
+
375
       g.append("g")
376
       g.append("g")
376
         .attr("class", "axis axis--x")
377
         .attr("class", "axis axis--x")
377
         .attr("transform", "translate(0," + height + ")")
378
         .attr("transform", "translate(0," + height + ")")
380
       g.append("g")
381
       g.append("g")
381
           .attr("class", "axis axis--y")
382
           .attr("class", "axis axis--y")
382
           .call(d3.axisLeft(yScale))
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
       // add the X gridlines
390
       // add the X gridlines
390
       g.append("g")     
391
       g.append("g")     
414
       author.append("path")
415
       author.append("path")
415
           .attr("class", "line")
416
           .attr("class", "line")
416
           .attr("d", function(d) { return line(d.values); })
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
       // Enable to show author at the end of the line
420
       // Enable to show author at the end of the line
420
       // author.append("text")
421
       // author.append("text")
441
             .attr('width', 10)
442
             .attr('width', 10)
442
             .attr('height', 10)
443
             .attr('height', 10)
443
             .style('fill', function(d) {
444
             .style('fill', function(d) {
444
-              return z(d.id);
445
+              return colors(d.id);
445
             });
446
             });
446
         legend.append('text')
447
         legend.append('text')
447
             .attr('x', chartWidth - 8)
448
             .attr('x', chartWidth - 8)

+ 1
- 0
Tools_Portal_TESTING

1
+Subproject commit ed2cb53a85e992cebd942b39c1f7b6fc5a2eebf4

+ 30
- 3
gitstats ファイルの表示

872
         f.write('<img src="day_of_week.png" alt="Day of Week">')
872
         f.write('<img src="day_of_week.png" alt="Day of Week">')
873
         fp.close()
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
         # Hour of Week
901
         # Hour of Week
876
         f.write(html_header(2, 'Hour of Week'))
902
         f.write(html_header(2, 'Hour of Week'))
877
         f.write('<table>')
903
         f.write('<table>')
880
         for hour in range(0, 24):
906
         for hour in range(0, 24):
881
             f.write('<th>%d</th>' % (hour))
907
             f.write('<th>%d</th>' % (hour))
882
         f.write('</tr>')
908
         f.write('</tr>')
883
-
884
         for weekday in range(0, 7):
909
         for weekday in range(0, 7):
885
             f.write('<tr><th>%s</th>' % (WEEKDAYS[weekday]))
910
             f.write('<tr><th>%s</th>' % (WEEKDAYS[weekday]))
886
             for hour in range(0, 24):
911
             for hour in range(0, 24):
890
                     commits = 0
915
                     commits = 0
891
                 if commits != 0:
916
                 if commits != 0:
892
                     f.write('<td')
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
                     f.write('>%d</td>' % commits)
920
                     f.write('>%d</td>' % commits)
921
+                    commits_by_author_tsv.write("%d\t%d\%d\n" %(weekday,hour,value))
896
                 else:
922
                 else:
897
                     f.write('<td></td>')
923
                     f.write('<td></td>')
924
+                    commits_by_author_tsv.write("%d\t%d\%d\n" %(weekday,hour,0))
898
             f.write('</tr>')
925
             f.write('</tr>')
899
 
926
 
900
         f.write('</table>')
927
         f.write('</table>')

+ 35
- 0
toWriteTest.py ファイルの表示

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