This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
/
generateR.rb
executable file
·46 lines (36 loc) · 1.56 KB
/
generateR.rb
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
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/ruby
# Copyright (c) 2016.
#
# This file is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
require 'fileutils'
EOL = "\n"
dirs = Dir["*"].select { |f| File.directory?(f) }
if dirs.empty?
puts "No data directories found. Run `../in2csv.rb` first."
Process.exit
end
File.open("analyses.R", "w") { |f|
f.write("# Generated by generateR.rb" + EOL*2)
dirs.each { |dir|
f.write(EOL + "# #{dir}" + EOL*2)
# Load plain data
f.write("#{dir}_products <- read.csv(\"#{dir}/products.csv\")" + EOL)
f.write("#{dir}_ordersXprod <- as.matrix(read.table(\"#{dir}/orderXprod.csv\", colClasses=\"integer\"))" + EOL)
# Histogram of product weights
f.write("hist(#{dir}_products$weight, xlab=\"weight\", ylab=\"nr of products\", main=\"#{dir}\")" + EOL)
# Histogram of order weights
f.write("hist(#{dir}_ordersXprod %*% #{dir}_products$weight, xlab=\"weight\", ylab=\"nr of orders\", main=\"#{dir}\")" + EOL)
}
puts "Analysis script written. Run `R -f analyses.R` to process."
}