Add decimal odds
SuccessfulCode/BritishHorseRacingApi/master There was a failure building this commit
SuccessfulCode/BritishHorseRacingApi/master There was a failure building this commit
This commit is contained in:
@@ -63,5 +63,19 @@ namespace BritishHorseRacingApi.Tests
|
|||||||
//Assert
|
//Assert
|
||||||
Assert.Equal(expectedResult, result);
|
Assert.Equal(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory()]
|
||||||
|
[InlineData("3/5",1.6)]
|
||||||
|
[InlineData("", null)]
|
||||||
|
[InlineData(" ", null)]
|
||||||
|
[InlineData(null, null)]
|
||||||
|
public void TestFractionOddsToDecimal(string value, double? expectedResult)
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
//Act
|
||||||
|
var result = DataConverterHelper.FractionOddsToDecimal(value);
|
||||||
|
//Assert
|
||||||
|
Assert.Equal(expectedResult, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,5 +67,19 @@ namespace BritishHorseRacingApi.Helpers
|
|||||||
var lossDifference = GetComponent(match, "lossDifference", 0d);
|
var lossDifference = GetComponent(match, "lossDifference", 0d);
|
||||||
return (int)TimeSpan.FromSeconds(lossDifference).TotalMilliseconds;
|
return (int)TimeSpan.FromSeconds(lossDifference).TotalMilliseconds;
|
||||||
}
|
}
|
||||||
|
private static Regex _ratioRegex = new Regex("(?'Numerator'[0-9]*)/(?'Denominator'[0-9]*)", RegexOptions.Compiled);
|
||||||
|
public static decimal? FractionOddsToDecimal(string fraction)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrWhiteSpace(fraction))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var match = _ratioRegex.Match(fraction);
|
||||||
|
if (match.Groups.Count != 2)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var numerator = Decimal.Parse(match.Groups["Numerator"].Value);
|
||||||
|
var denominator = Decimal.Parse(match.Groups["Denominator"].Value);
|
||||||
|
return (numerator / denominator) + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using BritishHorseRacingApi.Helpers;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BritishHorseRacingApi.Models
|
namespace BritishHorseRacingApi.Models
|
||||||
{
|
{
|
||||||
@@ -135,5 +136,7 @@ namespace BritishHorseRacingApi.Models
|
|||||||
|
|
||||||
[JsonProperty("lastRuns")]
|
[JsonProperty("lastRuns")]
|
||||||
public LastRun[] LastRuns { get; set; }
|
public LastRun[] LastRuns { get; set; }
|
||||||
|
|
||||||
|
public decimal? DecimalOdds() => DataConverterHelper.FractionOddsToDecimal(Odds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,7 @@ namespace BritishHorseRacingApi.Models
|
|||||||
public string RatingChase { get; set; }
|
public string RatingChase { get; set; }
|
||||||
public string RatingHurdle { get; set; }
|
public string RatingHurdle { get; set; }
|
||||||
public string RaceCriteriaRaceType { get; set; }
|
public string RaceCriteriaRaceType { get; set; }
|
||||||
|
public string ResultFinishDNF { get; set; }
|
||||||
public int Hro { get; set; }
|
public int Hro { get; set; }
|
||||||
public string FinishTime { get; set; }
|
public string FinishTime { get; set; }
|
||||||
public int? FinishTimeInMilliseconds() => DataConverterHelper.StopWatchStringToMilliseconds(FinishTime);
|
public int? FinishTimeInMilliseconds() => DataConverterHelper.StopWatchStringToMilliseconds(FinishTime);
|
||||||
|
|||||||
Reference in New Issue
Block a user