Skip to content

Commit

Permalink
Merge pull request #22 from AngelsSoftwareOrg/develop
Browse files Browse the repository at this point in the history
v1.0.0.8 - Cycle Release - LottoDataManagerSetup_v1.0.0.8
- Add dashboard report game next draw day
- Pluralized the label on the jackpot group items on Dashboard 
- Copying data to clipboard, increase the gap between waiting time to 200ms
- Add new Machine Learning - Draw Result Win Count Predictor
- Update ReadMe
  • Loading branch information
angelsburger90 authored Oct 7, 2021
2 parents ac017d6 + b44fe87 commit dece022
Show file tree
Hide file tree
Showing 32 changed files with 497 additions and 39 deletions.
2 changes: 1 addition & 1 deletion App.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<value>0</value>
</setting>
<setting name="version_release" serializeAs="String">
<value>7</value>
<value>8</value>
</setting>
<setting name="repository_name" serializeAs="String">
<value>LottoDataManager</value>
Expand Down
Binary file added DatabaseMain/MLModel_5H_DrawResultWinCount.zip
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Forms/MainFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private void ObjectLstVwLatestBetClipboardCopy()
sb.ToString(), // Text to store in clipboard
false, // Do not keep after our application exits
10, // Retry 10 times
100); // 100 ms delay between retries
200); // 100 ms delay between retries
}
}
catch (Exception ex)
Expand Down
15 changes: 2 additions & 13 deletions Forms/Others/MachineLearningFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using LottoDataManager.Includes.Classes.ML;
using LottoDataManager.Includes.Classes.ML.FastTree;
using LottoDataManager.Includes.Classes.ML.FastTreeRegression.LottoMatchCount;
using LottoDataManager.Includes.Classes.ML.FastTreeTweedie.DrawResultWinCount;
using LottoDataManager.Includes.Classes.ML.SDCARegression;
using LottoDataManager.Includes.Classes.ML.TrainerProcessor;
using LottoDataManager.Includes.Model;
Expand All @@ -28,32 +29,20 @@ public partial class MachineLearningFrm : Form
private delegate void StopRun();
private bool isUpdateProcessingStarted = false;
private LotteryDataServices lotteryDataServices;
private FastTreeTrainer machineLearningModelBuilderFastTree;
private SDCARegressionTrainer machineLearningModelBuilderSDCARegression;
private List<TrainerProcessorAbstract> trainerProcessorAbstractList;

