Coder Social home page Coder Social logo

prosperity's Introduction

Prosperity

Build Status

Prosperity easily lets you add a dashboard of arbitrary time series data to your rails app. Is lets you easily graph anything that changes over time using your existing ActiveRecord scopes or raw SQL.

This is still a work in progress, but it should already make it much easier to create dashboard withing your Rails app. Currently only tested with PostgreSQL, but should be easily portable to other DBs.

Screenshot

Install

Add this line to your application's Gemfile:

gem 'prosperity'

And then execute:

bundle
bundle exec rake db:migrate

Add a route to prosperity in config/routes.rb.

mount Prosperity::Engine => "/prosperity"

Usage

You can then generate your first metric.

rails g metric Users

This will generate app/prosperity/user_metric.rb

You can add custom scopes like so:

class UsersMetric < Prosperity::Metric
  scope { User }

  option 'active' do |scope|
    scope.where(state: 'active')
  end
end

By default, Prosperity will return a count of object grouped by period. You can also use other aggragation function such as minimum, maximum, average and sum.

You can use them as follow:

class UsersMetric < Prosperity::Metric
  scope { User.join(:subsriptions) }
  aggregate { sum(:price_in_cents) }
end

SQL support

Prosperity also supports raw SQL in queries.

class UsersMetric < Prosperity::Metric
  sql "SELECT * FROM users"
  group_by "created_at"
  aggregate { "SUM(value)" }
end

Unfortunately, there's currently a few limitations to SQL bases queries. PR to fix those are more than welcome :)

Ruby support

Sometime it's hard to get the data you want in plain SQL, or you might want to get data from somewhere other than your DB, like a from an API.

The ruby syntax is a way for you to define the value or something for a given point in the graph. This should return the total value of the metric you want to measure and the change and interval and change metrics will be calculated from that value.

Currently, there's no support for options, although this will likely change in the future.

class RubyUsersMetric < Prosperity::Metric
  value_at do |time, period, *|
    User.where("users.created_at <= ?", time).count
  end
end

Development

To get started with a development environment with pow, follow these instructions;

git clone https://github.com/smathieu/prosperity.git
ln -s `pwd`/prosperity/spec/dummy ~/.pow/prosperity
cd prosperity
bundle
rake db:create db:migrate RAILS_ENV=test
rake db:seed

and to run the tests;

bundl exec rspec

License

This project rocks and uses MIT-LICENSE.

TODO

See Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.