Demo Discussion
Forum Config Examples Contributions Vulnerabilities
  Contributions to ELOG  Not logged in ELOG logo
Message ID: 30     Entry time: Mon Jul 20 14:23:56 2009
Author: Stefan Ritt 
Author Email: stefan.ritt@psi.ch 
Category: Script 
Subject: Doing mathematical calculations with attributes 
Status: Stable 
Last Revision:  

Following entry was written by Richard Stamper. I moved it here for persistency:

On the matter of automatic calculation of fields, it is possible using included javascript but you have to do the work yourself.  For example, we have a log which computes responsivity as the ratio of a photocurrent and optical power.  With log attributes called "Photocurrent", "Optical Power" and "Responsivity" there is a file in the logbooks directory called photomixer_javascript.html containing something like:

<script>

if (document.form1.Photocurrent) {
  document.form1.Photocurrent.onchange = new Function(
    "mod();"+
    "var power = parseFloat(
document.form1.Optical_Power.value);"+
    "var current = parseFloat(
document.form1.Photocurrent.value);"+
    "if (!isNan(power) && !isNan(current) && power != 0.0) {"+
    "  
document.form1.Responsivity.value = Math.round(current/power*100)/100.0"+
    "}"
    );

  document.form1.Optical_Power.onchange = document.form1.Photocurrent.onchange;
}

</script>

and the elogd.cfg file includes

Bottom text = photomixer_javascript.html

for the relevant log.

The assignments to the onchange handlers are guarded because this javascript is included on all pages for that log, including the list pages where there is no such field as Photocurrent, (or Optical_Power) and the event handler function is defined dynamically for the same reason.

 

ELOG V3.1.5-fe60aaf