From 81311d321be26ccad433143290ddf5b8ee1bbafb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 22 Nov 2018 16:54:38 +0200 Subject: Working on Stats. --- .../Utilities/Tango.JobRunsGenerator/Program.cs | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs (limited to 'Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs') 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 messages = new List() + { + "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; + } + } + } + } +} -- cgit v1.3.1