16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/elephant-drive-service/response_builder.rb', line 16
def generate_average_usage_report_response
{data: [],
total_capacity: 0.0,
total_active_usage: 0.0,
total_inactive_usage: 0.0,
total_usage_percentage: 0.0,
total_active_usage_percentage: 0.0,
total_inactive_usage_percentage: 0.0}.tap do |report|
[[:ds][:diffgram].fetch(:new_data_set,{}).fetch(:table,[])].flatten.select { |h| h[:str_email] }.each do |user|
{
display_name: user[:str_display_name],
email: user[:str_email],
installed_user_id: user[:g_user_id],
status: user[:str_account_state],
total_capacity: user[:l_capacity_b].to_f,
total_usage: user[:l_usage_b].to_f || 0.0
}.tap { |entry|
entry[:usage_percentage] = entry[:total_usage] / entry[:total_capacity]
if entry[:status] =~ /^Suspended|Active/i
report[:total_capacity] += entry[:total_capacity]
case entry[:status]
when /^Active/i
report[:total_active_usage] += entry[:total_usage]
report[:total_active_usage_percentage] = entry[:total_usage] / entry[:total_capacity]
when /^Suspended/i
report[:total_inactive_usage] += entry[:total_usage]
report[:total_inactive_usage_percentage] = entry[:total_usage] / entry[:total_capacity]
end
end
report[:data] << entry
}
end
report[:total_usage_percentage] = ((report[:total_active_usage] + report[:total_inactive_usage]) / report[:total_capacity]).round(2) if report[:total_capacity] > 0.0
end
end
|