<commit_before>= Key Performance Indicators

This gem helps you to track key indicators in your Rails app.

Have you even wanted to get daily reports with information:
* how many users registered to my app?
* how many users registered today?
* what is a total revenue today?
* how many times certain event occurred in app?
and so on?

This gem lets you define your application state reports with ease. Look:

== Installation

=== Rails 3.x

Add to your Gemfile:

  gem "kpi"
  
and run in console in project directory:

  $ bundle
  
=== Rails 2.x

This gem is tested with Rails 2.3.8.

== Defining report

Example report in app/models/daily_kpi_report.rb:

  class DailyKpiReport < KPI::Report
    def users_count
      result "Users count", User.count, :description => "Total users count"
    end
    
    def today_registrations_count
      result "Today registrations count", User.where("created_at > ?", @time - 24.hours)
    end
    
    def total_income
      result "Total income", Order.sum(:total), :unit => 'EUR'
    end
    
    def today_income
      result "Total income", Order.where(:created_at => today).sum(:total), :unit => 'EUR'
    end
    
    private
    
    def today
      ((time - 24.hours)..time)
    end
  end

Each defined method should return a KPI::Entry object with following accessors:
* name
* value
* description
* unit

It is important, if your indicator depends on current time (last 24 hours, last week),
to rely on @time instance variable instead of Time.now. This lets you to generate report
for every moment in history:

  report = DailyKpiReport.new(:time => 2.days.ago)

=== Merged reports

You can create merged report from two or more reports of the same type. Look at examples:

    > today = DailyKpiReport.new
    > today.users_count.value
    # => 20
    > today.today_income.value
    # => 350
    > yesterday = DailyKpiReport.new(:time => 1.day.ago)
    > yesterday.users_count.value
    # => 16<commit_msg>Updating README<commit_after>= Key Performance Indicators

This gem helps you to track key indicators in your Rails app.

Have you even wanted to get daily reports with information:
* how many users registered to my app?
* how many users registered today?
* what is a total revenue today?
* how many times certain event occurred in app?
and so on?

This gem lets you define your application state reports with ease. Look:

== Installation

=== Rails 3.x

Add to your Gemfile:

  gem "kpi"
  
and run in console in project directory:

  $ bundle
  
=== Rails 2.x

This gem is tested with Rails 2.3.8.

== Defining report

Example report in app/models/daily_kpi_report.rb:

  class DailyKpiReport < KPI::Report
    def users_count
      result "Users count", User.count, :description => "Total users count"
    end
    
    def today_registrations_count
      result "Today registrations count", User.where("created_at > ?", @time - 24.hours)
    end
    
    def total_income
      result "Total income", Order.sum(:total), :unit => 'EUR'
    end
    
    def today_income
      result "Total income", Order.where(:created_at => today).sum(:total), :unit => 'EUR'
    end
    
    private
    
    def today
      ((time - 24.hours)..time)
    end
  end

Each defined method should return a KPI::Entry object with following accessors:
* name
* value
* description
* unit

A collection of KPI::Entry is available through Enuberable: Report#entries

It is important, if your indicator depends on current time (last 24 hours, last week),
to rely on @time instance variable instead of Time.now. This lets you to generate report
for every moment in history:

  report = DailyKpiReport.new(:time => 2.days.ago)

=== Merged reports

You can create merged report from two or more reports of the same type. Look at examples:

    > today = DailyKpiReport.new
    > today.users_count.value
    # => 20
    > today.today_income.value
    # => 350
    > yesterday = DailyKpiReport.new(:time => 1.day.ago)
    > yesterday.users_count.value
    # => 16
{'fraction_non_alphanumeric': 0.08558558558558559, 'fraction_numerical': 0.01001001001001001, 'mean_word_length': 3.180962343096234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1292981', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1160, 'n_words': 473}