简体   繁体   中英

How to pass values to the parameters of the function of a javascript and get the result

I have a javascript function which is the formula for calculating the number of agents required for a call center. It accepts 5 values and returns one one value which is the number of agents required.
Can anyone please show an example for this javascript by passing few values to it and getting an output for this particular function. I want to use in jsp page.

JS:

function Calculate( arrivalRate, callDuration, serviceLevelP, serviceLevelT, agentsCount ) {
    var rate = arrivalRate / 3600;
    var u = rate * callDuration;
    var sl = 0;
    var SL = serviceLevelP / 100;
    var m = Math.floor( u );
    var ummf = Math.pow( u, m ) / fact( m );
    var sm = 0;
    var ukkf = 1;
    for ( var i = 0;
    i < m;
    ++ i ) {
        ukkf = Math.pow( u, i ) / fact( i );
        sm += ukkf;
    }
    var tTs = serviceLevelT / callDuration;
    do {
        m ++;
        ummf *= u / m;
        ukkf *= u / ( m - 1 );
        sm += ukkf;
        var p = u / m;
        var E = ummf / ( ummf + ( 1 - p ) * sm );
        sl = 1 - E * Math.exp( ( u - m ) * tTs );
    }
    while ( sl < SL );
    agentsCount.SetValue( m );
    function fact( x ) {
        var ret = 1;
        for ( var i = 2;
        i <= x;
        ++ i ) {
            ret *= i;
        }
        return ret;
    }
}

A very general example - it is not clear how and where do you want get the values from:

<%@ page language="java" %>
...
<html>
  ...
  // somewhere in the <head> a <script> tag with your function
  ...
  <c:set var="jspArrivalRate" value="123" />
  <c:set var="jspCallDuration" value="456" />
  <c:set var="jspServiceLevelP" value="789" />
  <c:set var="jspServiceLevelT" value="1011" />
  <c:set var="jspAgentsCount" value="12" />
  ...
  <script>
    var result = Calculate(${jspArrivalRate}, ${jspCallDuration}, ${jspServiceLevelP}, ${jspServiceLevelT}, ${jspAgentsCount});
    // do whatever you want with the result
  </script>
  ...
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM