Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ingorichter committed Aug 8, 2014
1 parent 4d13856 commit e2699ea
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 82 deletions.
19 changes: 5 additions & 14 deletions downloadStats/logfileProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,11 @@ LogfileProcessor.prototype = {
var nextMarker = data.Contents[data.Contents.length - 1].Key;
_listObjects(bucketName, nextMarker, maxKeys);
} else {
var key,
i = data.Contents.length - 1;

// Skip any files in subfolders
while (i >= 0) {
var lastLogfileObject = data.Contents[i];
// Key without "/" is a file in this bucket and not in any subdirectory
if (lastLogfileObject.Key.indexOf("/") === -1) {
key = lastLogfileObject.Key;
break;
}

i = i - 1;
}
// this will get the Key off the last data item
// the log files for the registry are stored in a "subfolder"
// logs. Any file that appears in this bucket will be considered,
// even if it's located in a subfolder of logs
var key = data.Contents[data.Contents.length - 1].Key;

Promise.settle(allPromises).then(function () {
listObjectPromise.resolve(key);
Expand Down
23 changes: 14 additions & 9 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,19 @@ function updateRecentDownloadsForPackage(name, newRecentDownloadDatapoints) {

_currentRecentDownloadDatapoints = registry[name].recent;

_(newRecentDownloadDatapoints).keys().forEach(function (dataPoint) {
updatedRecentDownloads[dataPoint] = (newRecentDownloadDatapoints[dataPoint]);
_(newRecentDownloadDatapoints).forEach(function (value, index) {
updatedRecentDownloads[index] = updatedRecentDownloads[index] || 0;

updatedRecentDownloads[index] += value;
});

_(_currentRecentDownloadDatapoints).keys().forEach(function (dataPoint) {
updatedRecentDownloads[dataPoint] = (_currentRecentDownloadDatapoints[dataPoint]);
_(_currentRecentDownloadDatapoints).forEach(function (value, index) {
updatedRecentDownloads[index] = updatedRecentDownloads[index] || 0;

updatedRecentDownloads[index] += value;
});

// Cut off all except for the recent 7 datapoints
if (_currentRecentDownloadDatapoints.length !== _.size(updatedRecentDownloads)) {
var result = {};

Expand All @@ -145,13 +150,13 @@ function updateRecentDownloadsForPackage(name, newRecentDownloadDatapoints) {

/**
* Add the download data to an existing registry entry.
*
*
* @param {!String} name - extension name
* @param {!Object} newVersionDownloads - JSON object that contains download data for certain versions
* @param {!Object} recentDownloads - JSON object that contains accumulated daily download data for certain versions
*
*
* Examples:
*
*
* Extension version is the key, the value is the accumulated downloads for this specific version
* newVersionDownloads: "snippets-extension": {
* "downloads": {
Expand All @@ -163,7 +168,7 @@ function updateRecentDownloadsForPackage(name, newRecentDownloadDatapoints) {
* }
* }
* }
*
*
* The date is the key and the value denotes the accumulated download on this day for the most recent version
* of the extension.
* recentDownloads: "snippets-extension": {
Expand Down Expand Up @@ -210,7 +215,7 @@ function addDownloadDataToPackage(name, newVersionDownloads, recentDownloads) {
updated = true;
}
});

var recentDownloadsUpdated = updateRecentDownloadsForPackage(name, recentDownloads);

// save changes to registry if there were any updates
Expand Down
Loading

0 comments on commit e2699ea

Please sign in to comment.