Skip to content

Commit

Permalink
Merge pull request #123 from mongodb-developer/main
Browse files Browse the repository at this point in the history
Show similar players using different vectors
  • Loading branch information
snarvaez authored Mar 20, 2024
2 parents 1285551 + aae5e9f commit 6a884be
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 73 deletions.
287 changes: 215 additions & 72 deletions website/Pages/PlayerSimilar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
</div>
</div>
<div class="card bg-white">
@if (Player == null)
@if (!ready)
{
<p>
<em>Loading...</em>
</p>
}
else
{
}
else
{
<article class="card-body mx-auto" style="max-width: 400px;">
<h2 class="text-center">Player Dashboard</h2>
<h4 class="card-title mt-3 text-center">
Expand All @@ -72,7 +72,7 @@
</span>
</div>
<input id="teamname" @bind="Player.Team" name="" class="form-control" placeholder="" type="text"
disabled>
disabled>
</div> <!-- form-group// -->

<div class="form-group input-group">
Expand All @@ -87,74 +87,207 @@
</form>

</article>
}
}

</div> <!-- card.// -->


<div class="card bg-white">
@if (Player == null)
@if (!ready)
{
<p>
<em>Loading...</em>
</p>
}
else
{
<h4 class="card-title mt-3 text-center">Similar Players</h4>
foreach (SimilarRecording rec in Similar)
{
string chartUrl = ChartsUrl.CreateSimilarUrl(_atlasChartIdSimilar, rec.Id);
<center>
<h5>@rec.Name</h5>
<table style="width:60%;">
<tr>
<td>Score</td>
<td>@rec.SessionStatisticsPlain.Score</td>
</tr>
<tr>
<td>DamageDone</td>
<td>@rec.SessionStatisticsPlain.DamageDone</td>
</tr>
<tr>
<td>BulletsFired</td>
<td>@rec.SessionStatisticsPlain.BulletsFired</td>
</tr>
<tr>
<td>PelletsDestroyedLarge</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedLarge</td>
</tr>
<tr>
<td>PelletsDestroyedMedium</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedMedium</td>
</tr>
<tr>
<td>PelletsDestroyedSmall</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedSmall</td>
</tr>
<tr>
<td>PowerUpBulletDamageCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletDamageCollected</td>
</tr>
<tr>
<td>PowerUpBulletSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletSpeedCollected</td>
</tr>
<tr>
<td>PowerUpPlayerSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpPlayerSpeedCollected</td>
</tr>
</table>
<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="440" height="480" src=@chartUrl></iframe>
<div class="card" style="max-width: 400px; background:#00ed64; text-align: center">
<div style="display:inline">
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="/playerSimilar_json/?EventId=@_eventId&[email protected]">View JSON data</a>
&nbsp;&nbsp;&nbsp;
</div>
</div>
</center>
}
rec = Similar.First(); // this player
chartUrl = ChartsUrl.CreateSimilarUrl(_atlasChartIdSimilar, rec.Id);
<h4 class="card-title mt-3 text-center">Your Best Run</h4>
<center>
<h5>@rec.Name</h5>
<table style="width:60%;">
<tr>
<td>Score</td>
<td>@rec.SessionStatisticsPlain.Score</td>
</tr>
<tr>
<td>DamageDone</td>
<td>@rec.SessionStatisticsPlain.DamageDone</td>
</tr>
<tr>
<td>BulletsFired</td>
<td>@rec.SessionStatisticsPlain.BulletsFired</td>
</tr>
<tr>
<td>PelletsDestroyedLarge</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedLarge</td>
</tr>
<tr>
<td>PelletsDestroyedMedium</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedMedium</td>
</tr>
<tr>
<td>PelletsDestroyedSmall</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedSmall</td>
</tr>
<tr>
<td>PowerUpBulletDamageCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletDamageCollected</td>
</tr>
<tr>
<td>PowerUpBulletSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletSpeedCollected</td>
</tr>
<tr>
<td>PowerUpPlayerSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpPlayerSpeedCollected</td>
</tr>
</table>
<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="440" height="480" src=@chartUrl></iframe>
<div class="card" style="max-width: 400px; background:#00ed64; text-align: center">
<div style="display:inline">
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="/playerSimilar_json/?EventId=@_eventId&[email protected]">View JSON data</a>
&nbsp;&nbsp;&nbsp;
</div>
</div>
</center>

rec = Similar[1];
chartUrl = ChartsUrl.CreateSimilarUrl(_atlasChartIdSimilar, rec.Id);
<h4 class="card-title mt-3 text-center">Top Similar Player OVERALL </h4>
<center>
<h5>@rec.Name</h5>
<table style="width:60%;">
<tr>
<td>Score</td>
<td>@rec.SessionStatisticsPlain.Score</td>
</tr>
<tr>
<td>DamageDone</td>
<td>@rec.SessionStatisticsPlain.DamageDone</td>
</tr>
<tr>
<td>BulletsFired</td>
<td>@rec.SessionStatisticsPlain.BulletsFired</td>
</tr>
<tr>
<td>PelletsDestroyedLarge</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedLarge</td>
</tr>
<tr>
<td>PelletsDestroyedMedium</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedMedium</td>
</tr>
<tr>
<td>PelletsDestroyedSmall</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedSmall</td>
</tr>
<tr>
<td>PowerUpBulletDamageCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletDamageCollected</td>
</tr>
<tr>
<td>PowerUpBulletSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletSpeedCollected</td>
</tr>
<tr>
<td>PowerUpPlayerSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpPlayerSpeedCollected</td>
</tr>
</table>
<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="440" height="480" src=@chartUrl></iframe>
<div class="card" style="max-width: 400px; background:#00ed64; text-align: center">
<div style="display:inline">
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="/playerSimilar_json/?EventId=@_eventId&[email protected]">View JSON data</a>
&nbsp;&nbsp;&nbsp;
</div>
</div>
</center>

rec = SimilarBySpeed[1]; // 0 is this player
chartUrl = ChartsUrl.CreateSimilarUrl(_atlasChartIdSimilar, rec.Id);
<h4 class="card-title mt-3 text-center">Top Similar Player BY SPEED </h4>
<center>
<h5>@rec.Name</h5>
<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="440" height="480" src=@chartUrl></iframe>
<div class="card" style="max-width: 400px; background:#00ed64; text-align: center">
<div style="display:inline">
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="/playerSimilar_json/?EventId=@_eventId&[email protected]">View JSON data</a>
&nbsp;&nbsp;&nbsp;
</div>
</div>
</center>

rec = SimilarByAccel[1]; // 0 is this player
chartUrl = ChartsUrl.CreateSimilarUrl(_atlasChartIdSimilar, rec.Id);
<h4 class="card-title mt-3 text-center">Top Similar Player BY ACCELERATION</h4>
<center>
<h5>@rec.Name</h5>
<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="440" height="480" src=@chartUrl></iframe>
<div class="card" style="max-width: 400px; background:#00ed64; text-align: center">
<div style="display:inline">
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="/playerSimilar_json/?EventId=@_eventId&[email protected]">View JSON data</a>
&nbsp;&nbsp;&nbsp;
</div>
</div>
</center>

rec = SimilarByStats[1];
chartUrl = ChartsUrl.CreateSimilarUrl(_atlasChartIdSimilar, rec.Id);
<h4 class="card-title mt-3 text-center">Top Similar Player BY STATS</h4>
<center>
<h5>@rec.Name</h5>
<table style="width:60%;">
<tr>
<td>Score</td>
<td>@rec.SessionStatisticsPlain.Score</td>
</tr>
<tr>
<td>DamageDone</td>
<td>@rec.SessionStatisticsPlain.DamageDone</td>
</tr>
<tr>
<td>BulletsFired</td>
<td>@rec.SessionStatisticsPlain.BulletsFired</td>
</tr>
<tr>
<td>PelletsDestroyedLarge</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedLarge</td>
</tr>
<tr>
<td>PelletsDestroyedMedium</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedMedium</td>
</tr>
<tr>
<td>PelletsDestroyedSmall</td>
<td>@rec.SessionStatisticsPlain.PelletsDestroyedSmall</td>
</tr>
<tr>
<td>PowerUpBulletDamageCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletDamageCollected</td>
</tr>
<tr>
<td>PowerUpBulletSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpBulletSpeedCollected</td>
</tr>
<tr>
<td>PowerUpPlayerSpeedCollected</td>
<td>@rec.SessionStatisticsPlain.PowerUpPlayerSpeedCollected</td>
</tr>
</table>
<div class="card" style="max-width: 400px; background:#00ed64; text-align: center">
<div style="display:inline">
&nbsp;&nbsp;&nbsp;
<a target="_blank" href="/playerSimilar_json/?EventId=@_eventId&[email protected]">View JSON data</a>
&nbsp;&nbsp;&nbsp;
</div>
</div>
</center>
}
}
</div>
Expand All @@ -164,10 +297,15 @@

