Groovy web console

subscribe to the feed Subscribe
to this
site
aa (via #groovywebconsole)
tweet this snippet Tweet
this
script

aa

Published 8 months ago by aa
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
        def relativeDistanceScore(distance, score_min, score_max, value_max) {
          median_value = value_max / 2.0;

          // negative min score
          if (score_min < 0.0) {
            value_max = median_value; // median will be scored 0.0
          }

          println "-----";
          println "distance ${distance}";
          println "median_value ${median_value}";
          println "score_min ${score_min}";
          println "score_max ${score_max}";
          println "value_max ${value_max}";
          println "-----";

          if (distance > median_value) {
            return Math.max(score_min, score_max - (distance * (score_max/value_max)));
          } else {
            return Math.max(score_min, (distance * (score_min/value_max)) - score_min);
          }
        }

      distance = 26.0;
      score_min = -1.0;
      score_max = 1.0;
      value_min = 0.0;
      value_max = 50.0;

        custom_score = relativeDistanceScore(distance, score_min, score_max, value_max);

        println "custom_score ${custom_score}";