Skip to content

feat: Add a historical report for lab usage per learner, per month #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
_enrollment_report_pass_historical_filename: "pass_report_historical_{{ _enrollment_report_end_date }}{{ _enrollment_report_file_suffix }}"
_enrollment_report_percent_historical_filename: "percent_report_historical_{{ _enrollment_report_end_date }}{{ _enrollment_report_file_suffix }}"
_enrollment_report_lab_historical_filename: "lab_report_historical_{{ _enrollment_report_end_date }}{{ _enrollment_report_file_suffix }}"
_enrollment_report_lab_historical_by_learner_filename: "lab_report_historical_by_learner_{{ _enrollment_report_end_date }}{{ _enrollment_report_file_suffix }}"

- name: set output file paths
set_fact:
Expand All @@ -59,6 +60,7 @@
_enrollment_report_pass_historical_outfile: "{{ _enrollment_report_directory.path }}/{{ _enrollment_report_pass_historical_filename }}"
_enrollment_report_percent_historical_outfile: "{{ _enrollment_report_directory.path }}/{{ _enrollment_report_percent_historical_filename }}"
_enrollment_report_lab_historical_outfile: "{{ _enrollment_report_directory.path }}/{{ _enrollment_report_lab_historical_filename }}"
_enrollment_report_lab_historical_by_learner_outfile: "{{ _enrollment_report_directory.path }}/{{ _enrollment_report_lab_historical_by_learner_filename }}"

- name: create tempfile for enrollment report SQL
tempfile:
Expand Down Expand Up @@ -144,18 +146,30 @@
src: lab-report.sql.j2
mode: 0644

- name: create tempfile for historical "lab" report SQL
- name: create tempfile for "historical lab" report SQL
tempfile:
state: file
suffix: .sql
register: _enrollment_report_lab_historical_sql

- name: populate historical "lab" report SQL
- name: populate "historical lab" report SQL
template:
dest: "{{ _enrollment_report_lab_historical_sql.path }}"
src: lab-report-historical.sql.j2
mode: 0644

- name: create tempfile for "historical lab by learner" report SQL
tempfile:
state: file
suffix: .sql
register: _enrollment_report_lab_historical_by_learner_sql

- name: populate "historical_by lab by learner" report SQL
template:
dest: "{{ _enrollment_report_lab_historical_by_learner_sql.path }}"
src: lab-report-historical-by-learner.sql.j2
mode: 0644

- name: execute scripts
become: true
become_user: root
Expand All @@ -177,6 +191,8 @@
out: "{{ _enrollment_report_percent_historical_outfile }}"
- in: "{{ _enrollment_report_lab_historical_sql.path }}"
out: "{{ _enrollment_report_lab_historical_outfile }}"
- in: "{{ _enrollment_report_lab_historical_by_learner_sql.path }}"
out: "{{ _enrollment_report_lab_historical_by_learner_outfile }}"

- name: ensure output directory exists
file:
Expand All @@ -202,6 +218,7 @@
- "{{ enrollment_report_path }}/{{ _enrollment_report_pass_historical_filename }}"
- "{{ enrollment_report_path }}/{{ _enrollment_report_percent_historical_filename }}"
- "{{ enrollment_report_path }}/{{ _enrollment_report_lab_historical_filename }}"
- "{{ enrollment_report_path }}/{{ _enrollment_report_lab_historical_by_learner_filename }}"
when: enrollment_report_mail_enable

- name: send out enrollment reports
Expand Down Expand Up @@ -240,3 +257,4 @@
- "{{ _enrollment_report_pass_historical_sql.path }}"
- "{{ _enrollment_report_percent_historical_sql.path }}"
- "{{ _enrollment_report_lab_historical_sql.path }}"
- "{{ _enrollment_report_lab_historical_by_learner_sql.path }}"
24 changes: 24 additions & 0 deletions templates/lab-report-historical-by-learner.sql.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- -*- mode: sql; -*-
-- vim: ft=sql
SELECT
u.email,
YEAR(sl.suspend_timestamp) AS 'year',
MONTH(sl.suspend_timestamp) AS 'month',
SUM(TIMESTAMPDIFF(SECOND,
sl.launch_timestamp,
sl.suspend_timestamp)) AS lab_seconds
FROM hastexo_stacklog AS sl
INNER JOIN hastexo_stack AS s ON sl.stack_id=s.id
INNER JOIN auth_user u ON s.learner_id=u.id
WHERE
sl.status='SUSPEND_COMPLETE'
AND sl.suspend_timestamp<='{{ _enrollment_report_end_datetime }}'
GROUP BY
u.email,
year,
month
ORDER BY
year,
month,
u.email
;