/storage.rb (5939518153061fe23d7baefd876e15dad4df2594) (5608 bytes) (mode 100644) (type blob)
require 'ostruct'
require 'redis'
require 'json'
require 'will_paginate'
require 'will_paginate/array'
require './color_helper'
module Storage
@@rdb = Redis.new
def self.all_nodes
@@all_nodes = JSON.parse(@@rdb.smembers(CONFIG.node_index_key)[0]) unless defined? @@all_nodes
return @@all_nodes.map{|id| id.to_s}
end
def self.metric_names
@@metric_names = JSON.parse(@@rdb.smembers(CONFIG.metric_index_key)[0]) unless defined? @@metric_names
return @@metric_names
end
def self.score_names
@@score_names = JSON.parse(@@rdb.smembers(CONFIG.score_index_key)[0]) unless defined? @@score_names
return @@score_names
end
def self.get_node(nodeid)
node = OpenStruct.new
node.id = nodeid
node.metrics = {}
node.scores = {}
#get raw data from redis
all_values = @@rdb.hgetall(CONFIG.node_prefix+nodeid.to_s)
#build structured data
CONFIG.metric_names.each do |metric,name|
node.metrics[metric] = {}
node.metrics[metric][:name] = name
node.metrics[metric][:absolute] = all_values[metric].to_f
node.metrics[metric][:normalized] = all_values[metric+CONFIG.normalization_suffix].to_f
node.metrics[metric][:color_class] = ColorHelper.color_class_by_value(all_values[metric+CONFIG.normalization_suffix].to_f)
node.metrics[metric][:color_code] = ColorHelper.color_code_by_value(all_values[metric+CONFIG.normalization_suffix].to_f)
end
CONFIG.score_names.each do |score,name|
node.scores[score] = {}
node.scores[score][:name] = name
node.scores[score][:absolute] = all_values[score].to_f
node.scores[score][:color_class] = ColorHelper.color_class_by_value(all_values[score].to_f)
node.scores[score][:color_code] = ColorHelper.color_code_by_value(all_values[score].to_f)
end
node.neighbors = JSON.parse(@@rdb.smembers(CONFIG.node_neighbors_prefix+nodeid.to_s)[0])
return node
end
def self.get_metric_nodes(metric_name, page=1)
nodes = {}
@@rdb.zrevrange(CONFIG.metric_prefix+metric_name, 0, -1, {withscores: true}).each do |value|
nodes[value[0]] = {:id => value[0]}
nodes[value[0]][:absolute] = value[1].to_f
end
@@rdb.zrevrange(CONFIG.metric_prefix+metric_name+CONFIG.normalization_suffix, 0, -1, {withscores: true}).each do |value|
nodes[value[0]][:normalized] = value[1].to_f
nodes[value[0]][:color_class] = ColorHelper.color_class_by_value(value[1].to_f)
end
return nodes.to_a.paginate(:page => page, :per_page => CONFIG.nodes_per_page)
end
def self.get_all_metric_values_normalized(metric_name)
return @@rdb.zrevrange(CONFIG.metric_prefix+metric_name+CONFIG.normalization_suffix, 0, -1, {withscores: true}).map{|score| score[1]}
end
def self.get_score_nodes(score_name, page=1)
nodes = {}
@@rdb.zrevrange(CONFIG.score_prefix+score_name, 0, -1, {withscores: true}).each do |value|
nodes[value[0]] = {:id => value[0]}
nodes[value[0]][:absolute] = value[1].to_f
nodes[value[0]][:color_class] = ColorHelper.color_class_by_value(value[1].to_f)
end
return nodes.to_a.paginate(:page => page, :per_page => CONFIG.nodes_per_page)
end
def self.get_all_score_values(score_name)
return @@rdb.zrevrange(CONFIG.score_prefix+score_name, 0, -1, {withscores: true}).map{|score| score[1]}
end
def self.get_absolute_metric_statistics
data_metrics_absolute = {}
CONFIG.metric_names.each do |metric,mname|
metric_data = {}
CONFIG.statistical_indicators.each do |indicator,iname|
value = @@rdb.hget(CONFIG.statistics_prefix+metric, indicator)
metric_data[indicator] = value
end
metric_data['display_name'] = mname
data_metrics_absolute[metric] = metric_data
end
return data_metrics_absolute
end
def self.get_normalized_metric_statistics
data_metrics_normalized = {}
CONFIG.metric_names.each do |metric,mname|
metric_data = {}
CONFIG.statistical_indicators.each do |indicator,iname|
value = @@rdb.hget(CONFIG.statistics_prefix+metric+CONFIG.normalization_suffix, indicator)
metric_data[indicator] = value
end
metric_data['display_name'] = mname
data_metrics_normalized[metric] = metric_data
end
return data_metrics_normalized
end
def self.get_score_statistics
data_scores = {}
CONFIG.score_names.each do |score,sname|
score_data = {}
CONFIG.statistical_indicators.each do |indicator,iname|
value = @@rdb.hget(CONFIG.statistics_prefix+score, indicator)
score_data[indicator] = value
end
score_data['display_name'] = sname
data_scores[score] = score_data
end
return data_scores
end
def self.get_metric_correlations
correlation_data = {}
CONFIG.metric_names.each do |metric1,m1name|
correlation_data[metric1] = {:from => m1name, :correlation => {}}
CONFIG.metric_names.each do |metric2,m2name|
corr = @@rdb.hget(CONFIG.statistics_prefix+'correlations:'+metric1+':'+metric2, 'correlation')
conf = @@rdb.hget(CONFIG.statistics_prefix+'correlations:'+metric1+':'+metric2, 'confidence')
color_code = ColorHelper.color_code_by_value(corr.to_f.abs)
correlation_data[metric1][:correlation][metric2] = {:to => m2name, :correlation => corr, :confidence => conf, :color_code => color_code}
end
end
return correlation_data
end
end
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
32 |
02d771bb174550ee73ca245d5452a371c7ff568e |
Gemfile |
100644 |
blob |
71 |
5a0b34f4c7ea7ff499826db4642432a1e5940c5d |
Gemfile.lock |
100644 |
blob |
79 |
04e9bf5219f1065f2d2f20519a988f41a274d7d9 |
README.md |
100644 |
blob |
494 |
9eca68213c93af98fde713132b619df2393bbd39 |
color_helper.rb |
100644 |
blob |
3308 |
dca71f919a34986ed60ac3716f1bfbfab3535464 |
config.rb |
100644 |
blob |
79 |
a0f1048216dced361915ebb3a955fb637a7d5261 |
index.rb |
100644 |
blob |
516 |
1a41081b6d3d16270f8dfd81376d618d0c75c8ce |
metric_routes.rb |
100644 |
blob |
1478 |
d0c06b59ee66ca2a428d516cbee4a234e1722a19 |
node_routes.rb |
040000 |
tree |
- |
1e469524090bb9e333f8dc410b41ecb1e2515d02 |
public |
100644 |
blob |
297 |
6ecd1cc330e5a4919db79dba4f90bdd3b73b63a3 |
run.rb |
100644 |
blob |
450 |
c0946e5e0b88e95fa7a705b1e0c18e031b9b6c2b |
score_routes.rb |
100644 |
blob |
423 |
f981916c8eceac7fc69aeb01c3f2128f7def40f5 |
statistics_routes.rb |
100644 |
blob |
5608 |
5939518153061fe23d7baefd876e15dad4df2594 |
storage.rb |
040000 |
tree |
- |
ff59ff6ca204b1b5cf166aab50055785f550cf03 |
views |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/coria/coria-backend
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/coria/coria-backend
Clone this repository using git:
git clone git://git.rocketgit.com/user/coria/coria-backend
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main