public MachineLearningFrm(LotteryDataServices lotteryDataServices)
{
InitializeComponent();

this.lotteryDataServices = lotteryDataServices;
this.machineLearningModelBuilderFastTree = new FastTreeTrainer();
this.machineLearningModelBuilderSDCARegression = new SDCARegressionTrainer();
this.trainerProcessorAbstractList = new List<TrainerProcessorAbstract>();

trainerProcessorAbstractList.Add(new FastTreeTrainerDataIntake(this.lotteryDataServices));
trainerProcessorAbstractList.Add(new SDCARegressionTrainerDataIntake(this.lotteryDataServices));
trainerProcessorAbstractList.Add(new LottoMatchCountTrainerDataIntake(this.lotteryDataServices));

machineLearningModelBuilderFastTree.ProcessingStatus += MachineLearningModelBuilder_ProcessingStatus;
machineLearningModelBuilderSDCARegression.ProcessingStatus += MachineLearningModelBuilder_ProcessingStatus;
trainerProcessorAbstractList.Add(new DrawResultWinCountDataIntake(this.lotteryDataServices));
log(ResourcesUtils.GetMessage("mac_lrn_log_13"));
}
private void MachineLearningModelBuilder_ProcessingStatus(object sender, string e)
{
log(e);
Application.DoEvents();
}
private void btnExit_Click(object sender, EventArgs e)
{
if(!isUpdateProcessingStarted) this.Close();
Expand Down
1 change: 1 addition & 0 deletions Forms/Ticket/PickGeneratorFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private void EnlistGenerators()
DisplayGenerators(new RandomPredictionSDCARegression(this.lotteryDataServices));
DisplayGenerators(new RandomPredictionSDCARegressionInBetween(this.lotteryDataServices));
DisplayGenerators(new LottoCountMatchPredictionFastTreeRegression(this.lotteryDataServices));
DisplayGenerators(new DrawResultWinCountFastTreeTweedieRandomGenerator(this.lotteryDataServices));
}
private void DisplayGenerators(SequenceGenerator seqGen)
{
Expand Down
3 changes: 2 additions & 1 deletion Includes/Classes/Generator/GeneratorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum GeneratorType
RANDOM_PREDICTION_DRAW_RESULT = 15,
RANDOM_PREDICTION_SDCA_REGRESSION = 16,
RANDOM_PREDICTION_SDCA_REGRESSION_104_176 = 17,
LOTTO_MATCH_COUNT_PREDICTION_FAST_TREE_REGRESSION = 18
LOTTO_MATCH_COUNT_PREDICTION_FAST_TREE_REGRESSION = 18,
DRAW_RESULT_WIN_COUNT_PREDICTION_FAST_TREE_REGRESSION = 19
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using LottoDataManager.Includes.Classes.ML.FastTreeTweedie.DrawResultWinCount;
using LottoDataManager.Includes.Model.Details;
using LottoDataManager.Includes.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoDataManager.Includes.Classes.Generator.Types
{
public class DrawResultWinCountFastTreeTweedieRandomGenerator : AbstractSequenceGenerator, SequenceGenerator
{
public DrawResultWinCountFastTreeTweedieRandomGenerator(LotteryDataServices lotteryDataServices) : base(lotteryDataServices)
{
SeqGeneratorType = GeneratorType.DRAW_RESULT_WIN_COUNT_PREDICTION_FAST_TREE_REGRESSION;
this.Description = ResourcesUtils.GetMessage("pick_class_draw_result_win_count_match_desc");
SequenceParams = new List<SequenceGeneratorParams>();
SequenceParams.Add(new SequenceGeneratorParams()
{
GeneratorParamType = GeneratorParamType.COUNT,
Description = ResourcesUtils.GetMessage("pick_class_draw_result_win_count_match_lp_count"),
MaxCountValue = 99
});
SequenceParams.Add(new SequenceGeneratorParams()
{
GeneratorParamType = GeneratorParamType.COUNT,
Description = @ResourcesUtils.GetMessage("pick_class_draw_result_win_count_match_perc"),
MaxCountValue = 100
});
}

public bool AreParametersValueValid(out string errMessage)
{
return ValidateCountParamField(out errMessage, 0)
&& ValidateCountParamField(out errMessage, 1);
}

public List<int[]> GenerateSequence()
{
int maximumPickCount = GetFieldParamValueForCount(0);
int matchPerc = GetFieldParamValueForCount(1);
int maxLoopBreaker = 10000;
int maxLoopCtr = 0;
List<int[]> results = new List<int[]>();
DrawResultWinCountInputModel sampleData;
LotteryDrawResultSetup lotteryDrawResult = new LotteryDrawResultSetup();
lotteryDrawResult.GameCode = lotteryDataServices.LotteryDetails.GameCode;
Random ran = new Random();

while (results.Count < maximumPickCount)
{
int[] randomSeq = LuckyPickGenerator(ran);
lotteryDrawResult.ResetSequenceToZero();
lotteryDrawResult.FillNumberBySeq(randomSeq);
sampleData = lotteryDrawResult.GetDrawResultWinCountInputModel(true);
DrawResultWinCountOutputModel output = DrawResultWinCountPredictor.Predict(sampleData);
int score = (int)(output.Score * 100);

if (score >= matchPerc)
{
Array.Sort(randomSeq);
results.Add(randomSeq);
}
if (maxLoopCtr++ > maxLoopBreaker) break;
}
return results;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<int[]> GenerateSequence()

foreach (LotteryDrawResult lotDraw in lotteryDrawResults)
{
SDCARegressionInputModel sampleData = lotDraw.GetSDCARegressionInputModel();
SDCARegressionInputModel sampleData = lotDraw.GetSDCARegressionInputModel(true);
var predictionResult = SDCARegressionPredictor.Predict(sampleData);

//Console.WriteLine(String.Format("Data: {0}, {1},{2},{3},{4},{5},{6},{7},{8} ", sampleData.Draw_date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<int[]> GenerateSequence()

foreach (LotteryDrawResult lotDraw in lotteryDrawResults)
{
SDCARegressionInputModel sampleData = lotDraw.GetSDCARegressionInputModel();
SDCARegressionInputModel sampleData = lotDraw.GetSDCARegressionInputModel(true);
var predictionResult = SDCARegressionPredictor.Predict(sampleData);

//Console.WriteLine(String.Format("Data: {0}, {1},{2},{3},{4},{5},{6},{7},{8} ", sampleData.Draw_date,
Expand Down
4 changes: 3 additions & 1 deletion Includes/Classes/LotteryAppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using LottoDataManager.Includes.Classes.ML.FastTree;
using LottoDataManager.Includes.Classes.ML.FastTreeRegression;
using LottoDataManager.Includes.Classes.ML.FastTreeTweedie.DrawResultWinCount;
using LottoDataManager.Includes.Classes.ML.SDCARegression;
using LottoDataManager.Includes.Database.DAO.Impl;
using LottoDataManager.Includes.Database.DAO.Interface;
Expand Down Expand Up @@ -68,7 +69,8 @@ public bool TestMLMainModelFolderSource(String folderPath)
{
if (FastTreePredictor.IsMLModelExisting(folderPath) &&
LottoMatchCountPredictor.IsMLModelExisting(folderPath) &&
SDCARegressionPredictor.IsMLModelExisting(folderPath)) return true;
DrawResultWinCountPredictor.IsMLModelExisting(folderPath) &&
SDCARegressionPredictor.IsMLModelExisting(folderPath)) return true;
return false;
}
public String MLModelPath
Expand Down
7 changes: 7 additions & 0 deletions Includes/Classes/LotteryDataServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ public List<LotteryBet> GetLottoCountMatchMLDataset(GameMode gameMode, DateTime
{
return this.lotteryBetDao.GetLottoCountMatchMLDataset(gameMode, startingDate);
}
public List<LotteryDrawResult> GetDrawResultWinCountMLDataset(GameMode gameMode, DateTime startingDate)
{
return this.lotteryDrawResultDao.GetDrawResultWinCountMLDataset(gameMode, startingDate);
}



/// <summary>
/// Get all latest draw dates available in each lottery games.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using LottoDataManager.Includes.Classes.ML.TrainerProcessor;
using LottoDataManager.Includes.Model.Details;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoDataManager.Includes.Classes.ML.FastTreeTweedie.DrawResultWinCount
{
public class DrawResultWinCountDataIntake : TrainerProcessorAbstract
{
private static String DATA_TABLE_HEADERS = "game_cd,draw_date,num1,num2,num3,num4,num5,num6,draw_result\r\n";
private DrawResultWinCountTrainer drawResultWinCountTrainer;

public DrawResultWinCountDataIntake(LotteryDataServices lotteryDataServices) : base(DATA_TABLE_HEADERS)
{
this.LotteryDataServices = lotteryDataServices;
this.drawResultWinCountTrainer = new DrawResultWinCountTrainer();
this.drawResultWinCountTrainer.ProcessingStatus += CommonTrainerInstanceEvent_ProcessingStatus;
}

public override void StartUpdate()
{
CommonTrainerModelDrawResults();
}
protected override DateTime GetDrawDateEquivalent(Object lotteryObject)
{
LotteryDrawResult result = (LotteryDrawResult)lotteryObject;
return result.GetDrawDate();
}
protected override List<Object> GetTrainerDataSets(TrainerDataIntakeModel trainerDataIntakeModel)
{
return LotteryDataServices.GetDrawResultWinCountMLDataset(
trainerDataIntakeModel.GameMode, trainerDataIntakeModel.StartingDateTime).ToList<object>();
}
protected override String GetDataSetEntry(Object lotteryModel)
{
LotteryDrawResult model = (LotteryDrawResult)lotteryModel;
return model.GetDrawResultWinCountModelDataIntake();
}
protected override void CreateTrainerModel(String fileName)
{
try
{
CommonCreateTrainerModel(drawResultWinCountTrainer, fileName);
}
catch (Exception e)
{
log(e.StackTrace);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.ML.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoDataManager.Includes.Classes.ML.FastTreeTweedie.DrawResultWinCount
{
public class DrawResultWinCountInputModel
{
[ColumnName(@"game_cd"), LoadColumn(0)]
public float Game_cd { get; set; }

[ColumnName(@"draw_date"), LoadColumn(1)]
public string Draw_date { get; set; }

[ColumnName(@"num1"), LoadColumn(2)]
public float Num1 { get; set; }

[ColumnName(@"num2"), LoadColumn(3)]
public float Num2 { get; set; }

[ColumnName(@"num3"), LoadColumn(4)]
public float Num3 { get; set; }

[ColumnName(@"num4"), LoadColumn(5)]
public float Num4 { get; set; }

[ColumnName(@"num5"), LoadColumn(6)]
public float Num5 { get; set; }

[ColumnName(@"num6"), LoadColumn(7)]
public float Num6 { get; set; }

[ColumnName(@"draw_result"), LoadColumn(8)]
public float Draw_result { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoDataManager.Includes.Classes.ML.FastTreeTweedie.DrawResultWinCount
{
public class DrawResultWinCountOutputModel
{
public float Score { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Microsoft.ML;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoDataManager.Includes.Classes.ML.FastTreeTweedie.DrawResultWinCount
{
public class DrawResultWinCountPredictor : MLModelAbstract
{
private static readonly String MODEL_NAME = "MLModel_5H_DrawResultWinCount.zip";
public static readonly Lazy<PredictionEngine<DrawResultWinCountInputModel, DrawResultWinCountOutputModel>>
PredictEngine = new Lazy<PredictionEngine<DrawResultWinCountInputModel, DrawResultWinCountOutputModel>>(() =>
CreatePredictEngine(), true);

public static String MLNetModelPath
{
get
{
return GetCompleteModelPath(MODEL_NAME);
}
}

public static bool IsMLModelExisting(String folderPath = null)
{
return IsModelExists(MODEL_NAME, folderPath);
}


/// <summary>
/// Use this method to predict on <see cref="DrawResultWinCountOutputModel"/>.
/// </summary>
/// <param name="input">model input.</param>
/// <returns><seealso cref=" DrawResultWinCountInputModel"/></returns>
public static DrawResultWinCountOutputModel Predict(DrawResultWinCountInputModel input)
{
var predEngine = PredictEngine.Value;
return predEngine.Predict(input);
}

private static PredictionEngine<DrawResultWinCountInputModel, DrawResultWinCountOutputModel> CreatePredictEngine()
{
var mlContext = new MLContext();
ITransformer mlModel = mlContext.Model.Load(MLNetModelPath, out var _);
return mlContext.Model.CreatePredictionEngine<DrawResultWinCountInputModel, DrawResultWinCountOutputModel>(mlModel);
}

}
}
Loading

0 comments on commit dece022

Please sign in to comment.