create course storage report

refs CNVS-26643

test plan
 - report should run
 - report should have list of courses and storage
   used for each course

Change-Id: Ife1244ecfcef3b074cdf25954f7be07f0745e8de
Reviewed-on: https://gerrit.instructure.com/72421
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Tested-by: Jenkins
Reviewed-by: Simon Williams <simon@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2016-02-18 02:11:39 -07:00
parent 9828b45edd
commit aea3467f45
5 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<p><%= t(%{This report shows all the courses for a given term. The resulting csv
file will have one row per course and will show the course id, course sis id,
course short name, course name, account id, account sis id, account name,
storage used in MB.}) %></p>
<h3><%= t(%{Example}) %></h3>
<table class="report_example">
<thead>
<tr>
<th><%= t(%{id}) %></th>
<th><%= t(%{sis id}) %></th>
<th><%= t(%{short name}) %></th>
<th><%= t(%{name}) %></th>
<th><%= t(%{account id}) %></th>
<th><%= t(%{account sis id}) %></th>
<th><%= t(%{account name}) %></th>
<th><%= t(%{storage used in MB}) %></th>
</tr>
</thead>
<tbody>
<tr>
<td>345</td>
<td>c342</td>
<td>MATH101</td>
<td>Mathematics 101</td>
<td>14</td>
<td>MATH</td>
<td>Math Department</td>
<td>18.82</td>
</tr>
</tbody>
</table>

View File

@ -47,6 +47,52 @@ module AccountReports
csv(default_courses.where(:workflow_state => ['claimed', 'created']))
end
def course_storage
courses = root_account.all_courses.active.preload(:account)
courses = add_course_sub_account_scope(courses)
courses = add_term_scope(courses)
filename = AccountReports.generate_file(@account_report)
CSV.open(filename, "w") do |csv|
headers = []
headers << I18n.t('id')
headers << I18n.t('sis id')
headers << I18n.t('short name')
headers << I18n.t('name')
headers << I18n.t('account id')
headers << I18n.t('account sis id')
headers << I18n.t('account name')
headers << I18n.t('storage used in MB')
csv << headers
Shackles.activate(:slave) do
@total = courses.count(:all)
i = 0
courses.find_each do |c|
row = []
row << c.id
row << c.sis_source_id
row << c.course_code
row << c.name
row << c.account_id
row << c.account.sis_source_id
row << c.account.name
row << c.storage_quota_used_mb.round(2)
csv << row
i += 1
if i % 5 == 0
Shackles.activate(:master) do
@account_report.update_attribute(:progress, (i.to_f/@total)*100)
end
end
end
end
end
send_report(filename)
end
def csv(courses)
courses = add_course_sub_account_scope(courses)
courses = add_term_scope(courses)

View File

@ -47,6 +47,10 @@ module AccountReports
CourseReports.new(account_report).public_courses
end
def self.course_storage_csv(account_report)
CourseReports.new(account_report).course_storage
end
def self.unused_courses_csv(account_report)
CourseReports.new(account_report).unused_courses
end

View File

@ -258,6 +258,17 @@ module AccountReports
}
}
},
'course_storage_csv' => {
:title => proc { I18n.t('Course Storage') },
:description_partial => true,
:parameters_partial => 'term_selector_parameters',
:parameters => {
:enrollment_term_id => {
:required => false,
:description => 'The canvas id of the term to get courses from for storage report'
}
}
},
'unused_courses_csv' => {
:title => proc { I18n.t(:unused_courses_title, 'Unused Courses') },
:description_partial => true,

View File

@ -221,4 +221,48 @@ describe "Course Account Reports" do
end
end
describe "course storage report" do
before(:each) do
@report = 'course_storage_csv'
a = attachment_obj_with_context(@course1)
a.update_attribute(:size, 1.226.megabyte)
a = attachment_obj_with_context(@course2)
a.update_attribute(:size, 3.megabyte)
a = attachment_obj_with_context(@course5)
a.update_attribute(:size, 11.megabyte)
a = attachment_obj_with_context(@course5)
a.update_attribute(:size, 1.megabyte)
a = attachment_obj_with_context(@course4)
a.update_attribute(:size, 4.6521.megabyte)
a = attachment_obj_with_context(@course5)
a.update_attribute(:size, 80.megabyte)
end
it 'should add up storage for courses' do
parsed = read_report(@report, {account: @account, order: [1, 2], header: true})
expect(parsed.length).to eq 5
headers = parsed.shift
expect(headers.length).to eq parsed[0].length
expect(parsed[0]).to eq [@course1.id.to_s, 'SIS_COURSE_ID_1', 'ENG101',
'English 101', @sub_account.id.to_s, 'sub1',
'Math', '1.23']
expect(parsed[1]).to eq [@course3.id.to_s, 'SIS_COURSE_ID_3', 'SCI101',
'Science 101', @account.id.to_s, nil,
@account.name, '0']
expect(parsed[2]).to eq [@course5.id.to_s, nil, 'Tal101', 'talking 101',
@account.id.to_s, nil, @account.name, '92']
expect(parsed[3]).to eq [@course4.id.to_s, nil, 'self', 'self help',
@account.id.to_s, nil, @account.name, '4.65']
end
it 'should add up storage for courses in sub account' do
parsed = read_report(@report, {account: @sub_account})
expect(parsed.length).to eq 1
expect(parsed[0]).to eq [@course1.id.to_s, 'SIS_COURSE_ID_1', 'ENG101',
'English 101', @sub_account.id.to_s, 'sub1',
'Math', '1.23']
end
end
end