Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding package download statistics to Home page
- Loading branch information
Showing
13 changed files
with
218 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function getStats() { | ||
$.get('/Stats', function(data) { | ||
var section = $('section.aggstats'); | ||
section.show(); | ||
update(data, 'UniquePackages'); | ||
update(data, 'Downloads'); | ||
update(data, 'TotalPackages'); | ||
}) | ||
setTimeout(getStats, 30000); | ||
} | ||
|
||
function update(data, key) { | ||
var value = data[key].toString(); | ||
var self = $('#' + key); | ||
var currentValue = $.trim(self.text().replace(/\s/g, '')); | ||
if (currentValue != value) { | ||
var length = value.length; | ||
var currLength = currentValue.length; | ||
var items = self.children('span'); | ||
|
||
if (currLength > length) { | ||
while (items.length > length) { | ||
items.first().remove(); | ||
items = self.children('span'); | ||
} | ||
} | ||
else if (currLength < length) { | ||
var i; | ||
for (i = currLength; i < length; i++) { | ||
self.prepend('<span>' + value.charAt(length - i - 1) + '</span>'); | ||
} | ||
items = self.children('span'); | ||
currentValue = $.trim(self.text().replace(/\s/g, '')); | ||
currLength = currentValue.length; | ||
} | ||
|
||
$.each(value.split('').reverse(), function (i, e) { | ||
var c = (i < currLength) ? currentValue.charAt(currLength - i - 1) : ''; | ||
if (c != e) { | ||
var el = $(items[length - i - 1]); | ||
animateEl(el, e); | ||
} | ||
}); | ||
} | ||
|
||
function animateEl(el, v) { | ||
v = v || ''; | ||
var parent = e.parent(); | ||
el.animate({ top: 0.3 * parseInt(parent.height()) }, 350, 'linear', function () { | ||
$(this).html(v).css({ top: -0.8 * parseInt(parent.height()) }).animate({ top: 0 }, 350, 'linear') | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Data; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public class AggregateStatsService : IAggregateStatsService | ||
{ | ||
public AggregateStats GetAggregateStats() | ||
{ | ||
using (var dbContext = new EntitiesContext()) | ||
{ | ||
var database = dbContext.Database; | ||
using (var command = database.Connection.CreateCommand()) | ||
{ | ||
command.CommandText = @"Select | ||
(Select Count([Key]) from PackageRegistrations) as UniquePackages, | ||
(Select Count([Key]) from Packages where Listed = 1) as TotalPackages, | ||
( | ||
(Select Sum(DownloadCount) from Packages) + | ||
(Select Count([Key]) from PackageStatistics where [Key] > | ||
(Select DownloadStatsLastAggregatedId FROM GallerySettings) | ||
) | ||
) as DownloadCount"; | ||
|
||
database.Connection.Open(); | ||
using (var reader = command.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleRow)) | ||
{ | ||
reader.Read(); | ||
return new AggregateStats | ||
{ | ||
UniquePackages = reader.GetInt32(0), | ||
TotalPackages = reader.GetInt32(1), | ||
Downloads = reader.GetInt32(2), | ||
}; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
| ||
namespace NuGetGallery | ||
{ | ||
public interface IAggregateStatsService | ||
{ | ||
AggregateStats GetAggregateStats(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
| ||
namespace NuGetGallery | ||
{ | ||
public class AggregateStats | ||
{ | ||
public long Downloads { get; set; } | ||
|
||
public int UniquePackages { get; set; } | ||
|
||
public int TotalPackages { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters