Skip to content

Commit

Permalink
Merge pull request #325 from DNO-inc/bodya
Browse files Browse the repository at this point in the history
update event_init.sql
  • Loading branch information
m-o-d-e-r authored Mar 22, 2024
2 parents a5eeee9 + 74be219 commit d6bff1d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 15 deletions.
30 changes: 15 additions & 15 deletions burrito/apps/scheduler/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@
from burrito.plugins.loader import PluginLoader


with open("event_init.sql", "r", encoding="utf-8") as file:
db: MySQLDatabase = get_database_cursor()

for query in file.read().split(";"):
query = query.replace('\t', "").replace("\n", "")
query = ' '.join(query.split())

if not query:
continue

try:
db.execute_sql(query)
except Exception as e:
get_logger().error(e)

PluginLoader.load()

if __name__ == "__main__":
Expand All @@ -47,4 +32,19 @@
os.environ['TZ'] = str(CURRENT_TIME_ZONE)
time.tzset()

with open("event_init.sql", "r", encoding="utf-8") as file:
db: MySQLDatabase = get_database_cursor()

for query in file.read().split(";"):
query = query.replace('\t', "").replace("\n", "")
query = ' '.join(query.split())

if not query:
continue

try:
db.execute_sql(query)
except Exception as e:
get_logger().error(e)

start_scheduler()
65 changes: 65 additions & 0 deletions event_init.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
create or replace view tickets_by_faculties_scopes as (
select
f.faculty_id,
f.name,
count(q_r.scope) as "Reports",
count(q_q.scope) as "Q/A",
count(q_s.scope) as "Suggestion"
from faculties f
left join tickets t on (
t.faculty_id = f.faculty_id
and t.created > date(now() - interval 1 month)
)
left join queues q_r on (
t.queue_id = q_r.queue_id
and q_r.scope = 'Reports'
)
left join queues q_q on (
t.queue_id = q_q.queue_id
and q_q.scope = 'Q/A'
)
left join queues q_s on (
t.queue_id = q_s.queue_id
and q_s.scope = 'Suggestion'
)
group by f.faculty_id
);


create or replace view tickets_by_statuses as (
select
statuses.*, count(ticket_id) tickets_count
from statuses
left join (
select ticket_id, status_id
from tickets
where created > date(now() - interval 1 month)
) tickets_for_last_month
using (status_id)
group by statuses.status_id
);


create or replace view tickets_by_scopes as (
select
distinct scope, count(ticket_id) tickets_count
from queues q
left join tickets t on (
q.queue_id = t.queue_id
and t.created > date(now() - interval 1 month)
)
group by scope
);


create or replace view faculties_by_tickets as (
select
faculty_id,
name,
(select count(*) from tickets where f.faculty_id = faculty_id group by faculty_id) created_tickets_count
from faculties f
having created_tickets_count is not null
);



create event if not exists `tickets_by_faculties_scopes_stats` on schedule
every 1 hour
on completion not preserve
Expand Down

0 comments on commit d6bff1d

Please sign in to comment.