Skip to content
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

Decouple measuring of results from reporting results using formatters. #94

Merged
merged 25 commits into from
Jul 16, 2013

Conversation

robincurry
Copy link
Member

The idea here is to use similar approach that you see in libraries like simplecov, rspec or cucumber, where you can specify different formats (either pre-built or custom) from the command-line.

So, you could do something like:

metric_fu -r --format json --out '/path/to/output.json'

or

metric_fu -r --format html --format csv --out '/path/to/my.csv'

or perhaps even something like...

metric_fu -r --format redis

I think it opens up some interesting possibilities.

My intent is to keep everything backward-compatible (and I think so far, so good), so running metric_fu without specifying a format will use the built-in html formatter which uses the awesome templating / graphing stuff and produces your standard metric_fu report.

end
end
end
# TODO: Can we just remove this? Doesn't seem to be used and causes
Copy link
Member

Choose a reason for hiding this comment

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

yes. feel free to switch out the internals of the cli option parsing however you like

@bf4
Copy link
Member

bf4 commented Jul 5, 2013

In terms of directory structure as we move forward, here are my thoughts beyond what I've written elsewhere Also see my config PR and grapher PR

 lib/
    metric_fu.rb
    metric_fu_requires.rb
    metric_fu/
                   configuration.rb # contains MetricConfig
                     # which contains all the configuration info for each metric
                     # is in a collection of configured metrics in the Configuration
                     # has :configure method that sets the metric_name, metric_conf, if gaphed, when skipped/activated
                     # MetricFu::ChurnConfig
                   metric.rb # was generator, is interface for running, analyzing, formatting, outputting metrics
                   metrics/
                     MetricFu::Churn < MetricFu::Metric
                       churn/ 
                          config.rb # MetricFu::ChurnConfig
                       hotspots/
                         config.rb
                         analyzer/ # 
                   runner.rb # === generator :emit base used by each metric
                   formatter.rb # === generator :analyze / :to_h base used by each metric
                   environment.rb # contains info about ruby environs e.g. rails? mri? supports_ripper? 192?
                   file_system_operations.rb # ensure directories exists, knows code_dirs
                   report.rb # uses current results and historical
                     report/template.rb 
                     report/html_template.rb
                   graph
                     graph/grapher.rb
                   logger.rb
                   cli.rb
                     cli/etc.
                   parser.rb # has helpers that can get class and method name for a line number
                   run.rb / controller.rb # coordinates configuring, running, formatting, and outputting metrics
  tasks/
    metric_fu.rake
.metrics

Part of doing this is to not make the Configuration object create methods and instance variables everywhere. Each metric can configure itself and add itself to metric_fu (allows for plugins).

@robincurry
Copy link
Member Author

Directory structure seems reasonable to me. I think a lot of the templating/graphing stuff could move underneath formatter (i.e. /lib/metric_fu/formatter/html/templates/ and /lib/metric_fu/formatter/html/graphs/). What do you think?

@bf4
Copy link
Member

bf4 commented Jul 13, 2013

yes

On Sat, Jul 13, 2013 at 10:54 AM, Robin Curry notifications@github.comwrote:

Directory structure seems reasonable to me. I think a lot of the
templating/graphing stuff could move underneath formatter (i.e.
/lib/metric_fu/formatter/html/templates/ and
/lib/metric_fu/formatter/html/graphs/). What do you think?


Reply to this email directly or view it on GitHubhttps://github.com//pull/94#issuecomment-20921867
.

@bf4
Copy link
Member

bf4 commented Jul 14, 2013

Looking good. Lemme know if you want to chat about this here, on skype, or elsewhere

@robincurry
Copy link
Member Author

Cool, yeah. Anytime here, or I'm usually on gtalk (robin.curry@gmail.com) during the day and off and on in the evenings.

Now that the builds are passing, I think I've just about wrapped up what I had in mind on this pending any additional feedback you might have.

@bf4
Copy link
Member

bf4 commented Jul 14, 2013

