aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-11-22 16:54:38 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-11-22 16:54:38 +0200
commit81311d321be26ccad433143290ddf5b8ee1bbafb (patch)
tree1c81e31068a008ce99e8004e945f7849e3ee596a /Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs
parentb38870afe2ae248c09807f5f2ed6973d13752a07 (diff)
downloadTango-81311d321be26ccad433143290ddf5b8ee1bbafb.tar.gz
Tango-81311d321be26ccad433143290ddf5b8ee1bbafb.zip
Working on Stats.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs88
1 files changed, 88 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs
new file mode 100644
index 000000000..6c3c62606
--- /dev/null
+++ b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs
@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL;
+using Tango.BL.Builders;
+using Tango.BL.Entities;
+
+namespace Tango.JobRunsGenerator
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine("Job Runs Generator Started...");
+
+ DateTime now = DateTime.UtcNow;
+ DateTime yearago = DateTime.UtcNow.AddYears(-1);
+ Random rnd = new Random();
+ List<String> messages = new List<string>()
+ {
+ "Timeout failure",
+ "Thread Break",
+ "Application Exception",
+ "Over Temperature",
+ "Communication Error"
+ };
+
+ int count = 0;
+
+ using (ObservablesContext db = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS"))
+ {
+ var machines = db.Machines.ToList();
+
+ foreach (var machine in machines)
+ {
+ new MachineBuilder(db).Set(machine).WithJobs().Build();
+
+ foreach (var job in machine.Jobs)
+ {
+ using (ObservablesContext db2 = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS"))
+ {
+ 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()}...");
+
+ for (int i = 0; i < rnd.Next(0, 9); i++)
+ {
+ int status = rnd.Next(0, 3);
+ String message = messages[rnd.Next(0, messages.Count)];
+
+ 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,
+ });
+
+ count++;
+ }
+ }
+
+ db2.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;
+
+ if (key == ConsoleKey.Y)
+ {
+ Console.WriteLine("Saving changes to database...");
+ Console.WriteLine("Done!");
+ Console.ReadLine();
+ }
+ else
+ {
+ return;
+ }
+ }
+ }
+ }
+}