1 package edu.uci.iotproject;
3 import edu.uci.iotproject.comparison.seqalignment.AlignmentPricer;
4 import edu.uci.iotproject.comparison.seqalignment.SequenceAlignment;
5 import org.pcap4j.core.PcapPacket;
10 * TODO add class documentation.
12 * @author Janus Varmarken
14 public class SequenceExtraction {
17 private final SequenceAlignment<Integer> mAlignmentAlg;
20 public SequenceExtraction() {
21 mAlignmentAlg = new SequenceAlignment<>(new AlignmentPricer<>((i1,i2) -> Math.abs(i1-i2), i -> 10));
25 public SequenceExtraction(SequenceAlignment<Integer> alignmentAlgorithm) {
26 mAlignmentAlg = alignmentAlgorithm;
31 * @param convsForAction A set of {@link Conversation}s known to be associated with a single type of user action.
33 public void extract(List<Conversation> convsForAction) {
34 int maxDifference = 0;
36 for (int i = 0; i < convsForAction.size(); i++) {
37 for (int j = i+1; j < convsForAction.size(); i++) {
38 Integer[] sequence1 = getPacketLengthSequence(convsForAction.get(i));
39 Integer[] sequence2 = getPacketLengthSequence(convsForAction.get(j));
40 int alignmentCost = mAlignmentAlg.calculateAlignment(sequence1, sequence2);
41 if (alignmentCost > maxDifference) {
42 maxDifference = alignmentCost;
49 private Integer[] getPacketLengthSequence(Conversation c) {
50 List<PcapPacket> packets = c.getPackets();
51 Integer[] packetLengthSequence = new Integer[packets.size()];
52 for (int i = 0; i < packetLengthSequence.length; i++) {
53 packetLengthSequence[i] = packets.get(i).length();
55 return packetLengthSequence;