1083 lines
29 KiB
JavaScript
1083 lines
29 KiB
JavaScript
// defaults
|
|
var showNames = false
|
|
var showAllNames = false
|
|
var dataTableRows = ["site.institution", "site.abbreviation", "site.nationality", "site.network.bisection bandwidth"]
|
|
var dataTableRowsGraph = ["site.network.bisection bandwidth"]
|
|
|
|
var graphShowColumn = "site.supercomputer.nodes.count"
|
|
var aggregateByName = "site.nationality"
|
|
var orderlistBy = "site.supercomputer.nodes.count"
|
|
var siteAggregationOperator = "sum"
|
|
var siteAggregationOperatorGraph = "sum"
|
|
var equation = ""
|
|
var opt_export_URL = true
|
|
var equation_unit = ""
|
|
|
|
var sort_list_by = ""
|
|
var sort_list_asc = false
|
|
|
|
var sort_by = "site.supercomputer.nodes.count"
|
|
var sort_asc = false
|
|
var dataTableLimit = -1 // max number of elements to show
|
|
|
|
// end defaults
|
|
var equationParsed = null
|
|
var equationVariables = []
|
|
var siteLinkMap = []
|
|
var html_root = ""
|
|
var dataTableRowsGraphP = null
|
|
var dataTableRowsP = null
|
|
|
|
var dataTable = []
|
|
var dataAggregated = {}
|
|
var graphAggregated = []
|
|
var pie
|
|
var graph_height = 0
|
|
var graph_width = 0
|
|
|
|
var unitValueMap = {}
|
|
var schema_fields_numeric = {}
|
|
var schema_fields_string = {}
|
|
var schema_fields_string_names = {}
|
|
|
|
function loadNameMaps(){
|
|
siteLinkMap = {}
|
|
for (var site in repository){
|
|
var data = repository[site]["DATA"]
|
|
var abbr = extractValues(data, "site.abbreviation", false)
|
|
var name = extractValues(data, "site.institution", false)
|
|
var nat = extractValues(data, "site.nationality", false)
|
|
if( name.length == 0 || name[0].length < 2 ){
|
|
console.log(abbr + " " + name)
|
|
continue
|
|
}
|
|
siteLinkMap[name[0]] = [ nat[0].toLowerCase(), abbr[0] ]
|
|
}
|
|
}
|
|
|
|
String.prototype.replaceAll = function(search, replacement) {
|
|
var target = this;
|
|
return target.replace(new RegExp(search, 'g'), replacement);
|
|
};
|
|
|
|
function cleanVarName(x){
|
|
return x.replaceAll(" ", "").replaceAll("[.]([^0-9])", "_$1")
|
|
}
|
|
|
|
function parseEquation(){
|
|
if(equation == null || equation == ""){
|
|
return true
|
|
}
|
|
equationParsed = cleanVarName(equation)
|
|
jQuery("#dcl_siteequation").css({color: "black"})
|
|
var tmp = equation.match(/[a-zA-Z]+[.][a-zA-Z. ]+/g)
|
|
equationVariables = []
|
|
for(var c in tmp){
|
|
var d = tmp[c].trim()
|
|
if(equationVariables.indexOf(d) == -1){
|
|
equationVariables.push(d)
|
|
if(! (d in schema_fields_numeric)){
|
|
alert("Could not find the variable: " + d)
|
|
jQuery("#dcl_siteequation").css({color: "red"})
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
function updateGraphRows(){
|
|
dataTableRowsGraph.sort()
|
|
if(dataTableRowsGraph.indexOf("equation") >= 0){
|
|
dataTableRowsGraph.splice(dataTableRowsGraph.indexOf("equation"), 1)
|
|
}
|
|
if(equation != ""){
|
|
dataTableRowsGraph.unshift("equation")
|
|
}
|
|
dataTableRowsGraphP = dataTableRowsGraph.slice(0)
|
|
if(dataTableRowsGraphP.indexOf(aggregateByName) == -1){
|
|
dataTableRowsGraphP.push(aggregateByName)
|
|
}
|
|
if(dataTableRowsGraphP.indexOf(graphShowColumn) == -1){
|
|
dataTableRowsGraphP.push(graphShowColumn)
|
|
}
|
|
// append all necessary variables for the equation
|
|
if(equationParsed != null){
|
|
for(var v in equationVariables){
|
|
if (dataTableRowsGraphP.indexOf(equationVariables[v]) == -1){
|
|
dataTableRowsGraphP.push(equationVariables[v])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function updateDataTableRows(){
|
|
dataTableRows.sort()
|
|
if(dataTableRows.indexOf("equation") >= 0){
|
|
dataTableRows.splice(dataTableRows.indexOf("equation"), 1)
|
|
}
|
|
if(equation != ""){
|
|
dataTableRows.unshift("equation")
|
|
}
|
|
dataTableRowsP = dataTableRows.slice(0)
|
|
|
|
if(dataTableRowsP.indexOf("site.institution") >= 0){
|
|
dataTableRowsP.splice(dataTableRowsP.indexOf("site.institution"), 1)
|
|
dataTableRowsP.unshift("site.institution")
|
|
}
|
|
// append all necessary variables for the equation
|
|
if(equationParsed != null){
|
|
for(var v in equationVariables){
|
|
if (dataTableRowsP.indexOf(equationVariables[v]) == -1){
|
|
dataTableRowsP.push(equationVariables[v])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function prepareAvailableFields(){
|
|
walkAvailableFields(system, [], function(child, tag, parents){
|
|
var val = parents.join(".") + "." + tag
|
|
if (child["dtype"] == "number" || child["dtype"] == "integer"){
|
|
schema_fields_numeric[val] = child
|
|
}else{
|
|
if(tag == "name"){
|
|
schema_fields_string_names[val] = child
|
|
}else{
|
|
schema_fields_string[val] = child
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function isInt(value) {
|
|
return ! isNaN(value) && parseFloat(value) == value && ! isNaN(parseFloat(value));
|
|
}
|
|
|
|
function aggregateGraphValues(){
|
|
var aggregateBy = dataTableRowsGraphP.indexOf(aggregateByName)
|
|
var equationRow = dataTableRowsGraphP.indexOf("equation")
|
|
dataAggregated = {}
|
|
for (var site in repository){
|
|
var data = repository[site]["DATA"]
|
|
var lst = extractValues(data, dataTableRowsGraphP[aggregateBy], false)
|
|
|
|
if(lst.length == 0){
|
|
continue
|
|
}
|
|
// unify aggregates
|
|
var aggregates = {}
|
|
for(var l in lst){
|
|
aggregates[lst[l]] = true
|
|
}
|
|
|
|
for(var cls in aggregates){
|
|
var row = []
|
|
|
|
for (var m in dataTableRowsGraphP){
|
|
var numeric = dataTableRowsGraphP[m] in schema_fields_numeric
|
|
var val = extractValuesCheckParent(data, dataTableRowsGraphP[m], numeric, aggregateByName, cls)
|
|
var res = 0
|
|
if( m != equationRow){
|
|
if (numeric){
|
|
res = reduceSiteValues(val, siteAggregationOperatorGraph)
|
|
}else{
|
|
res = val
|
|
}
|
|
}
|
|
row.push(res)
|
|
}
|
|
|
|
if( equationRow >= 0){
|
|
try{
|
|
row[equationRow] = computeEquation(row, dataTableRowsGraphP)
|
|
}catch(err){
|
|
jQuery("#dcl_siteequation").css({color: "red"})
|
|
error = true
|
|
row[equationRow] = -1
|
|
}
|
|
}
|
|
var aggregate
|
|
if (cls in dataAggregated){
|
|
aggregate = dataAggregated[cls]
|
|
}else{
|
|
aggregate = []
|
|
for(var c in dataTableRowsGraphP){
|
|
if (dataTableRowsGraphP[c] in schema_fields_numeric || c == equationRow){
|
|
aggregate.push(0)
|
|
}else{
|
|
aggregate.push([])
|
|
}
|
|
}
|
|
}
|
|
|
|
for(var c in dataTableRowsGraphP){
|
|
var val = row[c]
|
|
if (isInt(val)){
|
|
aggregate[c] = aggregate[c] + parseFloat(val)
|
|
}else if(! (dataTableRowsGraphP[c] in schema_fields_numeric || c == equationRow)){
|
|
aggregate[c] = aggregate[c].concat(val)
|
|
}else{
|
|
aggregate[c] = NaN
|
|
}
|
|
}
|
|
dataAggregated[cls] = aggregate
|
|
}
|
|
}
|
|
var graphShowColumn_num = dataTableRowsGraphP.indexOf(graphShowColumn)
|
|
graphAggregated = []
|
|
for (var label in dataAggregated){
|
|
var val = dataAggregated[label]
|
|
var v = val[graphShowColumn_num]
|
|
v = parseFloat(valueToBaseUnit(graphShowColumn, v, true))
|
|
if(v > 0){
|
|
graphAggregated.push({"label" : label, "value" : v})
|
|
}
|
|
}
|
|
}
|
|
|
|
function prepareUnits(){
|
|
for (var type in units){
|
|
for (var n in units[type]){
|
|
var unit = units[type][n]
|
|
unitValueMap[unit[0]] = [unit[1], type]
|
|
}
|
|
}
|
|
}
|
|
|
|
function appendStringToArray(str, res_array){
|
|
var arr = str.split(",")
|
|
for(var i in arr){
|
|
res_array.push(arr[i].trim())
|
|
}
|
|
}
|
|
|
|
function extractRecusive(pos, link, obj, res_array, numeric){
|
|
if (obj == null || obj["type"] != link[pos]){
|
|
return;
|
|
}
|
|
if(pos + 2 == link.length){
|
|
// check if parent
|
|
var val = obj["att"][link[pos + 1]];
|
|
if (val instanceof Array){
|
|
var flt = parseFloat(val[0])
|
|
var unit = val[1]
|
|
val = val[0] * unitValueMap[unit][0]
|
|
res_array.push(val)
|
|
}else if(numeric){
|
|
val = parseFloat(val)
|
|
res_array.push(val)
|
|
}else if(val != null && val != ""){
|
|
appendStringToArray(val, res_array)
|
|
}
|
|
return
|
|
}
|
|
for(var c in obj["childs"]){
|
|
extractRecusive(pos + 1, link, obj["childs"][c], res_array, numeric)
|
|
}
|
|
}
|
|
|
|
function extractValues(obj, what, numeric){
|
|
var link = what.split(".")
|
|
var res_array = []
|
|
extractRecusive(0, link, obj, res_array, numeric)
|
|
return res_array
|
|
}
|
|
|
|
function compareStrPrefix(str, whichPrefix){
|
|
var arr = str.split(",")
|
|
for(var i in arr){
|
|
arr[i] = arr[i].trim()
|
|
}
|
|
return arr.indexOf(whichPrefix) > -1
|
|
}
|
|
|
|
function checkIfChildIsWrong(pos, obj, prefix, whichPrefix, checkPrefix, found){
|
|
if(obj["type"] != prefix[pos]){
|
|
return false
|
|
}
|
|
if(pos < prefix.length - 1){
|
|
if(pos == prefix.length - 2){
|
|
// discard all children if different
|
|
var s = prefix[pos + 1]
|
|
if (! (s in obj["att"])){
|
|
return true
|
|
}
|
|
if(compareStrPrefix(obj["att"][s], whichPrefix)){
|
|
found.push(true)
|
|
}
|
|
return true
|
|
}
|
|
}else{
|
|
return false
|
|
}
|
|
var ret = false
|
|
for(var c in obj["childs"]){
|
|
var ret = checkIfChildIsWrong(pos + 1, obj["childs"][c], prefix, whichPrefix, checkPrefix, found)
|
|
if(ret){
|
|
ret = true
|
|
}
|
|
}
|
|
return ret
|
|
}
|
|
|
|
function extractRecusiveCheckParent(pos, link, obj, res_array, numeric, prefix, whichPrefix, checkPrefix){
|
|
if (obj == null || obj["type"] != link[pos]){
|
|
return
|
|
}
|
|
if(obj["type"] != prefix[pos]){
|
|
checkPrefix = false
|
|
}
|
|
if(checkPrefix && pos < prefix.length - 1){
|
|
if(pos == prefix.length - 2){
|
|
// discard all children if different
|
|
var s = prefix[pos + 1]
|
|
if (! (s in obj["att"])){
|
|
return
|
|
}else if (compareStrPrefix(obj["att"][s], whichPrefix) == false){
|
|
return
|
|
}else{
|
|
checkPrefix = false
|
|
}
|
|
}
|
|
}
|
|
if(checkPrefix && pos > 0){
|
|
var found = []
|
|
var ret = checkIfChildIsWrong(pos, obj, prefix, whichPrefix, checkPrefix, found)
|
|
if(ret && found.length == 0){
|
|
return
|
|
}
|
|
}
|
|
if(pos + 2 == link.length){
|
|
// check if parent
|
|
var val = obj["att"][link[pos + 1]];
|
|
if (val instanceof Array){
|
|
var flt = parseFloat(val[0])
|
|
var unit = val[1]
|
|
val = val[0] * unitValueMap[unit][0]
|
|
res_array.push(val)
|
|
}else if(numeric){
|
|
val = parseFloat(val)
|
|
res_array.push(val)
|
|
}else if(val != null && val != ""){
|
|
appendStringToArray(val, res_array)
|
|
}
|
|
return
|
|
}
|
|
for(var c in obj["childs"]){
|
|
extractRecusiveCheckParent(pos + 1, link, obj["childs"][c], res_array, numeric, prefix, whichPrefix, checkPrefix)
|
|
}
|
|
}
|
|
|
|
function extractValuesCheckParent(obj, what, numeric, prefix, whichPrefix){
|
|
var res_array = []
|
|
extractRecusiveCheckParent(0, what.split("."), obj, res_array, numeric, prefix.split("."), whichPrefix, true)
|
|
return res_array
|
|
}
|
|
|
|
function reduceSiteValues(values, siteAggregationOperator){
|
|
// apply an operator to reduce all values reported by the site to a single number
|
|
if (siteAggregationOperator == "mean" || siteAggregationOperator == "sum"){
|
|
var sum = 0
|
|
for(v in values){
|
|
var val = values[v]
|
|
if (isNaN(val) || "undefined" == typeof val){
|
|
val = 0
|
|
}
|
|
sum = sum + val
|
|
}
|
|
if(siteAggregationOperator == "mean"){
|
|
return sum / values.length
|
|
}else{
|
|
return sum
|
|
}
|
|
}
|
|
if (siteAggregationOperator == "max"){
|
|
var red = 0
|
|
for(v in values){
|
|
var val = values[v]
|
|
if (isNaN(val) || "undefined" === typeof val){
|
|
continue
|
|
}
|
|
red = Math.max(red, val)
|
|
}
|
|
return red
|
|
}
|
|
if (siteAggregationOperator == "min"){
|
|
var red = Number.MAX_VALUE
|
|
for(v in values){
|
|
var val = values[v]
|
|
if (isNaN(val) || "undefined" === typeof val){
|
|
continue
|
|
}
|
|
red = Math.min(red, val)
|
|
}
|
|
if(red == Number.MAX_VALUE){
|
|
return 0
|
|
}
|
|
return red
|
|
}
|
|
}
|
|
|
|
function computeEquation(row, tbl){
|
|
var dict = {}
|
|
for (var m in tbl){
|
|
var name = cleanVarName(tbl[m])
|
|
var v = row[m]
|
|
if( v == "" || (v instanceof Array && v.length == 0)){ //if(isNaN(v)
|
|
v = 0
|
|
}
|
|
dict[name] = v
|
|
}
|
|
// max(site.supercomputer.nodes.count*site.supercomputer.nodes.processor.cores)
|
|
// => max(dotMultiply(site.supercomputer.nodes.count,site.supercomputer.nodes.processor.cores))
|
|
var c = math.eval(equationParsed, dict)
|
|
if(isNaN(c)){
|
|
return 0
|
|
}
|
|
return c
|
|
}
|
|
|
|
function computeSitesValues(){
|
|
jQuery("#dcl_siteequation").css({color: "black"})
|
|
var rows = []
|
|
var error = false
|
|
var equationRow = dataTableRowsP.indexOf("equation")
|
|
for (var site in repository){
|
|
var d = repository[site]
|
|
var row = []
|
|
var all_data = []
|
|
for (var m in dataTableRowsP){
|
|
var numeric = dataTableRowsP[m] in schema_fields_numeric
|
|
var a = extractValues(d["DATA"], dataTableRowsP[m], numeric)
|
|
var res = 0
|
|
if( m != equationRow){
|
|
if (numeric){
|
|
res = reduceSiteValues(a, siteAggregationOperator)
|
|
}else{
|
|
res = a
|
|
}
|
|
}
|
|
row.push(res)
|
|
all_data.push(a)
|
|
}
|
|
if( equationRow >= 0){
|
|
if(! error){
|
|
try{
|
|
row[equationRow] = computeEquation(all_data, dataTableRowsP)
|
|
}catch(err){
|
|
console.log(err)
|
|
jQuery("#dcl_siteequation").css({color: "red"})
|
|
error = true
|
|
row[equationRow] = 0
|
|
}
|
|
}else{
|
|
row[equationRow] = 0
|
|
}
|
|
}
|
|
rows.push(row)
|
|
}
|
|
//console.log(rows)
|
|
//d["DATA"]["att"][cols[c]]
|
|
dataTable = rows
|
|
}
|
|
|
|
jQuery(window).on("orientationchange",function(){
|
|
showGraphs(true)
|
|
});
|
|
|
|
jQuery( window ).resize(function() {
|
|
showGraphs(true)
|
|
});
|
|
|
|
|
|
function showGraphs(checkSize = false){
|
|
var old_graph_width = graph_width
|
|
graph_height = jQuery(window).height()
|
|
graph_width = jQuery(window).width()
|
|
if (graph_height > 600){
|
|
graph_height = 600
|
|
}
|
|
if(graph_width > 600){
|
|
graph_width = 600
|
|
if (old_graph_width == 600 && checkSize){
|
|
return
|
|
}
|
|
}
|
|
if(graph_height > graph_width){
|
|
graph_height = graph_width
|
|
}
|
|
|
|
if (pie != null){
|
|
pie.destroy()
|
|
}
|
|
if(graphAggregated == null || graphAggregated.length == 0){
|
|
return
|
|
}
|
|
|
|
jQuery("#dcl_pie").html("<h3>" + siteAggregationOperatorGraph + "(" + graphShowColumn + ") by " + aggregateByName + "</h3>")
|
|
|
|
pie = new d3pie("dcl_pie", { // http://d3pie.org/website/examples/tooltips_placeholders.html
|
|
size: {
|
|
canvasHeight: graph_height,
|
|
canvasWidth: graph_width
|
|
},
|
|
header: {
|
|
//title: {
|
|
//fontSize: 14
|
|
//}
|
|
},
|
|
effects: {
|
|
load: {
|
|
effect: "none"
|
|
}
|
|
},
|
|
data: {
|
|
content: graphAggregated
|
|
},
|
|
callbacks: {
|
|
//onMouseoverSegment: function(info) {
|
|
//console.log("mouseover:", info);
|
|
//},
|
|
//onMouseoutSegment: function(info) {
|
|
//console.log("mouseout:", info);
|
|
//}
|
|
},
|
|
tooltips: {
|
|
enabled: true,
|
|
type: "placeholder",
|
|
string: "{label}, {value}, {percentage}%"
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function add_sort_list_button(c, new_sort){
|
|
var id = "#dcl_sort_list_by_"+ c
|
|
jQuery( id ).click(function(e) {
|
|
e.preventDefault();
|
|
if (new_sort == sort_list_by){
|
|
sort_list_asc = ! sort_list_asc
|
|
}else{
|
|
sort_list_asc = false
|
|
sort_list_by = new_sort
|
|
orderlistBy = ""
|
|
jQuery( "#dcl_order_list_by" ).val("")
|
|
}
|
|
updateTable()
|
|
});
|
|
}
|
|
|
|
function addSiteLink(site){
|
|
var p = siteLinkMap[site]
|
|
if ( p == undefined || p.length != 2 ){
|
|
console.log(site)
|
|
return site;
|
|
}
|
|
var link = html_root + "/" + p[0] + "/" + p[1] + "/start"
|
|
return '<a href="' + link + '">' + site + '</a>'
|
|
}
|
|
|
|
function updateTable(){
|
|
var str = ''
|
|
var cols = dataTableRowsP
|
|
schema_fields_numeric["equation"] = {"default-unit" : equation_unit}
|
|
|
|
str = str + '<tr><th>#</th>'
|
|
for (var c in cols){
|
|
str = str + '<th><a href="#" id="dcl_sort_list_by_'+ c +'">' + cols[c] + '</a></th>'
|
|
}
|
|
str = str + '</tr>'
|
|
|
|
// headers
|
|
str = str + '<tr class="dcl_units"><th></th>'
|
|
str = str + ""
|
|
|
|
for (var c in cols){
|
|
var r = schema_fields_numeric[cols[c]]
|
|
if(r != null && "default-unit" in r){
|
|
str = str + "<th>in " + r["default-unit"] + "</th>"
|
|
}else{
|
|
str = str + "<th></th>"
|
|
}
|
|
}
|
|
str = str + '</tr>'
|
|
|
|
var sort_row_id
|
|
var sort_by_name
|
|
if (orderlistBy == ""){
|
|
sort_by_name = sort_list_by
|
|
}else{
|
|
sort_by_name = orderlistBy
|
|
}
|
|
sort_row_id = dataTableRowsP.indexOf(sort_by_name)
|
|
|
|
var dataList = []
|
|
for(var a in dataTable){
|
|
var l = dataTable[a]
|
|
dataList.push([l[sort_row_id], l])
|
|
}
|
|
|
|
if(sort_by_name in schema_fields_numeric){
|
|
if(sort_list_asc){
|
|
dataList = dataList.sort(function(a, b){
|
|
return a[0] - b[0];
|
|
});
|
|
}else{
|
|
dataList = dataList.sort(function(b, a){
|
|
return a[0] - b[0];
|
|
});
|
|
}
|
|
}else{
|
|
if(sort_list_asc){
|
|
dataList = dataList.sort(function(b, a){
|
|
return a[0].length - b[0].length || a > b;
|
|
});
|
|
}else{
|
|
dataList = dataList.sort(function(a, b){
|
|
return a[0].length - b[0].length || a > b;
|
|
});
|
|
}
|
|
}
|
|
var siteID = dataTableRowsP.indexOf("site.institution")
|
|
var equationID = dataTableRowsP.indexOf("equation")
|
|
|
|
for (var row in dataList){
|
|
if(dataTableLimit != -1 && row >= dataTableLimit){
|
|
break
|
|
}
|
|
str = str + '<tr>'
|
|
str = str + "<td>" + (Number(row)+1) + "</td>"
|
|
|
|
for (var c in cols){
|
|
var val = dataList[row][1][c]
|
|
var cls = ""
|
|
if (cols[c] in schema_fields_numeric){
|
|
val = valueToBaseUnit(cols[c], val, c != equationID)
|
|
}else if(c == siteID){
|
|
val = addSiteLink(val)
|
|
cls = ' class="str"'
|
|
}else{
|
|
cls = ' class="str"'
|
|
}
|
|
str = str + '<td' + cls +'> ' + val + '</td>'
|
|
}
|
|
str = str + '</tr>'
|
|
}
|
|
jQuery("#dcl_tbl").html(str)
|
|
|
|
for (var c in cols){
|
|
add_sort_list_button(c, cols[c])
|
|
}
|
|
}
|
|
|
|
function addToolbar(){
|
|
var str
|
|
str = '<label for="dcl_order_list_by">Order list by</label><select id="dcl_order_list_by"><option></option>'
|
|
for(var val in schema_fields_numeric){
|
|
if(val == orderlistBy){
|
|
str = str + '<option selected="selected">' + val + "</option>"
|
|
}else{
|
|
str = str + "<option>" + val + "</option>"
|
|
}
|
|
}
|
|
str = str + '</select>'
|
|
jQuery("#dcl_toolbar").append("<div>"+ str + "</div>")
|
|
|
|
jQuery( "#dcl_order_list_by" ).change(function() {
|
|
orderlistBy = jQuery(this).val()
|
|
sort_list_by = ""
|
|
sort_list_asc = false
|
|
exportURL()
|
|
updateDataTableRows()
|
|
computeSitesValues()
|
|
updateTable()
|
|
});
|
|
|
|
|
|
str = '<div><label for="dcl_siteAggregation">Site aggregation function</label><select id="dcl_siteAggregation">'
|
|
var ops = ["mean", "min", "max", "sum"]
|
|
for(var op in ops){
|
|
var selected = ""
|
|
if(ops[op] == siteAggregationOperator){
|
|
selected = ' selected="selected"'
|
|
}
|
|
str = str + '<option'+selected+'>' + ops[op] + "</option>"
|
|
}
|
|
str = str + '</select></div>'
|
|
jQuery("#dcl_toolbar").append(str)
|
|
jQuery( "#dcl_siteAggregation" ).change(function() {
|
|
siteAggregationOperator = jQuery(this).val()
|
|
exportURL()
|
|
computeSitesValues()
|
|
updateTable()
|
|
});
|
|
|
|
str = '<div><label for="dcl_siteequation">Equation</label><input id="dcl_siteequation" type="text" title="You may use any equation but use a reduce function like mean,max,min,sum to aggregate across values from a site" value="'+ equation +'"></input></div>'
|
|
jQuery("#dcl_toolbar").append(str)
|
|
jQuery( "#dcl_siteequation" ).change(function() {
|
|
equation = jQuery(this).val()
|
|
var ret = parseEquation()
|
|
if( ! ret ){
|
|
return
|
|
}
|
|
exportURL()
|
|
updateDataTableRows()
|
|
computeSitesValues()
|
|
updateTable()
|
|
updateGraphRows()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
showGraphs()
|
|
});
|
|
|
|
str = '<div><label for="dcl_siteequation_unit">Equation unit</label><input id="dcl_siteequation_unit" type="text" title="" value="'+ equation_unit +'"></input></div>'
|
|
jQuery("#dcl_toolbar").append(str)
|
|
jQuery( "#dcl_siteequation_unit" ).change(function() {
|
|
equation_unit = jQuery(this).val()
|
|
exportURL()
|
|
updateTable()
|
|
updateAggregatedTable()
|
|
showGraphs()
|
|
});
|
|
|
|
str = '<label for="dcl_tbl_add">Add table column</label><select id="dcl_tbl_add"><option></option>'
|
|
for(var val in schema_fields_numeric){
|
|
if(dataTableRowsP.indexOf(val) == -1){
|
|
str = str + '<option value="'+val+'">' + val + "</option>"
|
|
}
|
|
}
|
|
for(var val in schema_fields_string){
|
|
if(dataTableRowsP.indexOf(val) == -1){
|
|
str = str + '<option value="'+val+'">' + val + "</option>"
|
|
}
|
|
}
|
|
str = str + '</select>'
|
|
jQuery("#dcl_toolbar").append("<div>"+ str + "</div>")
|
|
|
|
jQuery( "#dcl_tbl_add" ).change(function() {
|
|
var val = jQuery(this).val()
|
|
if(val == ""){
|
|
return
|
|
}
|
|
jQuery("#dcl_tbl_add option[value='" + val + "']").remove();
|
|
jQuery("#dcl_tbl_remove").append('<option value="'+val+'">'+ val + '</option>');
|
|
dataTableRows.push(val)
|
|
exportURL()
|
|
updateDataTableRows()
|
|
computeSitesValues()
|
|
updateTable()
|
|
});
|
|
|
|
|
|
|
|
str = '<label for="dcl_tbl_remove">Remove table column</label><select id="dcl_tbl_remove"><option></option>'
|
|
for(var val in schema_fields_numeric){
|
|
if(dataTableRows.indexOf(val) >= 0){
|
|
str = str + '<option value="'+val+'">' + val + "</option>"
|
|
}
|
|
}
|
|
for(var val in schema_fields_string){
|
|
if(dataTableRows.indexOf(val) >= 0){
|
|
str = str + '<option value="'+val+'">' + val + "</option>"
|
|
}
|
|
}
|
|
str = str + '</select>'
|
|
jQuery("#dcl_toolbar").append("<div>" + str + "</div>")
|
|
|
|
jQuery( "#dcl_tbl_remove" ).change(function() {
|
|
var val = jQuery(this).val()
|
|
if(val == ""){
|
|
return
|
|
}
|
|
jQuery("#dcl_tbl_remove option[value='" + val + "']").remove();
|
|
jQuery("#dcl_tbl_add").append('<option value="'+val+'">'+ val + '</option>');
|
|
|
|
dataTableRows.splice(dataTableRows.indexOf(val), 1)
|
|
exportURL()
|
|
updateDataTableRows()
|
|
computeSitesValues()
|
|
updateTable()
|
|
});
|
|
}
|
|
|
|
|
|
function addToolbar_graph(){
|
|
var str
|
|
|
|
str = '<div><label for="dcl_siteAggregation2">Site aggregation function</label><select id="dcl_siteAggregation2">'
|
|
var ops = ["mean", "min", "max", "sum"]
|
|
for(var op in ops){
|
|
var selected = ""
|
|
if(ops[op] == siteAggregationOperatorGraph){
|
|
selected = ' selected="selected"'
|
|
}
|
|
str = str + '<option'+selected+'>' + ops[op] + "</option>"
|
|
}
|
|
str = str + '</select>'
|
|
str = str + '</div>'
|
|
jQuery("#dcl_toolbar_graph").append(str)
|
|
jQuery( "#dcl_siteAggregation2" ).change(function() {
|
|
siteAggregationOperatorGraph = jQuery(this).val()
|
|
exportURL()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
showGraphs()
|
|
});
|
|
|
|
str = '<label for="dcl_aggregate_by">Aggregate by</label><select id="dcl_aggregate_by">'
|
|
for(var val in schema_fields_string){
|
|
if(val == aggregateByName){
|
|
str = str + '<option selected="selected">' + val + "</option>"
|
|
}else{
|
|
str = str + "<option>" + val + "</option>"
|
|
}
|
|
}
|
|
str = str + '</select>'
|
|
jQuery("#dcl_toolbar_graph").append("<div>"+ str + "</div>")
|
|
|
|
jQuery( "#dcl_aggregate_by" ).change(function() {
|
|
aggregateByName = jQuery(this).val()
|
|
exportURL()
|
|
updateGraphRows()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
showGraphs()
|
|
});
|
|
|
|
str = '<label for="dcl_graph_column">Show graph value</label><select id="dcl_graph_column">'
|
|
str = str + '<option value="equation">equation</option>'
|
|
for(var val in schema_fields_numeric){
|
|
if(val == graphShowColumn){
|
|
str = str + '<option selected="selected">' + val + "</option>"
|
|
}else{
|
|
str = str + "<option>" + val + "</option>"
|
|
}
|
|
}
|
|
str = str + '</select>'
|
|
jQuery("#dcl_toolbar_graph").append("<div>"+ str + "</div>")
|
|
|
|
jQuery( "#dcl_graph_column" ).change(function() {
|
|
graphShowColumn = jQuery(this).val()
|
|
exportURL()
|
|
updateGraphRows()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
showGraphs()
|
|
});
|
|
|
|
str = '<label for="dcl_show_names">Show names</label><input id="dcl_show_names" type="checkbox"/>'
|
|
str = str + '<label for="dcl_show_all_names">Show all names</label><input id="dcl_show_all_names" type="checkbox"/>'
|
|
jQuery("#dcl_toolbar_graph").append("<div>" + str + "</div>")
|
|
|
|
jQuery("#dcl_show_names").prop("checked", showNames);
|
|
jQuery( "#dcl_show_names" ).change(function() {
|
|
showNames = jQuery(this).is(':checked')
|
|
if(showNames){
|
|
dataTableRowsGraph.push("site.institution")
|
|
}else{
|
|
dataTableRowsGraph.splice("site.institution", 1)
|
|
}
|
|
exportURL()
|
|
updateGraphRows()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
});
|
|
|
|
|
|
|
|
jQuery("#dcl_show_all_names").prop("checked", showAllNames);
|
|
jQuery( "#dcl_show_all_names" ).change(function() {
|
|
showAllNames = jQuery(this).is(':checked')
|
|
if(showAllNames){
|
|
for(var c in schema_fields_string_names){
|
|
dataTableRowsGraph.push(c)
|
|
}
|
|
}else{
|
|
for(var c in schema_fields_string_names){
|
|
dataTableRowsGraph.splice(dataTableRowsGraph.indexOf(c), 1)
|
|
}
|
|
}
|
|
exportURL()
|
|
updateGraphRows()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
});
|
|
|
|
str = '<label for="dcl_tbl_add2">Add table column</label><select id="dcl_tbl_add2"><option></option>'
|
|
for(var val in schema_fields_numeric){
|
|
if(dataTableRowsGraph.indexOf(val) == -1){
|
|
str = str + '<option value="'+val+'">' + val + "</option>"
|
|
}
|
|
}
|
|
str = str + '</select>'
|
|
jQuery("#dcl_toolbar_graph").append("<div>"+ str + "</div>")
|
|
|
|
jQuery( "#dcl_tbl_add2" ).change(function() {
|
|
var val = jQuery(this).val()
|
|
if(val == ""){
|
|
return
|
|
}
|
|
jQuery("#dcl_tbl_add2 option[value='" + val + "']").remove();
|
|
jQuery("#dcl_tbl_remove2").append('<option value="'+val+'">'+ val + '</option>');
|
|
dataTableRowsGraph.push(val)
|
|
exportURL()
|
|
updateGraphRows()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
showGraphs()
|
|
});
|
|
|
|
str = '<label for="dcl_tbl_remove2">Remove table column</label><select id="dcl_tbl_remove2"><option></option>'
|
|
for(var val in schema_fields_numeric){
|
|
if(dataTableRowsGraph.indexOf(val) >= 0){
|
|
str = str + '<option value="'+val+'">' + val + "</option>"
|
|
}
|
|
}
|
|
str = str + '</select>'
|
|
jQuery("#dcl_toolbar_graph").append("<div>" + str + "</div>")
|
|
|
|
jQuery( "#dcl_tbl_remove2" ).change(function() {
|
|
var val = jQuery(this).val()
|
|
if(val == ""){
|
|
return
|
|
}
|
|
jQuery("#dcl_tbl_remove2 option[value='" + val + "']").remove();
|
|
jQuery("#dcl_tbl_add2").append('<option value="'+val+'">'+ val + '</option>');
|
|
|
|
dataTableRowsGraph.splice(dataTableRowsGraph.indexOf(val), 1)
|
|
exportURL()
|
|
updateGraphRows()
|
|
aggregateGraphValues()
|
|
updateAggregatedTable()
|
|
showGraphs()
|
|
});
|
|
}
|
|
|
|
function add_sort_button(c, new_sort){
|
|
var id = "#dcl_sort_by_"+ c
|
|
jQuery( id ).click(function(e) {
|
|
e.preventDefault();
|
|
if (new_sort == sort_by){
|
|
sort_asc = ! sort_asc
|
|
}else{
|
|
sort_asc = false
|
|
sort_by = new_sort
|
|
}
|
|
updateAggregatedTable()
|
|
});
|
|
}
|
|
|
|
function valueToBaseUnit(metric, data, honorUnit){
|
|
var r = schema_fields_numeric[metric]
|
|
var val = parseFloat(data)
|
|
if(honorUnit && "default-unit" in r){
|
|
// convert to default unit
|
|
var unit = unitValueMap[r["default-unit"]][0]
|
|
val = val / unit
|
|
}
|
|
if (r["dtype"] == "number"){
|
|
val = val.toFixed(2)
|
|
}
|
|
return val
|
|
}
|
|
|
|
function updateAggregatedTable(){
|
|
var str = ''
|
|
var cols = dataTableRowsGraph
|
|
var aggregateBy = dataTableRowsGraphP.indexOf(aggregateByName)
|
|
|
|
var graphColumnOrig = dataTableRowsGraphP.indexOf(graphShowColumn)
|
|
var graphColumn = cols.indexOf(graphShowColumn)
|
|
schema_fields_numeric["equation"] = {"default-unit" : equation_unit}
|
|
|
|
str = str + '<tr>'
|
|
str = str + '<th> ' + aggregateByName + '</th>'
|
|
str = str + '<th> ' + graphShowColumn + '</th>'
|
|
|
|
for (var c in cols){
|
|
if( c == aggregateBy || c == graphColumn){
|
|
continue
|
|
}
|
|
if(cols[c] in schema_fields_numeric){
|
|
str = str + '<th><a href="#" id="dcl_sort_by_'+ c +'">' + cols[c] + '</a></th>'
|
|
}else{
|
|
str = str + '<th>' + cols[c] + '</th>'
|
|
}
|
|
}
|
|
str = str + '</tr>'
|
|
|
|
var siteID = dataTableRowsGraphP.indexOf("site.institution")
|
|
|
|
str = str + '<tr class="dcl_units"><th></th>'
|
|
var r = schema_fields_numeric[graphShowColumn]
|
|
if(r != null && "default-unit" in r){
|
|
str = str + '<th>in ' + r["default-unit"] + "</th>"
|
|
}else{
|
|
str = str + "<th></th>"
|
|
}
|
|
|
|
for (var c in cols){
|
|
if( c == aggregateBy || c == graphColumn){
|
|
continue
|
|
}
|
|
var r = schema_fields_numeric[cols[c]]
|
|
if(r != null && "default-unit" in r){
|
|
str = str + '<th>in ' + r["default-unit"] + "</th>"
|
|
}else{
|
|
str = str + "<th></th>"
|
|
}
|
|
}
|
|
str = str + '</tr>'
|
|
|
|
|
|
var sort_row_id = graphColumnOrig
|
|
var dataList = []
|
|
for(var a in dataAggregated){
|
|
var l = dataAggregated[a]
|
|
dataList.push([a, l[sort_row_id], l])
|
|
}
|
|
|
|
if(sort_by in schema_fields_numeric){
|
|
if(sort_asc){
|
|
dataList = dataList.sort(function(a, b){
|
|
return a[1] - b[1];
|
|
});
|
|
}else{
|
|
dataList = dataList.sort(function(a, b){
|
|
return b[1] - a[1];
|
|
});
|
|
}
|
|
}
|
|
var equationID = dataTableRowsGraphP.indexOf("equation")
|
|
var notEquation = "equation" != graphShowColumn
|
|
for (var a in dataList){
|
|
str = str + '<tr>'
|
|
str = str + '<td class="str"> ' + dataList[a][0] + '</td>'
|
|
str = str + '<td> ' + valueToBaseUnit(graphShowColumn,dataList[a][2][graphColumnOrig], notEquation) + '</td>'
|
|
for (var c in cols){
|
|
if( c == aggregateBy || c == graphColumn){
|
|
continue
|
|
}
|
|
if (cols[c] in schema_fields_numeric){
|
|
var val = valueToBaseUnit(cols[c], dataList[a][2][c], c != equationID)
|
|
str = str + '<td> ' + val + '</td>'
|
|
}else{
|
|
var val = dataList[a][2][c]
|
|
if( c == siteID ){
|
|
val = addSiteLink(val)
|
|
}
|
|
str = str + '<td class="str"> ' + val + '</td>'
|
|
}
|
|
}
|
|
str = str + '</tr>'
|
|
}
|
|
jQuery("#dcl_aggregated_tbl").html(str)
|
|
|
|
for (var c in cols){
|
|
if(cols[c] in schema_fields_numeric){
|
|
add_sort_button(c, cols[c])
|
|
}
|
|
}
|
|
}
|