Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release V1.2 #133

Merged
merged 17 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions Mate.DataCore/Data/DynamicInitializer/Tables/MasterTableResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Mate.DataCore.Data.Context;
using Mate.DataCore.DataModel;
using Mate.DataCore.Nominal.Model;

namespace Mate.DataCore.Data.DynamicInitializer.Tables
{
Expand Down Expand Up @@ -47,50 +48,73 @@ internal void CreateResourceTools(List<ResourceProperty> resourceProperties)
for (int i = 0; i < resourceProperties.Count; i++)
{
CreateTools(_capability.Capabilities[i], resourceProperties[i].SetupTime,
resourceProperties[i].OperatorCount);
resourceProperties[i].OperatorCount, limitedTools: false, numberOfWorker: 3);
}
}

//was sind operators? -> Personen, die Maschinen umrüsten
private void CreateTools(M_ResourceCapability capability, long setupTime, int numberOfOperators)
private void CreateTools(M_ResourceCapability capability, long setupTime, int numberOfOperators, bool limitedTools = false, int numberOfWorker = 0)
{
List<M_Resource> tools = new List<M_Resource>();
List<M_ResourceSetup> setups = new List<M_ResourceSetup>();
List<M_ResourceCapabilityProvider> capabilityProviders = new List<M_ResourceCapabilityProvider>();
List<M_Resource> operators = new List<M_Resource>();
List<M_Resource> workers = new List<M_Resource>();

for (int i = 1; i < 1 + numberOfOperators; i++)
{
operators.Add(CreateNewResource(capability.Name + " Operator " + i, true, true, capability.Name));
operators.Add(CreateNewResource(capability.Name + " Operator " + i, true, true, capability.Name + "O"));
}

for (int i = 1; i < 1 + numberOfWorker; i++)
{
workers.Add(CreateNewResource(capability.Name + " Worker " + i, true, true, capability.Name + "W"));
}

var numberOfTools = _capability.Capabilities
.Single(x => x.Name == capability.Name)
.ChildResourceCapabilities.Count();

for (int i = 0; i < numberOfTools; i++)
{
var tool = CreateNewResource($"Tool {capability.Name} {i}", false, false, null);
tools.Add(tool);
}

foreach (var resource in CapabilityToResourceDict.Single(x => x.Key == capability.Name).Value)
{
if (operators.Count > 0)
{
foreach (var op in operators)
var nTool = 0;
foreach (var subCapability in _capability.Capabilities
.Single(x => x.Name == capability.Name)
.ChildResourceCapabilities)
{
foreach (var subCapability in _capability.Capabilities
.Single(x => x.Name == capability.Name)
.ChildResourceCapabilities)

foreach (var op in operators)
{
foreach(var worker in workers) {
var capabilityProvider = new M_ResourceCapabilityProvider()
{
Name = $"Provides {subCapability.Name} {resource.Name}",
ResourceCapabilityId = subCapability.Id,
};
var tool = CreateNewResource($"Tool {resource.Name} {subCapability.Name}", false, false, null);
tools.Add(tool);

setups.Add(CreateNewSetup(op, capabilityProvider, false, true, 0));
setups.Add(CreateNewSetup(tool, capabilityProvider, true, true, setupTime));
setups.Add(CreateNewSetup(resource, capabilityProvider, true, true, 0));
capabilityProviders.Add(capabilityProvider);
// var tool = CreateNewResource($"Tool {resource.Name} {subCapability.Name}", false, false, null);
// tools.Add(tool);

setups.Add(CreateNewSetup(op, capabilityProvider, false, true, 0));
setups.Add(CreateNewSetup(tools[nTool], capabilityProvider, true, true, setupTime));
setups.Add(CreateNewSetup(resource, capabilityProvider, true, true, 0));
setups.Add(CreateNewSetup(worker, capabilityProvider, true, false, 0));
capabilityProviders.Add(capabilityProvider);
}
}
nTool++;
}
}
else
{
var nTool = 0;
foreach (var subCapability in _capability.Capabilities
.Single(x => x.Name == capability.Name)
.ChildResourceCapabilities)
Expand All @@ -100,18 +124,20 @@ private void CreateTools(M_ResourceCapability capability, long setupTime, int nu
Name = $"Provides {subCapability.Name} {resource.Name}",
ResourceCapabilityId = subCapability.Id,
};
var tool = CreateNewResource($"Tool {resource.Name} {subCapability.Name}", false, false, null);
tools.Add(tool);
//var tool = CreateNewResource($"Tool {resource.Name} {subCapability.Name}", false, false, null);
//tools.Add(tool);

setups.Add(CreateNewSetup(tool, capabilityProvider, true, true, setupTime));
setups.Add(CreateNewSetup(tools[nTool], capabilityProvider, true, true, setupTime));
setups.Add(CreateNewSetup(resource, capabilityProvider, true, true, 0));
capabilityProviders.Add(capabilityProvider);
nTool++;
}
}
CapabilityProviderDict.Add($"{resource.Name} Tooling", capabilityProviders);
CapabilityToSetupDict.Add($"{resource.Name} Tooling", setups);
CapabilityToResourceDict.Add($"{resource.Name} Tooling", tools);
CapabilityToResourceDict.Add($"{resource.Name} Operators", operators);
CapabilityToResourceDict.Add($"{resource.Name} Worker", workers);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using Mate.DataCore.Data.Context;
using Microsoft.EntityFrameworkCore;
using System.CodeDom;
using System.Collections.Generic;

namespace Mate.DataCore.Data.Initializer.StoredProcedures
{
public static class ArticleStatistics
{
public static void CreateProcedures(MateDb ctx)
{
List<string> ctes = new List<string>();

string sql = string.Format(
string sqlArticleCTE = string.Format(
@"CREATE OR ALTER PROCEDURE ArticleCTE
@ArticleId int
AS
Expand Down Expand Up @@ -47,13 +50,70 @@ UNION ALL
select Sum(u.dur) as SumDuration , sum(u.count) as SumOperations, sum(u.Po) as ProductionOrders from #Union u
END");

ctes.Add(sqlArticleCTE);


string sqlArticleCapabilityComplexityCTE = string.Format(
@"CREATE OR ALTER PROCEDURE [dbo].[ArticleCapabilityComplexity]
@ArticleId int
AS
BEGIN
SET NOCOUNT ON;
DROP TABLE IF EXISTS dbo.#Temp;
DROP TABLE IF EXISTS dbo.#Union;
WITH Parts(AssemblyID, ComponentID, PerAssemblyQty, ComponentLevel, ResourceCapabilityId) AS
(
SELECT b.ArticleParentId, b.ArticleChildId, CAST(b.Quantity AS decimal),0 AS ComponentLevel, 0 as ResourceCapabilityId
FROM dbo.M_ArticleBom AS b
join dbo.M_Article a on a.Id = b.ArticleParentId
where @ArticleId = a.Id
UNION ALL
SELECT bom.ArticleParentId, bom.ArticleChildId, CAST(PerAssemblyQty * bom.Quantity as DECIMAL), ComponentLevel + 1, 0 as ResourceCapabilityId
FROM dbo.M_ArticleBom AS bom
INNER join dbo.M_Article ac on ac.Id = bom.ArticleParentId
INNER JOIN Parts AS p ON bom.ArticleParentId = p.ComponentID
)
select * into #Temp
from (
select pr.Id,pr.Name, Sum(p.PerAssemblyQty) as qty, pr.ToBuild as ToBuild, p.ResourceCapabilityId as ResourceCapabilityId
FROM Parts AS p INNER JOIN M_Article AS pr ON p.ComponentID = pr.Id
Group By pr.Id, pr.Name, p.ComponentID, pr.ToBuild, p.ResourceCapabilityId) as x

select * into #Union from (
select Sum(o.Duration * t.qty) as dur, sum(t.qty) as count ,0 as 'Po', o.ResourceCapabilityId as ResourceCapabilityId
from dbo.M_Operation o join #Temp t on t.Id = o.ArticleId
FULL OUTER join M_ResourceCapability allCaps on allCaps.Id = o.ResourceCapabilityId
where o.ArticleId in (select t.Id from #Temp t)
group by o.ResourceCapabilityId
UNION ALL
SELECT SUM(ot.Duration) as dur, COUNT(*) as count , 0 as 'Po', ot.ResourceCapabilityId as ResourceCapabilityId
from dbo.M_Operation ot
FULL OUTER join M_ResourceCapability allCaps on allCaps.Id = ot.ResourceCapabilityId
where ot.ArticleId = @ArticleId
group by ot.ResourceCapabilityId
) as x
UNION ALL
SELECT 0 as dur, 0 as count, sum(t.qty) + 1 as 'Po', t.ResourceCapabilityId as ResourceCapabilityId
from #Temp t
FULL OUTER join M_ResourceCapability allCaps on allCaps.Id = t.ResourceCapabilityId
where t.ToBuild = 1
group by t.ResourceCapabilityId
select Sum(u.dur) as SumDuration , sum(u.count) as SumOperations, sum(u.Po) as ProductionOrders, allCaps.Id as ResourceCapabilityId from #Union u
FULL OUTER join M_ResourceCapability allCaps on allCaps.Id = u.ResourceCapabilityId
group by allCaps.Id
END");

ctes.Add(sqlArticleCapabilityComplexityCTE);

using (var command = ctx.Database.GetDbConnection().CreateCommand())
{
command.CommandText = sql;
ctx.Database.OpenConnection();
command.ExecuteNonQuery();
}
foreach(var cte in ctes)
{
command.CommandText = cte;
ctx.Database.OpenConnection();
command.ExecuteNonQuery();
}
}
}

public static long DeliveryDateEstimator(int articleId, double factor, MateDb dBContext)
Expand All @@ -69,10 +129,10 @@ public static long DeliveryDateEstimator(int articleId, double factor, MateDb dB
{
while (reader.Read())
{
System.Diagnostics.Debug.WriteLine(string.Format("Summe der Dauer {0}; Summe der Operationen {1}; Summe der Prodktionsaufträge {2}", reader[0], reader[1], reader[2]));
System.Diagnostics.Debug.WriteLine(string.Format("Summe der Dauer {0}; Anzahl der Operationen {1}; Summe der Produktionsaufträge {2}", reader[0], reader[1], int.Parse(reader[2].ToString()) + 1));
// TODO Catch false informations
estimatedProductDelivery = (long)(System.Convert.ToInt64(reader[0]) * factor);
System.Diagnostics.Debug.WriteLine("Estimated Product Delivery{0}", estimatedProductDelivery);
System.Diagnostics.Debug.WriteLine("Estimated Product Delivery {0}", estimatedProductDelivery);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Mate.DataCore/Data/Seed/CapbilityTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CapbilityTransformer
ToolCount = resourceConfig.GetToolsFor(i).Count,
ResourceCount = (int)resourceConfig.ResourceGroupList[i].ResourceQuantity,
SetupTime = (int)resourceConfig.GetMeanSetupDurationFor(i, 0).TotalMinutes,
OperatorCount = 2,
OperatorCount = 1,
IsBatchAble = false
});

Expand Down
19 changes: 11 additions & 8 deletions Mate.DataCore/Data/Seed/MaterialTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
using Seed.Generator.Material;
using System;
using System.Collections.Generic;
using System.Data.HashFunction.xxHash;
using System.Linq;

namespace Mate.DataCore.Data.Seed
{
public class MaterialTransformer
{
public static string BUSINESS_PARTNER_1 { get; private set; } = "BUSINESS_PARTNER_1";
public static string BUSINESS_PARTNER_2 { get; private set; } = "BUSINESS_PARTNER_2";

public static void Transform(MateDb mateDb, Materials materials, DynamicInitializer.Tables.MasterTableResourceCapability masterTableCapabilities)
{
Expand Down Expand Up @@ -79,15 +81,16 @@ public static void Transform(MateDb mateDb, Materials materials, DynamicInitiali
mateDb.ArticleBoms.AddRange(boms);
mateDb.SaveChanges();

CreateStocks(mateDb, businessPartners.First()); ;
CreateStocks(mateDb, businessPartners.ToList());

}

private static M_BusinessPartner[] CreateBusinessPartners(MateDb mateDb)
{
var businessPartners = new M_BusinessPartner[]
{
new M_BusinessPartner() {Debitor = true, Kreditor = false, Name = BUSINESS_PARTNER_1}
new M_BusinessPartner() {Debitor = true, Kreditor = false, Name = BUSINESS_PARTNER_1},
new M_BusinessPartner() {Debitor = false, Kreditor = true, Name = BUSINESS_PARTNER_2}
};
mateDb.BusinessPartners.AddRange(businessPartners);
mateDb.SaveChanges();
Expand Down Expand Up @@ -146,7 +149,7 @@ private static M_ArticleBom CreateBOM(M_Article articleFrom, M_Article articlesT

}

private static void CreateStocks(MateDb mateDb, M_BusinessPartner businessPartners)
private static void CreateStocks(MateDb mateDb, List<M_BusinessPartner> businessPartners)
{
// get the name -> id mappings
var dbArticles = mateDb.Articles.ToList();
Expand All @@ -161,18 +164,18 @@ private static void CreateStocks(MateDb mateDb, M_BusinessPartner businessPartne
{
ArticleForeignKey = article.Id,
Name = "Stock: " + article.Name,
Min = article.ToPurchase ? 500 : 0,
Max = 10000,
Min = article.ToPurchase ? 100 : 0,
Max = 1000,
Current = article.ToPurchase ? 1000 : 0,
StartValue = article.ToPurchase ? 1000 : 0,
});
articleToBusinessPartners.Add(
new M_ArticleToBusinessPartner
{
BusinessPartnerId = businessPartners.Id,
BusinessPartnerId = article.ToPurchase ? businessPartners.Single(x => x.Kreditor).Id : businessPartners.Single(x => x.Debitor).Id,
ArticleId = article.Id,
PackSize = 1000,
Price = 1000 * article.Price,
PackSize = 5000,
Price = 5000 * article.Price,
TimeToDelivery = 1440
});
}
Expand Down
Loading