Skip to content

Tune Python Remediation Points #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/cc/engine/analyzers/python/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ module Python
class Main < CC::Engine::Analyzers::Base
LANGUAGE = "python"
DEFAULT_PATHS = ["**/*.py"]
DEFAULT_MASS_THRESHOLD = 40
BASE_POINTS = 1000
DEFAULT_MASS_THRESHOLD = 32
BASE_POINTS = 1_500_000
POINTS_PER_OVERAGE = 50_000

def calculate_points(mass)
BASE_POINTS + (overage(mass) * POINTS_PER_OVERAGE)
end

private

def overage(mass)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about assigning a local overage variable directly in #mass, rather than the method call. Names are good, but extra indirection can be bad, and the fact that you have to thread the mass variable down to this private method is a point against IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean in #calculate_points?

That's fine by me...

I think it should be a separate refactor though.

So far, the ruby one uses the same format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to fix later, not to hold up this PR...

Wait, why do these methods exist more than once? Can't they be shared on Base then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes +1

I guess the overage method could already by shared innocuously.

The calculate_points method hasn't been moved yet because 2 of the 4 languages use the old calculate_points formula (base * mass)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculate_points method hasn't been moved yet because 2 of the 4 languages use the old calculate_points formula (base * mass)

Is that intentional? Is the card you're working on fix "Duplication" or fix "Python"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM I'd say Fix python-duplication which is the child of Fix python.

We've been tackling grade tuning on a per-language basis, descending into the language's engines.

Not sure if that's the best approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds good.

mass - mass_threshold
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's mass_threshold? Did you mean DEFAULT_MASS_THRESHOLD here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. OK.

end

def process_file(path)
Node.new(::CC::Engine::Analyzers::Python::Parser.new(File.binread(path), path).parse.syntax_tree, path).format
end
Expand Down
4 changes: 2 additions & 2 deletions spec/cc/engine/analyzers/python/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"path" => "foo.py",
"lines" => { "begin" => 1, "end" => 1 },
})
expect(json["remediation_points"]).to eq(6_000)
expect(json["remediation_points"]).to eq(1_600_000)
expect(json["other_locations"]).to eq([
{"path" => "foo.py", "lines" => { "begin" => 2, "end" => 2} },
{"path" => "foo.py", "lines" => { "begin" => 3, "end" => 3} }
Expand Down Expand Up @@ -56,7 +56,7 @@
"path" => "foo.py",
"lines" => { "begin" => 1, "end" => 1 },
})
expect(json["remediation_points"]).to eq(6_000)
expect(json["remediation_points"]).to eq(1_600_000)
expect(json["other_locations"]).to eq([
{"path" => "foo.py", "lines" => { "begin" => 2, "end" => 2} },
{"path" => "foo.py", "lines" => { "begin" => 3, "end" => 3} }
Expand Down