Skip to content

Commit

Permalink
Merge pull request #24 from AngelsSoftwareOrg/develop
Browse files Browse the repository at this point in the history
v1.0.0.9 - Cycle Release - LottoDataManagerSetup_v1.0.0.9
- Add progress bar on Pick Generator, for the selected pick generators type
- Remove the native ctrl+c function of object list view for Bets only.
- Clear out the highlight renderer on Pick Generator form pick list when generating or clearing the current list.
  • Loading branch information
angelsburger90 authored Nov 17, 2021
2 parents dece022 + 09c37a0 commit 030079d
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 109 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>8</value>
<value>9</value>
</setting>
<setting name="repository_name" serializeAs="String">
<value>LottoDataManager</value>
Expand Down
1 change: 1 addition & 0 deletions Forms/MainFrm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 103 additions & 58 deletions Forms/Ticket/PickGeneratorFrm.Designer.cs

Large diffs are not rendered by default.

62 changes: 60 additions & 2 deletions Forms/Ticket/PickGeneratorFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using LottoDataManager.Includes.Classes;
using LottoDataManager.Includes.Classes.Comparers;
using LottoDataManager.Includes.Classes.Generator;
using LottoDataManager.Includes.Classes.Generator.PickGenerationProgress;
using LottoDataManager.Includes.Classes.Generator.Types;
using LottoDataManager.Includes.Model;
using LottoDataManager.Includes.Model.Details;
Expand All @@ -27,7 +28,8 @@ public partial class PickGeneratorFrm : Form
private LotteryDataServices lotteryDataServices;
private LotteryTicketPanel lotteryTicketPanel;
private SequenceGeneratorParamFieldsFormFactory seqFactory = SequenceGeneratorParamFieldsFormFactory.GetInstance();

private String statusPickGenerationLabelCache;
private bool isPickGeneratorRunningStatus;
public PickGeneratorFrm(LotteryDataServices lotteryDataServices)
{
InitializeComponent();
Expand All @@ -37,6 +39,7 @@ public PickGeneratorFrm(LotteryDataServices lotteryDataServices)

private void PickGeneratorFrm_Load(object sender, EventArgs e)
{
statusLabel.Text = String.Empty;
this.Text = String.Format(ResourcesUtils.GetMessage("pick_grp_gen_form_title"),
this.lotteryDataServices.LotteryDetails.Description);
btnViewCompareHits.Text = ResourcesUtils.GetMessage("pick_btn_compare_hits");
Expand All @@ -50,6 +53,10 @@ private void PickGeneratorFrm_Load(object sender, EventArgs e)
btnAddSelected.Text = ResourcesUtils.GetMessage("pick_btn_place_bet");
btnExit.Text = ResourcesUtils.GetMessage("common_btn_exit");
linkUncheckAll.Text = ResourcesUtils.GetMessage("common_link_uncheck_all");
btnStop.Text = ResourcesUtils.GetMessage("common_btn_stop");
statusPickGenerationLabelCache = ResourcesUtils.GetMessage("pick_status_lbl_pick_generation");
btnStop.Visible = false;
isPickGeneratorRunningStatus = false;
SetupObjectListView();
EnlistGenerators();
}
Expand Down Expand Up @@ -228,6 +235,9 @@ private void btnClearSel_Click(object sender, EventArgs e)
objLvGenSeq.SetObjects(null);
objLvGenSeq.Tag = null;
ClearSequenceGenParametersValue();
statusLabel.Text = String.Empty;
this.objLvGenSeq.ModelFilter = null;
this.objLvGenSeq.DefaultRenderer = null;
}
private void ClearSequenceGenParametersValue()
{
Expand All @@ -243,14 +253,62 @@ private void btnGenerate_Click(object sender, EventArgs e)
if (lvGenType.SelectedObjects.Count > 0)
{
SequenceGenerator seqGen = (SequenceGenerator)lvGenType.SelectedObject;
AbstractSequenceGenerator seqGenAbstract = (AbstractSequenceGenerator) seqGen;
seqGenAbstract.PickGenerationProgress += SeqGenAbstract_PickGenerationProgress;
isPickGeneratorRunningStatus = true;
String errMsg = "";
if(!seqGen.AreParametersValueValid(out errMsg))
{
MessageBox.Show(errMsg);
return;
}
ButtonAvailabilityWhilePicking(true);
DisplayGeneratedSequence(seqGen.GenerateSequence());
}
ButtonAvailabilityWhilePicking(false);
}
private void SeqGenAbstract_PickGenerationProgress(object sender, PickGenerationProgressEvent e)
{
if(isPickGeneratorRunningStatus == false)
{
SequenceGenerator seqGen = (SequenceGenerator)lvGenType.SelectedObject;
AbstractSequenceGenerator seqGenAbstract = (AbstractSequenceGenerator)seqGen;
if (seqGenAbstract == null) return;
seqGenAbstract.StopPickGeneration();
}
statusLabel.Text = String.Format(statusPickGenerationLabelCache, e.GeneratedPickCount, e.GenerationAttemptCount);
if (e.GenerationAttemptCount % 200 == 0) Application.DoEvents();
}
private void btnStop_Click(object sender, EventArgs e)
{
isPickGeneratorRunningStatus = false;
}
private void ButtonAvailabilityWhilePicking(bool isPicking)
{
if (isPicking)
{
addBetToolStripMenuItem.Enabled = false;
lvGenType.Enabled = false;
btnAddSelected.Enabled = false;
btnViewCompareHits.Enabled = false;
btnClearSel.Enabled = false;
btnGenerate.Enabled = false;
btnStop.Visible = true;
this.objLvGenSeq.ModelFilter = null;
this.objLvGenSeq.DefaultRenderer = null;
}
else
{
addBetToolStripMenuItem.Enabled = true;
lvGenType.Enabled = true;
btnAddSelected.Enabled = true;
btnViewCompareHits.Enabled = true;
btnClearSel.Enabled = true;
btnGenerate.Enabled = true;
btnStop.Visible = false;
isPickGeneratorRunningStatus = false;
statusLabel.Text = String.Empty;
}
}
private void lvGenType_SelectionChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -293,6 +351,7 @@ private void listviewSorter(object sender, ColumnClickEventArgs e)
#endregion
private void btnExit_Click(object sender, EventArgs e)
{
this.btnStop_Click(sender, e);
this.Close();
}
private void linkUncheckAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Expand Down Expand Up @@ -381,7 +440,6 @@ private void btnViewCompareHits_Click(object sender, EventArgs e)
AutoCheckSelectedBetsFromHitComparisonForm(hitComparisonFrm.GetCheckedLotteryBets);
hitComparisonFrm.Dispose();
}

