summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-03-14 00:46:04 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-03-14 00:46:04 -0400
commit17365c1bf397423e4973f5b431bea44bf199076a (patch)
treed4f7cd051b3a1630b1fc1be2be6a6cf2495c3b1f
parentaced3e4562b3feac81a11e392ede8b1b30c40345 (diff)
match identification
-rw-r--r--dslog/LogDir.java (renamed from dslog/Logdir.java)45
-rw-r--r--dslog/LogSet.java74
-rw-r--r--dslog/Main.java4
3 files changed, 77 insertions, 46 deletions
diff --git a/dslog/Logdir.java b/dslog/LogDir.java
index ea7683b..d31d3a8 100644
--- a/dslog/Logdir.java
+++ b/dslog/LogDir.java
@@ -9,51 +9,8 @@ import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
-import java.util.function.Supplier;
-
-class Logdir {
- public static class LogSet {
- public final String name;
- public LogSet(String name) {
- this.name = name;
- }
- public Path dslogPath, dseventsPath, pdplogPath;
-
- public String toString() {
- return name+" "+verstr(this::dslog)+"/"+verstr(this::dsevents)+"/"+verstr(this::pdplog);
- }
-
- private static String verstr(Versioned.Supplier getter) {
- try (Versioned thing = getter.get()) {
- if (thing == null) {
- return "␕";
- }
- return ""+thing.version();
- } catch (IOException e) {
- return "☠";
- }
- }
-
- public DslogReader dslog() throws IOException {
- if (dslogPath == null) {
- return null;
- }
- return new DslogReader(Files.newInputStream(dslogPath));
- }
- public DseventsReader dsevents() throws IOException {
- if (dseventsPath == null) {
- return null;
- }
- return new DseventsReader(Files.newInputStream(dseventsPath));
- }
- public PdplogReader pdplog() throws IOException {
- if (pdplogPath == null) {
- return null;
- }
- return new PdplogReader(Files.newInputStream(pdplogPath));
- }
- }
+public class LogDir {
private static LogSet getSet(Map<String, LogSet> sets, String filename) {
String setname = filename.substring(0, filename.lastIndexOf('.'));
LogSet set;
diff --git a/dslog/LogSet.java b/dslog/LogSet.java
new file mode 100644
index 0000000..e284eba
--- /dev/null
+++ b/dslog/LogSet.java
@@ -0,0 +1,74 @@
+package dslog;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.function.Supplier;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.ArrayList;
+
+public class LogSet {
+ public final String name;
+ public LogSet(String name) {
+ this.name = name;
+ }
+ public Path dslogPath, dseventsPath, pdplogPath;
+
+ public String toString() {
+ return name+" "+verstr(this::dslog)+"/"+verstr(this::dsevents)+"/"+verstr(this::pdplog);
+ }
+
+
+ private static final Pattern fmsConnected = Pattern.compile("^FMS Connected: (?<matchname>[A-Za-z].+) - (?<matchnumber>[0-9:]+), Field Time: (?<fieldtime>[0-9/]+ [0-9:]+)$");
+
+ public String[] matches() throws IOException {
+ ArrayList<String> matches = new ArrayList<String>();
+ try (DseventsReader dsevents = dsevents()) {
+ if (dsevents == null) {
+ return matches.toArray(new String[matches.size()]);
+ }
+ while (dsevents.hasNext()) {
+ DseventsReader.Event event = dsevents.next();
+ // do a (cheap) `.startsWith` check before doing an (expensive) regex check.
+ if (event.message.startsWith("FMS Connected:")) {
+ Matcher m = fmsConnected.matcher(event.message);
+ if (m.matches()) {
+ matches.add(m.group("matchname") + " - " + m.group("matchnumber"));
+ }
+ }
+ }
+ }
+ return matches.toArray(new String[matches.size()]);
+ }
+
+ private static String verstr(Versioned.Supplier getter) {
+ try (Versioned thing = getter.get()) {
+ if (thing == null) {
+ return "␕";
+ }
+ return ""+thing.version();
+ } catch (IOException e) {
+ return "☠";
+ }
+ }
+
+ public DslogReader dslog() throws IOException {
+ if (dslogPath == null) {
+ return null;
+ }
+ return new DslogReader(Files.newInputStream(dslogPath));
+ }
+ public DseventsReader dsevents() throws IOException {
+ if (dseventsPath == null) {
+ return null;
+ }
+ return new DseventsReader(Files.newInputStream(dseventsPath));
+ }
+ public PdplogReader pdplog() throws IOException {
+ if (pdplogPath == null) {
+ return null;
+ }
+ return new PdplogReader(Files.newInputStream(pdplogPath));
+ }
+}
diff --git a/dslog/Main.java b/dslog/Main.java
index 159ee00..5fa0533 100644
--- a/dslog/Main.java
+++ b/dslog/Main.java
@@ -19,13 +19,13 @@ class Main {
}
public static void ls(String dirname) throws IOException {
- Logdir.opendir(dirname).forEach((k,v)->{
+ LogDir.opendir(dirname).forEach((k,v)->{
System.out.println(v);
});
}
public static void wch(String dirname) throws IOException {
- Logdir.opendir(dirname).forEach((k,v)->{
+ LogDir.opendir(dirname).forEach((k,v)->{
boolean match = false;
try (DseventsReader r = v.dsevents()) {
if (r == null || r.version() != 3)