tombenner / reports_kit

Beautiful, interactive charts and tables for Ruby on Rails
https://reportskit.co
MIT License
362 stars 31 forks source link

[Need help] How to create report with Hour (1 .. 24 hours) in Y axis and Date(Created At) in X axis #22

Open kirantpatil opened 6 years ago

kirantpatil commented 6 years ago

Hi,

I would like to create report where I need to know how many users created in which hour of the day.

Ex: If 2 users created at 1:10 pm and 1:20 pm, then I would like to show them on the map between 1 and 1:30 pm.

Usecase is to find the busiest hours of the day.

Thanks.

tombenner commented 6 years ago

Hm, I'm unclear about exactly what data you want to see here. Below is a guess at what you want, but if it's incorrect, could you provide a similar ASCII chart indicating what you want?

      5           |
      4           |
Count 3 |     |   |
      2 |     | | |
      1 |     | | |
        0 1 2 3 4 5 ... 23
            Hour of day

The above shows the number of users created by hour of the day. To generate it, you would use a custom dimension: https://www.reportskit.co/examples/dimension_custom_dimension

The custom dimension would be defined using raw SQL in your model (the following is for Postgres; you would have to adjust the SQL for other database technologies):

class User < ApplicationRecord
  include ReportsKit::Model
  reports_kit do
    dimension :hour_of_day, group: 'EXTRACT(HOUR FROM users.created_at)'
  end
end

The YAML would be similar to what's shown in the documentation:

measure: user
dimensions:
- hour_of_day
kirantpatil commented 6 years ago

@tombenner, thanks a lot, I will try it and get back to you.

smitakiran25 commented 6 years ago

Hi, I would like to create where i need to display how many incidents created in each hour i tried to created each day how many incidents created that is coming properly

screenshot from 2018-01-05 12-50-24

I would like to display in hours but its not coming properly the incidents has to display based on the hours (in 1pm how many incidents created 2.30 how many incidents created like that ) screenshot from 2018-01-05 13-06-33

i also sent that incident created details screenshot from 2018-01-05 13-05-39

and also tell me how to display hours or days in order

kirantpatil commented 6 years ago

@tombenner, your ascii representation is correct.

For us as you can see above created_at is in IST. The hours should have been 2, 5, 4, 12 but we are seeing 11, 9, 6, 12, 8.

Also graph is ordered based on count in ascending order rather on hour/day.

Where do we need to modify the code to get day/hour ordered and proper hours which are in IST ?

Thanks.

iACM1994 commented 5 years ago

Hi,

I would like to get reports for each days requested_at.

currently, it show reports for 7 days.

image

how should I write in dimensions: ?

and also for the aggregation of amount for each days, how to achieve it?

/reports_kit/reports/report_sales.yml

measure: 
  key: sale
  aggregation: sum_of_grand_total
dimensions:
- key: requested_at
  limit: 5
- key: payment_status
  limit: 3

in model

include ReportsKit::Model
reports_kit do
        aggregation :sum_of_grand_total, [:sum, 'grand_total']
end