I honestly want to 1) not have long-running branches 2) release code right
now that either adds features, fixes bugs, or doesn't break anything... so,
merging is good.. did you update the docs / README?

@robincurry
Copy link
Member Author

Ok, took a stab at updating README and HISTORY. Let me know if you need me to modify anything. Thanks @BJ4!

@bf4
Copy link
Member

bf4 commented Jul 15, 2013

Try running with RUBY_OPTS=-w or see here for warnings to address

btw, you got my handle wrong above; I'm bf4 :)

I'm looking at the commits now

@ghost ghost assigned robincurry Jul 15, 2013
@@ -71,6 +77,14 @@ def process!(arguments = ARGV)
validate(@result) if self.respond_to?("validate")
@result
end

def format_descriptions
Copy link
Member

Choose a reason for hiding this comment

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

Please add comment what this method does

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do!

Copy link
Member

Choose a reason for hiding this comment

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

So, in YaRDoc format, I believe this would be return, see example

# Build a nicely formatted list of built-in
# formatter keys and their descriptions
# @see MetricFu::Formatter::BUILTIN_FORMATS
# @example "  yaml :  ['MetricFu::Formatter::YAML', 'Generates the raw output as yaml']"
# @return [Array<String>] in the form of 
#    "   <key>  : <description>."
def format_descriptions

grapher_name = graph_type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } + graph_engine.to_s.capitalize + "Grapher"
self.clazz.push MetricFu.const_get(grapher_name).new
self.clazz.push MetricFu.const_get(grapher_name).new.tap{|g| g.output_directory = output_directory }
Copy link
Member

Choose a reason for hiding this comment

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

Don't you want to use constantize here, now that you've introduced it?

BTW, I hope we can soon clean up how hard to read the code is in this method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, indeed. Was just trying to limit changes to code outside of the realms of the PR.

@bf4
Copy link
Member

bf4 commented Jul 15, 2013

I've made a bunch of comments. This is awesome! You now have commit access when you feel ready to merge it in.

@robincurry
Copy link
Member Author

Ack! Sorry about the handle mistake. The perils of late night coding!

@bayleedev
Copy link

👍


# To configure different formatter(s) or output ...
# MetricFu::Configuration.run do |config|
# config.add_formatter(:html)
Copy link
Member

Choose a reason for hiding this comment

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

Probably has:

require 'metric_fu/formatter/my_custom'

@bf4
Copy link
Member

bf4 commented Jul 16, 2013

This is so awesome. Great work and great code!

@bf4
Copy link
Member

bf4 commented Jul 16, 2013

Got an error running tests on cruby 2.0.0-p195 on mac osx leopard via rvm

Failures:

1) MetricFu::Formatter::HTML In general creates a report yaml file
 Failure/Error: expect {
   The file "tmp/metric_fu/report.yml" existed before, so this test doesn't work
 # ./spec/metric_fu/formatter/html_spec.rb:23:in `block (3 levels) in <top (required)>'

And I see RailsBestPractices now has active_support as a dependency. Ugh

@robincurry
Copy link
Member Author

Hrm. Running the same locally and seems ok. As well as on travis. Happen to catch an rspec seed? Maybe order dependent? Something not getting cleaned up in a previous spec?

@bf4
Copy link
Member

bf4 commented Jul 16, 2013

Dunno, didn't see a seed. Passed again for me. Ran with order='random', got failures with seeds: 61176, 18737

@robincurry
Copy link
Member Author

Well, I've run the specs a good 20-30 times and can't seem to reproduce the spec failure. I'm going to go ahead and merge but I'll keep a close eye on it. I know there's nothing worse than an intermittent failing spec.

robincurry added a commit that referenced this pull request Jul 16, 2013
Decouple measuring of results from reporting results using formatters.
@robincurry robincurry merged commit a740d80 into metricfu:master Jul 16, 2013
@robincurry robincurry deleted the formatter branch July 16, 2013 19:15
@bf4
Copy link
Member

bf4 commented Jul 16, 2013

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants