-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ruleset rule S#1310 changed to None * data validators for calculations refactored * ui styles reworked * main view redone using mvvm * startup for main view using caliburn.micro * tutorial view redone using mvvm * results view redone using mvvm * added calculation header * added calculation footer * interaction logic for header and footer * bases for calculations interaction logic * aded ui for new calculation working with 2D plane * ui for dice calculation redone using mvvm * interaction logic for dice calculation ui * results placeholders for results view * old dice calculation ui removed * ui for coloredballs calculation redone * interaction logic for coloredballs calculation ui * removed old coloredballs calculation ui * obsolete panels removed * not needed extensions removed * not needed interfaces removed * not needed models removed * not needed utility removed * color translator refactored * only needed ui extension refactored * startup for ui and new styles added to App dictionary * added icon for application * added caliburn.micro for mvvm logic and livecharts library for results chart * added domain extensions * reworked calculation data objects * added enums for integer resource managment in application * removed not needed utility * refactored number translator * removed old resources * refactored resources structure * added czech localization * added validation exception * moved calculation interface to domain * project file updated * removed moved calculation data objects * removed moved calculation interface * added bases for calculations * added calculation data validation bases * refactored coloredballs calculation and validator * refactored dice calculation and validator * added new 2d plane calculation and validator * removed renamed validators * updated calculations project file * updated solution
- Loading branch information
Showing
197 changed files
with
9,550 additions
and
5,303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...imentalProbability.Calculations/CalculationDataValidation/BaseCalculationDataValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using ExperimentalProbability.Contracts.Enums; | ||
using ExperimentalProbability.Contracts.Exceptions; | ||
using ExperimentalProbability.Contracts.Models; | ||
using ExperimentalProbability.Contracts.Properties.Resources.Validation; | ||
using ExperimentalProbability.Contracts.Utilities; | ||
using GeneralCalcResources = ExperimentalProbability.Contracts.Properties.Resources.Calculations.General.Resources; | ||
|
||
namespace ExperimentalProbability.Calculations.CalculationDataValidation | ||
{ | ||
public abstract class BaseCalculationDataValidator | ||
{ | ||
public virtual void Validate(CalculationData data) | ||
{ | ||
ValidateNumber(data.SimulationsToRun, (int)GeneralNumbers.MinSimulations, (int)GeneralNumbers.MaxSimulations, GeneralCalcResources.ElementName_SimulationsToRun); | ||
} | ||
|
||
protected void ValidateNumber(int number, int min, int max, string elementName) | ||
{ | ||
if (number < min) | ||
{ | ||
throw new ValidationException(elementName, Resources.Error_Number_Min, min); | ||
} | ||
|
||
if (number > max) | ||
{ | ||
throw new ValidationException(elementName, Resources.Error_Number_Max, max); | ||
} | ||
} | ||
|
||
protected string AppendNumberPositionToString(int index, string elementName) | ||
{ | ||
return string.Concat(NumberTranslater.NumberToPosition[index], ' ', elementName); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...obability.Calculations/CalculationDataValidation/Pool/BasePoolCalculationDataValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using ExperimentalProbability.Contracts.Models; | ||
|
||
namespace ExperimentalProbability.Calculations.CalculationDataValidation.Pool | ||
{ | ||
public abstract class BasePoolCalculationDataValidator : BaseCalculationDataValidator | ||
{ | ||
public override void Validate(CalculationData data) | ||
{ | ||
base.Validate(data); | ||
ValidatePoolData(data); | ||
ValidateConditionData(data); | ||
} | ||
|
||
protected abstract void ValidatePoolData(CalculationData data); | ||
|
||
protected abstract void ValidateConditionData(CalculationData data); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...entalProbability.Calculations/CalculationDataValidation/Pool/ColoredBallsDataValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using ExperimentalProbability.Contracts.Enums; | ||
using ExperimentalProbability.Contracts.Exceptions; | ||
using ExperimentalProbability.Contracts.Models; | ||
using ExperimentalProbability.Contracts.Models.Pool; | ||
using ExperimentalProbability.Contracts.Properties.Resources.Calculations.Pool.ColoredBalls; | ||
|
||
namespace ExperimentalProbability.Calculations.CalculationDataValidation.Pool | ||
{ | ||
public class ColoredBallsDataValidator : BasePoolCalculationDataValidator | ||
{ | ||
protected override void ValidatePoolData(CalculationData data) | ||
{ | ||
var calcData = (ColoredBallsCalculationData)data; | ||
var ballCount = calcData.BallCount; | ||
|
||
ValidateNumber( | ||
ballCount, | ||
(int)ColoredBallsNumbers.MinNumberOfBalls, | ||
(int)ColoredBallsNumbers.MaxNumberOfBalls, | ||
Resources.ElementName_NumberOfBalls); | ||
|
||
var maxNumberOfColors = (int)ColoredBallsNumbers.MaxNumberOfColors; | ||
|
||
ValidateNumber( | ||
calcData.PoolColors.Length, | ||
(int)ColoredBallsNumbers.MinNumberOfColors, | ||
ballCount < maxNumberOfColors ? ballCount : maxNumberOfColors, | ||
Resources.ElementName_NumberOfColors); | ||
|
||
ValidateColors(calcData.PoolColors, Resources.ElementName_PoolColor); | ||
ValidateColorCounts(calcData); | ||
} | ||
|
||
protected override void ValidateConditionData(CalculationData data) | ||
{ | ||
var calcData = (ColoredBallsCalculationData)data; | ||
var ballCount = calcData.BallCount; | ||
var maxNumberOfTakenBalls = (int)ColoredBallsNumbers.MaxNumberOfTakenBalls; | ||
|
||
ValidateNumber( | ||
calcData.ConditionColors.Length, | ||
(int)ColoredBallsNumbers.MinNumberOfTakenBalls, | ||
ballCount < maxNumberOfTakenBalls ? ballCount : maxNumberOfTakenBalls, | ||
Resources.ElementName_NumberOfTakenBalls); | ||
|
||
ValidateColors(calcData.ConditionColors, Resources.ElementName_ConditionColor); | ||
} | ||
|
||
private void ValidateColorCounts(ColoredBallsCalculationData data) | ||
{ | ||
var sum = default(int); | ||
var counts = data.ColorCounts; | ||
var ballCount = data.BallCount; | ||
|
||
for (int i = default; i < counts.Length; i++) | ||
{ | ||
var count = counts[i]; | ||
|
||
ValidateNumber( | ||
count, | ||
(int)ColoredBallsNumbers.MinColorCount, | ||
ballCount - 1, | ||
AppendNumberPositionToString(i, Resources.ElementName_Counter)); | ||
|
||
sum += count; | ||
} | ||
|
||
ValidateNumber(sum, ballCount, ballCount, Resources.ElementName_CounterSum); | ||
} | ||
|
||
private void ValidateColors(object[] colors, string elementName) | ||
{ | ||
for (int i = default; i < colors.Length; i++) | ||
{ | ||
ValidateColor(colors[i], AppendNumberPositionToString(i, elementName)); | ||
} | ||
} | ||
|
||
private void ValidateColor(object color, string elementName) | ||
{ | ||
if (color == null) | ||
{ | ||
throw new ValidationException(elementName); | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
ExperimentalProbability.Calculations/CalculationDataValidation/Pool/DiceDataValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using ExperimentalProbability.Contracts.Enums; | ||
using ExperimentalProbability.Contracts.Models; | ||
using ExperimentalProbability.Contracts.Models.Pool; | ||
using ExperimentalProbability.Contracts.Properties.Resources.Calculations.Pool.Dice; | ||
|
||
namespace ExperimentalProbability.Calculations.CalculationDataValidation.Pool | ||
{ | ||
public class DiceDataValidator : BasePoolCalculationDataValidator | ||
{ | ||
protected override void ValidatePoolData(CalculationData data) | ||
{ | ||
ValidateNumber( | ||
((DiceCalculationData)data).SideCount, | ||
(int)DiceNumbers.SideCountTetrahedron, | ||
(int)DiceNumbers.SideCountIcosahedron, | ||
Resources.ElementName_Dice); | ||
} | ||
|
||
protected override void ValidateConditionData(CalculationData data) | ||
{ | ||
var calcData = (DiceCalculationData)data; | ||
|
||
ValidateNumber( | ||
calcData.ConditionSides.Length, | ||
(int)DiceNumbers.MinNumberOfRolls, | ||
(int)DiceNumbers.MaxNumberOfRolls, | ||
Resources.ElementName_NumberOfRolls); | ||
|
||
ValidateConditionSides(calcData); | ||
} | ||
|
||
private void ValidateConditionSides(DiceCalculationData data) | ||
{ | ||
var conditionSides = data.ConditionSides; | ||
|
||
for (int i = default; i < conditionSides.Length; i++) | ||
{ | ||
ValidateNumber( | ||
conditionSides[i], | ||
(int)DiceNumbers.MinRollResult, | ||
data.SideCount, | ||
AppendNumberPositionToString(i, Resources.ElementName_Roll)); | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...robability.Calculations/CalculationDataValidation/TwoDPlane/QuarterCircleDataValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ExperimentalProbability.Calculations.CalculationDataValidation.Calculations.TwoDPlane | ||
{ | ||
public class QuarterCircleDataValidator : BaseCalculationDataValidator | ||
{ | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
ExperimentalProbability.Calculations/Calculations/BaseCalculation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using ExperimentalProbability.Calculations.CalculationDataValidation; | ||
using ExperimentalProbability.Contracts.Enums; | ||
using ExperimentalProbability.Contracts.Interfaces; | ||
using ExperimentalProbability.Contracts.Models; | ||
|
||
namespace ExperimentalProbability.Calculations.Calculations | ||
{ | ||
public abstract class BaseCalculation : ICalculation | ||
{ | ||
private readonly BaseCalculationDataValidator _validator; | ||
|
||
private readonly BackgroundWorker _worker; | ||
|
||
private readonly Random _random; | ||
|
||
private CalculationResultData _resultData; | ||
|
||
public BaseCalculation(BaseCalculationDataValidator validator, BackgroundWorker worker) | ||
{ | ||
_validator = validator; | ||
_worker = worker; | ||
_random = new Random(); | ||
_resultData = new CalculationResultData(); | ||
} | ||
|
||
public virtual CalculationResultData Run(CalculationData data, DoWorkEventArgs workerEventArgs) | ||
{ | ||
ValidateData(data); | ||
return Calculate(data, workerEventArgs); | ||
} | ||
|
||
public abstract decimal CalculateResult(CalculationResultData data); | ||
|
||
public void ClearResultData() | ||
{ | ||
_resultData = new CalculationResultData(); | ||
} | ||
|
||
protected void ValidateData(CalculationData data) | ||
{ | ||
_validator.Validate(data); | ||
} | ||
|
||
protected CalculationResultData Calculate(CalculationData data, DoWorkEventArgs workerEventArgs) | ||
{ | ||
var updateProgress = data.SimulationsToRun / (int)GeneralNumbers.MaxProgress; | ||
var progress = default(int); | ||
|
||
for (int i = default; i < data.SimulationsToRun; i++) | ||
{ | ||
if (_worker.CancellationPending) | ||
{ | ||
workerEventArgs.Cancel = true; | ||
return null; | ||
} | ||
|
||
RunSimulation(data, _random, _resultData); | ||
|
||
progress = TryUpdateWorkerProgress(i, updateProgress, _resultData, data, progress); | ||
} | ||
|
||
CalculateResult(_resultData); | ||
return _resultData; | ||
} | ||
|
||
protected abstract bool CheckCondition(CalculationData data, object simResult); | ||
|
||
protected abstract object GetSimulationResult(CalculationData data, Random random); | ||
|
||
private void RunSimulation(CalculationData data, Random random, CalculationResultData resultData) | ||
{ | ||
if (CheckCondition(data, GetSimulationResult(data, random))) | ||
{ | ||
resultData.ConditionMet++; | ||
} | ||
|
||
resultData.SimulationsRan++; | ||
} | ||
|
||
private int TryUpdateWorkerProgress(int currentSim, int updateProgress, CalculationResultData resultData, CalculationData data, int currentProgress) | ||
{ | ||
if ((currentSim != 0 && currentSim % updateProgress == 0) | ||
|| resultData.SimulationsRan == data.SimulationsToRun) | ||
{ | ||
currentProgress++; | ||
resultData.Result = CalculateResult(resultData); | ||
_worker.ReportProgress(currentProgress, resultData.Result); | ||
} | ||
|
||
return currentProgress; | ||
} | ||
} | ||
} |
Oops, something went wrong.