Skip to content

Commit

Permalink
一括実行で、馬券の種類ごとのお金、回収率の表示を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Dec 11, 2022
1 parent 85b9783 commit 6a7e166
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 110 deletions.
4 changes: 4 additions & 0 deletions KmyKeiba/Converters/NonZeroVisibilityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
return uiv == default ? Visibility.Collapsed : Visibility.Visible;
}
if (value is long lv)
{
return lv == default ? Visibility.Collapsed : Visibility.Visible;
}
if (value is double dv)
{
return dv == default ? Visibility.Collapsed : Visibility.Visible;
Expand Down
36 changes: 31 additions & 5 deletions KmyKeiba/Models/Race/AnalysisTable/AggregateBuySimulator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KmyKeiba.Data.Db;
using CefSharp.Callback;
using KmyKeiba.Data.Db;
using KmyKeiba.Models.Analysis;
using KmyKeiba.Models.Race.Tickets;
using Reactive.Bindings;
Expand All @@ -18,27 +19,52 @@ public class AggregateBuySimulator
public Result CalcPayoff(PayoffInfo payoff, OddsInfo odds, IReadOnlyList<RaceHorseAnalyzer> horses, IReadOnlyList<(RaceHorseMark Mark, short Number)> markData)
{
var tickets = this.Items.SelectMany(i => i.ToTickets(markData));
payoff.UpdateTicketsData(tickets
var ticketItems = tickets
.Select(t => TicketItem.FromData(t, horses.Select(h => h.Data).ToArray(), odds))
.Where(t => t != null)
.Select(t => t!), horses.Select(h => h.Data).ToArray());
.Select(t => t!);
payoff.UpdateTicketsData(ticketItems, horses.Select(h => h.Data).ToArray());

ticketItems.Where(t => t.Type == TicketType.Single).Sum(t => t.Rows.Count * 100);

var result = new Result
{
PaidMoney = payoff.PayMoneySum.Value,
PayoffMoney = payoff.HitMoneySum.Value,
Income = payoff.Income.Value,
};
result.ResultPerTicketTypes[TicketType.Single] = this.ToResultObject(TicketType.Single, payoff.Singles, ticketItems);
result.ResultPerTicketTypes[TicketType.Place] = this.ToResultObject(TicketType.Place, payoff.Places, ticketItems);
result.ResultPerTicketTypes[TicketType.QuinellaPlace] = this.ToResultObject(TicketType.QuinellaPlace, payoff.QuinellaPlaces, ticketItems);
result.ResultPerTicketTypes[TicketType.Quinella] = this.ToResultObject(TicketType.Quinella, payoff.Quinellas, ticketItems);
result.ResultPerTicketTypes[TicketType.Exacta] = this.ToResultObject(TicketType.Exacta, payoff.Exactas, ticketItems);
result.ResultPerTicketTypes[TicketType.Trio] = this.ToResultObject(TicketType.Trio, payoff.Trios, ticketItems);
result.ResultPerTicketTypes[TicketType.Trifecta] = this.ToResultObject(TicketType.Trifecta, payoff.Trifectas, ticketItems);
return result;
}

private Result ToResultObject(TicketType type, IPayoffItemCollection payoff, IEnumerable<TicketItem> items)
{
var targets = items.Where(t => t.Type == type).ToArray();
if (targets.Any())
{
return new Result()
{
PayoffMoney = payoff.HitMoneySum.Value,
PaidMoney = targets.Sum(t => t.Rows.Count * 100),
};
}
return new();
}

public class Result
{
public int PaidMoney { get; init; }

public int PayoffMoney { get; init; }

public int Income { get; init; }
public int Income => this.PayoffMoney - this.PaidMoney;

public Dictionary<TicketType, Result> ResultPerTicketTypes { get; } = new();
}
}
}
19 changes: 19 additions & 0 deletions KmyKeiba/Models/Race/AnalysisTable/AnalysisTableBulkEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public async Task DoAsync(ScriptBulkModel model, IEnumerable<ScriptResultItem> i
var markData = sorted.Select(s => (s.MarkSuggestion.Value, s.Horse.Data.Number)).ToArray();
var result = simulator.CalcPayoff(payoff, odds, info.Horses, markData);

this.AddResultsToTicketTypeCollection(model, result);

item.PaidMoney.Value = result.PaidMoney;
item.PayoffMoney.Value = result.PayoffMoney;
item.Income.Value = result.Income;
Expand Down Expand Up @@ -133,6 +135,23 @@ public async Task DoAsync(ScriptBulkModel model, IEnumerable<ScriptResultItem> i
this.IsFinished = true;
}

private void AddResultsToTicketTypeCollection(ScriptBulkModel model, AggregateBuySimulator.Result result)
{
foreach (var item in result.ResultPerTicketTypes.Join(model.ResultsPerTicketType, r => r.Key, r => r.TicketType, (r1, r2) => new { Result = r1, Model = r2, }))
{
item.Model.PaidMoney.Value += item.Result.Value.PaidMoney;
item.Model.PayoffMoney.Value += item.Result.Value.PayoffMoney;
item.Model.IncomeMoney.Value += item.Result.Value.Income;
item.Model.IncomeComparation.Value = AnalysisUtil.CompareValue(item.Model.IncomeMoney.Value, 1, -1);
item.Model.RecoveryRate.Value = (double)item.Model.PayoffMoney.Value / item.Model.PaidMoney.Value;
}
model.TotalResult.PaidMoney.Value += result.PaidMoney;
model.TotalResult.PayoffMoney.Value += result.PayoffMoney;
model.TotalResult.IncomeMoney.Value += result.Income;
model.TotalResult.IncomeComparation.Value = AnalysisUtil.CompareValue(model.TotalResult.IncomeMoney.Value, 1, -1);
model.TotalResult.RecoveryRate.Value = (double)model.TotalResult.PayoffMoney.Value / model.TotalResult.PaidMoney.Value;
}

public void EnableBulk()
{
// Not to do
Expand Down
7 changes: 6 additions & 1 deletion KmyKeiba/Models/Race/PayoffInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@ public class TrifectaPayoffItem : PayoffItem
public short Number3 { get; init; }
}

public class PayoffItemCollection<T> : ReactiveCollection<T> where T : PayoffItem
public interface IPayoffItemCollection
{
ReactiveProperty<int> HitMoneySum { get; }
}

public class PayoffItemCollection<T> : ReactiveCollection<T>, IPayoffItemCollection where T : PayoffItem
{
public ReactiveProperty<int> HitMoneySum { get; } = new();

Expand Down
48 changes: 47 additions & 1 deletion KmyKeiba/Models/Script/ScriptBulkModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.System.Preview;
using static KmyKeiba.Models.Script.ScriptBulkModel;

namespace KmyKeiba.Models.Script
Expand All @@ -40,10 +41,14 @@ public class ScriptBulkModel

public ReactiveProperty<bool> IsError { get; } = new();

public ReactiveProperty<int> SumOfIncomes { get; } = new();
public ReactiveProperty<long> SumOfIncomes { get; } = new();

public ReactiveProperty<ValueComparation> IncomeComparation { get; } = new();

public ReactiveCollection<TicketTypeResultItem> ResultsPerTicketType { get; } = new();

public TicketTypeResultItem TotalResult { get; } = new(TicketType.Unknown);

public ReactiveProperty<bool> IsAnalysisTableMode { get; } = new(true);

public FinderModel FinderModelForConfig { get; } = new FinderModel(null, null, null);
Expand All @@ -60,6 +65,14 @@ public ScriptBulkModel()
this.BuySimulator.Items.Add(new AggregateBuyItem(TicketType.Trio));
this.BuySimulator.Items.Add(new AggregateBuyItem(TicketType.Trifecta));
this.FinderModelForConfig.Input.OtherSetting.IsFinishedRaceOnly.Value = true;

this.ResultsPerTicketType.Add(new TicketTypeResultItem(TicketType.Single));
this.ResultsPerTicketType.Add(new TicketTypeResultItem(TicketType.Place));
this.ResultsPerTicketType.Add(new TicketTypeResultItem(TicketType.QuinellaPlace));
this.ResultsPerTicketType.Add(new TicketTypeResultItem(TicketType.Quinella));
this.ResultsPerTicketType.Add(new TicketTypeResultItem(TicketType.Exacta));
this.ResultsPerTicketType.Add(new TicketTypeResultItem(TicketType.Trio));
this.ResultsPerTicketType.Add(new TicketTypeResultItem(TicketType.Trifecta));
}

public void BeginExecute()
Expand All @@ -85,6 +98,12 @@ public async Task ExecuteAsync(Func<IScriptBulkEngine> bulkEngineGenerator)
this.IsError.Value = false;
this.SumOfIncomes.Value = 0;

this.TotalResult.Reset();
foreach (var result in this.ResultsPerTicketType)
{
result.Reset();
}

short.TryParse(this.ThreadSize.Value, out var divitions);
if (divitions < 1)
{
Expand Down Expand Up @@ -210,6 +229,33 @@ public void Cancel()
this.IsCanceled = true;
}

public class TicketTypeResultItem
{
public TicketType TicketType { get; }

public ReactiveProperty<long> PaidMoney { get; } = new();

public ReactiveProperty<long> PayoffMoney { get; } = new();

public ReactiveProperty<long> IncomeMoney { get; } = new();

public ReactiveProperty<ValueComparation> IncomeComparation { get; } = new();

public ReactiveProperty<double> RecoveryRate { get; } = new();

public TicketTypeResultItem(TicketType type)
{
this.TicketType = type;
}

public void Reset()
{
this.PaidMoney.Value = this.PayoffMoney.Value = this.IncomeMoney.Value = 0;
this.IncomeComparation.Value = ValueComparation.Standard;
this.RecoveryRate.Value = double.NaN;
}
}

public interface IScriptBulkEngine : IDisposable
{
ReactiveProperty<ReactiveProperty<int>?> ProgressMax { get; }
Expand Down
Loading

0 comments on commit 6a7e166

Please sign in to comment.