From 235c448c8f28626e4af445e9955b0a9abe87ff82 Mon Sep 17 00:00:00 2001 From: Janus Varmarken Date: Wed, 15 Aug 2018 13:59:37 -0700 Subject: [PATCH] Stashing preliminary work on sequence extraction --- .../uci/iotproject/SequenceExtraction.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/SequenceExtraction.java diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/SequenceExtraction.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/SequenceExtraction.java new file mode 100644 index 0000000..ddf8010 --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/SequenceExtraction.java @@ -0,0 +1,57 @@ +package edu.uci.iotproject; + +import edu.uci.iotproject.comparison.seqalignment.AlignmentPricer; +import edu.uci.iotproject.comparison.seqalignment.SequenceAlignment; +import org.pcap4j.core.PcapPacket; + +import java.util.List; + +/** + * TODO add class documentation. + * + * @author Janus Varmarken + */ +public class SequenceExtraction { + + + private final SequenceAlignment mAlignmentAlg; + + + public SequenceExtraction() { + mAlignmentAlg = new SequenceAlignment<>(new AlignmentPricer<>((i1,i2) -> Math.abs(i1-i2), i -> 10)); + } + + + public SequenceExtraction(SequenceAlignment alignmentAlgorithm) { + mAlignmentAlg = alignmentAlgorithm; + } + + /** + * + * @param convsForAction A set of {@link Conversation}s known to be associated with a single type of user action. + */ + public void extract(List convsForAction) { + int maxDifference = 0; + + for (int i = 0; i < convsForAction.size(); i++) { + for (int j = i+1; j < convsForAction.size(); i++) { + Integer[] sequence1 = getPacketLengthSequence(convsForAction.get(i)); + Integer[] sequence2 = getPacketLengthSequence(convsForAction.get(j)); + int alignmentCost = mAlignmentAlg.calculateAlignment(sequence1, sequence2); + if (alignmentCost > maxDifference) { + maxDifference = alignmentCost; + } + } + } + + } + + private Integer[] getPacketLengthSequence(Conversation c) { + List packets = c.getPackets(); + Integer[] packetLengthSequence = new Integer[packets.size()]; + for (int i = 0; i < packetLengthSequence.length; i++) { + packetLengthSequence[i] = packets.get(i).length(); + } + return packetLengthSequence; + } +} -- 2.34.1