private void AutoCheckSelectedBetsFromHitComparisonForm(List<LotteryBet> selectedLotteryBets)
{
LotteryBet seqGenVisibleItem = null;
Expand Down
3 changes: 3 additions & 0 deletions Forms/Ticket/PickGeneratorFrm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<metadata name="ctxMenuBet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>155, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
7 changes: 4 additions & 3 deletions Includes/Classes/Generator/AbstractSequenceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LottoDataManager.Includes.Classes.Generator.PickGenerationProgress;
using LottoDataManager.Includes.Model.Details;
using LottoDataManager.Includes.Utilities;

namespace LottoDataManager.Includes.Classes.Generator
{
public abstract class AbstractSequenceGenerator
public abstract class AbstractSequenceGenerator: AbstractPickGenerationProgress
{
private String description;
private List<SequenceGeneratorParams> sequenceParams;
Expand All @@ -17,9 +18,9 @@ public abstract class AbstractSequenceGenerator
protected LotteryTicketPanel lotteryTicketPanel;
protected static int IN_BETWEEN_SUM_MIN = 104;
protected static int IN_BETWEEN_SUM_MAX = 176;

private GeneratorType seqGeneratorType;
protected AbstractSequenceGenerator(LotteryDataServices lotteryDataServices)
protected AbstractSequenceGenerator(LotteryDataServices lotteryDataServices): base()
{
this.lotteryDataServices = lotteryDataServices;
this.lotteryTicketPanel = this.lotteryDataServices.GetLotteryTicketPanel();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoDataManager.Includes.Classes.Generator.PickGenerationProgress
{
public abstract class AbstractPickGenerationProgress
{
public event EventHandler<PickGenerationProgressEvent> PickGenerationProgress;
private PickGenerationProgressEvent pickGenerationProgressEvent;
private Boolean isPickGenerationRunning;
protected AbstractPickGenerationProgress()
{
pickGenerationProgressEvent = new PickGenerationProgressEvent();
IsPickGenerationRunning = false;
}
protected PickGenerationProgressEvent PickGenerationProgressEvent { get => pickGenerationProgressEvent; }
public bool IsPickGenerationRunning { get => isPickGenerationRunning; set => isPickGenerationRunning = value; }
protected void RaisePickGenerationProgress()
{
if (PickGenerationProgress == null) return;
PickGenerationProgress.Invoke(this, PickGenerationProgressEvent);
}
protected bool IsContinuePickGenerationProgress()
{
RaisePickGenerationProgress();
if (!IsPickGenerationRunning) return false;
if (PickGenerationProgressEvent.IsGenerationAttemptCountReachMaxValue()) return false;
return true;
}
public void ResetPickGenerationStats()
{
PickGenerationProgressEvent.ResetCounters();
}
protected void StartPickGeneration()
{
IsPickGenerationRunning = true;
ResetPickGenerationStats();
}
public void StopPickGeneration()
{
IsPickGenerationRunning = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoDataManager.Includes.Classes.Generator.PickGenerationProgress
{
public class PickGenerationProgressEvent : EventArgs
{
private int generatedPickCount;
private long generationAttemptCount;
private long maxAttempt;

public PickGenerationProgressEvent()
{
maxAttempt = long.MaxValue - 100;
ResetCounters();
}
public int GeneratedPickCount { get => generatedPickCount; set => generatedPickCount = value; }
public long GenerationAttemptCount { get => generationAttemptCount; set => generationAttemptCount = value; }

public void ResetCounters()
{
GeneratedPickCount = 0;
GenerationAttemptCount = 0;
}
public void IncrementGeneratedPickCount()
{
GeneratedPickCount++;
}
public void IncrementGenerationAttemptCount()
{
GenerationAttemptCount++;
}
public bool IsGenerationAttemptCountReachMaxValue()
{
return (GenerationAttemptCount > maxAttempt);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,62 @@ public DrawResultWinCountFastTreeTweedieRandomGenerator(LotteryDataServices lott
this.Description = ResourcesUtils.GetMessage("pick_class_draw_result_win_count_match_desc");
SequenceParams = new List<SequenceGeneratorParams>();
SequenceParams.Add(new SequenceGeneratorParams()
{
GeneratorParamType = GeneratorParamType.COUNT,
{
GeneratorParamType = GeneratorParamType.COUNT,
Description = ResourcesUtils.GetMessage("pick_class_draw_result_win_count_match_lp_count"),
MaxCountValue = 99
});
SequenceParams.Add(new SequenceGeneratorParams()
{
GeneratorParamType = GeneratorParamType.COUNT,
{
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();
public bool AreParametersValueValid(out string errMessage)
{
return ValidateCountParamField(out errMessage, 0)
&& ValidateCountParamField(out errMessage, 1);
}

while (results.Count < maximumPickCount)
public List<int[]> GenerateSequence()
{
int[] randomSeq = LuckyPickGenerator(ran);
lotteryDrawResult.ResetSequenceToZero();
lotteryDrawResult.FillNumberBySeq(randomSeq);
sampleData = lotteryDrawResult.GetDrawResultWinCountInputModel(true);
DrawResultWinCountOutputModel output = DrawResultWinCountPredictor.Predict(sampleData);
int score = (int)(output.Score * 100);
StartPickGeneration();
int maximumPickCount = GetFieldParamValueForCount(0);
int matchPerc = GetFieldParamValueForCount(1);
int maxLoopBreaker = int.MaxValue-100;
int maxLoopCtr = 0;
List<int[]> results = new List<int[]>();
DrawResultWinCountInputModel sampleData;
LotteryDrawResultSetup lotteryDrawResult = new LotteryDrawResultSetup();
lotteryDrawResult.GameCode = lotteryDataServices.LotteryDetails.GameCode;
Random ran = new Random();

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

PickGenerationProgressEvent.IncrementGenerationAttemptCount();

if (score >= matchPerc)
{
Array.Sort(randomSeq);
results.Add(randomSeq);
PickGenerationProgressEvent.IncrementGeneratedPickCount();
}
if (!IsContinuePickGenerationProgress()) break;
if (maxLoopCtr++ > maxLoopBreaker) break;
}
if (maxLoopCtr++ > maxLoopBreaker) break;
RaisePickGenerationProgress();
StopPickGeneration();
return results;
}
return results;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public bool AreParametersValueValid(out string errMessage)

public List<int[]> GenerateSequence()
{
StartPickGeneration();
int maximumPickCount = GetFieldParamValueForCount(0);
int matchPerc = GetFieldParamValueForCount(1);
int maxLoopBreaker = 100000;
int maxLoopBreaker = int.MaxValue - 100;
int maxLoopCtr = 0;
List<int[]> results = new List<int[]>();
LottoMatchCountInputModel sampleData;
Expand All @@ -56,11 +57,14 @@ public List<int[]> GenerateSequence()
sampleData = lotteryBet.GetLottoMatchCountInputModel();
LottoMatchCountOutputModel output = LottoMatchCountPredictor.Predict(sampleData);
int score = (int)(output.Score * 100);
PickGenerationProgressEvent.IncrementGenerationAttemptCount();
if (score >= matchPerc)
{
Array.Sort(randomSeq);
results.Add(randomSeq);
PickGenerationProgressEvent.IncrementGeneratedPickCount();
}
if (!IsContinuePickGenerationProgress()) break;
if (maxLoopCtr++ > maxLoopBreaker) break;
}
return results;
Expand Down
Loading

0 comments on commit 030079d

Please sign in to comment.