Example #1
0
        public string GetEncounterName()
        {
            var log      = GetLog();
            var analyser = new LogAnalyser();

            return(analyser.GetEncounter(log).GetName());
        }
        public void Analyse_WithInvalidFilename_ReturnsFalse()
        {
            var webService = MockRepository.GenerateStub<IWebService>();
            var emailService = MockRepository.GenerateStub<IEmailService>();
            var logAnalyser = new LogAnalyser(webService, emailService);

            bool result = logAnalyser.Analyse(string.Empty);

            Assert.AreEqual(false, result);
        }
        public void Analyse_WithInvalidFilename_CallsWebService()
        {
            var webService = MockRepository.GenerateMock<IWebService>();
            var emailService = MockRepository.GenerateStub<IEmailService>();
            var logAnalyser = new LogAnalyser(webService, emailService);

            webService.Expect(x => x.LogError(""));

            logAnalyser.Analyse(string.Empty);
        }
        public void Analyse_WithInvalidFilename_ReturnsFalse()
        {
            var webService = new FakeWebService();
            var emailService = new FakeEmailService();
            var logAnalyser = new LogAnalyser(webService, emailService);

            bool result = logAnalyser.Analyse(string.Empty);

            Assert.AreEqual(false, result);
        }
        public void Analyse_WithInvalidFilename_CallsWebService()
        {
            var webService = new FakeWebService();
            var emailService = new FakeEmailService();
            var logAnalyser = new LogAnalyser(webService, emailService);

            logAnalyser.Analyse(string.Empty);

            Assert.AreEqual(true, webService.IsLogErrorCalled);
        }
        public void Analyse_ExceptionRaised_CallsEmailService()
        {
            var webService = new FakeWebService();
            webService.RaiseExceptionForLogError = true;
            var emailService = new FakeEmailService();
            var logAnalyser = new LogAnalyser(webService, emailService);

            logAnalyser.Analyse(string.Empty);

            Assert.AreEqual(true, emailService.IsSendEmailCalled);
        }