private string _eventId = string.Empty;

private Player Player { get; set; } = new();
private List<SimilarRecording> Similar { get; set; } = new();
private List<SimilarRecording> SimilarBySpeed { get; set; } = new();
private List<SimilarRecording> SimilarByAccel { get; set; } = new();
private Player? Player { get; set; } = new();
private List<SimilarRecording>? Similar { get; set; } = new();
private List<SimilarRecording>? SimilarByStats { get; set; } = new();
private List<SimilarRecording>? SimilarBySpeed { get; set; } = new();
private List<SimilarRecording>? SimilarByAccel { get; set; } = new();

private SimilarRecording? rec;
private string chartUrl = string.Empty;
private bool ready = false;

private string _name = string.Empty;
private string _atlasChartIdSimilar = string.Empty;
Expand All @@ -186,23 +324,28 @@
_name = queryParameters[Constants.QueryParameterName];
_eventId = queryParameters[Constants.QueryParameterEventId];
var playerFilter = new Dictionary<string, string>
{
{
{ "name", _name }
};

string playersUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, playerFilter);
var players = await _restClient.GetJsonAsync<List<Player>>(playersUrlWithQuery);
Player = players.First();

//string similarBySpeedUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilarBySpeed, playerFilter);
//SimilarBySpeed = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarBySpeedUrlWithQuery);
// overall similarity
string similarUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilar, playerFilter);
Similar = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarUrlWithQuery);
// by speed
string similarBySpeedUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilarBySpeed, playerFilter);
SimilarBySpeed = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarBySpeedUrlWithQuery);
// by stats
string similarByStatsUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilarByStats, playerFilter);
SimilarByStats = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarByStatsUrlWithQuery);
// by acceleration
string similarByAccelUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilarByAccel, playerFilter);
SimilarByAccel = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarByAccelUrlWithQuery);

//TO-DO: Revisit acceleration
//string similarByAccelUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointSimilarByAccel, playerFilter);
//SimilarByAccel = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarByAccelUrlWithQuery);
ready = Player != null && Similar != null && SimilarByStats != null && SimilarBySpeed != null && SimilarByAccel != null;

DotEnv.Load();
var envVars = DotEnv.Read();
Expand Down
2 changes: 1 addition & 1 deletion website/Pages/PlayerSimilar_json.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
</div>

<div class="bg-white">
<div class="bg-black" style="color:whitesmoke">
@if (recordingAsString == string.Empty)
if (_errorMessage != string.Empty)
{
Expand Down

0 comments on commit 6a884be

Please sign in to comment.