(function(){ EMapper={}; EMapper.map=null; EMapper.USE=0; EMapper.GEN=1; var E=0; var P=1; var _3=null; var _4=[]; var _5=[]; function parse(_6){ function error(_7){ throw new SyntaxError(_7+" (rest: `"+_6+"')"); } function whitespace(){ for(var i=0;i<_6.length;++i){ if(_6.charAt(i)!=" "&&_6.charAt(i)!="\t"){ _6=_6.substr(i); return; } } } function quantity(){ var v; var m=_6.match(_b); if(!m){ return error("id expected"); } var _c=m[0]; whitespace(); if(_c=="use"){ v=EMapper.USE; }else{ if(_c=="gen"){ v=EMapper.GEN; }else{ return null; } } _6=_6.substr(_c.length); return v; } function match(_d){ var v=null; whitespace(); if(_6.charAt(0)==_d){ v=true; _6=_6.substr(1); } return v; } function source(){ whitespace(); var m=_6.match(_10); if(!m){ return error("Source-name expected"); } _11=m[1]; _6=_6.substr(m[0].length); _12[E][_11]="v = new Int64 (a);"; _12[P][_11]="v = a;"; } function number(){ whitespace(); var m=_6.match(_14); if(!m){ return error("Expected number"); } var t=m[0]; _6=_6.substr(t.length); var c=parseInt(t); if(c==NaN){ return error("Expected number"); } return c; } function func(){ var op; var m=_6.match(_b); if(!m){ return error("id expected"); } var _19=m[0]; if(_19=="MAX"){ op=">"; }else{ if(_19=="MIN"){ op="<"; }else{ return error("Expected MIN or MAX"); } } _6=_6.substr(_19.length); whitespace(); if(!match("(")){ return error("Expected `('"); } source(); whitespace(); if(!match(",")){ return error("Expected `,'"); } var c=number().toString(); whitespace(); if(!match(")")){ return error("Expected `)'"); } _12[E][_11]+="c=new Int64("+c+");"; _12[E][_11]+="if(c.cmp(v)"+op+"0) v=c;"; _12[P][_11]+="if("+c+op+"v)v="+c+";"; } function addend(){ whitespace(); var _1b=1; if(_6.charAt(0)=="-"){ match("-"); _1b=-1; whitespace(); }else{ if(_6.charAt(0)=="+"){ match("+"); whitespace(); } } if(_6.charAt(0)=="\""){ source(); }else{ func(); } if(_1b<0){ _12[E][_11]+="v.neg ();"; _12[P][_11]+="v = -v;"; } } var _1c=true; var _12=[]; var _11=null; var _b=/^\w+/; var _10=/^\"([^\"]+)\"/; var _14=/^((0x[0-9a-fA-f]+)|[0-9]+)/; var op="+"; _12[E]={}; _12[P]={}; var q=quantity(); if(q==null){ return error("Expected quantity name (e.g., `use' or `gen')"); } if(!match("=")){ return error("Expected `='"); } while(1){ if(!_1c){ whitespace(); if(_6.charAt(0)=="+"){ match("+"); op="+"; }else{ if(_6.charAt(0)=="-"){ match("-"); op="-"; }else{ if(_6.length==0){ break; }else{ return error("Expected + or - operator"); } } } } _1c=false; addend(); if(op=="+"){ _12[E][_11]+="r["+q+"].add(v);"; }else{ _12[E][_11]+="r["+q+"].sub(v);"; } _12[P][_11]+="r["+q+"]"+op+"=v;"; _5[q]=true; } return _12; } EMapper.Map=function(_1f){ this.f=[]; this.f[E]={}; this.f[P]={}; _5[EMapper.USE]=false; _5[EMapper.GEN]=false; for(var i=E;i<=P;++i){ var _21={}; for(var j=0;j<_1f.length;++j){ var _23=parse(_1f[j]); for(var src in _23[i]){ if(!_21[src]){ if(i==E){ _21[src]="var v,c;"; }else{ _21[src]="var v;"; } } _21[src]+=_23[i][src]; } } for(var src in _21){ this.f[i][src]=new Function("a","r",_21[src]); } } }; EMapper.Map.prototype.energy=function(e){ var r=[]; r[EMapper.USE]=new Int64(0); r[EMapper.GEN]=new Int64(0); for(var src in e){ var f=this.f[E][src]; if(f){ f(e[src],r); } } return r; }; EMapper.Map.prototype.hasMapping=function(_29){ return _5[_29]; }; EMapper.Map.prototype.power=function(p){ var r=[]; r[EMapper.USE]=0; r[EMapper.GEN]=0; for(var src in p){ var f=this.f[P][src]; if(f){ f(p[src],r); } } return r; }; EMapper.Map.prototype.toString=function(){ var str="["; for(var i=E;i<=P;++i){ for(var src in this.f[i]){ str+=src+":"+this.f[i][src]; } if(i==E){ str+=","; } } str+="]"; return str; }; function getMap(xml){ var _32=1; var s=xml.getElementsByTagName("settings"); var _34=null; var _35=/^map([0-9]+)/; if(!s||s.length!=1){ return; } for(var n=s[0].firstChild;n;n=n.nextSibling){ if(n.nodeType!=_32){ continue; } var _37=n.nodeName; if(!n.firstChild){ continue; } var _38=n.firstChild.nodeValue; var m=_37.match(_35); if(m){ var i=m[1]; if(!_34){ _34=[]; } _34[i]=_38; } } if(!_34){ _34=[]; _34[0]="use=\"Grid\"+MAX(\"Solar\",0)"; _34[1]="gen=\"Solar\""; } EMapper.map=new EMapper.Map(_34); var _3b=_4; _4=[]; for(var i=0;i<_3b.length;++i){ _3b[i](); } } EMapper.fetchMap=function(_3c){ function process(arg,xml){ getMap(xml); } if(EMapper.map){ _3c(); return; } _4[_4.length]=_3c; if(_3){ return; } _3=new HTTPRequest(); var _3f=location.protocol+"//"+location.host; _3.send("GET",_3f+"/cgi-bin/egauge-cfg?",process); }; EMapper.IG_fetchMap=function(url,_41){ _4[_4.length]=_41; _3=1; _IG_FetchXmlContent(url+"/cgi-bin/egauge-cfg?",getMap,{refreshInterval:1}); }; })();