Skip to content

Commit

Permalink
Deployment Prep - Merge dev into master (#4096)
Browse files Browse the repository at this point in the history
* Make downloads link on home page a proper link (#4052)

* Fix the date format on stats page (#4057)

* Update telemetry processors (#4059)

* Average download shown incorrectly when its 1.x #4039 (#4040)

* Average download shown incorrectly when its 1.x #4039

* Moved logic to viewmodel and added UTs

* Package-Versions autocomplete endpoint does not properly handle semVerLevel when using the db #4086 (#4087)

* v2 package-versions auto-complete endpoint should exclude deleted versions #4092 (#4093)

* Remove auto-refresh AJAX call for total stats on home page #4090 (#4091)
  • Loading branch information
xavierdecoster authored Jun 9, 2017
1 parent 6a740b8 commit 59591cf
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 13 deletions.
2 changes: 1 addition & 1 deletion content/PROD/Home.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1>What is NuGet?</h1>
<section class="release">
<h2>Latest NuGet Releases</h2>
<p>
NuGet 3.5 for Visual Studio 2015 was released on October 27th, 2016. NuGet 2.12 for Visual Studio 2013 was released on June 27th 2016. <strong>Download</strong> these releases from http://nuget.org/downloads.
NuGet 3.5 for Visual Studio 2015 was released on October 27th, 2016. NuGet 2.12 for Visual Studio 2013 was released on June 27th 2016. <strong>Download</strong> these releases from <a href="https://nuget.org/downloads">downloads</a>.
</p>
<p>
For details about what's in the 3.5 release, read the <a href="https://docs.nuget.org/ndocs/release-notes/nuget-3.5-RTM">release notes</a>.
Expand Down
5 changes: 4 additions & 1 deletion src/NuGetGallery/App_Start/OwinStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ public static void Configuration(IAppBuilder app)
// Add processors
telemetryProcessorChainBuilder.Use(next =>
{
var processor = new TelemetryResponseCodeProcessor(next);
var processor = new RequestTelemetryProcessor(next);
processor.SuccessfulResponseCodes.Add(400);
processor.SuccessfulResponseCodes.Add(404);
return processor;
});

telemetryProcessorChainBuilder.Use(
next => new ExceptionTelemetryProcessor(next, Telemetry.TelemetryClient));

// Note: sampling rate must be a factor 100/N where N is a whole number
// e.g.: 50 (= 100/2), 33.33 (= 100/3), 25 (= 100/4), ...
// https://azure.microsoft.com/en-us/documentation/articles/app-insights-sampling/
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@
<HintPath>..\..\packages\NuGet.Services.KeyVault.1.0.0.0\lib\net45\NuGet.Services.KeyVault.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Services.Logging, Version=2.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Services.Logging.2.2.1\lib\net452\NuGet.Services.Logging.dll</HintPath>
<Reference Include="NuGet.Services.Logging, Version=2.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\NuGet.Services.Logging.2.2.3\lib\net452\NuGet.Services.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Services.Platform.Client, Version=3.0.29.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AutoCompleteDatabasePackageVersionsQuery
private const string _sqlFormat = @"SELECT p.[Version]
FROM Packages p (NOLOCK)
JOIN PackageRegistrations pr (NOLOCK) on pr.[Key] = p.PackageRegistrationKey
WHERE {0} AND pr.ID = {{0}}
WHERE p.[Deleted] <> 1 AND {0} AND pr.ID = {{0}}
{1}";

public AutoCompleteDatabasePackageVersionsQuery(IEntitiesContext entities)
Expand Down
2 changes: 0 additions & 2 deletions src/NuGetGallery/Scripts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// var section = $('section.aggstatserr');
// section.show();
});

setTimeout(function () { getStats(currData); }, 30000);
}

function update(data, currData, key) {
Expand Down
11 changes: 8 additions & 3 deletions src/NuGetGallery/Telemetry/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ namespace NuGetGallery
{
internal static class Telemetry
{
private static readonly TelemetryClient _telemetryClient = new TelemetryClient();
static Telemetry()
{
TelemetryClient = new TelemetryClient();
}

internal static TelemetryClient TelemetryClient { get; }

public static void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
try
{
_telemetryClient.TrackEvent(eventName, properties, metrics);
TelemetryClient.TrackEvent(eventName, properties, metrics);
}
catch
{
Expand All @@ -27,7 +32,7 @@ public static void TrackException(Exception exception, IDictionary<string, strin
{
try
{
_telemetryClient.TrackException(exception, properties, metrics);
TelemetryClient.TrackException(exception, properties, metrics);
}
catch
{
Expand Down
4 changes: 4 additions & 0 deletions src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public DisplayPackageViewModel(Package package, IOrderedEnumerable<Package> pack
TotalDaysSinceCreated = 0;
DownloadsPerDay = 0;
}

DownloadsPerDayLabel = DownloadsPerDay < 1 ? "<1" : DownloadsPerDay.ToNuGetNumberString();
}

public void SetPendingMetadata(PackageEdit pendingMetadata)
Expand Down Expand Up @@ -84,5 +86,7 @@ public bool HasNewerPrerelease
}

public bool? IsIndexed { get; set; }

public string DownloadsPerDayLabel { get; private set; }
}
}
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<p class="stat-label">@(Model.DownloadCount == 1 ? "Download" : "Downloads") of v @Model.Version</p>
</div>
<div class="stat">
<p class="stat-number" title="@Model.TotalDownloadCount.ToNuGetNumberString() @(Model.TotalDownloadCount == 1 ? "download" : "downloads") in @Model.TotalDaysSinceCreated @(Model.TotalDaysSinceCreated == 1 ? "day" : "days")">@(Model.DownloadsPerDay <= 1 ? "<1" : Model.DownloadsPerDay.ToNuGetNumberString())</p>
<p class="stat-number" title="@Model.TotalDownloadCount.ToNuGetNumberString() @(Model.TotalDownloadCount == 1 ? "download" : "downloads") in @Model.TotalDaysSinceCreated @(Model.TotalDaysSinceCreated == 1 ? "day" : "days")">@(Model.DownloadsPerDayLabel)</p>
<p class="stat-label">Average downloads per day</p>
</div>
<div class="stat">
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Statistics/_PivotTable.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</h1>

<div data-bind="if: $data && LastUpdatedUtc" class="last-updated">
<span data-bind="text: 'Statistics last updated at ' + moment(LastUpdatedUtc).format('YYYY-MM-dd HH:mm:ss') + ' UTC.'"></span>
<span data-bind="text: 'Statistics last updated at ' + moment(LastUpdatedUtc).format('YYYY-MM-DD HH:mm:ss') + ' UTC.'"></span>
</div>

<div data-bind="if: $data">
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<package id="NuGet.Packaging.Core" version="4.3.0-preview1-2524" targetFramework="net46" />
<package id="NuGet.Protocol" version="4.3.0-preview1-2524" targetFramework="net46" />
<package id="NuGet.Services.KeyVault" version="1.0.0.0" targetFramework="net46" />
<package id="NuGet.Services.Logging" version="2.2.1.0" targetFramework="net46" />
<package id="NuGet.Services.Logging" version="2.2.3.0" targetFramework="net46" />
<package id="NuGet.Services.Platform.Client" version="3.0.29-r-master" targetFramework="net46" />
<package id="NuGet.Versioning" version="4.3.0-preview1-2524" targetFramework="net46" />
<package id="ODataNullPropagationVisitor" version="0.5.4237.2641" targetFramework="net46" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using NuGet.Versioning;
using Xunit;
Expand Down Expand Up @@ -44,5 +45,68 @@ public void TheCtorSortsPackageVersionsProperly()
Assert.Equal("1.0.2", packageVersions[1].Version);
Assert.Equal("1.0.10", packageVersions[0].Version);
}

[Fact]
public void DownloadsPerDayLabelShowsLessThanOneWhenAverageBelowOne()
{
// Arrange
const int downloadCount = 10;
const int daysSinceCreated = 11;

var package = new Package
{
Dependencies = Enumerable.Empty<PackageDependency>().ToList(),
DownloadCount = downloadCount,
PackageRegistration = new PackageRegistration
{
Owners = Enumerable.Empty<User>().ToList(),
DownloadCount = downloadCount
},
Created = DateTime.UtcNow.AddDays(-daysSinceCreated),
Version = "1.0.10"
};

package.PackageRegistration.Packages = new[] { package };

var viewModel = new DisplayPackageViewModel(package, package.PackageRegistration.Packages.OrderByDescending(p => new NuGetVersion(p.Version)));

// Act
var label = viewModel.DownloadsPerDayLabel;

// Assert
Assert.Equal("<1", label);
}

[Theory]
[InlineData(10, 10)]
[InlineData(11, 10)]
[InlineData(14, 10)]
[InlineData(15, 10)]
public void DownloadsPerDayLabelShowsOneWhenAverageBetweenOneAndOnePointFive(int downloadCount, int daysSinceCreated)
{
// Arrange
var package = new Package
{
Dependencies = Enumerable.Empty<PackageDependency>().ToList(),
DownloadCount = downloadCount,
PackageRegistration = new PackageRegistration
{
Owners = Enumerable.Empty<User>().ToList(),
DownloadCount = downloadCount
},
Created = DateTime.UtcNow.AddDays(-daysSinceCreated),
Version = "1.0.10"
};

package.PackageRegistration.Packages = new[] { package };

var viewModel = new DisplayPackageViewModel(package, package.PackageRegistration.Packages.OrderByDescending(p => new NuGetVersion(p.Version)));

// Act
var label = viewModel.DownloadsPerDayLabel;

// Assert
Assert.Equal("1", label);
}
}
}

0 comments on commit 59591cf

Please sign in to comment.