Skip to content

Commit

Permalink
Merge pull request #16 from 64Soft/develop
Browse files Browse the repository at this point in the history
New AiRater API connection
  • Loading branch information
64Soft authored Feb 23, 2021
2 parents 826b456 + 609ba37 commit c9fbf2d
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 42 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Following functionalities are offered:
NRatings couldn't exist without contribution from these individuals and communities:

- https://racing-reference.info for providing the racing stats
- https://www.heliohost.org for providing the free hosting space for the backend. Please seriously consider donating to these guys if you like NRatings and use it often
- Following authors for providing the formulas that come embedded with the application:
- MasGrafx (S10Man / OmegaSeven)
- Dennis Grebe
Expand All @@ -36,7 +35,7 @@ NRatings couldn't exist without contribution from these individuals and communit

## Download

[Click here to download the latest executable version](https://nratings.heliohost.org/download/client/NRatings.Client.application)
[Click here to download the latest executable version](https://www.64soft.eu/nratings/download/client/NRatings.Client.application)

Since v5.1.0, it is now again required to log in when you want to use the real life racing data feature. This was re-introduced to protect the backend racing data API from being abused. The signup/login process is now however completely integrated in the application itself, and you can use social logins. However please note that earlier accounts (pre v5) will no longer work. You'll need to sign up for a new one, but you can reuse the same email address you used for the pre v5 version. However you are encouraged to use one of the social login options presented to you in the login screen.

Expand Down
12 changes: 7 additions & 5 deletions src/NRatings.Client/ApiClient/DTO/Race.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public class Race
public string RaceName { get; set; }
public int TrackId { get; set; }
public string TrackName { get; set; }
public DateTime RaceDate { get; set; }
public string TrackTypeId { get; set; }
public string TrackTypeName { get; set; }
public string NR2003TrackTypeId { get; set; }
public string NR2003TrackTypeName { get; set; }
public DateTime RaceDate { get; set; }
public double? TrackLengthMiles { get; set; }
public string Surface { get; set; }
public double? RaceLengthMiles { get; set; }
public int? Cautions { get; set; }
public int? CautionLaps { get; set; }
public int? LeadChanges { get; set; }
}
}
8 changes: 4 additions & 4 deletions src/NRatings.Client/ApiClient/NRatingsApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task<IList<TrackType>> GetTrackTypesAsync()
{
var request = this.GetApiFlurlRequest();

request.AppendPathSegment("tracktypes");
request.AppendPathSegment("racingdata/tracktypes");

return await request.GetJsonAsync<List<TrackType>>();

Expand All @@ -25,7 +25,7 @@ public async Task<IList<Series>> GetSeriesAsync()
{
var request = this.GetApiFlurlRequest();

request.AppendPathSegment("series");
request.AppendPathSegment("racingdata/series");

return await request.GetJsonAsync<List<Series>>();

Expand All @@ -35,7 +35,7 @@ public async Task<IList<Race>> GetRacesAsync(int seasonId)
{
var request = this.GetApiFlurlRequest();

request.AppendPathSegment("races");
request.AppendPathSegment("racingdata/races");
request.SetQueryParam("seasonId", seasonId);

return await request.GetJsonAsync<List<Race>>();
Expand All @@ -46,7 +46,7 @@ public async Task<RacesDetails> GetRacesDetailsAsync(IList<int> raceIds)
{
var request = this.GetApiFlurlRequest();

request.AppendPathSegment("races/details");
request.AppendPathSegment("nr2003/racedata");
return await request.PostJsonAsync(raceIds).ReceiveJson<RacesDetails>();

}
Expand Down
4 changes: 2 additions & 2 deletions src/NRatings.Client/App.Config
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<configBuilders>
<builders>
<add name="Secrets"
userSecretsFile="~/../../../../../Secrets/NRatings.Client.Secrets.xml"
userSecretsFile="~/../../../../../Secrets/NRatings.Client.Secrets.dev.xml"
type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets"/>
</builders>
</configBuilders>

<appSettings configBuilders="Secrets">
<add key="ApiBaseUri" value="https://localhost:5001"/>
<add key="ApiBaseUri" value="(secret)"/>
<add key="Auth0Domain" value="(secret)"/>
<add key="Auth0ClientId" value="(secret)"/>
<add key="Auth0ApiAudience" value="(secret)"/>
Expand Down
23 changes: 12 additions & 11 deletions src/NRatings.Client/Business/RRDataFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ public async Task<IList<Race>> GetRacesAsync(Season season)
RaceName = r.RaceName,
RaceDate = r.RaceDate,
Track = new Track() { Id = r.TrackId, Name = r.TrackName },
TrackTypeId = r.TrackTypeId,
NR2003TrackTypeId = r.NR2003TrackTypeId
TrackLengthMiles = r.TrackLengthMiles,
Surface = r.Surface,
RaceLengthMiles = r.RaceLengthMiles,
Cautions = r.Cautions,
CautionLaps = r.CautionLaps,
LeadChanges = r.LeadChanges
}).ToList();
}
catch (Exception ex)
Expand Down Expand Up @@ -149,13 +153,6 @@ public async Task<IList<DriverRaceData>> GetDriverRaceDataAsync(List<Race> raceL

IList<DriverRaceData> result = new List<DriverRaceData>();

IList<TrackType> trackTypes = dto.TrackTypes.Select(tt => new TrackType()
{
Id = tt.Id,
Name = tt.Name,
Description = tt.Description
}).ToList();

IList<Track> tracks = dto.Tracks.Select(t => new Track()
{
Id = t.Id,
Expand All @@ -168,8 +165,12 @@ public async Task<IList<DriverRaceData>> GetDriverRaceDataAsync(List<Race> raceL
RaceName = r.RaceName,
RaceDate = r.RaceDate,
Track = tracks.FirstOrDefault(t => t.Id == r.TrackId),
TrackTypeId = r.TrackTypeId,
NR2003TrackTypeId = r.NR2003TrackTypeId
TrackLengthMiles = r.TrackLengthMiles,
Surface = r.Surface,
RaceLengthMiles = r.RaceLengthMiles,
Cautions = r.Cautions,
CautionLaps = r.CautionLaps,
LeadChanges = r.LeadChanges
}).ToList();

IList<Driver> drivers = dto.Drivers.Select(d => new Driver()
Expand Down
52 changes: 49 additions & 3 deletions src/NRatings.Client/Domain/Race.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,55 @@ public class Race : IComparable<Race>
public Season Season { get; set; }
public string RaceName { get; set; }
public Track Track { get; set; }
public DateTime RaceDate { get; set; }
public string TrackTypeId { get; set; }
public string NR2003TrackTypeId { get; set; }
public DateTime RaceDate { get; set; }
public double? TrackLengthMiles { get; set; }
public string Surface { get; set; }
public double? RaceLengthMiles { get; set; }
public int? Cautions { get; set; }
public int? CautionLaps { get; set; }
public int? LeadChanges { get; set; }

public string TrackTypeId
{
get
{
if (this.Surface == "R")
return "RC";

if (this.TrackLengthMiles.HasValue)
{
if (TrackLengthMiles < 1.0)
return "ST";
if (TrackLengthMiles < 2.0)
return "SW";
if (TrackLengthMiles >= 2.0)
return "SS";
}

return null;
}
}

public string NR2003TrackTypeId
{
get
{
if (this.Surface == "R")
return "RC";

if (this.TrackLengthMiles.HasValue)
{
if (TrackLengthMiles < 1.0)
return "ST";
else if (this.Track.Name.Contains("Daytona") || this.Track.Name.Contains("Talladega"))
return "SS";
if (TrackLengthMiles >= 2.0)
return "SW";
}

return null;
}
}

public IList<RaceResult> RaceResults { get; set; }
public IList<PitStopData> PitStopDatas { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/NRatings.Client/Domain/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ private static async Task RefreshAccessToken()
Program.UserSettings.SaveAccessToken(tokenResult.AccessToken, tokenResult.AccessTokenExpiration);
if (tokenResult.RefreshToken != null)
Program.UserSettings.SaveRefreshToken(tokenResult.RefreshToken);

await SetUserFromAccessTokenAsync();
}
}

await SetUserFromAccessTokenAsync();
}

private static async Task SetUserFromAccessTokenAsync()
Expand Down
10 changes: 0 additions & 10 deletions src/NRatings.Client/GUI/frmRaceResults.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/NRatings.Client/NRatings.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>true</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>https://nratings.heliohost.org/download/client/</InstallUrl>
<InstallUrl>https://www.64soft.eu/nratings/download/client/</InstallUrl>
<SupportUrl>https://github.com/64Soft/NRatings.Client</SupportUrl>
<ProductName>NRatings</ProductName>
<PublisherName>64Soft</PublisherName>
Expand Down Expand Up @@ -514,7 +514,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.664.37</Version>
<Version>1.0.705.50</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
Expand Down Expand Up @@ -555,7 +555,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties Reactor_Enabled="0" Reactor_Lib="0" Reactor_Automatic="1" Reactor_Commands="" Reactor_Project="" Reactor_Output="[main_assembly_dir]NRatings_Secure\NRatings.exe" BuildVersion_UpdateAssemblyVersion="False" BuildVersion_UpdateFileVersion="False" BuildVersion_BuildVersioningStyle="None.None.None.None" BuildVersion_UseGlobalSettings="False" />
<UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.None.None" BuildVersion_UpdateFileVersion="False" BuildVersion_UpdateAssemblyVersion="False" Reactor_Output="[main_assembly_dir]NRatings_Secure\NRatings.exe" Reactor_Project="" Reactor_Commands="" Reactor_Automatic="1" Reactor_Lib="0" Reactor_Enabled="0" />
</VisualStudio>
</ProjectExtensions>
<PropertyGroup>
Expand Down

0 comments on commit c9fbf2d

Please sign in to comment.