0
0
Fork 0

Add examples

This commit is contained in:
Stormwind 2015-05-06 09:22:24 +02:00
parent 4aacca5f32
commit 1af0c806f1
3 changed files with 129 additions and 0 deletions

34
cpu_load_demo.html Normal file
View File

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function refresh(node) {
var times = 300; // gap in Milli Seconds;
(function startRefresh() {
var address;
if(node.src.indexOf('?')>-1)
address = node.src.split('?')[0];
else
address = node.src;
node.src = address+"?time="+new Date().getTime();
setTimeout(startRefresh,times);
})();
}
window.onload = function() {
var node = document.getElementById('img');
refresh(node);
// you can refresh as many images you want just repeat above steps
}
</script>
</head>
<body>
<img style="border: 1px black solid; margin: 10em 0 0 10em;" id="img" src="cpu_load.png" alt="This is the CPU load">
</body>
</html>

34
git-history.rb Normal file
View File

@ -0,0 +1,34 @@
require "git"
require "rubella"
require "rubella/output/image"
require "rubella/weighting/per_count"
# Get git history
repository = Git.open("../rubella/")
git_log = repository.log(1000000).since('1 year ago')
# Create an commit per day array
current_date = Time.now
commits_per_day = Array.new(1, 0)
git_log.each do |commit|
# Insert 0 until the date fits
until current_date.year == commit.date.year and
current_date.month == commit.date.month and
current_date.day == commit.date.day
commits_per_day.insert(0, 0)
current_date = current_date - (60*60*24)
end
commits_per_day[0] = commits_per_day.first + 1
end
# Give rubella this array
# Prepare classes
weighting = Rubella::Weighting::PerCount.new
storage = weighting.parse commits_per_day
# Get a heatmap of your commits
image = Rubella::Output::Image.new(storage, 15)
#image.background_color = "black"
image.render.write("git_commits.png")

61
streaming_load.rb Normal file
View File

@ -0,0 +1,61 @@
require "rubella"
require "rubella/input/base"
require "rubella/output/image"
require "rubella/output/ascii"
require "rubella/weighting/per_value"
require "rubella/weighting/per_overall_load"
require "rubella/weighting/expotential"
# Number of cores
cores = 8
# Number of buckets
buckets = 10
# Number of columns
col = 25
# Field size
size = 50
# Time intervall in sec.
time = 1
# Prepare classes
#weighting = Rubella::Weighting::PerValue.new buckets
weighting = Rubella::Weighting::PerOverallLoad.new buckets
#weighting = Rubella::Weighting::Expotential.new buckets
storage = Rubella::Storage.new Array.new(1, Array.new(cores, 0)), col
while true
dataset = Array.new()
Random.new_seed
# Generate new dataset
i = 0
dataset << Array.new(cores) do
core_load = 0
case i
when 0
core_load = 100
when 1..2
core_load = rand(80..100)
when 3..5
core_load = rand(50..80)
when 7
core_load = rand(0..15)
else
# Generate a value between 0 and 100
core_load = rand(100)
end
i = i + 1
core_load
end
#puts dataset.inspect
# Push new dataset through input && Weight data && Add new data to storage
new_storage = weighting.parse(Rubella::Input::Base.new(dataset))
#puts new_storage.data.inspect
storage = storage.add new_storage
# Dump new image
# Rubella::Output::Image.new(storage, size).render.write("cpu_load.png")
puts Rubella::Output::ASCII.new(storage, size).render
sleep(time)
end