Skip to content Skip to footer

Display the sum of choice list values on the header

In the below form script, A case is to calculate the total number of choices along with the score of the selected choices which will either be chosen as “Yes” or “No”. NA fields will not be considered.

var group1 = [
{
'gr':'Administrative_responsibility_for_shop_safety_has_been_clearly_defined', 'gname': 'g1'
},
{
'gr':'Employees_and_students_have_completed_machine_tool_and_facility_safety_training', 'gname': 'g1'
},
{
'gr':'Where_necessary__lock_out_tag_out_procedures_are_documented_for_each_piece_of_equipment__and_training_has_been_provided', 'gname': 'g1'
},
{
'gr':'Protective_eyewear_wom_at_all_times', 'gname': 'g1'
},
{
'gr':'Safety_training_documented_and_posted_in_a_central_location', 'gname': 'g1'
},
{
'gr':'Student_access_limited_to_regular_hours_of_operation_', 'gname': 'g1'
},
{
'gr':'Mandatory_student__buddy_system__enforced', 'gname': 'g1'
},
{
'gr':'Long__loose_hair_must_be_contained_in_a_scarf__cap_or_other_appropriate_fashion', 'gname': 'g1'
},
{
'gr':'Loose_clothing__loose_neck_wear_and_jewelry_not_being_wom_while_Joperating_or_in_proximity_to_machinery', 'gname': 'g1'
},
{
'gr':'Leather_shoes_are_required', 'gname': 'g1'
},
{
'gr':'Long_sleeves_on_shirts_must_be_rolled_up_smugly_above_the_elbows', 'gname': 'g1'
},
{
'gr':'Compressed_air_is_reduced_to_30_psi_and_is_not_used_to_clean_person_or_clothes', 'gname': 'g1'
}
]

var group2 = [

{
'gr':'Machinery_installed_to_prevent_unintentional_movement_or_tipping', 'gname': 'g2'
},
{
'gr':'A_brush_is_available_to_remove_stock_shavings_and_chips', 'gname': 'g2'
},
{
'gr':'Machinery_located_so_that_operator_and_others_tending_the_machine_do_not_stand_in_an_aisle', 'gname': 'g2'
},
{
'gr':'Powered_clectrical_equipment_has_an_on_off_switch', 'gname': 'g2'
},
{
'gr':'When_expected_motion_would_cause_injury__actuating_controls_are_guarded_or_located_to_prevent_accidental_actuation__and_precautions_have_been_taken_to_prevent_a_machine_from_automatically_restarting_upon_the_restoration_of_power_after_a_power_failure', 'gname': 'g2'
},
{
'gr':'A_red_emergency_stop_device_is_provided_where_the_machine_workstation_is_remotely_located_from_the_machine_controls', 'gname': 'g2'
},
{
'gr':'Actuation_of_the_controls_requires_continuous_depressions_during_the_hazardous_portion_of_the_machine_cycle_where_the_machine_workstation_is_remotely_located_from_the_machine_controls', 'gname': 'g2'
}
]


var group3 = [
{
'gr':'All_electrical_service_cords_are_in_good_condition', 'gname': 'g3'
},
{
'gr':'Electrically_powered_machines_are_grounded', 'gname': 'g3'
},
{
'gr':'Proper_use_of_extension_cords', 'gname': 'g3'
}

]

const all_group = [].concat(group1, group2, group3);

var total_score = 0;
var group1_score = 0;
var group2_score = 0;
var group3_score = 0;
var allgroup_score = 0;
var count = 0;
var group1_count = 0;
var group2_count = 0;
var group3_count = 0;

function abc(ws){
  total_score = 0;
  group1_score = 0;
  group2_score = 0;
  group3_score = 0;
  allgroup_score = 0;
  count=0;
  group1_count = 0;
  group2_count = 0;
  group3_count = 0;
  
  for(var i=0; i < all_group.length; i++){
    var val = all_group[i];
    var val_identifier = val['gr'];
    var value = JSON.parse(ws.getWidgetValue(val_identifier));
    calculation(ws, value)
    groupwisesum(ws, value, val)
  }
}

function groupwisesum(ws, value, val)
{
  if(value.indexOf('Yes') != -1 || value.indexOf('No') != -1){
    if(val['gname'] == 'g1'){group1_count++;}
    if(val['gname'] == 'g2'){group2_count++;}
    if(val['gname'] == 'g3'){group3_count++;}
    if(val['gname'] == 'g1' && value.indexOf('Yes') != -1){
      group1_score = group1_score + 1;
      //group1_count++;
    }else if (val['gname'] == 'g2' && value.indexOf('Yes') != -1){
      group2_score = group2_score + 1;
      //group2_count++;
    }else if (val['gname'] == 'g3' && value.indexOf('Yes') != -1){
      group3_score = group3_score + 1;
      //group3_count++;
    }
  }
	ws.setWidgetPrompt("General_Safety_2","General Safety (Score "+group1_score+" /"+group1_count+")");
    ws.reloadUICell("General_Safety_2");
    ws.setWidgetPrompt("General_Machine_Safety","General Machine Safety (Score "+group2_score+" /"+group2_count+")");
    ws.reloadUICell("General_Machine_Safety");
    ws.setWidgetPrompt("Electrical_Safety","Electrical Safety (Score "+group3_score+" /"+group3_count+")");
    ws.reloadUICell("Electrical_Safety");
    var a = group1_score+'/'+group2_score+'/'+group3_score;
    //ws.setWidgetPrompt("Total", a);
    //ws.reloadUICell("Total");
   
}

function calculation(ws, value){
  //count = 0;
  if(value.indexOf("Yes") != -1){
    allgroup_score = allgroup_score + 1;
    }
  
  if(value.indexOf("Yes") != -1 || value.indexOf("No") != -1){
    count++;
  }
  //+ + all_group.length
  var prompttext = allgroup_score +'/'+count;
  var percent = (allgroup_score / count) * 100;
  var percentt = 'Score '+percent.toFixed(2)+'% '+ prompttext;
  ws.setWidgetPrompt("Score_0___0_0",percentt);
  ws.reloadUICell("Score_0___0_0");
  
}

Was This Article Helpful?

0
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami