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
end2. 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 usersI18n
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"GitHub Models Prompts
metricdeck includes reusable AI prompts in .github/prompts/ for use with GitHub Models.
| Prompt | Purpose |
|---|---|
analyze-metric-card |
Deep-dive analysis of a single metric card |
compare-metric-cards |
Cross-metric correlation and trade-off analysis |
dashboard-summary |
Executive summary of a full dashboard |
generate-calculator-ideas |
AI-assisted brainstorming for new calculators |
metric-health-check |
Audit metrics for data quality issues |
Usage
- Go to GitHub Models
- Load a
.prompt.ymlfile from this repo - Paste your metric JSON in the
{{variable}}placeholders - Run the prompt against your chosen model
Customizing
Copy any .prompt.yml and adjust the model or modelParameters to suit your needs. See GitHub Docs for the full prompt file specification.
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:
service = Metricdeck::MetricCardService.new(namespace: Statistics::Calculators)