123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813 |
-
- //是否自定义公式
- function IsCustumFormula( fromStr)
- {
- var index=fromStr.indexOf("GETTAGSNAPSHORT(");
- if(index>=0)
- return true;
-
- index=fromStr.indexOf("GETTAGHISINTERVAL(");
- if(index>=0)
- return true;
-
- index=fromStr.indexOf("GETTIMEINTERVAL(");
- if(index>=0)
- return true;
-
- index=fromStr.indexOf("GETTIMESTASTIC(");
- if(index>=0)
- return true;
-
- return false;
- }
-
-
- function ApplyCustomFunc(spread)
- {
- var sheet = spread.getSheet(0);
-
- var getTagSnapShort = new goldenNameSpace.GetTagSnapShort();
- sheet.addCustomFunction(getTagSnapShort);
-
- var getTagHisInterval = new goldenNameSpace.GetTagHisInterval();
- sheet.addCustomFunction(getTagHisInterval);
-
- var getTimeInterval = new goldenNameSpace.GetTimeInterval();
- sheet.addCustomFunction(getTimeInterval);
-
- var getTimeStastic= new goldenNameSpace.GetTimeStastic();
- sheet.addCustomFunction(getTimeStastic);
-
- var getTagTimeStasticValue= new goldenNameSpace.GetTagTimeStasticValue();
- sheet.addCustomFunction(getTagTimeStasticValue);
-
- var getTagTimeStasticValue2= new goldenNameSpace.GetTagTimeStasticValue2();
- sheet.addCustomFunction(getTagTimeStasticValue2);
-
- var getTimeDisplayStr= new goldenNameSpace.GetTimeDisplayStr();
- sheet.addCustomFunction(getTimeDisplayStr);
- }
-
- //重新激活公式
- function ResetFormular(spread)
- {
- var sheet = spread.getSheet(0);
- //ApplyCustomFunc(spread);
- var colNum=sheet.getColumnCount();
- var rowNum=sheet.getRowCount();
- for( var i =0;i<colNum;i++)
- {
- for(var j=0;j<rowNum;j++)
- {
- var calcu=sheet.getFormula(j,i);
- if(calcu!=null)
- {
- //if(IsCustumFormula(calcu))
- //sheet.setFormula(j,i, "="+calcu);
- }
-
- /* var valueStr=sheet.getValue(j,i);
- if(!valueStr)
- continue;
- try
- {
- if(valueStr.indexOf("
")>=0)
- {
- var myCellType = new MyCellType();
- sheet.getCell(j,i).cellType(myCellType)
- }
- }
- catch(e)
- {
- }*/
- }
- sheet.autoFitColumn(i);
- }
- }
-
- //斜线表头
- function MyCellType() {
- }
- MyCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
- MyCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- //Paints a cell on the canvas.
- if (!ctx) {
- return;
- }
- ctx.save();
- ctx.beginPath();
- ctx.moveTo(x,y);
- ctx.lineTo(x+w,y+h);
- ctx.stroke();
- ctx.font = style.font;
-
- var text = value ? value.split(" ") : ["",""];
- ctx.fillText(text[0].trim() ,x + w *7/8, y + h/3);
- ctx.fillText(text[1].trim(),x + w /2, y + h*3/4);
- ctx.restore();
- };
-
- var goldenNameSpace = {};
- (function () {
-
-
- // 自定义公式(获取统计时间段值2)----------------------------------------------------------------------
- function GetTagTimeStasticValue2 ()
- {
- this.name = 'GetTagTimeStasticValue2';
- this.maxArgs = 4;
- this.minArgs = 4;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue2", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagTimeStasticValue2";
- }
- GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagTimeStasticValue2.prototype.evaluateMode = function () {
- return 0;
- };
- goldenNameSpace.GetTagTimeStasticValue2=GetTagTimeStasticValue2;
- GetTagTimeStasticValue2.prototype.evaluateAsync = function (context)
- {
- if(arguments.length>=5)
- {
- var ReportTag=arguments[1];
- var ReportStartTime=arguments[2];
- var ReportEndTime=arguments[3];
- var ReportSelectType=arguments[4];
-
- ReportStartTime= window[ReportStartTime];//获取控件中的变量值
- if(!ReportStartTime)
- return "";
-
- ReportEndTime= window[ReportEndTime];//获取控件中的变量值
- if(!ReportEndTime)
- return "";
- }
- else
- return "";
-
- var TempStartTime=new Date(Date.parse(ReportStartTime));
- var TempEndTime=new Date(Date.parse(ReportEndTime));
-
-
- console.log("ask:"+ReportTag);
- var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistorySummary?tagName=";
- urlStr+=ReportTag+"&beginTime="+TempStartTime.Format("yyyy-MM-dd hh:mm:ss")+"&endTime="+TempEndTime.Format("yyyy-MM-dd hh:mm:ss")+"&dataType=snap";
- $.ajax({
- type: 'GET',
- url: urlStr,
- dataType: 'json',
- cache: false,
- error:function(data)
- {
- context.setAsyncResult(data.responseText);
- },
- success: function (data)
- {
- if(!data)
- return;
-
- for (var key in data)
- {
- console.log("answer:"+key);
- var tagData= data[key];
- if(!tagData)
- continue;
- if(ReportSelectType=="avg")
- {
- var actVal=GetDital(tagData.CalcAvg,3);
- context.setAsyncResult(actVal);
- }
- else if(ReportSelectType=="max")
- {
- var actVal=GetDital(tagData.Max,3);
- context.setAsyncResult(actVal);
- }
- else if(ReportSelectType=="min")
- {
- var actVal=GetDital(tagData.Min,3);
- context.setAsyncResult(actVal);
- }
- else if(ReportSelectType=="sub")
- {
- var actVal=GetDital(tagData.Difference,3);
- context.setAsyncResult(actVal);
- }
- }
- }
- });
- }
-
-
- // 自定义公式(获取统计时间段值)----------------------------------------------------------------------
- function GetTagTimeStasticValue ()
- {
- this.name = 'GetTagTimeStasticValue';
- this.maxArgs = 4;
- this.minArgs = 4;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagTimeStasticValue";
- }
- GetTagTimeStasticValue.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagTimeStasticValue.prototype.evaluateMode = function () {
- return 0;
- };
- goldenNameSpace.GetTagTimeStasticValue=GetTagTimeStasticValue;
- GetTagTimeStasticValue.prototype.evaluateAsync = function (context)
- {
- if(arguments.length>=5)
- {
- ReportTag=arguments[1];
- ReportSelectTime=arguments[2];
- ReportTimeType=arguments[3];
- ReportSelectType=arguments[4];
-
- ReportSelectTime= window[ReportSelectTime];//获取控件中的变量值
- if(!ReportSelectTime)
- return "";
- }
- else
- return "";
-
- var TempStartTime=new Date(Date.parse(ReportSelectTime));
- var TempEndTime=new Date(Date.parse(ReportSelectTime));
- if(ReportTimeType=='d'||ReportTimeType=='D')
- {
- TempStartTime.setHours(0);
- TempStartTime.setMinutes(0);
- TempStartTime.setSeconds(0);
-
- TempEndTime.setHours(23);
- TempEndTime.setMinutes(59);
- TempEndTime.setSeconds(59);
- }
- else if(ReportTimeType=='m'||ReportTimeType=='M')
- {
- TempStartTime.setDate(1);
- TempStartTime.setHours(0);
- TempStartTime.setMinutes(0);
- TempStartTime.setSeconds(0);
-
- TempEndTime.setMonth( TempEndTime.getMonth()+1);
- TempEndTime.setHours(23);
- TempEndTime.setMinutes(59);
- TempEndTime.setSeconds(59);
- }
- else if(ReportTimeType=='y'||ReportTimeType=='Y')
- {
- TempStartTime.setMonth(0);
- TempStartTime.setDate(1);
- TempStartTime.setHours(0);
- TempStartTime.setMinutes(0);
- TempStartTime.setSeconds(0);
-
- var year= ReportSelectTime.getYear();
- TempEndTime.setYear(year+1+1900);
- TempEndTime.setMonth(0);
- TempEndTime.setDate(0);
- TempEndTime.setHours(23);
- TempEndTime.setMinutes(59);
- TempEndTime.setSeconds(59);
- }
- console.log("ask:"+ReportTag);
- var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistorySummary?tagName=";
- urlStr+=ReportTag+"&beginTime="+TempStartTime.Format("yyyy-MM-dd hh:mm:ss")+"&endTime="+TempEndTime.Format("yyyy-MM-dd hh:mm:ss")+"&dataType=snap";
- $.ajax({
- type: 'GET',
- url: urlStr,
- dataType: 'json',
- cache: false,
- error:function(data)
- {
- context.setAsyncResult(data.responseText);
- },
- success: function (data)
- {
- if(!data)
- return;
-
- for (var key in data)
- {
- console.log("answer:"+key);
- var tagData= data[key];
- if(!tagData)
- continue;
- if(ReportSelectType=="avg")
- {
- var actVal=GetDital(tagData.CalcAvg,3);
- context.setAsyncResult(actVal);
- }
- else if(ReportSelectType=="max")
- {
- var actVal=GetDital(tagData.Max,3);
- context.setAsyncResult(actVal);
- }
- else if(ReportSelectType=="min")
- {
- var actVal=GetDital(tagData.Min,3);
- context.setAsyncResult(actVal);
- }
- else if(ReportSelectType=="sub")
- {
- var actVal=GetDital(tagData.Difference,3);
- context.setAsyncResult(actVal);
- }
- else if(ReportSelectType=="start")
- {
-
- context.setAsyncResult(tagData.StartTime);
- }
- else if(ReportSelectType=="end")
- {
- context.setAsyncResult(tagData.EndTime);
- }
- }
- }
- });
- }
-
- // 自定义公式(获取统计时间段时间值)----------------------------------------------------------------------
- function GetTimeDisplayStr ()
- {
- this.name = 'GetTimeDisplayStr';
- this.maxArgs = 2;
- this.minArgs = 2;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeDisplayStr", 0, 0]);
- this.typeName = "goldenNameSpace.GetTimeDisplayStr";
- }
-
- goldenNameSpace.GetTimeDisplayStr=GetTimeDisplayStr;
- GetTimeDisplayStr.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTimeDisplayStr.prototype.evaluateMode = function () {
- return 0;
- };
- GetTimeDisplayStr.prototype.evaluateAsync = function (context)
- {
- //context.setAsyncResult("");
- //return;
- if(arguments.length>=2)
- {
- ReportSelectTime=arguments[1];
- ReportTimeFormat=arguments[2];
-
- ReportSelectTime= window[ReportSelectTime];//获取控件中的变量值
- if(!ReportSelectTime)
- {
- context.setAsyncResult("未找到时间变量!");
- return;
- }
- }
- else
- {
- context.setAsyncResult("参数数量不足!");
- return;
- }
-
- ReportSelectTime=new Date(Date.parse(ReportSelectTime));
- var ReportSelectTimeStr=ReportSelectTime.Format(ReportTimeFormat);
- context.setAsyncResult(ReportSelectTimeStr);
- }
-
- // 自定义公式(获取统计时间段值)----------------------------------------------------------------------
- // 自定义公式(获取统计时间段时间值)----------------------------------------------------------------------
- function GetTimeStastic ()
- {
- this.name = 'GetTimeStastic';
- this.maxArgs = 4;
- this.minArgs = 4;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeStastic", 0, 0]);
- this.typeName = "goldenNameSpace.GetTimeStastic";
- }
-
- goldenNameSpace.GetTimeStastic=GetTimeStastic;
- GetTimeStastic.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTimeStastic.prototype.evaluateMode = function () {
- return 0;
- };
- GetTimeStastic.prototype.evaluateAsync = function (context)
- {
- if(arguments.length>=5)
- {
- ReportSelectTime=arguments[1];
- ReportTimeType=arguments[2];
- ReportSelectType=arguments[3];
- ReportTimeFormat=arguments[4];
-
- ReportSelectTime= window[ReportSelectTime];//获取控件中的变量值
- }
- else
- {
- context.setAsyncResult("error!");
- return;
- }
-
- ReportSelectTime=new Date(Date.parse(ReportSelectTime));
- if(ReportTimeType=='d')
- {
- if(ReportSelectType=="start")
- {
- ReportSelectTime.setHours(0);
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else
- {
- ReportSelectTime.setHours(23);
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- else if(ReportTimeType=='m')
- {
- if(ReportSelectType=="start")
- {
- ReportSelectTime.setSeconds(0);
- }
- else
- {
- ReportSelectTime.setSeconds(59);
- }
- }
- else if(ReportTimeType=='h')
- {
- if(ReportSelectType=="start")
- {
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else
- {
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- else if(ReportTimeType=='M')
- {
- if(ReportSelectType=="start")
- {
- ReportSelectTime.setDate(1);
- ReportSelectTime.setHours(0);
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else
- {
- ReportSelectTime.setMonth( ReportSelectTime.getMonth()+1);
- ReportSelectTime.setDate(0);
- ReportSelectTime.setHours(23);
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- else if(ReportTimeType=='y')
- {
- if(ReportSelectType=="start")
- {
- ReportSelectTime.setMonth(0);
- ReportSelectTime.setDate(1);
- ReportSelectTime.setHours(0);
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else
- {
- var year= ReportSelectTime.getYear();
- ReportSelectTime.setYear(year+1+1900);
- ReportSelectTime.setMonth(0);
- ReportSelectTime.setDate(0);
- ReportSelectTime.setHours(23);
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- var ReportSelectTimeStr=ReportSelectTime.Format(ReportTimeFormat);
- context.setAsyncResult(ReportSelectTimeStr);
- }
- // 自定义公式(获取统计时间段时间值)----------------------------------------------------------------------
- // 自定义公式(获取时间段的等间隔显示)----------------------------------------------------------------------
- function GetTimeInterval () {
- this.name = 'GetTimeInterval';
- this.maxArgs = 6;
- this.minArgs = 6;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeInterval", 0, 0]);
- this.typeName = "goldenNameSpace.GetTimeInterval";
- }
- GetTimeInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTimeInterval.prototype.defaultValue = function () {return 'loading'};
-
- GetTimeInterval.prototype.evaluateMode = function () {
- return 0;
- };
-
- goldenNameSpace.GetTimeInterval=GetTimeInterval;
- //获取历史等间隔数据
- GetTimeInterval.prototype.evaluateAsync = function (context)
- {
- var args = arguments;
- var curCol=context.col;
- var curRow=context.row;
-
- if(args.length>=6)
- {
- var ReportStartTime=args[1];
- var ReportEndTime=args[2];
- var ReportInterval=args[3];
- var ReportIntervalType=args[4];
- var ReportTimeFormat=args[5];
- var ReportVH=args[6];
-
- ReportStartTime= window[ReportStartTime];
- ReportEndTime= window[ReportEndTime];
- //ReportInterval= window[ReportInterval];
- //ReportIntervalType = window[ReportIntervalType];
- }
- else
- {
- context.setAsyncResult(0);
- return;
- }
-
- var tempDateTime=new Date(Date.parse(ReportStartTime));
- var tempEndTime=new Date(Date.parse(ReportEndTime));
- var sheet =context.ctx.source;
- for(var i=1;i<200;i++)
- {
- if(ReportIntervalType=='s')
- {
- tempDateTime.setSeconds(tempDateTime.getSeconds()+ReportInterval);
- }
- else if(ReportIntervalType=='m')
- {
- tempDateTime.setMinutes(tempDateTime.getMinutes()+ReportInterval);
- }
- else if(ReportIntervalType=='h')
- {
- tempDateTime.setHours(tempDateTime.getHours()+ReportInterval);
- }
- else if(ReportIntervalType=='d')
- {
- tempDateTime.setDate(tempDateTime.getDate()+ReportInterval);
- }
- else if(ReportIntervalType=='M')
- {
- tempDateTime.setMonth(tempDateTime.getMonth()+ReportInterval);
- }
- else if(ReportIntervalType=='y')
- {
- tempDateTime.setYear(tempDateTime.getYear()+ReportInterval);
- }
- var tempDateStr=tempDateTime.Format(ReportTimeFormat);
-
- if(ReportVH=="v")
- {
- if(curRow+i<sheet.getRowCount()&&curCol<sheet.getColumnCount())
- sheet.setValue(curRow+i,curCol,tempDateStr);
- }
- else if(ReportVH=="h")
- {
- if(curRow<sheet.getRowCount()&&curCol+i<sheet.getColumnCount())
- sheet.setValue(curRow,curCol+i,tempDateStr);
- }
- if(tempDateTime>=tempEndTime)
- break;
- }
- tempDateTime=new Date(Date.parse(ReportStartTime));
- tempDateStr=tempDateTime.Format(ReportTimeFormat);
- context.setAsyncResult(tempDateStr);
- }
-
- // 自定义公式(获取时间段的等间隔显示)----------------------------------------------------------------------
- // 自定义公式(获取获取历史等间隔数据)----------------------------------------------------------------------
- function GetTagHisInterval () {
- this.name = 'GetTagHisInterval';
- this.maxArgs = 6;
- this.minArgs = 6;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisInterval", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagHisInterval";
- }
- goldenNameSpace.GetTagHisInterval=GetTagHisInterval;
- GetTagHisInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagHisInterval.prototype.defaultValue = function () {return 'loading'};
- GetTagHisInterval.prototype.evaluateMode = function () {
- return 0;
- };
- GetTagHisInterval.prototype.interval = function () {
- return 1000;
- };
- //获取历史等间隔数据
- GetTagHisInterval.prototype.evaluateAsync = function (context)
- {
- var args = arguments;
- var curCol=context.col;
- var curRow=context.row;
-
- if(args.length>=5)
- {
- var Reporttag=args[1];
- var ReportStartTime=args[2];
- var ReportEndTime=args[3];
- var ReportInterval=args[4];
- var ReportIntervalType=args[5];
- var ReportVH=args[6];
-
- ReportStartTime= window[ReportStartTime];
- ReportEndTime= window[ReportEndTime];
- //ReportInterval= window[ReportInterval];
- ReportIntervalType= "0";// window[ReportIntervalType];
- }
- else
- {
- context.setAsyncResult(0);
- return;
- }
-
- if(ReportIntervalType=="m")//分钟
- {
- ReportInterval=ReportInterval*60;
- }
- else if(ReportIntervalType=="h")//小时
- {
- ReportInterval=ReportInterval*3600;
- }
- else if(ReportIntervalType=="d")//天
- {
- ReportInterval=ReportInterval*3600*24;
- }
-
- var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName="; //+ cmdStr;
- pageIndex=1;
- tagsCount=200;
- urlStr += createSearchStr(Reporttag,ReportStartTime, ReportEndTime, ReportInterval, ReportIntervalType, ReportInterval)
- + '&pageIndex=' + pageIndex + '&pageSize='+ tagsCount;
- // getTableHisData(shotTablePane,url,shotTableTableModel,shotTablecolumns,shotTablerows);
- $.ajax({
- type: 'GET',
- url: urlStr,
- dataType: 'json',
- cache: false,
- success: function (data) {
- if(!data.Datas)
- {
- context.setAsyncResult("not find!");
- return;
- }
-
- for (var key in data.Datas)
- {
- var tagData= data.Datas[key];
- if(!tagData)
- continue;
- if(tagData.length>0)
- {
- var showCount=200;
-
- if(tagData.length<showCount)
- showCount=tagData.length;
- var actVal=GetDital(tagData[0].Value,3)
- context.setAsyncResult(actVal);
- var sheet =context.ctx.source;
- for(var i=0;i<showCount;i++)
- {
- actVal=GetDital(tagData[i].Value,3);
- if(ReportVH=="v")
- {
- if(curRow+i<sheet.getRowCount()&&curCol<sheet.getColumnCount())
- sheet.setValue(curRow+i,curCol,actVal);
- }
- else if(ReportVH=="h")
- {
- if(curRow<sheet.getRowCount()&&curCol+i<sheet.getColumnCount())
- sheet.setValue(curRow,curCol+i,actVal);
- }
- }
- //sheet.autoFitColumn(curCol);
- return;
- }
- else
- {
- context.setAsyncResult("not find!");
- return;
- }
- break;
- }
- var sheet =context.ctx.source;
- sheet.refresh();
- }
- })
- }
- //创建等间隔历史查询的查询字符串
- function createSearchStr (tagNameStr,beginTime, endTime, interval, valueType, count)
- {
- beginTime = beginTime || moment(new Date()).format("YYYY-MM-DD H:mm:ss");
- endTime = endTime || moment(new Date(beginTime)).add(30,'seconds').format("YYYY-MM-DD H:mm:ss");
- interval = interval || 10;
- valueType = valueType || 1;
- count = Math.floor((new Date(endTime) - new Date(beginTime)) / interval / 1000);
- var result = '';
- var tagsInfo = encodeURIComponent(tagNameStr);
- result = tagsInfo + '&beginTime=' + beginTime + '&endTime=' + endTime + '&interval=' + interval + '&count=' + count;
- if (valueType !== '0') {
- result += '&valueType=' + valueType;
- }
- return result;
- }
- // 自定义公式(获取获取历史等间隔数据)----------------------------------------------------------------------
-
-
- // 自定义公式(获取快照值)----------------------------------------------------------------------
- function GetTagSnapShort () {
- this.name = 'GETTAGSNAPSHORT';
- this.maxArgs = 2;
- this.minArgs = 2;
-
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagSnapShort", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagSnapShort";
- }
- goldenNameSpace.GetTagSnapShort=GetTagSnapShort;
- GetTagSnapShort.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagSnapShort.prototype.defaultValue = function () {return 'loading'};
- GetTagSnapShort.prototype.evaluateMode = function () {
- return 2;
- };
- GetTagSnapShort.prototype.interval = function () {
- return 1000;
- };
- GetTagSnapShort.prototype.evaluateAsync = function (context) {
- var args = arguments;
- if(args.length>1)
- tag=args[1];
- else
- {
- context.setAsyncResult(0);
- return;
- }
- var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot?tagName=";
- var para = tag;
- str = str + encodeURIComponent(para);
- $.ajax({
- url: str ,
- type: 'GET',
- dataType: 'json',
- cache: false,
- success: function (data) {
- if (data === null) return;
- var snapshots = eval(data);
- //判断快照是否为空
- if (snapshots != null) {
- var value=0;
- if(snapshots.length>0)
- value= snapshots[0].Value;
- var actVal= GetDital(value,3);
- context.setAsyncResult(actVal);
- }
- },
- complete: function (XHR, TS) {
- XHR = null;
- }
- }
- );
- }
- })();
-
- // 自定义公式(获取快照值)----------------------------------------------------------------------
- // 对Date的扩展,将 Date 转化为指定格式的String
- // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
- // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
- // 例子:
- // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
- // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
- Date.prototype.Format = function (fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
|