-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetaverage.rb
More file actions
36 lines (34 loc) · 752 Bytes
/
getaverage.rb
File metadata and controls
36 lines (34 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env ruby
# coding: utf-8
require 'fileutils'
array = Array.new
ARGV.each_with_index do |file, i|
array[i] = Array.new(13, 0.0)
count = Array.new(13, 0.0)
array[i][0] = file.to_i
open(file+'.csv', 'r:utf-8') do |f|
f.each do |line|
fields = line.chomp.split(',')
date = fields[0].chomp.split('/')
array[i][date[1].to_i] += fields[3].to_f
count[date[1].to_i] += 1
end
for j in 1..12
array[i][j] /= count[j]
end
end
end
print " :"
ARGV.each do |file|
printf(" %d\t", file)
end
print ': 平均' + "\n"
for i in 1..12
printf("%2d月:", i)
avg = 0
for j in 0...ARGV.size
printf(" %0.2f\t", array[j][i])
avg += array[j][i]
end
printf(": %.2f\n", avg/ARGV.size)
end