public LaptimeImporter() { DbContextOptionsBuilder <FormulaContext> builder = new DbContextOptionsBuilder <FormulaContext>(); builder.UseSqlServer("Server=OVSPC435\\SQLEXPRESS; Database=formula;User Id=formula; Password=formula;"); _context = new FormulaContext(builder.Options); }
public void BaseSaveAndUpdateTest() { Formula formual = Formula.Create("F1", "AC20-120-水下", null); formual.AddFormulaItem(FormulaItem.Create(string.Empty, "B1", "N1", 10)); formual.AddFormulaItem(FormulaItem.Create(string.Empty, "B2", "N2", 20)); formual.AddFormulaItem(FormulaItem.Create(string.Empty, "B3", "N3", 30)); Assert.Equal(3, formual.FormulaItemCount); DbContextOptions <FormulaContext> options = InMemoryDbContextFactory.CreateOptions <FormulaContext>("Formula-Base"); using (FormulaContext content = new FormulaContext(options)) { var obj = content.Formulas.Find("F1"); Assert.Null(obj); content.Formulas.Add(formual); content.SaveChanges(); var objRead = content.Formulas.Find("F1"); Assert.NotNull(objRead); Assert.Equal(3, objRead.FormulaItemCount); } }
private static void SeedTyreData(FormulaContext context) { if (!context.Tyres.Any() && !context.Strategies.Any() && !context.TyreStrategies.Any()) { // Add base Grooved tyre var groovedTyre = new Tyre { Id = 1, TyreName = "Grooved", TyreColour = "#666699", StintLen = 20, Pace = 0, MinWear = 0, MaxWear = 0 }; context.Tyres.Add(groovedTyre); // Add default strategy var baseStrategy = new Strategy { StrategyId = 1, RaceLen = 20 }; context.Strategies.Add(baseStrategy); // Combine the default grooved tyre and strategy to a single TyreStrategy object var raceStrategy = new TyreStrategy { TyreId = 1, StrategyId = 1, StintNumberApplied = 1 }; context.TyreStrategies.Add(raceStrategy); } }
private Messages.v1.TransferObjects.FormulaContext GetFormulaContext(FormulaContext formulaContext) { var responseFormulaContext = new Messages.v1.TransferObjects.FormulaContext { Result = formulaContext.Result, DateStarted = formulaContext.DateStarted, DateCompleted = formulaContext.DateCompleted }; foreach (var usedArgumentValue in formulaContext.UsedArgumentValues()) { responseFormulaContext.ArgumentAnswers.Add(new Messages.v1.TransferObjects.ArgumentValue { Id = usedArgumentValue.Id, Value = usedArgumentValue.Value }); } foreach (var containedFormulaContext in formulaContext.ContainedFormulaContexts()) { responseFormulaContext.FormulaContexts.Add(GetFormulaContext(containedFormulaContext)); } return(responseFormulaContext); }
public TyreStrategiesController(FormulaContext context, UserManager <SimUser> userManager, ITyreStrategyService tyreStrategyService) : base(context, userManager) { _tyreStrats = tyreStrategyService; }
public RubbersController(FormulaContext context, UserManager <SimUser> userManager, IRubberService dataService) : base(context, userManager) { _rubbers = dataService; }
public ChampionshipsController(FormulaContext context, UserManager <SimUser> userManager, IChampionshipService service) : base(context, userManager) { _champService = service; }
public TeamRepository(FormulaContext formulaContext) { if (formulaContext == null) { throw new ArgumentNullException("formulaContext"); } _context = formulaContext; }
public TeamsController(FormulaContext context, UserManager <SimUser> userManager, PagingHelper pagingHelper, ITeamService dataService) : base(context, userManager, pagingHelper, dataService) { _teams = dataService; }
public EnginesController(FormulaContext context, UserManager <SimUser> userManager, PagingHelper pagingHelper, IEngineService dataService) : base(context, userManager, pagingHelper, dataService) { _engines = dataService; }
protected ViewDataController(FormulaContext context, UserManager <SimUser> userManager, PagingHelper pagingHelper, IDataService <T> dataService) : base(context, userManager) { PagingHelper = pagingHelper; DataService = dataService; }
// There is a possibility that the IEmailSender is setup as soon as I understand how that could work //private readonly IEmailSender _emailSender; public AccountsController(FormulaContext context, UserManager <SimUser> userManager, SignInManager <SimUser> signInManager, ILogger <AccountsController> logger) : base(context, userManager) { _signInManager = signInManager; _logger = logger; }
public Func<Dictionary<string, double>, double> BuildFormula(Operation operation, IFunctionRegistry functionRegistry) { Func<FormulaContext, double> func = BuildFormulaInternal(operation, functionRegistry); return a => { FormulaContext context = new FormulaContext(a, functionRegistry); return func(context); }; }
public Func <Dictionary <string, double>, double> BuildFormula(Operation operation, IFunctionRegistry functionRegistry) { Func <FormulaContext, double> func = BuildFormulaInternal(operation, functionRegistry); return(a => { FormulaContext context = new FormulaContext(a, functionRegistry); return func(context); }); }
public Func<Dictionary<string, double>, double> BuildFormula(Operation operation, IFunctionRegistry functionRegistry) { Func<FormulaContext, double> func = BuildFormulaInternal(operation, functionRegistry); return variables => { variables = EngineUtil.ConvertVariableNamesToLowerCase(variables); FormulaContext context = new FormulaContext(variables, functionRegistry); return func(context); }; }
public DriversController(FormulaContext context, UserManager <SimUser> userManager, PagingHelper pagingHelper, IDriverService dataService, ISeasonService seasonService, ITraitService traitService) : base(context, userManager, pagingHelper, dataService) { _drivers = dataService; _seasons = seasonService; _traits = traitService; }
public Func <IDictionary <string, double>, double> BuildFormula(Operation operation, IFunctionRegistry functionRegistry) { Func <FormulaContext, double> func = BuildFormulaInternal(operation, functionRegistry); return(variables => { variables = EngineUtil.ConvertVariableNamesToLowerCase(variables); FormulaContext context = new FormulaContext(variables, functionRegistry); return func(context); }); }
public SeasonController(FormulaContext context, UserManager <SimUser> userManager, ISeasonService seasons, IChampionshipService championships, ITrackService tracks, RaceBuilder raceBuilder) : base(context, userManager) { _seasons = seasons; _championships = championships; _tracks = tracks; _raceBuilder = raceBuilder; }
public static double GetVariableValueOrThrow(string variableName, FormulaContext context) { if (context.Variables.TryGetValue(variableName, out double result)) { return(result); } else if (context.ConstantRegistry.IsConstantName(variableName)) { return(context.ConstantRegistry.GetConstantInfo(variableName).Value); } else { throw new VariableNotDefinedException($"The variable \"{variableName}\" used is not defined."); } }
public void Switch(FormulaContext context, int i) { if (-1 == i) { SwitchWhenEndCharacter(context); } else if ('"' == (char)i) { SwitchWhenEscapeCharacter(context); } else { SwitchWhenOtherCharacter(context); } }
public RacesController(FormulaContext context, UserManager <SimUser> userManager, IRaceService raceService, ISeasonService seasonService, ITrackService trackService, RaceResultGenerator raceResultGenerator, RaceBuilder raceBuilder) : base(context, userManager) { _raceService = raceService; _seasonService = seasonService; _trackService = trackService; _resultGenerator = raceResultGenerator; _raceBuilder = raceBuilder; }
public static double CheckIfVariableExists(string variableName, FormulaContext context) { if (context.Variables.TryGetValue(variableName, out double result)) { return(1.0); } else if (context.ConstantRegistry.IsConstantName(variableName)) { return(1.0); } else { return(0.0); } }
public HomeController(FormulaContext context, UserManager <SimUser> userManager, IChampionshipService championshipService, ISeasonService seasonService, IRaceService raceService, ISeasonDriverService seasonDriverService, ISeasonTeamService seasonTeamService) : base(context, userManager) { _championships = championshipService; _seasons = seasonService; _races = raceService; _seasonDrivers = seasonDriverService; _seasonTeams = seasonTeamService; }
public Func <IDictionary <string, double>, double> BuildFormula(Operation operation, IFunctionRegistry functionRegistry, IConstantRegistry constantRegistry, IDictionary <string, double> vars) { Func <FormulaContext, double> func = BuildFormulaInternal(operation, functionRegistry, vars); return(adjustVariableCaseEnabled ? (Func <IDictionary <string, double>, double>)(variables => { variables = EngineUtil.ConvertVariableNamesToLowerCase(variables); FormulaContext context = new FormulaContext(variables, functionRegistry, constantRegistry); return func(context); }) : (Func <IDictionary <string, double>, double>)(variables => { return func(new FormulaContext(variables, functionRegistry, constantRegistry)); })); }
private static string CopyFormula(string formula, int span) { FormulaContext context = new FormulaContext(formula); context.Parse(); return(context.Formula.ToString(part => { if (part.Type.Equals(PartType.Formula)) { Regex regex = new Regex(@"([A-Z]+)(\d+)"); return regex.Replace(part.ToString(), (m) => $"{m.Groups[1].Value}{int.Parse(m.Groups[2].Value) + span}"); } else { return part.ToString(); } })); }
protected override CommandResult HandlePlayerCommand(Player player) { // NOTE: taking into account that WIN health reduce ~ health, it does it make sense to have maximal health // Instead, we try to balance at the very boundary of FAIL health reduce, buying weapons (while it make sense) or just saving coins for bad times. // Player state indicators // Use functions instead of direct values, because some indicators might be relatively 'heavy' // and also to try new C# features :) bool LowHealth() => player.Health <= _attackOptions.LoseHealthReduce; bool CanPurchaseHealing() => player.Coins >= _purchaseHealingHandlerOptions.Price; bool NeedWeapon() { // Estimating if new weapon (with +1 bonus) will increase our win probablility var formulaContext = new FormulaContext(player); var currentProb = _calculator.Calculate(_attackOptions.WinProbFormula, formulaContext); formulaContext.PlayerPower = formulaContext.PlayerPower + 1; var nextProb = _calculator.Calculate(_attackOptions.WinProbFormula, formulaContext); return(nextProb > currentProb); } bool CanPurchaseWeapon() => player.Coins >= _purchaseWeaponHandlerOptions.Price; RedirectResult result; // If we are at risk (i.e. next attack may kill us) - heal at first priority if (LowHealth() && CanPurchaseHealing()) { result = new RedirectResult(new PurchaseHealingCommand(), "Health is too low, want to heal"); } // Otherwise it might make sense to by a weapon else if (CanPurchaseWeapon() && NeedWeapon()) { result = new RedirectResult(new PurchaseWeaponCommand(), "Looks like it worth byuing a weapon"); } else { result = new RedirectResult(new AttackCommand(), "Well, let's kill somebody"); } return(result); }
private static void SeedConfig(FormulaContext context) { if (!context.AppConfig.Any()) { var appConfig = new AppConfig { DisqualifyChance = 4, MistakeLowerValue = -30, MistakeUpperValue = -15, RainAdditionalRNG = 10, StormAdditionalRNG = 20, SunnyEngineMultiplier = 0.9, OvercastEngineMultiplier = 1.1, WetEngineMultiplier = 1, RainDriverReliabilityModifier = -3, StormDriverReliabilityModifier = -5, MistakeAmountRolls = 2, ChassisModifierDriverStatus = 2 }; context.AppConfig.Add(appConfig); } }
public double Calculate(string formula, FormulaContext context) { var runner = GetCompiledFormula(formula); double result; try { result = runner(context).Result; } catch (Exception ex) { throw new ApplicationException($"Error when executing '{formula}'.", ex); } if (result < 0 || result > 1) { throw new ApplicationException($"Calculated formula result '{result}' should be in range [0,1]"); } return(result); }
public FormulaContext formula() { FormulaContext _localctx = new FormulaContext(Context, State); EnterRule(_localctx, 0, RULE_formula); try { EnterOuterAlt(_localctx, 1); { State = 24; expression(0); State = 25; Match(Eof); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public abstract void SwitchWhenOtherCharacter(FormulaContext context);
public static Expression<Func<FormulaContext, object>> ParseExpression(string text, FormulaContext context) { throw new NotImplementedException(); }
public abstract void Handle(FormulaContext context, char c);
public RaceService(FormulaContext context) : base(context) { }