## @brief Compute the Quantitative Worthiness Assessment Criteria for Sayings (QWACS).
## See https://friengineers.co.za/blog/stupid-sayings/the-worthiness-assessment-criteria-for-sayings-qwacs/
## @param x The values for from the rubrics.
## License: MIT License
function OverallScore = QWACS(x)
  # Check args
  if(length(x) != 7)
    error("Must be 7 criteria values");
  endif
  
  x1 = x(1);
  x2 = x(2);
  x3 = x(3);
  x4 = x(4);
  x5 = x(5);
  x6 = x(6);
  x7 = x(7);
  N = length(x);
  
  if(max(x) > 2 || min(x) < -2)
    error("All criteria values should be between -2 and 2");
  endif
  
  # Truth only has two values:
##  if(x1 != 2 && x1 != -2)
##    error("Truth must be -2 or 2");
##  endif
  
  if(x3 < 0)
    error("Wit must be >= 0");
  endif
  
  if(x6 > 0)
    error("Sloganasunetos: Only supports <= 0");
  endif
  
  if(x7 > 0)
    error("Superiority signalling: Only supports <= 0");
  endif
  
  
  w11 = 1;
  w12 = 1;
  if(x1 > 0 && x2 < 0)
    w11 = 0;
  endif
  if(x1 < 0 && x3 > 0)
    w12 = 0;
  endif
  w1 = 1 * w11 * w12
  w21 = 1;
  if(x3 > 0 && x2 < 0)
    w21 = 0;
  endif
  w2 = 1 * w21
  w3 = 1
  w4 = 1
  w5 = 1
  
  if(x5 < 0)
    w7 = 1;
  else
    w7 = 0;
  endif
  
  w = zeros(size(x));
  w(1) = w1;
  w(2) = w2;
  w(3) = w3;
  w(4) = w4;
  w(5) = w5;
  w(6) = 0;
  w(7) = w7;
  
  w6 = -(sum(x(1:5) .* w(1:5)) + sum(x(7:7) .* w(7:7))) / (N-1)
  
  w(6) = w6;
  
  w
  x
  wx = w .* x
  Kf = 0.5;
  OverallScore = Kf * sum(w .* x);
endfunction