123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- export default {
- compareDate:function(d1,d2){
- return d1.getTime()-d2.getTime();
- },
- roundHour:function(date,add){
- add=add||0;
- var h=Math.floor(date/(1000*60*60));
- return (h+add)*1000*60*60;
- },
- diffDate:function(d1,d2,tag){
- tag=tag||"HH";
- var diff=d1-d2;
- if(tag=="HH"){
- return diff/(1000*60*60);
- }
- else if(tag=="mm"){
- return diff/(1000*60);
- }
- },
- parseDate:function(str){
- str=str.replace(/-/g,"/");
- return new Date(str);
- },
- format:function(millis,fmt){
- fmt=fmt||"MM.dd HH:00";
- var date=new Date(millis);
- if(fmt=="MM.dd HH:00"){
- return (date.getMonth()+1)+"."+date.getDate()+" "+date.getHours()+":00";
- }
- if(fmt=="MM.dd HH:mm"){
- return (date.getMonth()+1)+"."+date.getDate()+" "+date.getHours()+":"+date.getMinutes();
- }
- if(fmt=="MM.dd HH:mm:ss"){
- return (date.getMonth()+1)+"."+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
- }
- return null;
- },
- getProjValDevider:function(minVal,maxVal,count){
- var opts=[0.1,0.2,0.5,1,2,3,4,5,10,15,20,25,30,35,40,45,50];
- var devider=(maxVal-minVal)/count;
- if(devider>50){
- return Math.ceil(devider/50)*50;
- }
- else{
- var idx=this.search(devider,opts);
- return opts[idx];
- }
- },
-
- search:function(item,ary){
- for (var i= 0, len= ary.length; i < len; i++) {
- if (ary[i]>=item) {
- return i;
- }
- }
- return ary.length - 1;
- },
- waveFilter:function(datas,winsize){
- let fileterWin=[]
- let sumWin=0
- let outItm=null
- let rst=datas.map((data,index)=>{
- if(index>=winsize){
- outItm=fileterWin.shift()
- sumWin-=outItm[1]
- }
- fileterWin.push(data)
- sumWin+=data[1]
-
- return [data[0],sumWin/fileterWin.length]
-
- })
- return rst
- }
- }
|