pairing_matrix 2.0 → 2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62a28ef71e8e75af4ca2fe8f8d83bee4737f55ea
4
- data.tar.gz: 552cb865cd768accfee93d7886de6c5045599faa
3
+ metadata.gz: bbe4d5bda921f70c585704c0021380570c41393f
4
+ data.tar.gz: 8299d6cbc89154810b30388d8e6e424dfffa8c4b
5
5
  SHA512:
6
- metadata.gz: e6ecaa54d4da86876f90807d0ce33adc23af0f116776a72567d479ad0c590faa5e44d9345fc94c2008241db0ea822d956137893a22764a7ed617858538e38cee
7
- data.tar.gz: f366b968892a4759180d082676217f1c6259fa36bad89b55cb61bcb0937694b428b8f7fb1da38171651c685c9c3669c4e679dacd8139559b594e09e3ed485c80
6
+ metadata.gz: 5062d6a462b5802c747dde64798d89773be670618372ec1a510ecd121a2898cc2f6ad5f445a3dc78aaef5c8c5359cb8c41c9c781c3c15eb5435945b3706b715f
7
+ data.tar.gz: 52363d79a8221d0df7c4405a8299c69274b8e97d53700709fec7e80b40bbd390335d591ad16ddad87e950061f835a4b078301673e4bf546ce726363d3702df65
@@ -0,0 +1,38 @@
1
+ require 'date'
2
+
3
+ module PairingMatrix
4
+ def self.enable_caching=(enabled)
5
+ @cache_enabled = enabled
6
+ end
7
+
8
+ def self.cache_enabled
9
+ @cache_enabled
10
+ end
11
+
12
+ class CommitCache
13
+ def initialize
14
+ @cache = {}
15
+ @timestamp = Date.today
16
+ end
17
+
18
+ def put(date, response)
19
+ @cache[date] = response
20
+ end
21
+
22
+ def get(date)
23
+ return nil unless PairingMatrix.cache_enabled
24
+
25
+ if Date.today == @timestamp
26
+ @cache[date]
27
+ else
28
+ invalidate_cache
29
+ nil
30
+ end
31
+ end
32
+
33
+ private
34
+ def invalidate_cache
35
+ @cache = {}
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,6 @@
1
1
  require 'octokit'
2
2
  require 'eldritch'
3
+ require_relative './commit_cache'
3
4
 
4
5
  Octokit.auto_paginate = true
5
6
 
@@ -8,9 +9,13 @@ module PairingMatrix
8
9
  def initialize(config)
9
10
  super(config)
10
11
  @github_client = github_client
12
+ @cache = CommitCache.new
11
13
  end
12
14
 
13
15
  def read(since)
16
+ cache = @cache.get(since)
17
+ return cache unless cache.nil?
18
+
14
19
  commits = []
15
20
  together do
16
21
  @config.github_repos.map do |repo|
@@ -19,7 +24,9 @@ module PairingMatrix
19
24
  end
20
25
  end
21
26
  end
22
- commits.flatten
27
+ result = commits.flatten
28
+ @cache.put(since, result)
29
+ result
23
30
  end
24
31
 
25
32
  private
@@ -5,24 +5,46 @@
5
5
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
6
6
  <link rel="stylesheet" href="style.css"/>
7
7
  <link rel="stylesheet" href="loader.css"/>
8
+ <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
8
9
 
9
10
  <script language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
10
11
  <script language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
11
12
  <script language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.7.3/d3.min.js"></script>
12
13
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
14
+ <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
13
15
  <script language="javascript" src="matrix.js"></script>
14
16
  <script language="javascript" src="index.js"></script>
15
17
  </head>
16
18
 
17
19
  <body>
18
20
  <div class="visualize_matrix_container form-group form-inline">
19
- <input type="number" class="form-control" id="days" value="10"/>
20
- <button id="visualize" class="btn btn-primary form-control">Visualize</button>
21
- </div>
22
- <div class="info">
23
- <span>Displaying data of last</span>
24
- <span id="no_of_days"></span>
25
- <span>days</span>
21
+ <div class="row">
22
+ <div class="col-lg-offset-3 col-lg-6">
23
+ <div class="input-group">
24
+ <div class="input-group">
25
+ <span class="input-group-addon" id="basic-addon2">Days</span>
26
+ <input type="text" id="days" value="30" class="form-control" placeholder="Recipient's username" aria-describedby="basic-addon2">
27
+ </div>
28
+ <span class="input-group-btn">
29
+ <div class="btn-group">
30
+ <button id="visualize" type="button" class="btn btn-primary">Visualize</button>
31
+ <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
32
+ <span class="caret"></span>
33
+ <span class="sr-only">Toggle Dropdown</span>
34
+ </button>
35
+ <ul class="dropdown-menu">
36
+ <li><a id="a_week" href="#">A Week</a></li>
37
+ <li><a id="two_weeks" href="#">Two Weeks</a></li>
38
+ <li><a id="a_month" href="#">A Month</a></li>
39
+ <li><a id="two_months" href="#">Two Months</a></li>
40
+ </ul>
41
+ </div>
42
+ </span>
43
+ </div>
44
+ </div>
45
+ <input class="cache-toggle" type="checkbox" data-toggle="toggle"
46
+ data-on="Cache Enabled" data-off="Cache Disabled"/>
47
+ </div>
26
48
  </div>
27
49
 
28
50
  <div class="loaderContainer">
