Last active
October 3, 2020 23:59
-
-
Save yoomlam/bf720a75fad832d934323a6e09654eb1 to your computer and use it in GitHub Desktop.
Dispatched AMA Appeals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subq1=select([ | |
func.date_trunc('month', tasksT.columns['closed_at']).label('closed_month'), | |
tasksT.c.appeal_type, | |
tasksT.c.appeal_id | |
])\ | |
.where(and_( | |
tasksT.c.type.in_(['BvaDispatchTask']), | |
tasksT.c.status == 'completed', | |
tasksT.c.closed_at > '2018-10-01 04:00:00' | |
))\ | |
.group_by(tasksT.c.appeal_id, tasksT.c.appeal_type, 'closed_month')\ | |
.order_by(tasksT.c.appeal_id) | |
dispatchesQ=subq1.alias('dispatchesByMonth') | |
stmt=select([func.to_char(dispatchesQ.c.closed_month, 'YYYY-mm').label('monthStr'), | |
dispatchesQ.c.appeal_type, | |
func.count().label('count')])\ | |
.group_by(text("1"), text("2"))\ | |
.order_by(text("1"), text("2")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
span=Time.new(2018,10)..Time.new(2019,10)-1 | |
BvaDispatchTask.where(status: :completed, closed_at: span, appeal_type: :Appeal).group(:appeal_id).count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT month, appeal_type, count(*) | |
FROM ( | |
SELECT | |
DATE_TRUNC('month', closed_at) AS month | |
, appeal_type ,appeal_id | |
FROM tasks | |
WHERE type IN ('BvaDispatchTask') | |
AND status = 'completed' | |
AND closed_at > '2018-10-01 04:00:00' | |
GROUP BY appeal_id, appeal_type, month | |
) as subq | |
GROUP BY 1, 2 | |
ORDER BY 1, 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment