private void MenuFileNew_Click(object sender, RoutedEventArgs e) { if (port != null) { StartStop_Click(sender, e); } logFile = null; average = new List <double>(); presure = new List <double>(); vibe = new List <double>(); time = new List <double>(); output = new List <double>(); outtime = new List <double>(); var oGraphs = new List <LineGraph>(); foreach (var graph in Lines.Children) { if (graph is LineGraph g && g.Description.Contains("O****m")) { oGraphs.Add(g); } } foreach (var g in oGraphs) { Lines.Children.Remove(g); } _last_input = DateTimeOffset.Now; Dispatcher?.Invoke(() => { AverageGraph.Plot(time, average); PressureGraph.Plot(time, presure); MototGraph.Plot(time, vibe); OutputGraph.Plot(outtime, output); }); }
private void AnalyserOnOutputChange(object sender, OutputChangeArgs e) { var last = 0.0; if (output.Any()) { last = output.Last() / 1000; } if (DateTimeOffset.Now.Subtract(_last_output).TotalMilliseconds > 100 || // throttle (last > 0.01 && e.Intensity < 0.01) || // stop Math.Abs(e.Intensity - last) > 0.25) // 25% change { _last_output = DateTimeOffset.Now; var t = _last_output.ToUnixTimeMilliseconds(); output.Add(e.Intensity * 1000); outtime.Add(t - startTime); var text = t + ":output:" + e.Intensity; Console.WriteLine(text); w?.WriteLine(text); if (output.Count > 10000) { var range = output.Count - 1000; output.RemoveRange(0, range); outtime.RemoveRange(0, range); } Dispatcher?.Invoke(() => { OutputGraph.Plot(outtime, output); }); ButtplugPanel.SendVibrateCmd(e.Intensity); ButtplugPanel.SendRotateCmd(e.Intensity, true); ButtplugPanel.SendOscillateCmd(e.Intensity); } }
private void MenuFileOpen_Click(object sender, RoutedEventArgs e) { //ToDo: Dirty check var open = new Microsoft.Win32.OpenFileDialog { DefaultExt = ".log", Filter = "Logs (.log)|*.log" }; // Process save file dialog box results if (open.ShowDialog() == true) { if (port != null) { StartStop_Click(sender, e); } logFile = null; average = new List <double>(); presure = new List <double>(); vibe = new List <double>(); time = new List <double>(); output = new List <double>(); outtime = new List <double>(); var oGraphs = new List <LineGraph>(); foreach (var graph in Lines.Children) { if (graph is LineGraph g && g.Description.Contains("O****m")) { oGraphs.Add(g); } } foreach (var g in oGraphs) { Lines.Children.Remove(g); } _last_input = DateTimeOffset.Now; Dispatcher?.Invoke(() => { AverageGraph.Plot(time, average); PressureGraph.Plot(time, presure); MototGraph.Plot(time, vibe); OutputGraph.Plot(outtime, output); }); //ToDo: Background this? StreamReader stream = null; try { stream = new StreamReader(File.OpenRead(open.FileName)); } catch (ArgumentException ex) { MessageBox.Show($"Error on opening file: {ex.Message}", "Error Opening File", MessageBoxButton.OK, MessageBoxImage.Error); } try { string line; while ((line = stream?.ReadLine()) != null) { //ToDo: Abstract log event consumer var m = logRegex.Match(line.ToLower(CultureInfo.CurrentCulture)); if (m.Success) { if (!long.TryParse(m.Groups[1].Value, out var t)) { continue; } switch (m.Groups[2].Value) { case "nogasm:": var m2 = nogasmRegex.Match(m.Groups[3].Value); if (m2.Success) { average.Add(Convert.ToDouble(m2.Groups[5].Value, new NumberFormatInfo())); presure.Add(Convert.ToDouble(m2.Groups[3].Value, new NumberFormatInfo())); vibe.Add(Convert.ToDouble(m2.Groups[1].Value, new NumberFormatInfo())); time.Add(t); if (time.Count > 2 && Math.Abs(average[average.Count - 2] - average[average.Count - 1]) < 0.001 && Math.Abs(presure[presure.Count - 2] - presure[presure.Count - 1]) < 0.001 && Math.Abs(vibe[vibe.Count - 2] - vibe[vibe.Count - 1]) < 0.001) { time.RemoveAt(time.Count - 1); average.RemoveAt(time.Count - 1); presure.RemoveAt(time.Count - 1); vibe.RemoveAt(time.Count - 1); } } break; case "user:o****m": var oGraph = new LineGraph(); oGraph.Description = "O****m"; Dispatcher?.Invoke(() => { Lines.Children.Add(oGraph); oGraph.Plot(new double[] { t, t }, new double[] { 0, 4000 }); }); break; case "output:": if (double.TryParse(m.Groups[3].Value, out var val)) { output.Add(val * 1000); outtime.Add(t); } break; } } } Dispatcher?.Invoke(() => { AverageGraph.Plot(time, average); PressureGraph.Plot(time, presure); MototGraph.Plot(time, vibe); OutputGraph.Plot(outtime, output); }); } catch (IOException ex) { MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK, MessageBoxImage.Error); } catch (OutOfMemoryException ex) { MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK, MessageBoxImage.Error); } catch (ArgumentNullException ex) { MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK, MessageBoxImage.Error); } catch (RegexMatchTimeoutException ex) { MessageBox.Show($"Error parsing file: {ex.Message}", "Error Opening File", MessageBoxButton.OK, MessageBoxImage.Error); } stream?.Close(); } }