Example #7
0
        private void btnAnalyseFile_Click(object sender, EventArgs e)
        {
            //Fetch the file path.
            var filepath = tbxClarityLogFile.Text;

            //Verify that the file is valid.
            if (!File.Exists(filepath))
            {
                MessageBox.Show("The selected file does not exist.", "File does not exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Analyse the file.
            var log = new LogAnalyser(filepath, nudInclusiveGlucoseTopLimit.Value);

            //Show the analyse result.
            showAnalyseResult(log);
        }
Example #8
0
 public LogAnalytics(EVTCParser parser, LogProcessor processor, LogAnalyser analyser)
 {
     Parser    = parser ?? throw new ArgumentNullException(nameof(parser));
     Processor = processor ?? throw new ArgumentNullException(nameof(processor));
     Analyser  = analyser ?? throw new ArgumentNullException(nameof(analyser));
 }
Example #9
0
        private static void MeasureTimes(string filename, EVTCParser parser, LogProcessor processor, LogAnalyser analyser, GW2ApiData apiData, TextWriter outputWriter)
        {
            var stopwatch = Stopwatch.StartNew();
            var log       = parser.ParseLog(filename);

            var parsedTime = stopwatch.Elapsed;

            stopwatch.Restart();
            var processedLog = processor.GetProcessedLog(log);

            var processedTime = stopwatch.Elapsed;

            stopwatch.Restart();
            var statistics = analyser.GetStatistics(processedLog, apiData);

            var statisticsTime = stopwatch.Elapsed;

            var totalTime = parsedTime + processedTime + statisticsTime;

            outputWriter.WriteLine(
                $"{filename},{parsedTime.TotalMilliseconds},{processedTime.TotalMilliseconds},{statisticsTime.TotalMilliseconds},{totalTime.TotalMilliseconds}");
            outputWriter.Flush();
        }
Example #10
0
 /// <summary>
 /// Shows the result from the analyse of the log file.
 /// </summary>
 /// <param name="log">The analyser object holding the result.</param>
 private void showAnalyseResult(LogAnalyser log)
 {
     rtbAnalyseResult.Text = log.GetResult();
 }
Example #11
0
        } = null;                                                // TODO: Add support

        public MakerForm()
        {
            Title      = "Scratch HTML log maker";
            ClientSize = new Size(800, 600);
            var formLayout = new DynamicLayout();

            Content = formLayout;

            var openFileDialog = new OpenFileDialog {
                MultiSelect = true
            };

            openFileDialog.Filters.Add(new FileFilter("EVTC logs", ".evtc", ".evtc.zip", ".zevtc"));

            var openFilesButton = new Button {
                Text = "Select EVTC logs"
            };
            var processButton = new Button {
                Text = "Create HTML logs"
            };

            var notDoneListBox = new ListBox();
            var doneListBox    = new ListBox();

            doneListBox.DataStore = finishedFileNames.ToArray();

            var splitter = new Splitter {
                Panel1 = notDoneListBox, Panel2 = doneListBox, Position = 400
            };

            formLayout.BeginVertical(spacing: new Size(10, 10));
            formLayout.AddRow(openFilesButton, processButton);
            formLayout.EndVertical();
            formLayout.BeginVertical();
            formLayout.Add(splitter);
            formLayout.EndVertical();

            openFilesButton.Click += (sender, args) =>
            {
                if (openFileDialog.ShowDialog((Control)sender) == DialogResult.Ok)
                {
                    foreach (var file in openFileDialog.Filenames)
                    {
                        notFinishedFileNames.Enqueue(file);
                    }

                    notDoneListBox.DataStore = notFinishedFileNames.Select(Path.GetFileName).ToArray();
                }
            };

            processButton.Click += (sender, args) =>
            {
                Task.Run(() =>
                {
                    var times = new List <(string taskName, double milliseconds)>();
                    var totalTimeStopwatch = Stopwatch.StartNew();

                    var parser    = new EVTCParser();
                    var processor = new LogProcessor();
                    var analysis  = new LogAnalyser();
                    var generator = new HtmlGenerator(ApiData);

                    int finishedTaskCount = 0;
                    while (notFinishedFileNames.Count > 0)
                    {
                        var taskStopwatch = Stopwatch.StartNew();
                        string filename   = "";
                        filename          = notFinishedFileNames.Dequeue();

                        var fileDirectory = Path.GetDirectoryName(filename);
                        var newName       = Path.GetFileNameWithoutExtension(filename);
                        if (newName.EndsWith(".evtc"))
                        {
                            newName = newName.Substring(0, newName.Length - 5);
                        }
                        var resultFilename = Path.Combine(fileDirectory, ResultFilePrefix + newName + ".html");

                        try
                        {
                            var lastElapsed = taskStopwatch.Elapsed;

                            var parsedLog = parser.ParseLog(filename);
                            times.Add(("parsing", (taskStopwatch.Elapsed - lastElapsed).TotalMilliseconds));
                            lastElapsed = taskStopwatch.Elapsed;

                            var processedLog = processor.GetProcessedLog(parsedLog);
                            times.Add(("processing", (taskStopwatch.Elapsed - lastElapsed).TotalMilliseconds));
                            lastElapsed = taskStopwatch.Elapsed;

                            var stats = analysis.GetStatistics(processedLog, ApiData);

                            times.Add(("stats", (taskStopwatch.Elapsed - lastElapsed).TotalMilliseconds));
                            lastElapsed = taskStopwatch.Elapsed;

                            using (var htmlStringWriter = new StreamWriter(resultFilename))
                            {
                                generator.WriteHtml(htmlStringWriter, stats);
                            }

                            times.Add(("html", (taskStopwatch.Elapsed - lastElapsed).TotalMilliseconds));
                            lastElapsed = taskStopwatch.Elapsed;

                            finishedFileNames.Add(resultFilename);
                            Application.Instance.Invoke(() =>
                            {
                                notDoneListBox.DataStore = notFinishedFileNames.Select(Path.GetFileName).ToArray();
                                doneListBox.DataStore    = finishedFileNames.Select(Path.GetFileName).ToArray();
                            });
                        }
                        catch (Exception e)
                        {
                            finishedFileNames.Add($"FAILED: {resultFilename} ({e.Message})");
                            Application.Instance.Invoke(() =>
                            {
                                notDoneListBox.DataStore = notFinishedFileNames.Select(Path.GetFileName).ToArray();
                                doneListBox.DataStore    = finishedFileNames.Select(Path.GetFileName).ToArray();
                            });
                        }
                        Console.WriteLine($"{newName} done, time {taskStopwatch.Elapsed}");
                        finishedTaskCount++;
                    }

                    Console.WriteLine($"All done, total time {totalTimeStopwatch.Elapsed}");

                    foreach ((string taskName, double totalMs) in times.GroupBy(x => x.taskName).Select(x => (x.Key, x.Sum(y => y.milliseconds))).OrderByDescending(x => x.Item2))
                    {
                        Console.WriteLine($"{taskName}, total {totalMs}ms, average {totalMs/Math.Max(finishedTaskCount, 1)}ms");
                    }
                });
            };
        }