Commit 7a7e0602 authored by Coraline Ada Ehmke's avatar Coraline Ada Ehmke

Extension to detect arg clumps

parent accdf8c2
......@@ -12,6 +12,7 @@ require_relative "snuffle/formatters/csv"
require_relative "snuffle/formatters/html"
require_relative "snuffle/formatters/html_index"
require_relative "snuffle/formatters/text"
require_relative "snuffle/args_clump"
require_relative "snuffle/latent_object"
require_relative "snuffle/line_of_code"
require_relative "snuffle/node"
......
module Snuffle
class Cohort
include PoroPlus
attr_accessor :element, :neighbors, :line_numbers
def self.from(nodes)
nodes = nodes.non_sends.hashes
clumps = Element::Hash.materialize(nodes.to_a).inject([]) do |cohorts, element|
clump = ArgsClump.new(args: element.args, line_numbers: element.node.line_numbers )
if clump.values.count > 1 && clump.near_neighbors.count > 0
clumps << clump
end
clumps
end
end
def has_near_neighbors?
near_neighbors.present?
end
def near_neighbors
@near_neighbors ||= neighbors.select{ |n| (n.args & args).size == args.size }
end
def neighbors
@neighbors ||= [element.node.siblings - [self.element.node]].flatten.map{|sibling| Element::Hash.materialize([sibling]).first}
end
def args
@args ||= self.element.args
end
def neighbor
Struct.new(:element, :distance)
end
def distance(primary_matrix, token_matrix)
Snuffle::Util::Correlation.distance(primary_matrix, token_matrix)
end
end
end
\ No newline at end of file
......@@ -36,7 +36,6 @@ module Snuffle
def report(summary, source)
text_report(summary)
cvs_report(summary)
end
def create_html_index(summaries, start_path)
......
......@@ -39,8 +39,7 @@ module Snuffle
end
def filename
base = "#{summary.filename}"
base + file_extension
"#{summary.filename}" + file_extension
end
def file_extension
......
......@@ -74,7 +74,7 @@
%div.column
%h3.indented.highlighted
Data Clumps:
- if summary.cohorts.count == 0
- if summary.cohorts.count == 0 && summary.arg_clumps.count == 0
%p.indented
%em None
- else
......@@ -87,6 +87,14 @@
(line
= ":#{cohorts.map(&:line_numbers).join(', :')}"
)
- summary.arg_clumps.group_by{|c| c.values.sort }.each do |values, clumps|
- if clumps.count > 0
%li
= values.map{|c| ".#{c}" }.join(", ")
%br
(line
= ":#{clumps.map(&:line_numbers).join(', :')}"
)
%div.column
%h3.indented.highlighted-method
Possible Latent Objects:
......
......@@ -5,7 +5,7 @@ module Snuffle
include Ephemeral::Base
include PoroPlus
attr_accessor :id, :name, :type, :child_ids, :parent_id, :line_numbers
attr_accessor :id, :name, :type, :child_ids, :parent_id, :line_numbers, :args
scope :by_id, lambda{|id| where(:id => id)}
scope :by_type, lambda{|type| where(:type => type)}
......
......@@ -73,6 +73,14 @@ module Snuffle
@ast ||= Parser::CurrentRuby.parse(source)
end
def extracted_args(ast_node)
begin
ast_node.children[1].children.map{|child| child.children}.flatten
rescue
[]
end
end
def extract_nodes_from(ast_node, nodes=Ephemeral::Collection.new("Snuffle::Node"), parent_id=:root)
if name = name_from(ast_node)
if ast_node.respond_to?(:type)
......@@ -81,7 +89,8 @@ module Snuffle
type: ast_node.type,
parent_id: parent_id,
name: name,
line_numbers: lines.map(&:line_number)
line_numbers: lines.map(&:line_number),
args: extracted_args(ast_node)
)
else
extracted_node = Snuffle::Node.new(
......
......@@ -2,51 +2,41 @@ class Customer
attr_accessor :customer_id, :customer_name, :company_name
attr_accessor :street_address_1, :street_address_2
# attr_accessor :city, :state, :postal_code
attr_accessor :city, :state, :postal_code, :phone_number
MY_CONSTANT = "TheOtherZachIsThePrimaryZach"
def self.api_root
end
def my_condition
puts "MAGIC" if true == false
"http://localhost/api/"
end
def address_is_residence?
self.company_name.nil?
end
def get_coords_for_address
# fake_api_call(city: city, state: state, postal_code: postal_code)
end
def neighborhood
make_neighborhood_api_call(state: self.state, city: self.city, postal_code: self.postal_code)
end
def something_else
# fake_neighborhood_api_call(city: self.city, state: self.state)
NeighborhoodApi.post(
state: self.state,
city: self.city,
postal_code: self.postal_code
).results[:neighborhood]
end
def and_something_else_again
fake_neighborhood_api_call(city: self.city)
def verified_state
NeighborhoodApi.post(
city: self.city,
postal_code: self.postal_code
).results[:state]
end
def and_something_else_again_and_again
fake_neighborhood_api_call(state: self.state)
end
def fake_neighborhood_api_call(args={})
"Probably River North"
end
def fake_api_call(args={})
[112.32, 124.11]
def verified_country
NeighborhoodApi.post(
state: self.state,
).results[:country]
end
def business_card_api_call
{name: customer_name, business: company_name}
{name: customer_name, business: company_name, phone: phone_number}
end
def letterhead_api_call
......@@ -63,7 +53,7 @@ class Customer
string << self.company_name if address_is_residence?
string << self.street_address_1
string << self.street_address_2 if street_address_2.present?
# string << "#{self.city}, #{self.state} #{self.postal_code}"
string << "#{self.city}, #{self.state} #{self.postal_code}"
string.join", "
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment