format rating output + ability to sort
This commit is contained in:
@@ -84,23 +84,32 @@ namespace OnePeek.Api
|
||||
throw new ArgumentException("Please provide a valid store culture");
|
||||
}
|
||||
|
||||
string xml = await ApiHttpClient.Instance.Get(
|
||||
EndpointUris.GetWindowsPhoneMetadataUri(appId, storeCulture.ToString())
|
||||
);
|
||||
|
||||
IEnumerable<XElement> xel = XDocument.Parse(xml).Elements().First().Descendants();
|
||||
|
||||
// create rating
|
||||
AppRating result = new AppRating();
|
||||
result.Culture = storeCulture;
|
||||
result.RatingCount = Convert.ToInt32(xel.Get("userRatingCount"));
|
||||
result.AverageRating = xel.GetFloat("averageUserRating");
|
||||
if (Configuration.UseFiveStarSystem)
|
||||
{
|
||||
result.AverageRating = (float)(result.AverageRating * 0.5);
|
||||
}
|
||||
|
||||
return result;
|
||||
try
|
||||
{
|
||||
string xml = await ApiHttpClient.Instance.Get(
|
||||
EndpointUris.GetWindowsPhoneMetadataUri(appId, storeCulture.ToString())
|
||||
);
|
||||
|
||||
IEnumerable<XElement> xel = XDocument.Parse(xml).Elements().First().Descendants();
|
||||
|
||||
// update rating
|
||||
result.RatingCount = Convert.ToInt32(xel.Get("userRatingCount"));
|
||||
result.AverageRating = xel.GetFloat("averageUserRating");
|
||||
if (Configuration.UseFiveStarSystem)
|
||||
{
|
||||
result.AverageRating = (float)(result.AverageRating * 0.5);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result.RatingNotAvailable = true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@ namespace OnePeek.Entities
|
||||
/// </summary>
|
||||
public StoreCultureType Culture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// In case this is set to true, the Microsoft service didn't respond with a valid dataset to the requested culture
|
||||
/// </summary>
|
||||
public bool RatingNotAvailable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average rating of the app from 1-10 (can be changed to 1-5 with Configuration.UseFiveStarSystem).
|
||||
/// Is dependent on the current culture.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using OnePeek.Api;
|
||||
using OnePeek.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
namespace OnePeek.WebConsole.Modules
|
||||
@@ -34,8 +35,29 @@ namespace OnePeek.WebConsole.Modules
|
||||
|
||||
Get["/ratings", true] = async (ctx, token) =>
|
||||
{
|
||||
var order = Request.Query["order"];
|
||||
IEnumerable<AppRating> ratings = await metaEndpoint.GetRatingsForAllCultures(Request.Query["id"], StoreType.WindowsPhone8, new System.Threading.CancellationTokenSource().Token, null);
|
||||
return View["Ratings", new { Ratings = ratings }];
|
||||
|
||||
if (order == "rating")
|
||||
{
|
||||
ratings = ratings.OrderByDescending(x => x.AverageRating).ThenByDescending(x => x.RatingCount);
|
||||
}
|
||||
else if (order == "name")
|
||||
{
|
||||
ratings = ratings.OrderBy(x => x.Culture);
|
||||
}
|
||||
else
|
||||
{
|
||||
order = "count";
|
||||
ratings = ratings.OrderByDescending(x => x.RatingCount);
|
||||
}
|
||||
|
||||
return View["Ratings", new
|
||||
{
|
||||
Order = order,
|
||||
Id = Request.Query["id"],
|
||||
Ratings = ratings
|
||||
}];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,29 @@
|
||||
Layout = "_Layout.cshtml";
|
||||
}
|
||||
|
||||
ORDER BY<br />
|
||||
<ul class="button-group radius">
|
||||
<li><a href="/ratings?id=@(Model.Id)" class="button radius@(Model.Order == "count" ? "" : " secondary")">count</a></li>
|
||||
<li><a href="/ratings?id=@(Model.Id)&order=rating" class="button radius@(Model.Order == "rating" ? "" : " secondary")">rating</a></li>
|
||||
<li><a href="/ratings?id=@(Model.Id)&order=name" class="button radius@(Model.Order == "name" ? "" : " secondary")">name</a></li>
|
||||
</ul>
|
||||
|
||||
<br />
|
||||
|
||||
@foreach (var rating in Model.Ratings)
|
||||
{
|
||||
string percentage = ((float)rating.AverageRating * 20f).ToString("0.00").Replace(",", ".");
|
||||
<div class="rating">
|
||||
<h3>@rating.Culture</h3>
|
||||
<p><b>@rating.AverageRating</b> (@rating.RatingCount)</p>
|
||||
<p><span class="label @(rating.RatingNotAvailable ? "alert" : "success")">@(rating.RatingNotAvailable ? "ERROR" : "OK")</span> <b>@rating.AverageRating</b> (@rating.RatingCount)</p>
|
||||
</div>
|
||||
<hr />
|
||||
|
||||
<div class="progress round secondary"><span class="meter" style="width:@(percentage)%;"></span></div>
|
||||
}
|
||||
|
||||
<style>
|
||||
.rating {
|
||||
|
||||
.progress {
|
||||
background: white;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user