Skip to content

Commit

Permalink
Merge pull request #119 from mongodb-developer/feature/add-qr-code
Browse files Browse the repository at this point in the history
Show json data per similar recording
  • Loading branch information
snarvaez authored Mar 19, 2024
2 parents e9cca46 + b5f652c commit 44aca3d
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 53 deletions.
11 changes: 11 additions & 0 deletions rest_service/Controllers/RecordingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public async Task<IActionResult> PostRecording([FromBody] RecordingRequest recor
return Ok(new { Message = "Recording created successfully." });
}

[HttpGet(Name = "GetRecording")]
public async Task<string> GetRecording([FromQuery] string id)
{
Recording recording = _recordingsCollection
.Find(r => r.Id.ToString() == id)
.Limit(1).ToList().First();

return recording.ToJson();
}


private async Task AddLocation(Recording recording)
{
var eventId = recording.Event.Id;
Expand Down
105 changes: 56 additions & 49 deletions website/Pages/PlayerSimilar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -102,54 +102,61 @@
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>
</center>
}
}
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>
}
}
}
</div>


Expand Down Expand Up @@ -187,10 +194,10 @@
var players = await _restClient.GetJsonAsync<List<Player>>(playersUrlWithQuery);
Player = players.First();

//string similarBySpeedUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointSimilarBySpeed, playerFilter);
//string similarBySpeedUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilarBySpeed, playerFilter);
//SimilarBySpeed = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarBySpeedUrlWithQuery);
string similarUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointSimilar, playerFilter);
string similarUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilar, playerFilter);
Similar = await _restClient.GetJsonAsync<List<SimilarRecording>>(similarUrlWithQuery);

//TO-DO: Revisit acceleration
Expand Down
97 changes: 97 additions & 0 deletions website/Pages/PlayerSimilar_json.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
@page "/playerSimilar_json"
@using RestSharp
@using website.Utils
@using dotenv.net

@inject NavigationManager NavigationManager
@inject Blazored.LocalStorage.ILocalStorageService localStore
@inject IJSRuntime JSRuntime

<style>
/* this in inside the body tag */
body {
background-color: #023430;
}
.atlascharts_iframe {
/*background: #21313C; */
border: none;
border-radius: 2px;
/* box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2); */
width: 100%;
height: 200vh;
margin: auto;
}
</style>

<a href="\?EventId=@_eventId">

<img src="\mongodb-logo-green-bg.jpg" class="rounded mx-auto d-block" alt="logo">
</a>

<div class="card" style="max-width:400px;background:yellow;text-align:center">
<div style="display:inline">
<a href="https://www.mongodb.com/solutions/solutions-library/gaming-player-profiles-solution" target="_blank">Solution</a>
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<a href="https://www.mongodb.com/use-cases/gaming" target="_blank">MDB for Gaming</a>
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<a href="https://github.com/mongodb-developer/leafsteroids" target="_blank">GitHub</a>
</div>
</div>

<div class="bg-white">
@if (recordingAsString == string.Empty)
if (_errorMessage != string.Empty)
{
<p>@_errorMessage</p>
}
else
{
<p><em>Loading... [@_recordingId]</em></p>
}
else
{
@recordingAsString
}
</div>


@code {

private string _eventId = string.Empty;
private string _recordingId = string.Empty;

private string recordingAsString = string.Empty;
private string _errorMessage = string.Empty;
private readonly RestClient _restClient = RestServiceClient.Create();

private string chartFilter = string.Empty;

protected override async Task OnInitializedAsync()
{
try
{
var queryParameters = UrlHelper.GetParameters(NavigationManager.Uri);

_eventId = queryParameters[Constants.QueryParameterEventId];
_recordingId = queryParameters[Constants.QueryParameterRecordingId].ToString();

var recordingFilter = new Dictionary<string, string>
{
{ "id", _recordingId }
};

string recordingUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordings, recordingFilter);
recordingAsString = await _restClient.GetJsonAsync<string>(recordingUrlWithQuery);

DotEnv.Load();
var envVars = DotEnv.Read();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
_errorMessage = "EXCEPTION: " + e.Message + e.StackTrace;
}
}
}
10 changes: 6 additions & 4 deletions website/Utils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public static class Constants
public const string RestServiceEndpointPlayers = "players";
public const string RestServiceEndpointPlayersAutoComplete = "players/autocomplete";
public const string RestServiceEndpointPlayersSearch = "players/search";
public const string RestServiceEndpointSimilar = "recordings/similar";
public const string RestServiceEndpointSimilarBySpeed = "recordings/similarBySpeed";
public const string RestServiceEndpointSimilarByAccel = "recordings/similarByAcceleration";
public const string RestServiceEndpointSimilarByStats = "recordings/similarByStats";
public const string RestServiceEndpointRecordings = "recordings";
public const string RestServiceEndpointRecordingsSimilar = "recordings/similar";
public const string RestServiceEndpointRecordingsSimilarBySpeed = "recordings/similarBySpeed";
public const string RestServiceEndpointRecordingsSimilarByAccel = "recordings/similarByAcceleration";
public const string RestServiceEndpointRecordingsSimilarByStats = "recordings/similarByStats";
public const string QueryParameterEventId = "EventId";
public const string QueryParameterName = "Name";
public const string QueryParameterRecordingId = "recordingId";
}

0 comments on commit 44aca3d

Please sign in to comment.