Class: SprintReport
- Inherits:
-
Object
- Object
- SprintReport
- Defined in:
- app/models/sprint_report.rb
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, start_date, end_date) ⇒ SprintReport
constructor
A new instance of SprintReport.
- #to_a ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(user, start_date, end_date) ⇒ SprintReport
Returns a new instance of SprintReport.
4 5 6 7 8 |
# File 'app/models/sprint_report.rb', line 4 def initialize(user, start_date, end_date) @user = user @start_date = start_date @end_date = end_date end |
Instance Attribute Details
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
2 3 4 |
# File 'app/models/sprint_report.rb', line 2 def end_date @end_date end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
2 3 4 |
# File 'app/models/sprint_report.rb', line 2 def start_date @start_date end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
2 3 4 |
# File 'app/models/sprint_report.rb', line 2 def user @user end |
Instance Method Details
#to_a ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/sprint_report.rb', line 14 def to_a User.connection.select_rows(" SELECT\n sprints.end_date,\n SUM(completed.effort),\n SUM(checked_out.effort)\n FROM sprints\n\n LEFT OUTER JOIN (\n SELECT\n sprints_tasks.sprint_id,\n SUM(tasks.effort) \"effort\"\n FROM sprints_tasks\n INNER JOIN tasks ON sprints_tasks.task_id=tasks.id\n INNER JOIN sprints ON sprints_tasks.sprint_id=sprints.id\n WHERE COALESCE(tasks.first_commit_at, tasks.completed_at) BETWEEN sprints.end_date - interval '6 days' AND sprints.end_date + interval '1 day'\n \#{\"AND sprints_tasks.checked_out_by_id=\#{user.id}\" if user}\n GROUP BY sprints_tasks.sprint_id\n ) AS completed\n ON completed.sprint_id=sprints.id\n\n LEFT OUTER JOIN (\n SELECT\n sprints_tasks.sprint_id,\n SUM(tasks.effort) \"effort\"\n FROM sprints_tasks\n INNER JOIN tasks ON sprints_tasks.task_id=tasks.id\n \#{\"WHERE sprints_tasks.checked_out_by_id=\#{user.id}\" if user}\n GROUP BY sprints_tasks.sprint_id\n ) AS checked_out\n ON checked_out.sprint_id=sprints.id\n\n WHERE sprints.end_date BETWEEN '\#{start_date.strftime \"%Y-%m-%d\"}' AND '\#{end_date.strftime \"%Y-%m-%d\"}'\n GROUP BY sprints.end_date\n ORDER BY sprints.end_date ASC\n SQL\n .map { |(date, completed, checked_out)|\n [ date.to_date,\n completed.to_f,\n checked_out.to_f - completed.to_f ] }\nend\n") |
#to_json ⇒ Object
10 11 12 |
# File 'app/models/sprint_report.rb', line 10 def to_json to_a.to_json end |