You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

function cycleAdd(rets, ar)
{
var ret = rets;
for(var i=0;i<ar.length;i++)
{
if(ar[i].last>ret.last) ret.last = ar[i].last;
ret.number+=ar[i].number;
for(var index in ar[i].countries)
{
if(index in ret.countries)
ret.countries[index]+=ar[i].countries[index];
else
ret.countries[index]= ar[i].countries[index];
}
ret.threads+=ar[i].threads;
ret.comments+=ar[i].comments;
ret.subjects+=ar[i].subjects;
ret.images+=ar[i].images;
ret.names+=ar[i].names;
ret.trips+=ar[i].trips;
ret.nametrips+=ar[i].nametrips;
ret.ids+=ar[i].ids;
}
return ret;
}
function acc(a, m, n)
{
return ((a*n)+m)/(n+1);
}
function cycleAcc(rets, ar, n)
{
var ret = rets;
for(var i in ar)
{
if(ar[i].last>ret.last) ret.last = ar[i].last;
ret.number= acc(ret.number, ar[i].number, n);
/*for(var index in ar[i].countries)
{
if(index in ret.countries)
ret.countries[index]= acc(ret.countries[index], ar[i].countries[index], n);
else
ret.countries[index]= acc(0, ar[i].countries[index], n);
}*/ //TODO: Implement this
ret.threads= acc(ret.threads, ar[i].threads, n);
ret.comments = acc(ret.comments, ar[i].comments, n);
ret.subjects = acc(ret.subjects, ar[i].subjects, n);
ret.images = acc(ret.images, ar[i].images, n);
ret.names = acc(ret.names, ar[i].names, n);
ret.trips = acc(ret.trips, ar[i].trips, n);
ret.nametrips = acc(ret.nametrips, ar[i].nametrips, n);
ret.ids = acc(ret.ids, ar[i].ids, n);
n+=1;
}
return ret;
}
if(typeof module !== 'undefined') {
module.exports.cycleAdd = cycleAdd;
module.exports.cycleAcc = cycleAcc;
}