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

Timestamp added to score on top-n scenario #616

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, string
{
foreach (ScoreItem scr in sortedListPositionsBelowCurrent)
{
sortedResult.Add(new LeaderboardItem { Rank = 0, Player = scr.Player, Score = scr.Score });
sortedResult.Add(new LeaderboardItem { Rank = 0, Player = scr.Player, Timestamp = src.Timestamp, Score = scr.Score });
}
}

Expand Down Expand Up @@ -171,6 +171,8 @@ public class ScoreItem
public string Player { get; set; }
[JsonProperty(PropertyName = "playerId")]
public string PlayerId { get; set; }
[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set; }
[JsonProperty(PropertyName = "score")]
public double Score { get; set; }
}
Expand All @@ -181,6 +183,8 @@ public class LeaderboardItem
public int Rank { get; set; }
[JsonProperty(PropertyName = "player")]
public string Player { get; set; }
[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set; }
[JsonProperty(PropertyName = "score")]
public double Score { get; set; }
}
14 changes: 9 additions & 5 deletions src/cloud/functions/leaderboards/around-me/score/run.csx
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,17 @@ public static int NumberWithSameScores(List<LeaderboardItem> listToRank, int sta
public class ScoreItem
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
public string Id { get; set;}
[JsonProperty(PropertyName = "leaderboard")]
public string Leaderboard { get; set; }
public string Leaderboard { get; set;}
[JsonProperty(PropertyName = "player")]
public string Player { get; set; }
public string Player { get; set;}
[JsonProperty(PropertyName = "playerId")]
public string PlayerId { get; set; }
public string PlayerId { get; set;}
[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set; }
[JsonProperty(PropertyName = "score")]
public double Score { get; set; }
public double Score { get; set;}
}

public class LeaderboardItem
Expand All @@ -217,6 +219,8 @@ public class LeaderboardItem
public int Rank { get; set; }
[JsonProperty(PropertyName = "player")]
public string Player { get; set; }
[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set; }
[JsonProperty(PropertyName = "score")]
public double Score { get; set; }
}
6 changes: 5 additions & 1 deletion src/cloud/functions/leaderboards/top-n/leaderboard/run.csx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceW
var query =
(from s in leaderboard
orderby s.Score descending
select new LeaderboardItem {Player = s.Player, Score = s.Score}).Take(lengthOfLeaderboard);
select new LeaderboardItem {Player = s.Player, Timestamp = s.Timestamp, Score = s.Score}).Take(lengthOfLeaderboard);

var leaders = query.ToList();

Expand Down Expand Up @@ -98,6 +98,8 @@ public class ScoreItem
public string Player { get; set;}
[JsonProperty(PropertyName = "playerId")]
public string PlayerId { get; set;}
[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set; }
[JsonProperty(PropertyName = "score")]
public double Score { get; set;}
}
Expand All @@ -108,6 +110,8 @@ public class LeaderboardItem
public int Rank { get; set; }
[JsonProperty(PropertyName = "player")]
public string Player { get; set; }
[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set; }
[JsonProperty(PropertyName = "score")]
public double Score { get; set; }
}
4 changes: 4 additions & 0 deletions src/cloud/functions/leaderboards/top-n/score/run.csx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceW
postedScore.PlayerId = data?.playerId;
postedScore.Player = data?.player;
postedScore.Score = data?.score;
postedScore.Timestamp = DateTime.UtcNow;

try
{
Expand All @@ -84,6 +85,7 @@ public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceW
if (postedScore.Score>existingPlayer.Score)
{
existingPlayer.Score = postedScore.Score;
existingPlayer.Timestamp = postedScore.Timestamp;
await client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(db, collection, existingPlayer.Id), postedScore);
return req.CreateResponse(HttpStatusCode.OK, $"The score for user {existingPlayer.PlayerId} has been updated to {postedScore.Score}");
}
Expand All @@ -107,6 +109,8 @@ public class ScoreItem
public string Player { get; set;}
[JsonProperty(PropertyName = "playerId")]
public string PlayerId { get; set;}
[JsonProperty(PropertyName = "timestamp")]
public DateTime Timestamp { get; set;}
[JsonProperty(PropertyName = "score")]
public double Score { get; set;}
}