aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Utilities/Tango.JobRunsGenerator
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.JobRunsGenerator')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/App.config20
-rw-r--r--Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs152
-rw-r--r--Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Tango.JobRunsGenerator.csproj21
-rw-r--r--Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/packages.config3
4 files changed, 51 insertions, 145 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/App.config b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/App.config
index eb619b843..b3646d281 100644
--- a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/App.config
+++ b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/App.config
@@ -13,24 +13,4 @@
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <!--<dependentAssembly>
- <assemblyIdentity name="Z.EntityFramework.Extensions" publicKeyToken="59b66d028979105b" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.0.50.0" newVersion="4.0.50.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-5.0.5.0" newVersion="5.0.5.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
- </dependentAssembly>-->
- </assemblyBinding>
- </runtime>
</configuration> \ No newline at end of file
diff --git a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs
index 71d5779a6..6c3c62606 100644
--- a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs
+++ b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs
@@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
-using System.Data.Entity;
-using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Builders;
using Tango.BL.Entities;
-using Tango.Core;
-using Tango.Integration.Operation;
-using Z.EntityFramework.Plus;
namespace Tango.JobRunsGenerator
{
@@ -18,120 +13,75 @@ namespace Tango.JobRunsGenerator
{
static void Main(string[] args)
{
- DataSource dataSource = new DataSource();
- dataSource.Catalog = "Tango_DEV";
- dataSource.Address = "twine.database.windows.net";
- dataSource.IntegratedSecurity = false;
- dataSource.UserName = "Roy";
- dataSource.Password = "Aa123456";
+ Console.WriteLine("Job Runs Generator Started...");
- using (ObservablesContext db = ObservablesContext.CreateDefault(dataSource))
+ DateTime now = DateTime.UtcNow;
+ DateTime yearago = DateTime.UtcNow.AddYears(-1);
+ Random rnd = new Random();
+ List<String> messages = new List<string>()
{
- var count = db.JobRuns.Where(x => x.JobGuid != null).Count();
+ "Timeout failure",
+ "Thread Break",
+ "Application Exception",
+ "Over Temperature",
+ "Communication Error"
+ };
- int index = 0;
- int saveIndex = 0;
+ int count = 0;
- var runsGroup = db.JobRuns.Where(x => x.JobGuid != null).GroupBy(x => x.JobGuid).ToList();
+ using (ObservablesContext db = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS"))
+ {
+ var machines = db.Machines.ToList();
- foreach (var runGroup in runsGroup)
+ foreach (var machine in machines)
{
- var runs = runGroup;
-
- var firstRun = runs.First();
-
- var job = new JobBuilder(db).Set(x => x.Guid == firstRun.JobGuid).WithSegments().WithBrushStops().WithRML().Build();
-
- if (job == null)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Job '{firstRun.JobGuid}' was not found on the database!");
- Console.ForegroundColor = ConsoleColor.Gray;
- continue;
- }
-
- var machine = new MachineBuilder(db).Set(job.MachineGuid).WithConfiguration().Build();
+ new MachineBuilder(db).Set(machine).WithJobs().Build();
- foreach (var segment in job.Segments)
+ foreach (var job in machine.Jobs)
{
- foreach (var stop in segment.BrushStops)
+ using (ObservablesContext db2 = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS"))
{
- stop.SetLiquidVolumes(machine.Configuration, job.Rml, job.Rml.GetActiveProcessGroup().ProcessParametersTables.First());
- }
- }
-
- foreach (var run in runs)
- {
- Console.WriteLine($"Fixing job {job.Name}... ({index++}/{count})");
- run.MachineGuid = job.MachineGuid;
-
- run.JobSource = job.Source;
+ for (DateTime date = yearago; date < now; date = date.AddDays(1))
+ {
+ Console.WriteLine($"Adding job runs for machine '{machine.SerialNumber}' job '{job.Name}' date {date.ToShortDateString()}...");
- if (run.JobLength == 0) run.JobLength = job.LengthIncludingNumberOfUnits;
- if (run.JobName == null) run.JobName = job.Name;
- if (run.RmlGuid == null) run.RmlGuid = job.RmlGuid;
- if (run.JobString == null) run.JobString = job.ToJobFileWhenLoaded().ToString();
- if (run.LiquidQuantityString == null) run.LiquidQuantities = MachineOperator.CreateJobRunLiquidQuantities(job, machine.Configuration, job.Rml.GetActiveProcessGroup().ProcessParametersTables.First(), run.EndPosition, job.LengthIncludingNumberOfUnits);
- if (run.UserGuid == null) run.UserGuid = job.UserGuid;
- if (run.UploadingStartDate == null) run.UploadingStartDate = run.StartDate;
- if (run.HeatingStartDate == null) run.HeatingStartDate = run.StartDate;
- if (run.ActualStartDate == null) run.ActualStartDate = run.StartDate;
- run.IsGradient = job.Segments.Any(x => x.BrushStops.Count > 1);
+ for (int i = 0; i < rnd.Next(0, 9); i++)
+ {
+ int status = rnd.Next(0, 3);
+ String message = messages[rnd.Next(0, messages.Count)];
- //Set new liquid quantities.
- if (run.CyanQuantity == 0 &&
- run.MagentaQuantity == 0 &&
- run.YellowQuantity == 0 &&
- run.BlackQuantity == 0 &&
- run.TransparentQuantity == 0 &&
- run.LubricantQuantity == 0 &&
- run.CleanerQuantity == 0)
- {
- //Cyan
- var cyan = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Cyan);
- run.CyanQuantity = cyan != null ? cyan.Quantity : 0;
+ db2.JobRuns.Add(new JobRun()
+ {
+ StartDate = date,
+ EndDate = date.AddMinutes(rnd.Next(10, 61)),
+ JobGuid = job.Guid,
+ EndPosition = job.Length / rnd.Next(1, 11),
+ Status = status,
+ FailedMessage = status == 2 ? message : null,
+ });
- //Magenta
- var magenta = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Magenta);
- run.MagentaQuantity = magenta != null ? magenta.Quantity : 0;
+ count++;
+ }
+ }
- //Yellow
- var yellow = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Yellow);
- run.YellowQuantity = yellow != null ? yellow.Quantity : 0;
-
- //Black
- var black = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Black);
- run.BlackQuantity = black != null ? black.Quantity : 0;
-
- //TI
- var ti = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.TransparentInk);
- run.TransparentQuantity = ti != null ? ti.Quantity : 0;
-
- //Lubricant
- var lubricant = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Lubricant);
- run.LubricantQuantity = lubricant != null ? lubricant.Quantity : 0;
-
- //Cleaner
- var cleaner = run.LiquidQuantities.FirstOrDefault(x => x.LiquidType == BL.Enumerations.LiquidTypes.Cleaner);
- run.CleanerQuantity = cleaner != null ? cleaner.Quantity : 0;
- }
-
- saveIndex++;
-
- if (saveIndex > 100)
- {
- saveIndex = 0;
- Console.WriteLine("Saving changes...");
- db.SaveChanges();
+ db2.SaveChanges();
}
}
}
- Console.WriteLine("Saving changes...");
- db.SaveChanges();
+ Console.WriteLine($"The generator is about to insert {count} job runs to the database are you sure? [Y/N]:");
+ var key = Console.ReadKey().Key;
- Console.WriteLine("Done!");
- Console.ReadLine();
+ if (key == ConsoleKey.Y)
+ {
+ Console.WriteLine("Saving changes to database...");
+ Console.WriteLine("Done!");
+ Console.ReadLine();
+ }
+ else
+ {
+ return;
+ }
}
}
}
diff --git a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Tango.JobRunsGenerator.csproj b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Tango.JobRunsGenerator.csproj
index e8f5af6f3..04e647f46 100644
--- a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Tango.JobRunsGenerator.csproj
+++ b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Tango.JobRunsGenerator.csproj
@@ -48,15 +48,6 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
- <Reference Include="Z.EntityFramework.Extensions, Version=5.1.6.0, Culture=neutral, PublicKeyToken=59b66d028979105b, processorArchitecture=MSIL">
- <HintPath>..\..\packages\Z.EntityFramework.Extensions.5.1.6\lib\net45\Z.EntityFramework.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="Z.EntityFramework.Plus.EF6, Version=5.1.6.0, Culture=neutral, PublicKeyToken=59b66d028979105b, processorArchitecture=MSIL">
- <HintPath>..\..\packages\Z.EntityFramework.Plus.EF6.5.1.6\lib\net45\Z.EntityFramework.Plus.EF6.dll</HintPath>
- </Reference>
- <Reference Include="Z.Expressions.Eval, Version=4.0.27.0, Culture=neutral, PublicKeyToken=59b66d028979105b, processorArchitecture=MSIL">
- <HintPath>..\..\packages\Z.Expressions.Eval.4.0.27\lib\net45\Z.Expressions.Eval.dll</HintPath>
- </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Versioning\GlobalVersionInfo.cs">
@@ -78,18 +69,6 @@
<Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
<Name>Tango.Core</Name>
</ProjectReference>
- <ProjectReference Include="..\..\Tango.Integration\Tango.Integration.csproj">
- <Project>{4206AC58-3B57-4699-8835-90BF6DB01A61}</Project>
- <Name>Tango.Integration</Name>
- </ProjectReference>
- <ProjectReference Include="..\..\Tango.PMR\Tango.PMR.csproj">
- <Project>{e4927038-348d-4295-aaf4-861c58cb3943}</Project>
- <Name>Tango.PMR</Name>
- </ProjectReference>
- <ProjectReference Include="..\..\Tango.Transport\Tango.Transport.csproj">
- <Project>{74E700B0-1156-4126-BE40-EE450D3C3026}</Project>
- <Name>Tango.Transport</Name>
- </ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/packages.config b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/packages.config
index 6d95e7b5d..b3daf0d6c 100644
--- a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/packages.config
+++ b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/packages.config
@@ -1,7 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
- <package id="Z.EntityFramework.Extensions" version="5.1.6" targetFramework="net461" />
- <package id="Z.EntityFramework.Plus.EF6" version="5.1.6" targetFramework="net461" />
- <package id="Z.Expressions.Eval" version="4.0.27" targetFramework="net461" />
</packages> \ No newline at end of file