socialforge/app/helpers/statistics_helper.rb

34 lines
841 B
Ruby
Raw Normal View History

2018-02-05 12:03:35 +08:00
module StatisticsHelper
2018-02-05 15:13:03 +08:00
include AttachmentsHelper
2018-05-08 16:25:59 +08:00
def data_format_string num
result = num
if num < 1
2018-05-11 10:05:18 +08:00
result = format("%0.1f", (num*1024)).to_s + " KB"
elsif num < 1024
2018-05-11 10:05:18 +08:00
result = format("%0.1f", num).to_s + " MB"
elsif num < 1024 * 1024
result = format("%0.1f", (num/1024)).to_s + " GB"
2018-05-08 16:25:59 +08:00
else
result = format("%0.1f", (num/(1024*1024))).to_s + " TB"
2018-05-08 16:25:59 +08:00
end
source = result.split(".")
source[0] = source[0].gsub(/(\d)(?=(\d{3})+(?!\d))/, "\\1,")
return source.join(".")
2018-05-08 16:25:59 +08:00
end
2018-06-05 14:58:45 +08:00
# excel中的数据大小转换成MB
def file_size_revert size_str
result = 0
unit = size_str[-2, 2]
if unit == "GB"
result = size_str.to_f * 1024
elsif unit == "KB"
result = (size_str.to_f / 1024).round(3)
else
result = size_str.to_f
end
result
end
2018-02-05 12:03:35 +08:00
end