@@ -1,23 +1,24 @@
1
1
  $(document).ready(function () {
2
2
  var playground = new PlayGround(".area");
3
3
  var pairingData = [];
4
- var renderMatrix = function (days) {
5
- $('#no_of_days').text(days);
4
+ var renderMatrix = function () {
5
+ var days = $('#days').val();
6
6
  hideMatrix();
7
7
  showLoader();
8
- $.get('/data/' + days).done(function (data) {
8
+ $.get('/data/' + days + "?cache_enabled=" + isCachingEnabled()).done(function (data) {
9
9
  pairingData = JSON.parse(data);
10
10
  playground.load(pairingData);
11
11
  hideLoader();
12
12
  showMatrix();
13
13
  }).fail(function () {
14
- alert('error occurred!');
14
+ alert('Error fetching data from server!');
15
15
  hideLoader();
16
16
  showMatrix();
17
17
  });
18
18
  };
19
19
 
20
20
  var hideMatrix = function () {
21
+ $(".authors_container").hide();
21
22
  $('.viz_container').hide();
22
23
  };
23
24
 
@@ -35,7 +36,7 @@ $(document).ready(function () {
35
36
  return 0;
36
37
  });
37
38
  _.each(sortedNames, function (name) {
38
- $('.authors').append("<input type='checkbox' checked='true' name='" + name + "'><label for='" + name + "'>" + name + "</label></br>");
39
+ $('.authors').append("<input type='checkbox' class='author' checked='true' name='" + name + "'><label for='" + name + "'>" + name + "</label></br>");
39
40
  });
40
41
 
41
42
  $(".authors_container").show();
@@ -49,21 +50,51 @@ $(document).ready(function () {
49
50
  $('.loaderContainer').show();
50
51
  };
51
52
 
53
+ var enableCaching = function () {
54
+ $('.cache-toggle').bootstrapToggle('on');
55
+ };
56
+
57
+ var isCachingEnabled = function () {
58
+ return $('.cache-toggle').prop('checked');
59
+ };
60
+
61
+ var updateDays = function(days) {
62
+ var $days = $('#days');
63
+ $days.val(days);
64
+ };
65
+
52
66
  $('#visualize').on('click', function () {
53
- $(".authors_container").hide();
54
- renderMatrix($('#days').val())
67
+ renderMatrix()
55
68
  });
56
69
 
57
- renderMatrix($('#days').val());
70
+ $('#a_week').on('click', function () {
71
+ updateDays('7');
72
+ renderMatrix()
73
+ });
74
+
75
+ $('#two_weeks').on('click', function () {
76
+ updateDays('14');
77
+ renderMatrix()
78
+ });
79
+
80
+ $('#a_month').on('click', function () {
81
+ updateDays('30');
82
+ renderMatrix()
83
+ });
84
+
85
+ $('#two_months').on('click', function () {
86
+ updateDays('60');
87
+ renderMatrix()
88
+ });
58
89
 
59
90
  $('#reset').click(function () {
60
- _.each($('input[type="checkbox"]'), function (e) {
91
+ _.each($('.author'), function (e) {
61
92
  e.checked = false;
62
93
  });
63
94
  });
64
95
 
65
96
  $('#render').click(function (e) {
66
- var checked = _.filter($('input[type="checkbox"]'), function (e) {
97
+ var checked = _.filter($('.author'), function (e) {
67
98
  return e.checked
68
99
  });
69
100
  var names = _.map(checked, function (checkbox) {
@@ -76,4 +107,7 @@ $(document).ready(function () {
76
107
 
77
108
  playground.load(filteredPairingData);
78
109
  });
110
+
111
+ enableCaching();
112
+ renderMatrix();
79
113
  });
@@ -196,7 +196,7 @@ function PlayGround(selector) {
196
196
 
197
197
  this.getValidPairs = function (pairingData) {
198
198
  return _.filter(pairingData, function (data) {
199
- return (!_.isEmpty(data[0]) && !_.isEmpty(data[1]));
199
+ return (!_.isEmpty(data[0]) && !_.isEmpty(data[1])) && data.length == 3;
200
200
  })
201
201
  };
202
202
 
@@ -3,6 +3,7 @@ require 'json'
3
3
  require_relative '../../pairing_matrix'
4
4
  require_relative '../config/config_reader'
5
5
  require_relative '../commit_reader'
6
+ require_relative '../commit_cache'
6
7
  require_relative '../github_commit_reader'
7
8
 
8
9
  module PairingMatrix
@@ -20,12 +21,14 @@ module PairingMatrix
20
21
  use Rack::CommonLogger, logging_file
21
22
  end
22
23
 
24
+ PairingMatrix.enable_caching = true
23
25
  config_reader = PairingMatrix::ConfigReader.new('pairing_matrix.yml')
24
26
  config = config_reader.config
25
27
  commit_reader = PairingMatrix::CommitReader.new(config)
26
28
  commit_reader = PairingMatrix::GithubCommitReader.new(config) if config.fetch_from_github?
27
29
 
28
30
  get '/data/:days' do
31
+ PairingMatrix.enable_caching = params[:cache_enabled] != 'false'
29
32
  commit_reader.authors_with_commits(params['days'].to_i).to_json
30
33
  end
31
34
 
@@ -1,3 +1,3 @@
1
1
  module PairingMatrix
2
- VERSION = '2.0'
2
+ VERSION = '2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pairing_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: '2.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajit Singh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - bin/pairing_matrix
83
83
  - lib/pairing_matrix.rb
84
+ - lib/pairing_matrix/commit_cache.rb
84
85
  - lib/pairing_matrix/commit_reader.rb
85
86
  - lib/pairing_matrix/config/config.rb
86
87
  - lib/pairing_matrix/config/config_reader.rb