Hitachi Vantara Pentaho Community Forums
Results 1 to 1 of 1

Thread: Calculate score based on fields in a table

  1. #1
    Join Date
    Sep 2017
    Posts
    18

    Default Calculate score based on fields in a table

    Hello,

    I want to calculate a score or indicator based on certain fields in a table. For now let's assume that all values in the table are relevant to the score.

    My initial idea was, since I already have a snippet of code that modifies the fields in the table based on their value to use that incrementing a "parameter", which will end up showing in a text component.

    This is the script I use to color and resize the values in the table:

    this.setAddInOptions("colType","formattedText",function(cell_data){
    var days = cell_data.value;
    if(!cell_data.value) {//checking the null possibility
    this.value = '00000';
    }

    if(cell_data.colIdx == '0') {
    if(days >= 20) {
    return { textFormat: function(v, st) { return "<font size='30' color='red'>"+v+"%</font>"; } };
    }
    else if(days <= 5) {
    return { textFormat: function(v, st) { return "<font size='30' color='green'>"+v+"%</font>"; } };
    }
    else if(true) {
    return { textFormat: function(v, st) { return "<font size='30' color='orange'>"+v+"%</font>"; } };
    }
    }

    if(cell_data.colIdx == '1') {
    if(days >= 20) {
    return { textFormat: function(v, st) { return "<font size='30' color='red'>"+v+"%</font>"; } };
    }
    else if(days <= 4) {
    return { textFormat: function(v, st) { return "<font size='30' color='green'>"+v+"%</font>"; } };
    }
    else if(true) {
    return { textFormat: function(v, st) { return "<font size='30' color='orange'>"+v+"%</font>"; } };
    }
    }

    if(cell_data.colIdx == '2') {
    if(days >= 40) {
    return { textFormat: function(v, st) { return "<font size='30' color='red'>"+v+"%</font>"; } };
    }
    else if(days <= 10) {
    return { textFormat: function(v, st) { return "<font size='30' color='green'>"+v+"%</font>"; } };
    }
    else if(true) {
    return { textFormat: function(v, st) { return "<font size='30' color='orange'>"+v+"%</font>"; } };
    }
    }


    }) ;
    }


    So I wanted to combine the "Dashboard.fireChange(param, param_value)" and the "getParameterValue(param)" to get and set the score parameter inbetween lines of the other script, updating it 3 times and calclating the final score based on the previous fields that are being evaluated.

    However I haven't been able to acomplish my task so I think my idea may have not been the correct one and there can be a simpler way of achieving this task.

    How would you go about it? - DONE

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    EDIT:

    Ended up fiiguring it out. I had made a mistake in some point of the code. As initially considered, I ended up using the getParameterValue and fireChange functions. This is the final code in case anyone is interested:

    function f(){
    //conditional coloring of cells
    this.setAddInOptions("colType","formattedText",function(cell_data){
    var c=0;
    var d=0;
    var days = cell_data.value;
    if(!cell_data.value) {//checking the null possibility
    this.value = '00000';
    }
    if(cell_data.colIdx == '0') {
    c=0;
    dashboard.fireChange('Score',c);
    d=Number(c);
    if(days >= 20) {
    return { textFormat: function(v, st) { return "<font size='30' color='red'>"+v+"%</font>"; } };
    }
    else if(days <= 5) {
    d=d+40;
    dashboard.fireChange('Score',d);
    return { textFormat: function(v, st) { return "<font size='30' color='green'>"+v+"%</font>"; } };
    }
    else if(true) {
    d=d+20;
    dashboard.fireChange('Score',d);
    return { textFormat: function(v, st) { return "<font size='30' color='orange'>"+v+"%</font>"; } };
    }
    }

    if(cell_data.colIdx == '1') {
    c=dashboard.getParameterValue("Score");
    d=Number(c);
    if(days >= 20) {
    return { textFormat: function(v, st) { return "<font size='30' color='red'>"+v+"%</font>"; } };
    }
    else if(days <= 4) {
    d=d+40;
    dashboard.fireChange('Score',d);
    return { textFormat: function(v, st) { return "<font size='30' color='green'>"+v+"%</font>"; } };
    }
    else if(true) {
    d=d+20;
    dashboard.fireChange('Score',d);
    return { textFormat: function(v, st) { return "<font size='30' color='orange'>"+v+"%</font>"; } };
    }
    }

    if(cell_data.colIdx == '2') {
    c=dashboard.getParameterValue("Score");
    d=Number(c);
    if(days >= 40) {
    dashboard.fireChange('Score',d);
    return { textFormat: function(v, st) { return "<font size='30' color='red'>"+v+"%</font>"; } };
    }
    else if(days <= 10) {
    d=20+d;
    dashboard.fireChange('Score',d);
    return { textFormat: function(v, st) { return "<font size='30' color='green'>"+v+"%</font>"; } };
    }
    else if(true) {
    d=10+d;
    dashboard.fireChange('Score',d);
    return { textFormat: function(v, st) { return "<font size='30' color='orange'>"+v+"%</font>"; } };
    }
    }
    }) ;
    }

    Then, in a simple text component I get the score parameter

    function fun() {
    var score=this.dashboard.getParameterValue("Score");
    score=Number(score);
    var v="Score: " + score;
    return "<font size='30' color='black'>"+v+"</font>";
    }
    Last edited by qwerty123; 10-16-2017 at 05:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.