metricdeck
A pluggable metric card framework for Ruby on Rails applications.
Installation
Add to your Gemfile:
gem 'metricdeck'
Usage
1. Create a calculator
# app/metrics/calculators/users_calculator.rb
module Metrics
module Calculators
class UsersCalculator
include Metricdeck::Calculators::BaseCalculator
include Metricdeck::Helpers::CardHelpers
def validate_context(context)
# optional validation
end
def perform_calculation(context)
current = User.active.count
previous = User.active.where('created_at <= ?', 1.month.ago).count
create_metric_card(
card_id,
value: current,
current: current,
previous: previous
)
end
end
end
end
2. Fetch metric cards
service = Metricdeck::MetricCardService.new(namespace: Metrics::Calculators)
cards = service.get_cards({ employee_id: 42 })
3. Generate a calculator
rails g metricdeck:calculator users
I18n
Add translations under:
en:
metricdeck:
cards:
users:
title: "Active Users"
unit: "users"
comparisons:
previous_period: "vs previous period"
last_month: "vs last month"
last_year: "vs last year"
Migrating from Athar EMS People Service
If you're migrating from the internal Statistics module in the Athar EMS people service:
- Replace
Statistics::Calculators::BaseCalculatorwithMetricdeck::Calculators::BaseCalculator - Replace
Statistics::Helpers::CardHelperswithMetricdeck::Helpers::CardHelpers - Replace
Statistics::Helpers::DateHelperswithMetricdeck::Helpers::DateHelpers - Replace
Statistics::MetricCardServicewithMetricdeck::MetricCardService - Replace
Statistics::MetricCardwithMetricdeck::MetricCard - Update i18n keys from
statistics.*tometricdeck.* - Pass your calculator namespace explicitly:
ruby service = Metricdeck::MetricCardService.new(namespace: Statistics::Calculators)