Example #1
0
File: viz.py Project: rampa069/kss
FEATURES = [ 
  F('kl-all'    , util.getAllKeystrokeLengths                     , 50, 2),
  F('kl-anon'   , util.getAnonKeystrokeLengths                    , 50, 2),
  F('kl-back'   , util.getBackKeystrokeLengths                    , 50, 2),
  F('kl-ctrl'   , util.getCtrlKeystrokeLengths                    , 50, 2),
  F('kl-arrow'  , util.getArrowKeystrokeLengths                   , 50, 2),
  F('kl-enter'  , util.getEnterKeystrokeLengths                   , 50, 2),
  F('kl-pgnav'  , util.getPgNavKeystrokeLengths                   , 50, 2),
  F('kl-shift'  , util.getShiftKeystrokeLengths                   , 50, 2),
  F('kl-space'  , util.getSpaceKeystrokeLengths                   , 50, 2),
  F('kl-delete' , util.getDeleteKeystrokeLengths                  , 50, 2),
  F('word-dur'  , _getWordDurations                               , 50, 10),
  F('word-len'  , _getWordLengths                                 , 50, 30),
  F('ko'        , util.getKeyOverlaps                             , 50, 2),
  F('wp'        , _getWordPauses                                  , 50, 10),
  F('md-shift'  , lambda s: util.getModifierDelays(s, util._SHIFT), 50, 10),
  F('kk-shift'  , lambda s: util.getKeyToKeys(s, util._SHIFT)     , 50, 60),
  F('kk-ctrl'   , lambda s: util.getKeyToKeys(s, util._CTRL)      , 50, 60)
]

if __name__ == '__main__':
  import matplotlib.pyplot as plt

  args = parser.parse_args()
  createDirectoryIfNotExist(args.odir)

  # do plots of user-vs-user stuff
  userList = os.listdir(args.dir)
  for v in FEATURES:
    userFeatures = {}
    allFeatures = []
Example #2
0
FEATURES = [
    F('kl-all', util.getAllKeystrokeLengths, 50, 2),
    F('kl-anon', util.getAnonKeystrokeLengths, 50, 2),
    F('kl-back', util.getBackKeystrokeLengths, 50, 2),
    F('kl-ctrl', util.getCtrlKeystrokeLengths, 50, 2),
    F('kl-arrow', util.getArrowKeystrokeLengths, 50, 2),
    F('kl-enter', util.getEnterKeystrokeLengths, 50, 2),
    F('kl-pgnav', util.getPgNavKeystrokeLengths, 50, 2),
    F('kl-shift', util.getShiftKeystrokeLengths, 50, 2),
    F('kl-space', util.getSpaceKeystrokeLengths, 50, 2),
    F('kl-delete', util.getDeleteKeystrokeLengths, 50, 2),
    F('word-dur', _getWordDurations, 50, 10),
    F('word-len', _getWordLengths, 50, 30),
    F('ko', util.getKeyOverlaps, 50, 2),
    F('wp', _getWordPauses, 50, 10),
    F('md-shift', lambda s: util.getModifierDelays(s, util._SHIFT), 50, 10),
    F('kk-shift', lambda s: util.getKeyToKeys(s, util._SHIFT), 50, 60),
    F('kk-ctrl', lambda s: util.getKeyToKeys(s, util._CTRL), 50, 60)
]

if __name__ == '__main__':
    import matplotlib.pyplot as plt

    args = parser.parse_args()
    createDirectoryIfNotExist(args.odir)

    # do plots of user-vs-user stuff
    userList = os.listdir(args.dir)
    for v in FEATURES:
        userFeatures = {}
        allFeatures = []
Example #3
0
def main(args):
  createDirectoryIfNotExist(args.odir)

  userList = os.listdir(args.dir)
  for user in userList:
    createDirectoryIfNotExist(args.odir + '/' + user)
    sites = os.listdir(args.dir + '/' + user)
    for site in sites:
      relName = user + '/' + site
      createDirectoryIfNotExist(args.odir + '/' + relName)
      stream = util.filterKeystrokes(util.openStream(args.dir + '/' + relName))
      sessions = util.segmentStream(stream)

      # We want histograms of keystroke usage per user
      allLengths = list(util.getAllKeystrokeLengths(stream))
      if len(allLengths) > 0:
        plt.clf()
        plt.hist(list(allLengths), 200)
        plt.savefig(args.odir + '/' + user + '/all-kl-' + site + '.png')

      for i in range(len(keyCombos)):
        lengths = list(util.getKeystrokeLengths(stream, keyCombos[i]))
        if len(lengths) > 0:
          plt.clf()
          plt.hist(list(lengths), 200)
          plt.savefig(args.odir + '/' + user + '/' + names[i] + '-kl-' + site + '.png')

      # Also want histograms of word data, per user
      wordData = zip(*chain(*[util.getWordData(s) for s in sessions]))
      if len(wordData) > 0 and len(wordData[0]) > 0:
        plt.clf()
        plt.hist(list(d for d in wordData[0] if abs(d) < 10), 200)
        plt.savefig(args.odir + '/' + user + '/word-dur-' + site + '.png')
        plt.clf()
        plt.hist(list(wordData[1]), 200)
        plt.savefig(args.odir + '/' + user + '/word-len-' + site + '.png')

      # Key overlaps
      #keyOverlaps = list(chain.from_iterable(util.getKeyOverlaps(s) for s in sessions))
      keyOverlaps = list(x for x in util.getKeyOverlaps(stream) if abs(x) < 5)
      if len(keyOverlaps) > 0:
        plt.clf()
        plt.hist(keyOverlaps, 100)
        plt.savefig(args.odir + '/' + user + '/overlap-' + site + '.png')

      # Word pauses
      wordPauses = list(x for x in util.getWordPauses(stream) if abs(x) < 60)
      if len(wordPauses) > 0:
        plt.clf()
        plt.hist(wordPauses, 100)
        plt.savefig(args.odir + '/' + user + '/word-pause-' + site + '.png')

      # Time between shift key and modified key
      shiftTime = list(x for x in util.getModifierDelays(stream, util._SHIFT) if abs(x) < 5)
      if len(shiftTime) > 0:
        plt.clf()
        plt.hist(shiftTime, 100)
        plt.savefig(args.odir + '/' + user + '/shift-delay-' + site + '.png')

      # Time between shift-to-shift
      shiftShift= list(x for x in util.getModifierDelays(stream, util._SHIFT) if abs(x) < 1200)
      if len(shiftShift) > 0:
        plt.clf()
        plt.hist(shiftShift, 100)
        plt.savefig(args.odir + '/' + user + '/shift-shift-' + site + '.png')