codesnik / calculate-all Goto Github PK
View Code? Open in Web Editor NEWcalculate_all method for aggregate functions in Active Record
License: MIT License
calculate_all method for aggregate functions in Active Record
License: MIT License
Hi and thanks for this great gem.
There is one issue I am seeing when used together with groupdate
. The resulting hash's keys are always DateTimes (e.g. 2018-01-03 00:00:00 UTC
) no matter format
parameter is given to groupdate
. See https://github.com/ankane/groupdate#keys. It seems that the format is overwritten somewhere?
Example without calculate_all
:
User.group_by_day(:created_at, format: "%d.%m").count
=> {"16.07"=>147, "17.07"=>1049, "18.07"=>885, "19.07"=>957, "20.07"=>1195, "21.07"=>1123, "22.07"=>1249, "23.07"=>304}
But with calculate_all
:
User.group_by_day(:created_at, format: "%d.%m").calculate_all(:count)
=> {2018-07-15 22:00:00 UTC=>146, 2018-07-16 22:00:00 UTC=>1049, 2018-07-17 22:00:00 UTC=>885, 2018-07-18 22:00:00 UTC=>957, 2018-07-19 22:00:00 UTC=>1195, 2018-07-20 22:00:00 UTC=>1123, 2018-07-21 22:00:00 UTC=>1249, 2018-07-22 22:00:00 UTC=>304}
This is great gem especially when combined with groupdate. Is there anyway to get it to format multie aggregates when used with groupdate so that it will work with chartkick?
Have you checked it against Rails 5? After running the following:
Feed.all.calculate_all(:visits_count)
I get:
fatal: exception reentered
from /home/vasilakisfil/.rvm/gems/ruby-2.3.1/gems/pry-0.10.4/lib/pry/pry_instance.rb:355:in `eval'
Feed is a relatively simple model.
Just a quick note, I tried CalculateAll with groupdate 4.1.1 and noticed it didn't show dates when there are empty values, then I tried version 3.2.1 and got it working as expected, but it would be nice to have the improvements in v4.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.