require 'redis'
require 'ostruct'
require 'json'
CONFIG = OpenStruct.new
CONFIG.redis_db_index = 1
CONFIG.redis = Redis.new(:db => CONFIG.redis_db_index)
CONFIG.graph_index_key = 'all_graphs'
# initialise octothorpes
CONFIG.info_index_key = Hash.new
CONFIG.node_index_key = Hash.new
CONFIG.metric_index_key = Hash.new
CONFIG.score_index_key = Hash.new
CONFIG.percolation_index_key = Hash.new
CONFIG.layout_index_key = Hash.new
CONFIG.node_neighbors_prefix = Hash.new
CONFIG.node_prefix = Hash.new
CONFIG.metric_prefix = Hash.new
CONFIG.score_prefix = Hash.new
CONFIG.statistics_prefix = Hash.new
CONFIG.percolation_prefix = Hash.new
CONFIG.metric_names = Hash.new
CONFIG.score_names = Hash.new
CONFIG.percolation_methods = Hash.new
CONFIG.percolation_pctages = Hash.new
CONFIG.layout_names = Hash.new
CONFIG.all_graphs = CONFIG.redis.smembers(CONFIG.graph_index_key)
# for each graph in all_graphs
CONFIG.all_graphs.each do |graph|
CONFIG.info_index_key.store(graph, graph+':'+'general_info')
CONFIG.node_index_key.store(graph, graph+':'+'all_nodes')
CONFIG.metric_index_key.store(graph, graph+':'+'all_metrics')
CONFIG.score_index_key.store(graph, graph+':'+'all_scores')
CONFIG.percolation_index_key.store(graph, graph+':'+'all_percolation_modes')
CONFIG.layout_index_key.store(graph,graph+':'+'all_layouts')
CONFIG.node_neighbors_prefix.store(graph, graph+':'+'node_neighbors:')
CONFIG.node_prefix.store(graph, graph+':'+'node_metrics:')
CONFIG.metric_prefix.store(graph, graph+':'+'metric:')
CONFIG.score_prefix.store(graph, graph+':'+'score:')
CONFIG.statistics_prefix.store(graph, graph+':'+'statistics:')
CONFIG.percolation_prefix.store(graph, graph+':'+'percolation:')
#automatic retrieval and naive naming of available metrics from Redis
CONFIG.metric_names[graph] = CONFIG.redis.smembers(CONFIG.metric_index_key[graph]).inject({}) do |h,metric|
h[metric] = metric.split('_').map(&:capitalize).join(' ')
h
end
#CONFIG.metric_names = {
# 'clustering_coefficient' => "Clustering Coefficient",
# 'corrected_clustering_coefficient' => "Clustering Coefficient (Corrected)",
# 'degree' => "Node Degree",
# 'average_neighbor_degree' => "Average Neighbor Degree",
# 'corrected_average_neighbor_degree' => "Average Neighbor Degree (Corrected)",
# 'iterated_average_neighbor_degree' => "Iterated Average Neighbor Degree",
# 'corrected_iterated_average_neighbor_degree' => "Iterated Average Neighbor Degree (Corrected)",
# 'betweenness_centrality' => "Betweenness Centrality",
# 'eccentricity' => "Eccentricity",
# 'average_shortest_path_length' => "Average Shortest Path Length"
#}
#automatic retrieval and naive naming of available scores from Redis
CONFIG.score_names[graph] = CONFIG.redis.smembers(CONFIG.score_index_key[graph]).inject({}) do |h,score|
h[score] = score.split('_').map(&:capitalize).join(' ')
h
end
# scores have to be readable in redis
#CONFIG.score_names = {
# 'unified_risk_score' => "Unified Risk Score (URS)",
# 'advanced_unified_risk_score' => "Advanced URS"
#}
#puts JSON.parse(CONFIG.redis.smembers(CONFIG.node_index_key[graph]).to_s)
#automatic retrieval and naive naming of available percolation methods from Redis
CONFIG.percolation_methods[graph] = CONFIG.redis.smembers(CONFIG.percolation_index_key[graph]).inject({}) do |h,method|
# h[method] = method.split(':').map{|string| string.capitalize}.join(' - ').split('_').map(&:capitalize).join(' ')
h[method] = method.split(':').map{|string| string.split('_').map(&:capitalize).join(' ')}.join(' - ')
h
end
#retrieval of percolation percentages
CONFIG.percolation_pctages[graph] = CONFIG.redis.hget(CONFIG.info_index_key[graph], 'percentages').split(';')
#automatic retrieval and naive naming of available layouts from Redis
CONFIG.layout_names[graph] = CONFIG.redis.smembers(CONFIG.layout_index_key[graph]).inject({}) do |h,layout|
h[layout] = layout.split('_').map(&:capitalize).join(' ')
h
end
end
CONFIG.normalization_suffix = '_normalized'
CONFIG.statistical_indicators = { 'min' => "Minimum",
'max' => "Maximum",
'average' => "Average Value" ,
'median' => "Median Value",
'standard_deviation' => "Standard Deviation"}
# css classes for status indication ordered from "good" to "bad"
CONFIG.color_classes = ['success','info', 'warning', 'danger']
#HTML color codes from green to red in 0x11-steps
CONFIG.color_codes = ['#FF0000','#FF1100','#FF2200','#FF3300','#FF4400',
'#FF5500','#FF6600','#FF7700','#FF8800','#FF9900',
'#FFAA00','#FFBB00','#FFCC00','#FFDD00','#FFEE00',
'#FFFF00','#EEFF00','#DDFF00','#CCFF00','#BBFF00',
'#AAFF00','#99FF00','#88FF00','#77FF00','#66FF00',
'#55FF00','#44FF00','#33FF00','#22FF00','#11FF00',
'#00FF00'].reverse
#can be metric or score
CONFIG.node_coloring_field = 'unified_risk_score'
# max number of neighbors for graphical representation with d3.js
CONFIG.max_graph_neighbors = 150
CONFIG.nodes_per_page = 25