2013-05-31 07:28:01 +02:00
|
|
|
require 'RMagick'
|
2013-06-01 08:49:02 +02:00
|
|
|
require 'json'
|
2013-05-31 07:28:01 +02:00
|
|
|
|
|
|
|
include Magick
|
|
|
|
|
2013-06-01 08:49:02 +02:00
|
|
|
data = JSON::load(File.new('load_values.json', 'r'))
|
2013-05-31 07:28:01 +02:00
|
|
|
|
2013-06-01 08:49:02 +02:00
|
|
|
# prepare data
|
|
|
|
dummyList = Array.new()
|
|
|
|
data.each do |cores|
|
2013-05-31 09:21:23 +02:00
|
|
|
|
|
|
|
# Add all loads to compute how much % is one % load
|
|
|
|
loadSum = 0
|
|
|
|
cores.each { |core| loadSum = loadSum + core }
|
|
|
|
percentLoad = 100.0/loadSum
|
|
|
|
|
2013-05-31 07:28:01 +02:00
|
|
|
# every 10 load percent one heatpoint
|
|
|
|
i = 0
|
2013-06-01 08:49:02 +02:00
|
|
|
dummyList << Array.new(10) do
|
2013-05-31 09:21:23 +02:00
|
|
|
# get all cores in the certain percentage
|
|
|
|
selectedCores= cores.select { |core| core >= i and core < (i+10)}
|
|
|
|
# (go to next level here)
|
2013-05-31 07:28:01 +02:00
|
|
|
i = i + 10
|
2013-05-31 09:21:23 +02:00
|
|
|
# add the load of the resulting cores and multiply it with the overall value
|
|
|
|
loadSum = 0
|
|
|
|
selectedCores.each { |core| loadSum = loadSum + core }
|
|
|
|
percent = loadSum*percentLoad
|
2013-05-31 07:28:01 +02:00
|
|
|
end
|
2013-06-01 08:49:02 +02:00
|
|
|
|
2013-05-31 07:28:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# puts dummyList.inspect
|
|
|
|
|
2013-06-01 08:49:02 +02:00
|
|
|
# image size
|
|
|
|
x = dummyList.length*15
|
|
|
|
|
2013-05-31 07:28:01 +02:00
|
|
|
# start drawing the damn thing
|
2013-06-01 08:49:02 +02:00
|
|
|
loadImg = Image.new(x,150) { self.background_color = "white" }
|
2013-05-31 07:28:01 +02:00
|
|
|
|
|
|
|
i = 0
|
|
|
|
dummyList.each do |point|
|
|
|
|
j = 0
|
2013-05-31 08:25:32 +02:00
|
|
|
point.reverse.each do |cores|
|
2013-05-31 07:28:01 +02:00
|
|
|
# draw a red rectangle on the white background
|
|
|
|
core = Draw.new
|
|
|
|
|
2013-05-31 09:21:23 +02:00
|
|
|
l = (255-((cores*1.275))).round
|
2013-05-31 07:28:01 +02:00
|
|
|
core.fill(Pixel.from_hsla(0, 255, l, 1).to_color)
|
|
|
|
core.rectangle((i*15), (j*15), ((i+1)*15), ((j+1)*15))
|
|
|
|
core.draw loadImg
|
|
|
|
j = j + 1
|
|
|
|
end
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
loadImg.display
|
2013-06-01 08:49:02 +02:00
|
|
|
# loadImg.write('loadimage.png')
|