本帖最后由 boyjoo 于 2014-7-4 17:58 编辑
想说通过分析后 证明AVIRA是实时安装用户数字的。(一段时间自动调整比对一次)
只不过前台显示略规律让你们产生误解。
见动态统计:http://www.avira.com/installscounter.php
官方用时间戳算的,时间戳每秒都不一样。
current是时间戳,看看JS便知。
var installsCounter = {
init: function(json) {
if (typeof json == "string" && json) {
json = $.parseJSON(json);
}
obj = this;
obj.jsonUrl = ('https:' == document.location.protocol ? 'https:' : 'http:') + "//www.avira.com/installscounter.php?t=" + new Date().getTime();
obj.counterContainer = $("#counter");
if (!json) {
this.fetchNewData(obj);
return;
}
obj.samples = json.samples;
obj.currentTimestamp = parseInt(json.current);
obj.endTimestamp = parseInt(json.current) + parseInt(json.interval);
obj.interval = parseInt(json.interval);
var samples = [];
for (timestamp in obj.samples) {
samples.push({
'timestamp': parseInt(timestamp),
'counter': parseInt(obj.samples[timestamp])
});
}
lastSample = samples[samples.length - 1];
currentTimestamp = ((obj.currentTimestamp - lastSample.timestamp) % obj.interval) + (lastSample.timestamp - obj.interval) + (samples[1].timestamp - samples[0].timestamp);
tempLeft = null;
tempRight = null;
$(samples).each(function(idx, value) {
if (value.timestamp <= currentTimestamp) {
tempLeft = value;
}
if (value.timestamp > currentTimestamp) {
tempRight = value;
return false;
}
samples.splice(0, 1);
});
currentValue = Math.round((tempRight.counter - tempLeft.counter) / ((tempRight.timestamp - tempLeft.timestamp) / (currentTimestamp - tempLeft.timestamp))) + tempLeft.counter;
obj.count(obj, {
'timestamp': currentTimestamp,
'counter': currentValue
}, samples);
},
count: function(obj, start, samples) {
nextStart = samples.splice(0, 1);
seconds = nextStart[0].timestamp - start.timestamp;
items = nextStart[0].counter - start.counter;
timeout = Math.round((seconds * 1000) / items);
obj.displayCount(obj, timeout, start.counter, nextStart[0], samples);
},
displayCount: function(obj, timeout, start, nextStart, samples) {
timeoutIdx = setTimeout(function() {
$(obj.counterContainer).html(obj.formatNumber(obj, ++start));
if (parseInt(nextStart.counter) == start) {
clearTimeout(timeoutIdx);
samples.splice(0, 1);
if (samples.length) {
obj.count(obj, nextStart, samples);
} else {
obj.fetchNewData(obj);
}
return false;
} else {
obj.displayCount(obj, timeout, start, nextStart, samples);
}
}, timeout);
},
formatNumber: function(obj, number, formated) {
formated = typeof formated == "undefined" ? formated = "" : formated;
var rest = obj.pad(number % 1000, 3, 0);
var remaining = number >= 1000 ? parseInt(number / 1000) : number;
formated = rest + " " + formated;
if (number >= 1000) {
formated = obj.formatNumber(obj, remaining, formated);
}
return formated;
},
pad: function(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
},
fetchNewData: function(obj) {
$.ajax(obj.jsonUrl, {
dataType: "json",
success: function(data, textStatus, jqXHR) {
obj.init(data);
}
});
}
}; |