{"id":15648021,"url":"https://github.com/accessd/models_stats","last_synced_at":"2025-04-30T08:23:00.067Z","repository":{"id":23717650,"uuid":"27090397","full_name":"accessd/models_stats","owner":"accessd","description":"Charts for your rails models with MetricsGraphics.js and NVD3","archived":false,"fork":false,"pushed_at":"2015-01-09T10:39:16.000Z","size":778,"stargazers_count":42,"open_issues_count":2,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-26T13:41:58.675Z","etag":null,"topics":["activerecord","collect-statistics","graphics","metricsgraphics","nvd3","rails","ruby","statistics"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/accessd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-24T19:06:40.000Z","updated_at":"2024-03-21T16:13:34.000Z","dependencies_parsed_at":"2022-08-20T13:10:39.758Z","dependency_job_id":null,"html_url":"https://github.com/accessd/models_stats","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessd%2Fmodels_stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessd%2Fmodels_stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessd%2Fmodels_stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessd%2Fmodels_stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/accessd","download_url":"https://codeload.github.com/accessd/models_stats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251666977,"owners_count":21624412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","collect-statistics","graphics","metricsgraphics","nvd3","rails","ruby","statistics"],"created_at":"2024-10-03T12:22:46.576Z","updated_at":"2025-04-30T08:23:00.044Z","avatar_url":"https://github.com/accessd.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ModelsStats\n\nGraphics for your rails models. It may show count(or average, or sum, or another sql agregate function) of models for each day with grouping, conditions.\n\nFor graphics it uses for your choice [MetricsGraphics.js](https://github.com/mozilla/metrics-graphics) or/and [NVD3](http://nvd3.org/).\n\nDependencies: [Redis](http://redis.io/) for store statistics.\n[D3](http://d3js.org/), [jQuery](http://jquery.com/), [Bootstrap](http://getbootstrap.com/) it's dependencies of MetricsGraphics.js.\n\nPreview:\n\nNVD3:\n\n![ScreenShot](https://raw.github.com/accessd/models_stats/master/doc/img/nvd3_example.png)\n\n![ScreenShot](https://raw.github.com/accessd/models_stats/master/doc/img/nvd3_users_example.png)\n\nMetricsGraphics.js\n\n![ScreenShot](https://raw.github.com/accessd/models_stats/master/doc/img/mg_example.png)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'models_stats', github: 'accessd/models_stats'\n```\n\nAnd then execute:\n\n    $ bundle\n\nIn your application.js manifest:\n\n    //= require models_stats/nvd3\n\nor/and\n\n    //= require models_stats/metrics_graphics\n\nif you want use MetricsGraphics.\n\nIn your application.css.scss manifest:\n\n    //= require models_stats/nvd3\n\nor/and\n\n    //= require models_stats/metrics_graphics\n\nif you want use MetricsGraphics.\n\nAlso if you use MetricsGraphics.js you must have [jQuery](http://jquery.com/) and [Bootstrap](http://getbootstrap.com/) js/css included.\n\n\n## Usage\n\n### Configuration\n\nAdd config file `config/models_stats.yml`, for example:\n\nminimal configuration:\n\n```yaml\n  ---\n  - total_users:\n      description: \"Total users\"\n      model: User\n```\n\nit would be calculate total users for day.\n\nEnhanced configuration:\n\n```yaml\n  ---\n  - total_links_by_error_types: # Statistics alias, must be uniq\n      description: \"Total links by error types\"\n      model: Link\n      datetime_attr: :created_at # Date or datetime attribute, allows to calculate the count of models per day\n      group_by: :error_type_id\n      conditions: \"error_type_id != \u003c%= Link::NO_ERROR %\u003e\"\n      group_by_values_map: \u003c%= ModelsStats.convert_hash_to_yaml(Link::ERROR_NAMES) %\u003e # for example maping integer field to text representation\n      graph_width: 430\n      graph_height: 140\n      graphic_lib: nvd3 # By default, or can be metrics_graphics\n      graphic_type: stacked # It's can be using with nvd3, by default line\n      date_tick: day # By default, or can be month or week\n      date_format: '%d/%m' # By default is %x, more information about formattting time available at https://github.com/mbostock/d3/wiki/Time-Formatting\n  - average_by_keyword_positions:\n      description: \"Average by keyword positions\"\n      select_statement: \"AVG(google_position) AS count\" # Right here you may specify select query, `count` alias for function required\n      model: KeywordPosition\n```\n\nIf you want using specific redis for store statistics, set it in `config/initializers/models_stats.rb`, for example:\n\n    ModelsStats.redis_connection = Redis.new(host: '127.0.0.1', port: 6379, db: 5)\n\nDefault graphics library can be configured through:\n\n    ModelsStats.default_lib_for_graphics = :nvd3 # Or metrics_graphics\n\nDefault graphics type:\n\n    ModelsStats.default_graphics_type = :line # Or stacked\n\nDefault graph width:\n\n    ModelsStats.default_graphics_width = 500\n\nDefault graph height:\n\n    ModelsStats.default_graphics_height = 120\n\nDefault date tick:\n\n    ModelsStats.default_date_tick = :day # Or month, week\n\nDefault date format:\n\n    ModelsStats.default_date_format = '%d/%m'\n\nFor the full list of directives for formatting time, refer to [this list](https://github.com/mbostock/d3/wiki/Time-Formatting)\n\n### Collecting statistics\n\nAdd to your crontab(may use [whenever](https://github.com/javan/whenever)) rake task `models_stats:collect_stat_for_yesterday`, run it at 00:00 or later and it will collect statistics for yesterday.\nFor collecting statistics for last month run rake task `models_stats:collect_stat_for_last_month`.\nAlso you may collect statistics for specific date and config, for example:\n\n```ruby\n  date = 2.days.ago.to_date\n  statistics_alias = 'total_links_by_error_types' # statistic alias which you define in `config/models_stats.yml`\n  ModelsStats::StatisticsCollector.new.collect(statistics_alias, date) # By default date is yestarday\n```\n\n### Clear statistics\n\nYou may clear statistics data for particular alias.\n\n```ruby\n  c = ModelsStats::StatisticsCollector.new\n  c.clear_all_data('total_links_by_error_types')\n```\n\n### Display graphics\n\nIn your views use helpers:\n\nRender single graphic for total_links_by_error_types statistic alias(which you define in `config/models_stats.yml`) and last week:\n\n    = render_models_stats_graph('total_links_by_error_types', 1.week, 800, 200) # By default period is 1.month\n\nWith two last parameters you can customize width and height of the chart. In this case it will be 800px and 200px.\n\nRender all defined graphics splited by two columns - first for new models count, second for total models count\n\n    = render_models_stats_dashboard\n\n## Contributing\n\n1. Fork it ( https://github.com/accessd/models_stats/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccessd%2Fmodels_stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faccessd%2Fmodels_stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccessd%2Fmodels_stats/lists"}