Initial commit
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
using SwiftyMessageHub.Core;
|
||||
using System;
|
||||
|
||||
namespace AutoBet.DataRecorded
|
||||
{
|
||||
[MessageType("PreRaceDataSnapshotDetails")]
|
||||
public class PreRaceDataCollectDetails
|
||||
{
|
||||
public DateTime DateToCollect { get; set; }
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using SwiftyMessageHub.Core;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoBet.DataRecorded.MessageControllers
|
||||
{
|
||||
public class PreRaceDataCollectorController : MessageController
|
||||
{
|
||||
[MessageRoute]
|
||||
public async Task CollectPreRaceData(PreRaceDataCollectDetails details)
|
||||
{
|
||||
var client = new BritishHorseRacingApi.ApiClient();
|
||||
var date = details.DateToCollect;
|
||||
Console.WriteLine("Loading races");
|
||||
var races = await client.GetAllRacesForDay(date.Year, date.Month, date.Day);
|
||||
foreach (var race in races)
|
||||
{
|
||||
Console.WriteLine($"Race id {race.RaceId} loaded");
|
||||
await CurrentContext.Hub.SendMessage(race);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
using BritishHorseRacingApi.Models;
|
||||
using AutoBet.DataRecorded.PreRaceRunnerCollector;
|
||||
using SwiftyMessageHub.Core;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace AutoBet.DataRecorded.PreRaceDataRecorder
|
||||
{
|
||||
public class PreRaceDataRecorderController : MessageController
|
||||
{
|
||||
[MessageRoute]
|
||||
public async Task CollectPreRaceData(Race details)
|
||||
{
|
||||
Console.WriteLine($"Saving race id {details.RaceId}");
|
||||
using (var db = new Db.HorseRacingDataContext())
|
||||
{
|
||||
db.Races.Add(new Db.Race()
|
||||
{
|
||||
DistanceChangeText = details.DistanceChangeText,
|
||||
BlackTypeRace = details.BlackTypeRace,
|
||||
AbandonedReasonCode = details.AbandonedReasonCode,
|
||||
RaceCriteriaRaceType = details.RaceCriteriaRaceType,
|
||||
DistanceChange = details.DistanceChange,
|
||||
DistanceText = details.DistanceText,
|
||||
DistanceValue = details.DistanceValue,
|
||||
DistanceUnits = details.DistanceUnits,
|
||||
RawDistanceText = details.RawDistanceText,
|
||||
RatingBand = details.RatingBand,
|
||||
RaceClass = details.RaceClass,
|
||||
PrizeCurrency = details.PrizeCurrency,
|
||||
PrizeAmount = details.PrizeAmount,
|
||||
AgeLimit = details.AgeLimit,
|
||||
RaceName = details.RaceName,
|
||||
RaceTime = details.RaceTime,
|
||||
RaceDate = details.RaceDate,
|
||||
DivisionSequence = details.DivisionSequence,
|
||||
YearOfRace = details.YearOfRace,
|
||||
RaceId = details.RaceId,
|
||||
Plus10 = details.Plus10,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
await CurrentContext.Hub.SendMessage(new PreRaceRunnerCollectDetails()
|
||||
{
|
||||
DateToCollect = details.RaceDate,
|
||||
RaceId = details.RaceId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace AutoBet.DataRecorded.PreRaceRunnerCollector
|
||||
{
|
||||
public class PreRaceRunnerCollectDetails
|
||||
{
|
||||
public PreRaceRunnerCollectDetails()
|
||||
{
|
||||
}
|
||||
|
||||
public DateTime DateToCollect { get; set; }
|
||||
public int RaceId { get; set; }
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
using BritishHorseRacingApi.Models;
|
||||
using SwiftyMessageHub.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoBet.DataRecorded.PreRaceRunnerCollector
|
||||
{
|
||||
public class PreRaceRunnerCollectorController : MessageController
|
||||
{
|
||||
public static SemaphoreSlim semaphore = new SemaphoreSlim(1);
|
||||
[MessageRoute]
|
||||
public async Task CollectPreRaceData(PreRaceRunnerCollectDetails details)
|
||||
{
|
||||
var client = new BritishHorseRacingApi.ApiClient();
|
||||
var date = details.DateToCollect;
|
||||
Console.WriteLine($"Preparing to load runners for race id {details.RaceId}");
|
||||
await semaphore.WaitAsync();
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"Loading runners for race id {details.RaceId}");
|
||||
var runners = await client.GetRaceRunners(date.Year, details.RaceId);
|
||||
foreach (var runner in runners.Data)
|
||||
{
|
||||
Console.WriteLine($"Loaded runner {runner.RacehorseName} id {details.RaceId}");
|
||||
await CurrentContext.Hub.SendMessage(runner);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
using BritishHorseRacingApi.Models;
|
||||
using SwiftyMessageHub.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoBet.DataRecorded.PreRaceRunnerRecorder
|
||||
{
|
||||
public class PreRaceRunnerRecorderController : MessageController
|
||||
{
|
||||
[MessageRoute]
|
||||
public async Task RecordRunner(Runner details)
|
||||
{
|
||||
Console.WriteLine($"Saving runner {details.RacehorseName}");
|
||||
using (var db = new Db.HorseRacingDataContext())
|
||||
{
|
||||
db.Runners.Add(new Db.Runner()
|
||||
{
|
||||
HeadGearWearingCode = details.HeadGearWearingCode,
|
||||
HeadGearWearingSheepSkin = details.HeadGearWearingSheepSkin,
|
||||
HeadGearDescription = details.HeadGearDescription,
|
||||
HeadGearAbbreviation = details.HeadGearAbbreviation,
|
||||
JockeyProfile = details.JockeyProfile,
|
||||
CourseWinner = details.CourseWinner,
|
||||
DistanceWinner = details.DistanceWinner,
|
||||
WindSurgeryFirstRun = details.WindSurgeryFirstRun,
|
||||
TrainerId = details.TrainerId,
|
||||
TrainerName = details.TrainerName,
|
||||
OwnerId = details.OwnerId,
|
||||
OwnerName = details.OwnerName,
|
||||
WbSilkCode = details.WbSilkCode,
|
||||
WbSilkDescription = details.WbSilkDescription,
|
||||
SilkImage = details.SilkImage,
|
||||
Plus10 = details.Plus10,
|
||||
ForecastPriceNumerator = details.ForecastPriceNumerator,
|
||||
ForecastPriceDenominator = details.ForecastPriceDenominator,
|
||||
WeightText = details.WeightText,
|
||||
WeightsJockeyClaiming = details.WeightsJockeyClaiming,
|
||||
Odds = details.Odds,
|
||||
DecimalOdds = details.DecimalOdds(),
|
||||
JockeyName = details.JockeyName,
|
||||
Status = (Db.Status)details.Status,
|
||||
RaceId = details.RaceId,
|
||||
YearOfRace = details.YearOfRace,
|
||||
DivisionSequence = details.DivisionSequence,
|
||||
AnimalId = details.AnimalId,
|
||||
RacehorseName = details.RacehorseName,
|
||||
AgeYears = details.AgeYears,
|
||||
Bred = details.Bred,
|
||||
ClothNumber = details.ClothNumber,
|
||||
DrawnStall = details.DrawnStall,
|
||||
ReserveNumber = details.ReserveNumber,
|
||||
BhaRating = details.BhaRating,
|
||||
FormFigures = details.FormFigures,
|
||||
WeightValue = details.WeightValue,
|
||||
PenaltyValue = details.PenaltyValue,
|
||||
SexType = (Db.SexType)details.SexType,
|
||||
NonRunnerDeclaredReason = details.NonRunnerDeclaredReason,
|
||||
NonRunnerDeclaredDate = details.NonRunnerDeclaredDate,
|
||||
NonRunnerDeclaredTime = details.NonRunnerDeclaredTime,
|
||||
RunnerNumber = details.RunnerNumber,
|
||||
JockeyId = details.JockeyId,
|
||||
RaceHorseNameWithoutCountry = details.RacehorseNameWithoutCountry,
|
||||
WeightInGrams = details.WeightInGrams,
|
||||
LastRuns = details.LastRuns?.Select(e => new Db.LastRun()
|
||||
{
|
||||
Days = e.Days,
|
||||
RaceType = e.RaceType
|
||||
}).ToList()
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user