Skip to content

Commit 3c30f38

Browse files
committed
modified code for including multiple calls for rolling-count and rolling-time within an expression
1 parent 6f078e4 commit 3c30f38

1 file changed

Lines changed: 92 additions & 23 deletions

File tree

filter.js

Lines changed: 92 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,97 @@
11
var fs = require('fs');
22
var _=require('highland');
3+
var rollingCount=require('./rollingCount');
34
var readableStream = fs.createReadStream('logs.json');
45
readableStream.setEncoding('utf8');
5-
var keys=['insertions','deletions','authorName','authorEmail'];
6-
//var exp="select record.insertions deletions authorName authorEmail from StreamA if(insertions>max(rollingCount(1min,insertions)))"
7-
var exp="select record.insertions deletions authorName authorEmail from StreamA if(insertions>deletions)"
8-
9-
var condition =exp.match(/if\(.+[><=(!=)(contains)][(avesrage)(max)(min)]\)/g)
6+
var keys;
7+
var exp="select record.insertions record.deletions record.authorName record.authorEmail from StreamA if(rollingCount(22).avg(record.insertions)> rollingCount(11).max(record.insertions))"
8+
//var exp="select record.insertions deletions authorName authorEmail from StreamA if(insertions>deletions)"
9+
var RT=[];//function constructors generated from expression for rollingTime
10+
var RC=[];//function constructors generated from expression for rollingCounts
11+
var condition =exp.match(/if\(.+[><=(!=)(contains)]\)/g)
1012
condition=condition.toString();
11-
condition="if((record.insertions>record.deletions) || record.type=='commit' )";
12-
var through = _.pipeline(
13-
_.map(function (chunk) {
14-
var data=JSON.parse(chunk); // assuming the chunk/stream to be array of objects
15-
data.map(function(record) {
16-
var bool='false';
17-
bool=eval(condition+"true");
18-
if(bool)
19-
record.highlight=true;
20-
})
21-
return JSON.stringify(data);
22-
}),
23-
_.filter(function (chunk) {
24-
// console.log("index of all highlights"+);
25-
return chunk
26-
})
27-
);
28-
_(readableStream).pipe(through).pipe(process.stdout);
13+
var rollingCountemp=condition.match(/rollingCount\D\d+\D/g);
14+
if (rollingCountemp) {
15+
var rollingCountVars=[];
16+
for (var i = 0; i < rollingCountemp.length; i++) {
17+
rollingCountVars.push(rollingCountemp[i].match(/\d+/g))
18+
}
19+
for (var i = 0; i < rollingCountemp.length; i++) {
20+
RC.push(new rollingCount(parseInt(rollingCountVars[i])));
21+
}
22+
for (var i = 0; i < 2; i++) {
23+
condition=condition.replace(rollingCountemp[i],'RC['+i+']')
24+
}
25+
26+
}//if ends RollingCount
27+
var rollingTimetemp=condition.match(/rollingTime\D\d+\D/g);
28+
if(rollingTimetemp){
29+
var rollingTimeVars=[];
30+
// for (var i = 0; i < rollingTimetemp.length; i++) {
31+
// rollingTimeVars.push(rollingTimetemp[i].match(/\d+/g))
32+
// }
33+
// for (var i = 0; i < rollingTimetemp.length; i++) {
34+
// RT.push(new rollingTime(parseInt(rollingTimeVars[i])));
35+
// }
36+
37+
for (var i = 0; i < 2; i++) {
38+
condition=condition.replace(rollingTimetemp[i],'RT['+i+']')
39+
}
40+
}//if ends rollingTimetemp
41+
42+
43+
44+
45+
46+
// //condition="if(record.insertions>disp())";
47+
// var through = _.pipeline(
48+
// _.map(function (chunk) {
49+
// var data=JSON.parse(chunk); // assuming the chunk/stream to be array of objects
50+
// if(!keys)
51+
// keys=Object.keys(data[0])
52+
// if(!expkeys)
53+
// {
54+
// var temp=exp.split(" ");
55+
// if(temp[1]=='*');
56+
// {
57+
// expkeys=keys; //keys in expression
58+
// }
59+
// else{
60+
// var i=1;
61+
// while(temp[i]!=='from')
62+
// expkeys.push(temp[i].substr(7))
63+
// }
64+
// }
65+
// data.map(function(record) {
66+
// var bool='false';
67+
// bool=eval(condition+"true");
68+
// if(bool)
69+
// record.highlight=true;
70+
// })
71+
// return JSON.stringify(data);
72+
// }),
73+
// _.filter(function (chunk) {
74+
// return chunk
75+
// })
76+
// );
77+
// _(readableStream).pipe(through).pipe(process.stdout);
78+
/************************************rollingCount***********************************************/
79+
function rollingCount(value,n,aggregate) {
80+
81+
82+
83+
84+
}
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
/*********************************rollingTime***************************************************/

0 commit comments

Comments
 (0)