From c67cc167853e0634be0b983597f06164895f9848 Mon Sep 17 00:00:00 2001 From: "ec.huyinghuan@gmail.com" Date: Fri, 10 Jan 2014 14:44:29 +0800 Subject: [PATCH 1/2] genarition Report file --- .../StatisticsReportNoGraphicMonitoring.html | 36 +++++++++---------- .../StatisticsReportNoGraphicStatistical.html | 13 +++++-- .../server/report/StatisticsReportFactory.js | 27 ++++++++++---- eccmeteor/server/startup.js | 2 +- .../test/StatisticsReportFactoryTest.js | 5 ++- 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html b/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html index a659c574..01260093 100644 --- a/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html +++ b/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html @@ -4,34 +4,32 @@
-

<%= basedata.reportTitle%>

-

<%= startTime%> ~ <%= endTime%>

+

<%= baseData.reportTitle%>

+

<%= baseData.startTime%> ~ <%= baseData.endTime%>

监测 - + - - - - - - + + + + + - <%for(var i = 0 ; i < tableData.length ; i++){%> + <%for(i in records){%> - - - - - - - + + + + + + - <%}%> - statistical + <%}%> +
名称返回值名称最大值最小值平均值最近一次最大值时间正常(%)危险(%)错误(%)禁止(%)阀值
<%= tableData[i].MonitorName%><%= tableData[i].ReturnName%><%= tableData[i].max%><%= tableData[i].min%><%= tableData[i].average%><%= tableData[i].latest%><%= tableData[i].when_max%><%= records[i].MonitorName%><%= records[i].okPercent%><%= records[i].warnPercent%><%= records[i].errorPercent%><%= (100 - ((+records[i].okPercent) + (+records[i].warnPercent) + (+records[i].errorPercent))).toFixed(2)%><%= records[i].errorCondition%>
diff --git a/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html b/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html index c835a91f..61f5c418 100644 --- a/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html +++ b/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html @@ -9,13 +9,22 @@ 名称 - 返回值名称 + 返回值 最大值 平均值 - 最近一次 + 最新值 + <%for(i in records){%> + + <%= records[i].MonitorName%> + <%= records[i].ReturnName%> + <%= records[i].max%> + <%= records[i].average%> + <%= records[i].latest%> + + <%}%> diff --git a/eccmeteor/server/report/StatisticsReportFactory.js b/eccmeteor/server/report/StatisticsReportFactory.js index 941e4080..4006d09c 100644 --- a/eccmeteor/server/report/StatisticsReportFactory.js +++ b/eccmeteor/server/report/StatisticsReportFactory.js @@ -1,10 +1,12 @@ +var fs = Npm.require('fs'); StatisticsReportFactory = function(reportConfigureId){ this.setting = {}; this.monitorIds = []; this.extentDate = []; this.fileType = []; this._options = { - NoGraphicReportMnotoring:"StatisticsReportNoGraphicMonitoring" + NoGraphicReportMnotoringHtmlTemplate:"StatisticsReportNoGraphicMonitoring.html", + NoGraphicStatisticalHtmlTemplate:"StatisticsReportNoGraphicStatistical.html" } this.init(reportConfigureId); }; @@ -55,7 +57,12 @@ StatisticsReportFactory.prototype.getExtentDate = function(){ //拼接时间 StatisticsReportFactory.prototype.joinTime = function(obj){ - return obj.year + "-" + obj.month + "-" + obj.day+ " " +obj.hour + ":" +obj.minute+":"+obj.second; + return obj.year + + "-" + (obj.month < 10 ? ("0" + obj.month):obj.month ) + + "-" + (obj.day < 10 ? ("0" + obj.day) :obj.day ) + + " " + obj.hour + + ":" + obj.minute + + ":" + obj.second; } StatisticsReportFactory.prototype.buildTime = function(extent){ @@ -111,15 +118,23 @@ StatisticsReportFactory.prototype.drawNoGraphicReport = function(){ delete monitoringRecords[x]; } } + //console.log(monitoringRecords); var baseData = this.buildNoGraphicReportOtherSetting(); var monitoringContext = { baseData:baseData, records:monitoringRecords } - var monitoringTemplate = this._option.NoGraphicReportMnotoring; + var statisticalContext = { + baseData:baseData, + records:statisticalRecords + } + var monitoringTemplate = this._options.NoGraphicReportMnotoringHtmlTemplate; + var statisticalTemplate = this._options.NoGraphicStatisticalHtmlTemplate; var uuid = Meteor.uuid(); var monitoring = HtmlTemplate.render(monitoringTemplate,monitoringContext); - + var statistical = HtmlTemplate.render(statisticalTemplate,statisticalContext); + _self.writeToHtml(monitoring,"/home/ec/a.html"); + _self.writeToHtml(statistical,"/home/ec/b.html"); } StatisticsReportFactory.prototype.buildNoGraphicReportOtherSetting=function(){ @@ -136,6 +151,6 @@ StatisticsReportFactory.prototype.buildNoGraphicReportOtherSetting=function(){ } } -StatisticsReportFactory.prototype.write = function(string){ - +StatisticsReportFactory.prototype.writeToHtml = function(htmlContent,fileName){ + fs.writeFileSync(fileName,new Buffer(htmlContent)); } \ No newline at end of file diff --git a/eccmeteor/server/startup.js b/eccmeteor/server/startup.js index 0fa52d48..72c2f837 100755 --- a/eccmeteor/server/startup.js +++ b/eccmeteor/server/startup.js @@ -74,7 +74,7 @@ var SetSvdbAddr = function(){ Meteor.startup(function(){ process.sv_init(); SetSvdbAddr(); - if(!TestUnit.test(1)){ + if(!TestUnit.test(0)){ return; } var status = AssetsUtils.getDevConfig("initDatabase"); diff --git a/eccmeteor/server/test/StatisticsReportFactoryTest.js b/eccmeteor/server/test/StatisticsReportFactoryTest.js index bfbd26af..56c7fb83 100644 --- a/eccmeteor/server/test/StatisticsReportFactoryTest.js +++ b/eccmeteor/server/test/StatisticsReportFactoryTest.js @@ -1,7 +1,7 @@ StatisticsReportFactoryTest = function(){}; Object.defineProperty(StatisticsReportFactoryTest,"getRecords",{ value:function(){ - var factory = new StatisticsReportFactory("5qSjY2kbgb655MRaD"); + var factory = new StatisticsReportFactory("w8rGbu9BKPMbSMkB7"); factory.genaritionReport(); } @@ -10,6 +10,9 @@ Object.defineProperty(StatisticsReportFactoryTest,"getRecords",{ Object.defineProperty(StatisticsReportFactoryTest,"test",{ value:function(){ StatisticsReportFactoryTest.getRecords(); + //console.log(SvseStatisticalresultlist.find().fetch());{nIndex:reportConfigureId} + //console.log(SvseStatisticalresultlist.findOne("w8rGbu9BKPMbSMkB7")); + } }); /* From affb5739ef556b0472f7fe18840f85887ea64266 Mon Sep 17 00:00:00 2001 From: "ec.huyinghuan@gmail.com" Date: Fri, 10 Jan 2014 18:16:41 +0800 Subject: [PATCH 2/2] some function add --- .../StatisticsReportNoGraphicMonitoring.html | 8 ++ .../StatisticsReportNoGraphicStatistical.html | 8 ++ eccmeteor/private/test/test.json | 2 +- eccmeteor/server/lib/EccSystem.js | 32 ++++++- eccmeteor/server/report/ReportExport.js | 7 ++ .../server/report/StatisticsReportFactory.js | 91 ++++++++++++++----- eccmeteor/server/startup.js | 2 +- eccmeteor/server/test/EccSystemTest.js | 6 ++ 8 files changed, 131 insertions(+), 25 deletions(-) create mode 100644 eccmeteor/server/test/EccSystemTest.js diff --git a/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html b/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html index 01260093..d2fb0c1b 100644 --- a/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html +++ b/eccmeteor/private/report/StatisticsReportNoGraphicMonitoring.html @@ -3,6 +3,14 @@ +
+ 首页 + 前一页 + 后一页 + 末页 + 共 :<%= baseData.theTotalPage%>页 + 当前是第:<%= baseData.theCurrentPage + 1 %>页 +

<%= baseData.reportTitle%>

<%= baseData.startTime%> ~ <%= baseData.endTime%>

diff --git a/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html b/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html index 61f5c418..69e24034 100644 --- a/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html +++ b/eccmeteor/private/report/StatisticsReportNoGraphicStatistical.html @@ -3,6 +3,14 @@ +
+ 首页 + 前一页 + 后一页 + 末页 + 共 :<%= baseData.theTotalPage%>页 + 当前是第:<%= baseData.theCurrentPage + 1 %>页 +
统计 diff --git a/eccmeteor/private/test/test.json b/eccmeteor/private/test/test.json index 72e41ae2..588c9e83 100644 --- a/eccmeteor/private/test/test.json +++ b/eccmeteor/private/test/test.json @@ -1 +1 @@ -[{"name":"StatisticsReportFactoryTest","fn":"test"}] \ No newline at end of file +[{"name":"EccSystemTest","fn":"test"}] \ No newline at end of file diff --git a/eccmeteor/server/lib/EccSystem.js b/eccmeteor/server/lib/EccSystem.js index bbb872c9..63d3f4cc 100755 --- a/eccmeteor/server/lib/EccSystem.js +++ b/eccmeteor/server/lib/EccSystem.js @@ -4,7 +4,7 @@ Date:2013-11-04 14:43 Content:增加获取应用根目录的方法 getRootPath */ -EccSystem = {}; +EccSystem = function(){}; Object.defineProperty(EccSystem,"require",{ value:function(modulname){ return Npm.require(modulname); @@ -34,4 +34,32 @@ Object.defineProperty(EccSystem,"joinPath",{ var path = EccSystem.require("path"); return path.join.apply(null,arguments); } -}) \ No newline at end of file +}); + + +Object.defineProperty(EccSystem,"mkdir",{ + value:function(dirpath,dirname){ + var fs = Npm.require("fs"); + var path = Npm.require('path'); + //判断是否是第一次调用 + if(typeof dirname === "undefined"){ + if(fs.existsSync(dirpath)){ + return; + }else{ + arguments.callee(dirpath,path.dirname(dirpath)); + } + }else{ + //判断第二个参数是否正常,避免调用时传入错误参数 + if(dirname !== path.dirname(dirpath)){ + arguments.callee(dirpath); + return; + } + if(fs.existsSync(dirname)){ + fs.mkdirSync(dirpath) + }else{ + arguments.callee(dirname,path.dirname(dirname)); + fs.mkdirSync(dirpath); + } + } + } +}); \ No newline at end of file diff --git a/eccmeteor/server/report/ReportExport.js b/eccmeteor/server/report/ReportExport.js index b98ceaa3..2bcdb0c6 100644 --- a/eccmeteor/server/report/ReportExport.js +++ b/eccmeteor/server/report/ReportExport.js @@ -80,4 +80,11 @@ Meteor.Router.add("/TimeContrastReport",'GET',function(){ 'Content-type': 'text/html', 'Content-Disposition': "attachment; filename=timecontrast_report.html" },new Buffer(DrawTimeContrastReport.export(mid,[st1,et1,st2,et2],type))]; +}); + + +Meteor.Router.add("/StatisticsReport/:_reportId",'GET',function(){ + console.log(_reportId); + var _reportPage = this.request.query.page; + var isDownLoad = this.request.query.isDownLoad; }) \ No newline at end of file diff --git a/eccmeteor/server/report/StatisticsReportFactory.js b/eccmeteor/server/report/StatisticsReportFactory.js index 4006d09c..75af7673 100644 --- a/eccmeteor/server/report/StatisticsReportFactory.js +++ b/eccmeteor/server/report/StatisticsReportFactory.js @@ -6,7 +6,8 @@ StatisticsReportFactory = function(reportConfigureId){ this.fileType = []; this._options = { NoGraphicReportMnotoringHtmlTemplate:"StatisticsReportNoGraphicMonitoring.html", - NoGraphicStatisticalHtmlTemplate:"StatisticsReportNoGraphicStatistical.html" + NoGraphicStatisticalHtmlTemplate:"StatisticsReportNoGraphicStatistical.html", + _perPage:24, } this.init(reportConfigureId); }; @@ -112,45 +113,93 @@ StatisticsReportFactory.prototype.drawNoGraphicReport = function(){ */ var monitoringRecords = SvseMonitorDaoOnServer.getMonitorReportDataByfilter(monitorIds,dateExtent[0],dateExtent[1],filter,false); var statisticalRecords = []; + + var perPage = this._options._perPage; + + var pagerMonitoringRecords = []; + var totalMonitoringRecords = []; + + var pagerStatisticalRecords = []; + var totalStatisticalRecords = []; + + for(x in monitoringRecords){ if(x.indexOf("Return") !== -1 || x.indexOf("return") !== -1){ - statisticalRecords.push(monitoringRecords[x]); - delete monitoringRecords[x]; + pagerStatisticalRecords.push(monitoringRecords[x]); + if(pagerStatisticalRecords.length == perPage){ + totalStatisticalRecords.push(pagerStatisticalRecords); + pagerStatisticalRecords = new Array(); + } + continue; + } + pagerMonitoringRecords.push(monitoringRecords[x]); + if(pagerMonitoringRecords.length == perPage){ + totalMonitoringRecords.push(pagerMonitoringRecords); + pagerMonitoringRecords = new Array(); } } - //console.log(monitoringRecords); - var baseData = this.buildNoGraphicReportOtherSetting(); - var monitoringContext = { - baseData:baseData, - records:monitoringRecords + + if(pagerStatisticalRecords.length){ + totalStatisticalRecords.push(pagerStatisticalRecords); } - var statisticalContext = { - baseData:baseData, - records:statisticalRecords + + if(pagerMonitoringRecords.length){ + totalMonitoringRecords.push(pagerMonitoringRecords); } + + var uuid = Meteor.uuid(); + + var totalPage = totalMonitoringRecords.length + totalStatisticalRecords.length; + var monitoringTemplate = this._options.NoGraphicReportMnotoringHtmlTemplate; + + for(var i = 0 ; i < totalMonitoringRecords.length ; i++){ + var baseData = this.buildNoGraphicReportOtherSetting(i,totalPage); + var monitoringContext = { + baseData:baseData, + records:totalMonitoringRecords[i] + } + var monitoring = HtmlTemplate.render(monitoringTemplate,monitoringContext); + _self.writeToHtml(monitoring,"/home/ec/testReportWritefile/"+i+".html"); + } + var statisticalTemplate = this._options.NoGraphicStatisticalHtmlTemplate; - var uuid = Meteor.uuid(); - var monitoring = HtmlTemplate.render(monitoringTemplate,monitoringContext); - var statistical = HtmlTemplate.render(statisticalTemplate,statisticalContext); - _self.writeToHtml(monitoring,"/home/ec/a.html"); - _self.writeToHtml(statistical,"/home/ec/b.html"); + for(var j = 0 ; j < totalStatisticalRecords.length ; j++){ + var baseData = this.buildNoGraphicReportOtherSetting(i+j,totalPage); + var statisticalContext = { + baseData:baseData, + records:totalStatisticalRecords[j] + } + var statistical = HtmlTemplate.render(statisticalTemplate,statisticalContext); + _self.writeToHtml(statistical,"/home/ec/testReportWritefile/"+(i+j)+".html"); + } } -StatisticsReportFactory.prototype.buildNoGraphicReportOtherSetting=function(){ +StatisticsReportFactory.prototype.buildNoGraphicReportOtherSetting=function(currentPage,totalPage){ var self = this; var dateExtent = this.getExtentDate(); + var theLastPage = totalPage-1; return { reportTitle: self.setting.Title.split("\|")[0], startTime:self.joinTime(dateExtent[0]), endTime:self.joinTime(dateExtent[0]), - theLastPage:0, - theBeforePage:0, - theBeforePage:0, - theAfterPage:0 + theFirstPage:0, + theLastPage:theLastPage, + theCurrentPage:currentPage, + theBeforePage:currentPage == 0 ? 0 : (currentPage - 1), + theAfterPage:currentPage == theLastPage ? currentPage : (currentPage + 1), + theTotalPage:totalPage } } StatisticsReportFactory.prototype.writeToHtml = function(htmlContent,fileName){ fs.writeFileSync(fileName,new Buffer(htmlContent)); +} + + +StatisticsReportFactory.prototype.getReportSvaePath = function(uuid){ + var path = "/home/ec/testReportWritefile"; + path = EccSystem.joinPath(path,uuid); + EccSystem.mkdir(path); + return path; } \ No newline at end of file diff --git a/eccmeteor/server/startup.js b/eccmeteor/server/startup.js index 72c2f837..0fa52d48 100755 --- a/eccmeteor/server/startup.js +++ b/eccmeteor/server/startup.js @@ -74,7 +74,7 @@ var SetSvdbAddr = function(){ Meteor.startup(function(){ process.sv_init(); SetSvdbAddr(); - if(!TestUnit.test(0)){ + if(!TestUnit.test(1)){ return; } var status = AssetsUtils.getDevConfig("initDatabase"); diff --git a/eccmeteor/server/test/EccSystemTest.js b/eccmeteor/server/test/EccSystemTest.js new file mode 100644 index 00000000..ac8bb661 --- /dev/null +++ b/eccmeteor/server/test/EccSystemTest.js @@ -0,0 +1,6 @@ +EccSystemTest = function(){}; +Object.defineProperty(EccSystemTest,"test",{ + value:function(){ + EccSystem.mkdir("/home/ec/asdasdsads"); + } +}); \ No newline at end of file