stichproben nach linie
This commit is contained in:
parent
7cb8a1cbbc
commit
9afffb28e0
@ -6,6 +6,10 @@
|
||||
|
||||
public class ExeConfig
|
||||
{
|
||||
public static readonly string DllFilePath
|
||||
= typeof(ExeConfig).Assembly.Location;
|
||||
public static readonly ExeConfig Current = new ExeConfig();
|
||||
|
||||
public int PickingSlot
|
||||
{
|
||||
get
|
||||
@ -74,9 +78,8 @@
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
var dll = typeof(ExeConfig).Assembly.Location;
|
||||
var configuration = ConfigurationManager.OpenExeConfiguration(dll);
|
||||
|
||||
var configuration = ConfigurationManager.OpenExeConfiguration(DllFilePath);
|
||||
var settings = configuration?.AppSettings?.Settings ?? new KeyValueConfigurationCollection();
|
||||
|
||||
if (!settings.AllKeys.Contains(key))
|
||||
@ -95,7 +98,7 @@
|
||||
}
|
||||
|
||||
var dll = typeof(ExeConfig).Assembly.Location;
|
||||
var configuration = ConfigurationManager.OpenExeConfiguration(dll);
|
||||
var configuration = ConfigurationManager.OpenExeConfiguration(DllFilePath);
|
||||
var settings = configuration?.AppSettings?.Settings ?? new KeyValueConfigurationCollection();
|
||||
|
||||
if (!settings.AllKeys.Contains(key))
|
||||
|
||||
@ -144,7 +144,6 @@ namespace CordonelAssemblyLine.Model
|
||||
|
||||
|
||||
private Timer tmrAutoDetect;
|
||||
private readonly Stichproben.Cordonel.Stichproben stichproben;
|
||||
|
||||
public LeakViewModel(Int32 slotNR, Int32? stationID = null)
|
||||
{
|
||||
@ -161,8 +160,6 @@ namespace CordonelAssemblyLine.Model
|
||||
$"2x10-7 { System.Environment.NewLine} " +
|
||||
$"2*10^-7 { System.Environment.NewLine} " +
|
||||
"0,0000002";
|
||||
|
||||
this.stichproben = new Stichproben.Cordonel.Stichproben(typeof(LeakViewModel).Assembly.Location);
|
||||
}
|
||||
|
||||
public Boolean isHydraulicStaion()
|
||||
@ -392,7 +389,9 @@ namespace CordonelAssemblyLine.Model
|
||||
if (int.TryParse($"{this.CurrentPcbID}", out var pcbId))
|
||||
{
|
||||
CurrentMeter.Login();
|
||||
var result = this.stichproben.ShouldBePressureTested(pcbId);
|
||||
|
||||
// jedes mal neu wegen die ExeConfig.Current.LeakStationId
|
||||
var result = new StichprobenManager(ExeConfig.Current.LeakStationId).ShouldBePressureTested(pcbId);
|
||||
|
||||
if (result.ShouldBePressureTested)
|
||||
{
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
namespace Stichproben.Cordonel
|
||||
{
|
||||
using System;
|
||||
|
||||
internal class Stichprobe
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int LineId { get; set; }
|
||||
|
||||
public int PcbId { get; set; }
|
||||
|
||||
public int Nummer { get; set; }
|
||||
@ -13,5 +17,7 @@
|
||||
public bool IstStichprobe { get; set; }
|
||||
|
||||
public bool? IstDicht { get; set; }
|
||||
|
||||
public DateTime Datum { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,5 +17,8 @@
|
||||
public int Number { get; }
|
||||
|
||||
public bool ShouldBePressureTested { get; }
|
||||
|
||||
public override string ToString()
|
||||
=> $"Test: {this.Number,5} Rule: {this.Rule,3}%/{this.Count} ShouldBePressureTested: {this.ShouldBePressureTested}";
|
||||
}
|
||||
}
|
||||
@ -2,73 +2,152 @@
|
||||
{
|
||||
using LaaPackages.SqlClient;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
internal class StichprobenDbContext
|
||||
{
|
||||
private readonly int leakStationId;
|
||||
private readonly SqlConnection sqlConnection;
|
||||
|
||||
public StichprobenDbContext(string connectionString)
|
||||
public StichprobenDbContext(int leakStationId)
|
||||
{
|
||||
this.sqlConnection = SqlConnection.CreateSqlConnection(connectionString, error =>
|
||||
{
|
||||
Console.WriteLine(error);
|
||||
});
|
||||
this.leakStationId = leakStationId;
|
||||
this.sqlConnection = SqlConnection.CreateSqlConnection("Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;");
|
||||
}
|
||||
|
||||
public void AddNew(Stichprobe stichprobe)
|
||||
public void AddStichprobe(Stichprobe stichprobe)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
INSERT INTO Stichproben
|
||||
( PcbId
|
||||
, LineId
|
||||
, Nummer
|
||||
, Prozentsatz
|
||||
, IstStichprobe)
|
||||
VALUES (@{nameof(stichprobe.PcbId)}
|
||||
, @{nameof(this.leakStationId)}
|
||||
, @{nameof(stichprobe.Nummer)}
|
||||
, @{nameof(stichprobe.Prozentsatz)}
|
||||
, @{nameof(stichprobe.IstStichprobe)})")
|
||||
.SetParameter(nameof(stichprobe.PcbId), stichprobe.PcbId)
|
||||
.SetParameter(nameof(this.leakStationId), this.leakStationId)
|
||||
.SetParameter(nameof(stichprobe.Nummer), stichprobe.Nummer)
|
||||
.SetParameter(nameof(stichprobe.Prozentsatz), stichprobe.Prozentsatz)
|
||||
.SetParameter(nameof(stichprobe.IstStichprobe), stichprobe.IstStichprobe)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public Stichprobe GetLastOrDefault()
|
||||
public StichprobenRule FindRuleOrMin(int prozentsatz)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand(@"
|
||||
.CreateCommand($@"
|
||||
SELECT TOP 1
|
||||
Id
|
||||
, LineId
|
||||
, [%]
|
||||
, Count
|
||||
FROM StichprobenRegeln
|
||||
WHERE LineId = @{nameof(this.leakStationId)}
|
||||
AND ([%] = @{nameof(prozentsatz)} OR 1 = 1)
|
||||
ORDER BY [%]")
|
||||
.SetParameter(nameof(this.leakStationId), this.leakStationId)
|
||||
.SetParameter(nameof(prozentsatz), prozentsatz)
|
||||
.FirstOrDefault(x => new StichprobenRule
|
||||
{
|
||||
Id = x.GetValue<int>(0),
|
||||
LineId = x.GetValue<int>(1),
|
||||
Percent = x.GetValue<int>(2),
|
||||
Count = x.GetValue<int>(3),
|
||||
});
|
||||
|
||||
public StichprobenRule GetMaxRule()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT TOP 1
|
||||
Id
|
||||
, LineId
|
||||
, [%]
|
||||
, Count
|
||||
FROM StichprobenRegeln
|
||||
WHERE LineId = @{nameof(this.leakStationId)}
|
||||
ORDER BY [%] DESC")
|
||||
.SetParameter(nameof(this.leakStationId), this.leakStationId)
|
||||
.FirstOrDefault(x => new StichprobenRule
|
||||
{
|
||||
Id = x.GetValue<int>(0),
|
||||
LineId = x.GetValue<int>(1),
|
||||
Percent = x.GetValue<int>(2),
|
||||
Count = x.GetValue<int>(3),
|
||||
});
|
||||
|
||||
public StichprobenRule GetMinRule()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT TOP 1
|
||||
Id
|
||||
, LineId
|
||||
, [%]
|
||||
, Count
|
||||
FROM StichprobenRegeln
|
||||
WHERE LineId = @{nameof(this.leakStationId)}
|
||||
ORDER BY [%]")
|
||||
.SetParameter(nameof(this.leakStationId), this.leakStationId)
|
||||
.FirstOrDefault(x => new StichprobenRule
|
||||
{
|
||||
Id = x.GetValue<int>(0),
|
||||
LineId = x.GetValue<int>(1),
|
||||
Percent = x.GetValue<int>(2),
|
||||
Count = x.GetValue<int>(3),
|
||||
});
|
||||
|
||||
public StichprobenRule GetNextRuleOrMin(int prozentsatz)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT TOP 1
|
||||
Id
|
||||
, LineId
|
||||
, [%]
|
||||
, Count
|
||||
FROM StichprobenRegeln
|
||||
WHERE LineId = @{nameof(this.leakStationId)}
|
||||
AND ([%] < @{nameof(prozentsatz)} OR 1 = 1)
|
||||
ORDER BY [%]")
|
||||
.SetParameter(nameof(this.leakStationId), this.leakStationId)
|
||||
.SetParameter(nameof(prozentsatz), prozentsatz)
|
||||
.FirstOrDefault(x => new StichprobenRule
|
||||
{
|
||||
Id = x.GetValue<int>(0),
|
||||
LineId = x.GetValue<int>(1),
|
||||
Percent = x.GetValue<int>(2),
|
||||
Count = x.GetValue<int>(3),
|
||||
});
|
||||
|
||||
public Stichprobe GetLastStichprobeOrDefault()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT Id
|
||||
, PcbId
|
||||
, LineId
|
||||
, Nummer
|
||||
, Prozentsatz
|
||||
, IstStichprobe
|
||||
, IstDicht
|
||||
, Datum
|
||||
FROM Stichproben
|
||||
WHERE LineId = @{nameof(this.leakStationId)}
|
||||
ORDER BY Id DESC")
|
||||
.SetParameter(nameof(this.leakStationId), this.leakStationId)
|
||||
.FirstOrDefault(x => new Stichprobe
|
||||
{
|
||||
Id = x.GetValue<int>(0),
|
||||
PcbId = x.GetValue<int>(1),
|
||||
Nummer = x.GetValue<int>(2),
|
||||
Prozentsatz = x.GetValue<int>(3),
|
||||
IstStichprobe = x.GetValue<bool>(4),
|
||||
IstDicht = x.GetValue<bool?>(5),
|
||||
LineId = x.GetValue<int>(1),
|
||||
PcbId = x.GetValue<int>(2),
|
||||
Nummer = x.GetValue<int>(3),
|
||||
Prozentsatz = x.GetValue<int>(4),
|
||||
IstStichprobe = x.GetValue<bool>(5),
|
||||
IstDicht = x.GetValue<bool?>(6),
|
||||
});
|
||||
|
||||
public void SetPressureTestPassed(int id, bool? pressureTestPassed)
|
||||
public bool IsAnyStichprobeUndicht()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
UPDATE Stichproben
|
||||
SET IstDicht = @{nameof(pressureTestPassed)}
|
||||
WHERE Id = @{nameof(id)}")
|
||||
.SetParameter(nameof(pressureTestPassed), pressureTestPassed)
|
||||
.SetParameter(nameof(id), id)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public bool IsAnyUndicht()
|
||||
{
|
||||
var missingResults = this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
UPDATE Stichproben
|
||||
SET IstDicht = d.Dicht
|
||||
@ -76,34 +155,10 @@
|
||||
FROM Stichproben AS s
|
||||
LEFT JOIN Druckpruefung AS d
|
||||
ON s.PcbId = d.FabNr
|
||||
WHERE s.IstDicht IS NULL")
|
||||
.ExecuteReader(x => x.GetValue<bool?>(0));
|
||||
|
||||
return missingResults?.Any(x => x == false) ?? false;
|
||||
}
|
||||
|
||||
//public bool? PressureTestPassed(int pcbId)
|
||||
//{
|
||||
// var missingResults = this.sqlConnection
|
||||
// .CreateCommand($@"
|
||||
// UPDATE Stichproben
|
||||
// SET IstDicht = d.Dicht
|
||||
// OUTPUT inserted.IstDicht
|
||||
// FROM Stichproben AS s
|
||||
// LEFT JOIN Druckpruefung AS d
|
||||
// ON s.PcbId = d.FabNr
|
||||
// WHERE s.IstDicht IS NULL")
|
||||
// .SetParameter(nameof(pcbId), pcbId)
|
||||
// .ExecuteReader(x => x.GetValue<bool?>(0));
|
||||
|
||||
// return this.sqlConnection
|
||||
// .CreateCommand($@"
|
||||
// SELECT TOP 1 Dicht
|
||||
// FROM Druckpruefung
|
||||
// WHERE FabNr = @{nameof(pcbId)}
|
||||
// ORDER BY Pruefgang DESC")
|
||||
// .SetParameter(nameof(pcbId), pcbId)
|
||||
// .FirstOrDefault(x => x.GetValue<bool?>(0));
|
||||
//}
|
||||
WHERE s.LineId = @{nameof(this.leakStationId)}
|
||||
AND s.IstDicht IS NULL")
|
||||
.SetParameter(nameof(this.leakStationId), this.leakStationId)
|
||||
.ExecuteReader(x => x.GetValue<bool?>(0))
|
||||
.Any(x => x == false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,23 @@
|
||||
namespace Stichproben.Cordonel
|
||||
{
|
||||
public class Stichproben
|
||||
public class StichprobenManager
|
||||
{
|
||||
private readonly StichprobenRules stichprobenRules;
|
||||
private readonly StichprobenDbContext stichprobenDb;
|
||||
|
||||
public Stichproben(string assemblyLocation)
|
||||
{
|
||||
this.stichprobenRules = new StichprobenRules(assemblyLocation);
|
||||
this.stichprobenDb = new StichprobenDbContext("Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;");
|
||||
}
|
||||
public StichprobenManager(int leakStationId)
|
||||
=> this.stichprobenDb = new StichprobenDbContext(leakStationId);
|
||||
|
||||
public StichprobeResult ShouldBePressureTested(int pcbId)
|
||||
{
|
||||
var isAnyUndicht = this.stichprobenDb.IsAnyUndicht();
|
||||
var previousStichprobe = this.stichprobenDb.GetLastOrDefault();
|
||||
var isAnyUndicht = this.stichprobenDb.IsAnyStichprobeUndicht();
|
||||
var previousStichprobe = this.stichprobenDb.GetLastStichprobeOrDefault();
|
||||
|
||||
if (previousStichprobe is null)
|
||||
{
|
||||
previousStichprobe = new Stichprobe();
|
||||
}
|
||||
|
||||
var stichprobenRule = this.stichprobenRules.Min();
|
||||
var stichprobenRule = this.stichprobenDb.GetMinRule();
|
||||
var currentStichprobe = new Stichprobe
|
||||
{
|
||||
PcbId = pcbId
|
||||
@ -29,24 +25,26 @@
|
||||
|
||||
if (isAnyUndicht == false)
|
||||
{
|
||||
stichprobenRule = this.stichprobenRules.FindRuleOrMin(previousStichprobe.Prozentsatz);
|
||||
stichprobenRule = this.stichprobenDb.FindRuleOrMin(previousStichprobe.Prozentsatz);
|
||||
|
||||
if (previousStichprobe.Nummer >= stichprobenRule.Count)
|
||||
{
|
||||
stichprobenRule = this.stichprobenRules.GetNext(previousStichprobe.Prozentsatz);
|
||||
stichprobenRule = this.stichprobenDb.GetNextRuleOrMin(previousStichprobe.Prozentsatz);
|
||||
}
|
||||
else if (previousStichprobe.Nummer != 0)
|
||||
|
||||
if (previousStichprobe.Nummer != 0)
|
||||
{
|
||||
currentStichprobe.Nummer = previousStichprobe.Nummer + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stichprobenRule = this.stichprobenRules.Max();
|
||||
stichprobenRule = this.stichprobenDb.GetMaxRule();
|
||||
}
|
||||
|
||||
var percent = stichprobenRule.Percent;
|
||||
var moduloDevider = 100 / percent;
|
||||
|
||||
currentStichprobe.Prozentsatz = percent;
|
||||
currentStichprobe.IstStichprobe = currentStichprobe.Nummer % moduloDevider == 0;
|
||||
|
||||
@ -57,7 +55,7 @@
|
||||
|
||||
if (previousStichprobe.PcbId != currentStichprobe.PcbId)
|
||||
{
|
||||
this.stichprobenDb.AddNew(currentStichprobe);
|
||||
this.stichprobenDb.AddStichprobe(currentStichprobe);
|
||||
}
|
||||
|
||||
return new StichprobeResult(currentStichprobe.IstStichprobe, currentStichprobe.Nummer, stichprobenRule.Percent, stichprobenRule.Count);
|
||||
@ -2,6 +2,10 @@
|
||||
{
|
||||
internal class StichprobenRule
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int LineId { get; set; }
|
||||
|
||||
public int Percent { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
@ -1,112 +0,0 @@
|
||||
namespace Stichproben.Cordonel
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
internal class StichprobenRules
|
||||
{
|
||||
private readonly List<StichprobenRule> rules;
|
||||
|
||||
public StichprobenRules(string assemblyLocation)
|
||||
{
|
||||
this.rules = new List<StichprobenRule>();
|
||||
|
||||
this.LoadOrCreateRules(assemblyLocation);
|
||||
}
|
||||
|
||||
public void Add(int percent, int count)
|
||||
{
|
||||
var rule = new StichprobenRule
|
||||
{
|
||||
Percent = percent,
|
||||
Count = count
|
||||
};
|
||||
|
||||
var rulesCount = this.rules.Count;
|
||||
var insertIndex = default(int);
|
||||
|
||||
for (; insertIndex < rulesCount; insertIndex++)
|
||||
{
|
||||
var current = this.rules[insertIndex];
|
||||
|
||||
if (percent >= current.Percent)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.rules.Insert(insertIndex, rule);
|
||||
}
|
||||
|
||||
public StichprobenRule FindRuleOrMin(int percent)
|
||||
=> this.rules.FirstOrDefault(x => x.Percent == percent)
|
||||
?? this.rules.LastOrDefault();
|
||||
|
||||
public StichprobenRule GetNext(int percent)
|
||||
{
|
||||
var stichprobenRule = this.Min();
|
||||
|
||||
foreach (var rule in this.rules)
|
||||
{
|
||||
if (rule.Percent < percent)
|
||||
{
|
||||
stichprobenRule = rule;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return stichprobenRule;
|
||||
}
|
||||
|
||||
public StichprobenRule Min()
|
||||
=> this.rules.LastOrDefault();
|
||||
|
||||
public StichprobenRule Max()
|
||||
=> this.rules.FirstOrDefault();
|
||||
|
||||
private void LoadOrCreateRules(string assemblyLocation)
|
||||
{
|
||||
var configuration = ConfigurationManager.OpenExeConfiguration(assemblyLocation);
|
||||
var settings = configuration.AppSettings.Settings;
|
||||
var stichprobenRulesKeys = settings
|
||||
.AllKeys
|
||||
.Where(x => Regex.IsMatch($"{x}", $@"{nameof(Stichprobe)}\.(?<percent>\d+)"));
|
||||
|
||||
if (stichprobenRulesKeys.Any())
|
||||
{
|
||||
foreach (var key in stichprobenRulesKeys)
|
||||
{
|
||||
var tokens = key.Split(new [] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (!int.TryParse($"{tokens[1]}", out var percent))
|
||||
{
|
||||
percent = 5;
|
||||
}
|
||||
|
||||
if (!int.TryParse($"{settings[key].Value}", out var count))
|
||||
{
|
||||
count = 100;
|
||||
}
|
||||
|
||||
this.Add(percent, count);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.Add($"{nameof(Stichprobe)}.100", "25");
|
||||
settings.Add($"{nameof(Stichprobe)}.50", "50");
|
||||
settings.Add($"{nameof(Stichprobe)}.10", "100");
|
||||
settings.Add($"{nameof(Stichprobe)}.5", "100");
|
||||
|
||||
configuration.Save(ConfigurationSaveMode.Modified);
|
||||
ConfigurationManager.RefreshSection("appSettings");
|
||||
|
||||
this.LoadOrCreateRules(assemblyLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,10 +45,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Cordonel\Stichprobe.cs" />
|
||||
<Compile Include="Cordonel\Stichproben.cs" />
|
||||
<Compile Include="Cordonel\StichprobenManager.cs" />
|
||||
<Compile Include="Cordonel\StichprobenDbContext.cs" />
|
||||
<Compile Include="Cordonel\StichprobenRule.cs" />
|
||||
<Compile Include="Cordonel\StichprobenRules.cs" />
|
||||
<Compile Include="Cordonel\StichprobeResult.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user