spotlight query for all cultures

This commit is contained in:
2015-05-05 01:03:01 +02:00
parent 221c1c19ed
commit 53437cdc8c
6 changed files with 101 additions and 7 deletions
+37 -2
View File
@@ -152,7 +152,7 @@ namespace OnePeek.Api
/// <param name="store">The store where the app is published.</param>
/// <param name="storeCulture">Culture of the query (returns location specific metadata + ratings).</param>
/// <returns></returns>
public async Task<IEnumerable<string>> GetSpotlightIds(StoreSpotlightType spotlightType, StoreType store, StoreCultureType storeCulture)
public async Task<StoreSpotlightIdResults> GetSpotlightIds(StoreSpotlightType spotlightType, StoreType store, StoreCultureType storeCulture)
{
if (storeCulture == StoreCultureType.Unknown || storeCulture == StoreCultureType.All)
{
@@ -161,10 +161,22 @@ namespace OnePeek.Api
Uri uri = EndpointUris.GetWindowsPhoneSpotlightUri(storeCulture.ToString(), spotlightType.GetEnumDisplayName());
try
{
string xml = await ApiHttpClient.Instance.Get(uri);
IEnumerable<string> ids = XDocument.Parse(xml).Elements().First().Descendants().Where(x => x.Name.LocalName == "application").Select(x => x.Descendants().Get("id").Split(':').Last());
return ids;
return new StoreSpotlightIdResults()
{
StoreCultureType = storeCulture,
Ids = ids
};
}
catch
{
return null;
}
}
@@ -403,6 +415,29 @@ namespace OnePeek.Api
return await Task.WhenAll(tasks).ConfigureAwait(false);
}
/// <summary>
/// Get spotlight entries for the current day in the specified culture.
/// This only returns IDs for fast access.
/// Warning: This method makes a request per culture (100+) which can take a while.
/// </summary>
/// <param name="spotlightType">Can either be apps or games. Both return approx. 20 new results per day.</param>
/// <param name="store">The store where the app is published.</param>
/// <param name="ct">The canellation token.</param>
/// <param name="progress">The progress event gets triggered as soon as new data arrives.</param>
/// <returns></returns>
public async Task<IEnumerable<StoreSpotlightIdResults>> GetSpotlightIdsForAllCultures(StoreSpotlightType spotlightType, StoreType store, CancellationToken ct, IProgress<DownloadProgressChangedEventArgs> progress = null)
{
IEnumerable<StoreCultureType> cultures = Enum.GetValues(typeof(StoreCultureType))
.Cast<StoreCultureType>()
.Where(x => x != StoreCultureType.All && x != StoreCultureType.Unknown);
IEnumerable<Task<StoreSpotlightIdResults>> tasks = cultures.Select(culture => GetSpotlightIds(spotlightType, store, culture));
return (await Task.WhenAll(tasks).ConfigureAwait(false)).Where(x => x != null);
}
}
@@ -33,4 +33,19 @@ namespace OnePeek.Entities
/// </summary>
public IEnumerable<AppMetadata> Results { get; set; }
}
public partial class StoreSpotlightIdResults
{
/// <summary>
/// The culture is relevant for the review results,
/// as they are unique per country
/// </summary>
public StoreCultureType StoreCultureType { get; set; }
/// <summary>
/// List of result ids.
/// </summary>
public IEnumerable<string> Ids { get; set; }
}
}
+16 -3
View File
@@ -4,6 +4,8 @@ using OnePeek.Entities;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System;
namespace OnePeek.WebConsole.Modules
{
@@ -19,11 +21,8 @@ namespace OnePeek.WebConsole.Modules
StoreSpotlightResults apps = await api.GetSpotlight(StoreSpotlightType.Apps, StoreType.WindowsPhone8, StoreCultureType.EN_US);
StoreSpotlightResults games = await api.GetSpotlight(StoreSpotlightType.Games, StoreType.WindowsPhone8, StoreCultureType.EN_US);
IEnumerable<string> appIds = await api.GetSpotlightIds(StoreSpotlightType.Apps, StoreType.WindowsPhone8, StoreCultureType.EN_US);
return View["Index", new
{
SpotlightIds = appIds,
Spotlight = apps,
SpotlightGames = games
}];
@@ -51,6 +50,20 @@ namespace OnePeek.WebConsole.Modules
};
Get["/spotlight", true] = async (ctx, token) =>
{
IEnumerable<StoreSpotlightIdResults> results = await api.GetSpotlightIdsForAllCultures(StoreSpotlightType.Apps, StoreType.WindowsPhone8, default(CancellationToken));
Dictionary<string, int> count = results
.SelectMany(x => x.Ids)
.GroupBy(x => x)
.OrderByDescending(x => x.Count())
.ToDictionary(x => x.Key, x => x.Count());
return View["Spotlight", count];
};
Get["/ratings", true] = async (ctx, token) =>
{
var order = Request.Query["order"];
@@ -81,6 +81,7 @@
<Content Include="Views\Reviews.cshtml" />
<Content Include="Views\Ratings.cshtml" />
<Content Include="Views\Search.cshtml" />
<Content Include="Views\Spotlight.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
@@ -36,6 +36,14 @@
<div style="clear:both;"></div>
<br /><br />
<div class="large-12 columns">
<h3>SPOTLIGHT SUMMARY</h3>
<a href="/spotlight" class="button">load</a>
</div>
<div style="clear:both;"></div>
<br /><br />
<div class="large-12 columns">
<h3>APPS SPOTLIGHT</h3>
<div class="spotlight">
@@ -75,6 +83,7 @@
</div>
</div>
<div style="clear:both;float:none;"></div>
<br /><br /><br /><br />
@@ -0,0 +1,21 @@
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@{
Layout = "_Layout.cshtml";
}
<br />
@foreach (var kv in Model)
{
<div class="rating">
<a href="/meta/?id=@kv.Key">@kv.Key</a>
<p>@kv.Value</p>
</div>
}
<style>
.progress {
background: white;
border: 1px solid #ddd;
}
</style>