attractor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +127 -0
- data/LICENSE +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/attractor.gemspec +48 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/attractor +3 -0
- data/lib/attractor/calculator.rb +61 -0
- data/lib/attractor/cli.rb +28 -0
- data/lib/attractor/value.rb +26 -0
- data/lib/attractor/version.rb +3 -0
- data/lib/attractor.rb +10 -0
- data/lib/templates/index.html.erb +162 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a376669bcb5272332c0cf9cb6863729cd34e7f4f40008587df643e8e8c93560
|
4
|
+
data.tar.gz: e99947a68c9ab26dda3f4d412c171f0953a7ed6f0438291c52313186a89a0e09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2de1c37b46ffb02682a05d0048eb170b6d0fc71c9513ba014c6a429835c14ebfa9cdc7638a8e53e104b99228c78f4219be74ce97ce6df448827d127283ced22
|
7
|
+
data.tar.gz: 33bef8d6aacea9a1a50eec12042d5fc27f036a9b7b69b5edff6fb30e2ff3c8337dbfd613ceac63fa16101a24c4c01d107d6aa2c37faf54e2339b307d60f20bb9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
attractor (0.1.0)
|
5
|
+
churn
|
6
|
+
descriptive_statistics
|
7
|
+
flog (~> 4.0)
|
8
|
+
thor
|
9
|
+
tilt
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
arrayfields (4.9.2)
|
15
|
+
aruba (0.14.11)
|
16
|
+
childprocess (>= 0.6.3, < 3.0.0)
|
17
|
+
contracts (~> 0.9)
|
18
|
+
cucumber (>= 1.3.19)
|
19
|
+
ffi (~> 1.9)
|
20
|
+
rspec-expectations (>= 2.99)
|
21
|
+
thor (~> 0.19)
|
22
|
+
backports (3.15.0)
|
23
|
+
builder (3.2.3)
|
24
|
+
childprocess (2.0.0)
|
25
|
+
rake (< 13.0)
|
26
|
+
chronic (0.10.2)
|
27
|
+
churn (1.0.4)
|
28
|
+
chronic (>= 0.2.3)
|
29
|
+
hirb
|
30
|
+
json_pure
|
31
|
+
main
|
32
|
+
rest-client (>= 1.6.0)
|
33
|
+
ruby_parser (~> 3.0)
|
34
|
+
sexp_processor (~> 4.1)
|
35
|
+
coderay (1.1.2)
|
36
|
+
contracts (0.16.0)
|
37
|
+
cucumber (3.1.2)
|
38
|
+
builder (>= 2.1.2)
|
39
|
+
cucumber-core (~> 3.2.0)
|
40
|
+
cucumber-expressions (~> 6.0.1)
|
41
|
+
cucumber-wire (~> 0.0.1)
|
42
|
+
diff-lcs (~> 1.3)
|
43
|
+
gherkin (~> 5.1.0)
|
44
|
+
multi_json (>= 1.7.5, < 2.0)
|
45
|
+
multi_test (>= 0.1.2)
|
46
|
+
cucumber-core (3.2.1)
|
47
|
+
backports (>= 3.8.0)
|
48
|
+
cucumber-tag_expressions (~> 1.1.0)
|
49
|
+
gherkin (~> 5.0)
|
50
|
+
cucumber-expressions (6.0.1)
|
51
|
+
cucumber-tag_expressions (1.1.1)
|
52
|
+
cucumber-wire (0.0.1)
|
53
|
+
descriptive_statistics (2.5.1)
|
54
|
+
diff-lcs (1.3)
|
55
|
+
domain_name (0.5.20190701)
|
56
|
+
unf (>= 0.0.5, < 1.0.0)
|
57
|
+
fattr (2.4.0)
|
58
|
+
ffi (1.11.1)
|
59
|
+
flog (4.6.2)
|
60
|
+
path_expander (~> 1.0)
|
61
|
+
ruby_parser (~> 3.1, > 3.1.0)
|
62
|
+
sexp_processor (~> 4.8)
|
63
|
+
gherkin (5.1.0)
|
64
|
+
hirb (0.7.3)
|
65
|
+
http-accept (1.7.0)
|
66
|
+
http-cookie (1.0.3)
|
67
|
+
domain_name (~> 0.5)
|
68
|
+
json_pure (2.2.0)
|
69
|
+
main (6.2.3)
|
70
|
+
arrayfields (~> 4.7, >= 4.7.4)
|
71
|
+
chronic (~> 0.6, >= 0.6.2)
|
72
|
+
fattr (~> 2.2, >= 2.2.0)
|
73
|
+
map (~> 6.1, >= 6.1.0)
|
74
|
+
map (6.6.0)
|
75
|
+
method_source (0.9.2)
|
76
|
+
mime-types (3.2.2)
|
77
|
+
mime-types-data (~> 3.2015)
|
78
|
+
mime-types-data (3.2019.0331)
|
79
|
+
multi_json (1.13.1)
|
80
|
+
multi_test (0.1.2)
|
81
|
+
netrc (0.11.0)
|
82
|
+
path_expander (1.0.4)
|
83
|
+
pry (0.12.2)
|
84
|
+
coderay (~> 1.1.0)
|
85
|
+
method_source (~> 0.9.0)
|
86
|
+
rake (10.5.0)
|
87
|
+
rest-client (2.1.0)
|
88
|
+
http-accept (>= 1.7.0, < 2.0)
|
89
|
+
http-cookie (>= 1.0.2, < 2.0)
|
90
|
+
mime-types (>= 1.16, < 4.0)
|
91
|
+
netrc (~> 0.8)
|
92
|
+
rspec (3.8.0)
|
93
|
+
rspec-core (~> 3.8.0)
|
94
|
+
rspec-expectations (~> 3.8.0)
|
95
|
+
rspec-mocks (~> 3.8.0)
|
96
|
+
rspec-core (3.8.2)
|
97
|
+
rspec-support (~> 3.8.0)
|
98
|
+
rspec-expectations (3.8.4)
|
99
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
100
|
+
rspec-support (~> 3.8.0)
|
101
|
+
rspec-mocks (3.8.1)
|
102
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
103
|
+
rspec-support (~> 3.8.0)
|
104
|
+
rspec-support (3.8.2)
|
105
|
+
ruby_parser (3.13.1)
|
106
|
+
sexp_processor (~> 4.9)
|
107
|
+
sexp_processor (4.12.1)
|
108
|
+
thor (0.20.3)
|
109
|
+
tilt (2.0.9)
|
110
|
+
unf (0.1.4)
|
111
|
+
unf_ext
|
112
|
+
unf_ext (0.0.7.6)
|
113
|
+
|
114
|
+
PLATFORMS
|
115
|
+
ruby
|
116
|
+
|
117
|
+
DEPENDENCIES
|
118
|
+
aruba
|
119
|
+
attractor!
|
120
|
+
bundler (~> 2.0)
|
121
|
+
cucumber
|
122
|
+
pry
|
123
|
+
rake (~> 10.0)
|
124
|
+
rspec (~> 3.0)
|
125
|
+
|
126
|
+
BUNDLED WITH
|
127
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 julianrubisch
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Attractor 
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/attractor`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
TODO: Delete this and the text above, and describe your gem
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'attractor'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install attractor
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
To create a HTML report in `attractor_output/index.html`, try
|
28
|
+
|
29
|
+
$ attractor report
|
30
|
+
|
31
|
+
If you'd like to specify a directory, use the file prefix option:
|
32
|
+
|
33
|
+
$ attractor report --file_prefix app/models
|
34
|
+
|
35
|
+
Or shorter:
|
36
|
+
|
37
|
+
$ attractor report -p app/models
|
38
|
+
|
39
|
+
## CLI Commands and Options
|
40
|
+
|
41
|
+
Print a simple output to console:
|
42
|
+
|
43
|
+
$ attractor calc
|
44
|
+
|
45
|
+
Generate a full report
|
46
|
+
|
47
|
+
$ attractor report
|
48
|
+
$ --file_prefix|-p app/models
|
49
|
+
|
50
|
+
## Development
|
51
|
+
|
52
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
53
|
+
|
54
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/julianrubisch/attractor.
|
data/Rakefile
ADDED
data/attractor.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'attractor/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'attractor'
|
9
|
+
spec.version = Attractor::VERSION
|
10
|
+
spec.authors = ['Julian Rubisch']
|
11
|
+
spec.email = ['julian@julianrubisch.at']
|
12
|
+
|
13
|
+
spec.summary = 'Churn vs Complexity Chart Generator'
|
14
|
+
spec.description = <<-DESCRIPTION
|
15
|
+
Many authors (Michael Feathers, Sandi Metz) have shown that an evaluation of
|
16
|
+
churn vs complexity of files in software projects provide a valuable metric
|
17
|
+
towards code quality. This is another take on the matter, for ruby code, using the
|
18
|
+
`churn` and `flog` projects.
|
19
|
+
DESCRIPTION
|
20
|
+
spec.homepage = 'https://github.com/julianrubisch/attractor'
|
21
|
+
|
22
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
23
|
+
spec.metadata['source_code_uri'] = 'https://github.com/julianrubisch/attractor'
|
24
|
+
spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
|
25
|
+
# spec.metadata['changelog_uri'] = 'https://github.com/julianrubisch/attractor/CHANGELOG.md'
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
+
end
|
32
|
+
spec.bindir = 'exe'
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ['lib']
|
35
|
+
|
36
|
+
spec.add_dependency 'churn'
|
37
|
+
spec.add_dependency 'descriptive_statistics'
|
38
|
+
spec.add_dependency 'flog', '~> 4.0'
|
39
|
+
spec.add_dependency 'thor'
|
40
|
+
spec.add_dependency 'tilt'
|
41
|
+
|
42
|
+
spec.add_development_dependency 'aruba'
|
43
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
44
|
+
spec.add_development_dependency 'cucumber'
|
45
|
+
spec.add_development_dependency 'pry'
|
46
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
47
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
48
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "attractor"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/attractor
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'churn/calculator'
|
4
|
+
require 'csv'
|
5
|
+
require 'date'
|
6
|
+
require 'descriptive_statistics/safe'
|
7
|
+
require 'flog'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'tilt'
|
10
|
+
|
11
|
+
require 'attractor/value'
|
12
|
+
|
13
|
+
module Attractor
|
14
|
+
# calculates churn and complexity
|
15
|
+
class Calculator
|
16
|
+
def self.calculate(file_extension: 'rb', minimum_churn_count: 3, file_prefix: '')
|
17
|
+
churn = ::Churn::ChurnCalculator.new(
|
18
|
+
file_extension: file_extension,
|
19
|
+
file_prefix: file_prefix,
|
20
|
+
minimum_churn_count: minimum_churn_count,
|
21
|
+
start_date: Date.today - 365 * 5
|
22
|
+
).report(false)
|
23
|
+
|
24
|
+
churn[:churn][:changes].map do |change|
|
25
|
+
flogger = Flog.new(all: true)
|
26
|
+
flogger.flog(change[:file_path])
|
27
|
+
complexity = flogger.total_score
|
28
|
+
Value.new(file_path: change[:file_path], churn: change[:times_changed], complexity: complexity)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.output_console
|
33
|
+
values = calculate
|
34
|
+
puts values.map(&:to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.report(format: 'html', file_prefix: '')
|
38
|
+
@values = calculate(file_prefix: file_prefix)
|
39
|
+
|
40
|
+
@suggestions = get_suggestions(@values)
|
41
|
+
|
42
|
+
template = Tilt.new(File.expand_path('../templates/index.html.erb', __dir__))
|
43
|
+
output = template.render self
|
44
|
+
|
45
|
+
FileUtils.mkdir_p './attractor_output'
|
46
|
+
|
47
|
+
case format
|
48
|
+
when 'html'
|
49
|
+
File.open('./attractor_output/index.html', 'w') { |file| file.write(output) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.get_suggestions(values)
|
54
|
+
products = values.map { |val| val.churn * val.complexity }
|
55
|
+
products.extend(DescriptiveStatistics)
|
56
|
+
top_95_quantile = products.percentile(95)
|
57
|
+
|
58
|
+
values.select { |val| val.churn * val.complexity > top_95_quantile }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
require 'attractor'
|
6
|
+
|
7
|
+
module Attractor
|
8
|
+
# contains methods implementing the CLI
|
9
|
+
class CLI < Thor
|
10
|
+
desc 'calc', 'Calculates churn and complexity for all ruby files in current directory'
|
11
|
+
def calc
|
12
|
+
puts 'Calculated churn and complexity'
|
13
|
+
puts
|
14
|
+
puts "file_path#{' ' * 53}complexity churn"
|
15
|
+
puts '-' * 80
|
16
|
+
Attractor::Calculator.output_console
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'report', 'Generates an HTML report'
|
20
|
+
option :format, aliases: :f, default: 'html'
|
21
|
+
option :file_prefix, aliases: :p
|
22
|
+
def report
|
23
|
+
puts 'Generating an HTML report'
|
24
|
+
Attractor::Calculator.report(format: options[:format], file_prefix: options[:file_prefix])
|
25
|
+
puts "Generated HTML report at #{File.expand_path './attractor_output/index.html'}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Attractor
|
4
|
+
# holds a churn/complexity value
|
5
|
+
class Value
|
6
|
+
attr_reader :file_path, :churn, :complexity
|
7
|
+
|
8
|
+
def initialize(file_path: '', churn: 1, complexity: 0)
|
9
|
+
@file_path = file_path
|
10
|
+
@churn = churn
|
11
|
+
@complexity = complexity
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
format('%-64s%8.1f%8i', @file_path, @complexity, @churn)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
{ file_path: file_path, x: churn, y: complexity }
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_json(_opt)
|
23
|
+
to_h.to_json
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/attractor.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<link href="https://fonts.googleapis.com/css?family=Red+Hat+Display|Red+Hat+Text&display=swap" rel="stylesheet">
|
4
|
+
<style type="text/css">
|
5
|
+
body {
|
6
|
+
font-family: "Red Hat Text", sans-serif;
|
7
|
+
}
|
8
|
+
h1 {
|
9
|
+
font-family: "Red Hat Display";
|
10
|
+
text-align: center;
|
11
|
+
font-size: 3rem;
|
12
|
+
text-shadow: deeppink 3px 3px;
|
13
|
+
}
|
14
|
+
#container {
|
15
|
+
display: flex;
|
16
|
+
justify-content: center;
|
17
|
+
flex-direction: column;
|
18
|
+
align-items: center;
|
19
|
+
}
|
20
|
+
#root {
|
21
|
+
width: 600px;
|
22
|
+
}
|
23
|
+
#suggestions {
|
24
|
+
width: 600px;
|
25
|
+
}
|
26
|
+
#suggestions ul {
|
27
|
+
list-style: none;
|
28
|
+
}
|
29
|
+
|
30
|
+
.regression {
|
31
|
+
stroke: black;
|
32
|
+
fill: none;
|
33
|
+
}
|
34
|
+
</style>
|
35
|
+
<title>Attractor Output</title>
|
36
|
+
<script src="https://d3js.org/d3.v5.min.js"></script>
|
37
|
+
<script src="https://unpkg.com/d3-regression@1.2.4/dist/d3-regression.min.js"></script>
|
38
|
+
<script type="text/javascript">
|
39
|
+
const width = 600;
|
40
|
+
const height = 600;
|
41
|
+
|
42
|
+
const margin = ({top: 20, right: 30, bottom: 30, left: 40});
|
43
|
+
|
44
|
+
const data = <%= JSON.generate(@values) %>;
|
45
|
+
|
46
|
+
const color = d3.scaleLog()
|
47
|
+
.domain(d3.extent(data, d => d.x * d.y))
|
48
|
+
.range(["green", "red"]);
|
49
|
+
|
50
|
+
const xScale = d3.scaleLinear()
|
51
|
+
.domain(d3.extent(data, d => d.x)).nice()
|
52
|
+
.range([margin.left, width - margin.right]);
|
53
|
+
|
54
|
+
const yScale = d3.scaleLinear()
|
55
|
+
.domain(d3.extent(data, d => d.y)).nice()
|
56
|
+
.range([height - margin.bottom, margin.top]);
|
57
|
+
|
58
|
+
const xAxis = g => g
|
59
|
+
.attr("transform", `translate(0,${height - margin.bottom})`)
|
60
|
+
.call(d3.axisBottom(xScale))
|
61
|
+
.call(g => g.select(".domain").remove())
|
62
|
+
.call(g => g.append("text")
|
63
|
+
.attr("x", width - margin.right)
|
64
|
+
.attr("y", -4)
|
65
|
+
.attr("fill", "#000")
|
66
|
+
.attr("font-weight", "bold")
|
67
|
+
.attr("text-anchor", "end")
|
68
|
+
.text(data.x));
|
69
|
+
|
70
|
+
const yAxis = g => g
|
71
|
+
.attr("transform", `translate(${margin.left},0)`)
|
72
|
+
.call(d3.axisLeft(yScale))
|
73
|
+
.call(g => g.select(".domain").remove())
|
74
|
+
.call(g => g.select(".tick:last-of-type text").clone()
|
75
|
+
.attr("x", 4)
|
76
|
+
.attr("text-anchor", "start")
|
77
|
+
.attr("font-weight", "bold")
|
78
|
+
.text(data.y));
|
79
|
+
|
80
|
+
const regressionGenerator = d3.regressionPow()
|
81
|
+
.x(d => d.x)
|
82
|
+
.y(d => d.y)
|
83
|
+
.domain([0, d3.max(data, item => item.x)]);
|
84
|
+
|
85
|
+
|
86
|
+
const regressionData = regressionGenerator(data);
|
87
|
+
|
88
|
+
const lineGenerator = d3.line()
|
89
|
+
.x(d => xScale(d[0]))
|
90
|
+
.y(d => yScale(d[1]));
|
91
|
+
|
92
|
+
const svg = d3.create("svg")
|
93
|
+
.attr("viewBox", [0, 0, width, height]);
|
94
|
+
|
95
|
+
const g = svg.append("g");
|
96
|
+
|
97
|
+
g.append("g")
|
98
|
+
.attr("class", "axis")
|
99
|
+
.call(xAxis)
|
100
|
+
.selectAll(".tick line")
|
101
|
+
.classed("baseline", d => d === 0);
|
102
|
+
|
103
|
+
g.append("g")
|
104
|
+
.attr("class", "axis")
|
105
|
+
.call(yAxis)
|
106
|
+
.selectAll(".tick line")
|
107
|
+
.classed("baseline", d => d === 0);
|
108
|
+
|
109
|
+
g.append("g")
|
110
|
+
.attr("stroke-width", 1.5)
|
111
|
+
.attr("font-family", "Red Hat Text")
|
112
|
+
.attr("font-size", 12)
|
113
|
+
.selectAll("g")
|
114
|
+
.data(data)
|
115
|
+
.join("g")
|
116
|
+
.attr("transform", d => `translate(${xScale(d.x)},${yScale(d.y)})`)
|
117
|
+
.call(g => g.append("circle")
|
118
|
+
.attr("fill", d => color(d.x * d.y))
|
119
|
+
.attr("stroke", d => color(d.x * d.y))
|
120
|
+
.attr("r", 4))
|
121
|
+
.call(g => g.append("text")
|
122
|
+
.attr("dy", "0.35em")
|
123
|
+
.attr("x", 7)
|
124
|
+
.text(d => d.file_path))
|
125
|
+
|
126
|
+
g.append("g")
|
127
|
+
.attr("font-family", "Red Hat Text")
|
128
|
+
.attr("font-size", 24)
|
129
|
+
.call(g => g.append("path")
|
130
|
+
.attr("class", "regression")
|
131
|
+
.datum(regressionGenerator(data))
|
132
|
+
.attr("d", lineGenerator))
|
133
|
+
.call(g => g.append("text")
|
134
|
+
.attr("dy", "60")
|
135
|
+
.attr("dx", "33%")
|
136
|
+
.text(`R^2 = ${regressionData.rSquared.toFixed(2)}`))
|
137
|
+
.call(g => g.append("text")
|
138
|
+
.attr("dy", "30")
|
139
|
+
.attr("dx", "33%")
|
140
|
+
.text(`y = ${regressionData.a.toFixed(2)} x ^ ${regressionData.b.toFixed(2)}`));
|
141
|
+
|
142
|
+
document.addEventListener('DOMContentLoaded', () => {
|
143
|
+
document.querySelector('#root').appendChild(svg.node());
|
144
|
+
});
|
145
|
+
</script>
|
146
|
+
</head>
|
147
|
+
<body>
|
148
|
+
<h1>Attractor</h1>
|
149
|
+
<div id="container">
|
150
|
+
<div id="root"></div>
|
151
|
+
<div id="suggestions">
|
152
|
+
<h3>Refactoring Candidates</h3>
|
153
|
+
<h5>Top 95 Percentile of `churn * complexity`</h5>
|
154
|
+
<ul>
|
155
|
+
<% @suggestions.each do |val| %>
|
156
|
+
<li><%= val.file_path %></li>
|
157
|
+
<% end %>
|
158
|
+
</ul>
|
159
|
+
</div>
|
160
|
+
</div>
|
161
|
+
</body>
|
162
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attractor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julian Rubisch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: churn
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: descriptive_statistics
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: flog
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tilt
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: cucumber
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '10.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '10.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
description: |2
|
168
|
+
Many authors (Michael Feathers, Sandi Metz) have shown that an evaluation of
|
169
|
+
churn vs complexity of files in software projects provide a valuable metric
|
170
|
+
towards code quality. This is another take on the matter, for ruby code, using the
|
171
|
+
`churn` and `flog` projects.
|
172
|
+
email:
|
173
|
+
- julian@julianrubisch.at
|
174
|
+
executables:
|
175
|
+
- attractor
|
176
|
+
extensions: []
|
177
|
+
extra_rdoc_files: []
|
178
|
+
files:
|
179
|
+
- ".gitignore"
|
180
|
+
- ".rspec"
|
181
|
+
- ".rubocop.yml"
|
182
|
+
- ".travis.yml"
|
183
|
+
- Gemfile
|
184
|
+
- Gemfile.lock
|
185
|
+
- LICENSE
|
186
|
+
- README.md
|
187
|
+
- Rakefile
|
188
|
+
- attractor.gemspec
|
189
|
+
- bin/console
|
190
|
+
- bin/setup
|
191
|
+
- exe/attractor
|
192
|
+
- lib/attractor.rb
|
193
|
+
- lib/attractor/calculator.rb
|
194
|
+
- lib/attractor/cli.rb
|
195
|
+
- lib/attractor/value.rb
|
196
|
+
- lib/attractor/version.rb
|
197
|
+
- lib/templates/index.html.erb
|
198
|
+
homepage: https://github.com/julianrubisch/attractor
|
199
|
+
licenses: []
|
200
|
+
metadata:
|
201
|
+
homepage_uri: https://github.com/julianrubisch/attractor
|
202
|
+
source_code_uri: https://github.com/julianrubisch/attractor
|
203
|
+
bug_tracker_uri: https://github.com/julianrubisch/attractor/issues
|
204
|
+
post_install_message:
|
205
|
+
rdoc_options: []
|
206
|
+
require_paths:
|
207
|
+
- lib
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - ">="
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: '0'
|
218
|
+
requirements: []
|
219
|
+
rubygems_version: 3.0.3
|
220
|
+
signing_key:
|
221
|
+
specification_version: 4
|
222
|
+
summary: Churn vs Complexity Chart Generator
|
223
|
+
test_files: []
|