diff --git a/tasks/main.yml b/tasks/main.yml index 67af252..c436955 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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: @@ -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: @@ -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 @@ -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: @@ -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 @@ -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 }}" diff --git a/templates/lab-report-historical-by-learner.sql.j2 b/templates/lab-report-historical-by-learner.sql.j2 new file mode 100644 index 0000000..f7f04bc --- /dev/null +++ b/templates/lab-report-historical-by-learner.sql.j2 @@ -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 +;