-
Notifications
You must be signed in to change notification settings - Fork 866
/
Copy pathrun.py
95 lines (72 loc) · 2.8 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# Copyright 2014-2015 Numenta Inc.
#
# Copyright may exist in Contributors' modifications
# and/or contributions to the work.
#
# Use of this source code is governed by the MIT
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
import argparse
import os
try:
import simplejson as json
except ImportError:
import json
from nab.runner import Runner
from nab.util import checkInputs
from nab.detectors.htmjava.htmjava_detector import HtmjavaDetector
def get_nth_parent_dir(n, path):
"""
Return the Nth parent of `path` where the 0th parent is the direct parent
directory.
"""
parent = os.path.dirname(path)
if n == 0:
return parent
return get_nth_parent_dir(n-1, parent)
def main(args):
filepath = os.path.realpath(__file__)
# Find the main NAB folder
# Assuming `filepath` is ~ <...>/NAB/nab/detectors/htmjava/run.py
root = get_nth_parent_dir(3, filepath)
numCPUs = int(args.numCPUs) if args.numCPUs is not None else None
dataDir = os.path.join(root, args.dataDir)
windowsFile = os.path.join(root, args.windowsFile)
resultsDir = os.path.join(root, args.resultsDir)
profilesFile = os.path.join(root, args.profilesFile)
runner = Runner(dataDir=dataDir,
labelPath=windowsFile,
resultsDir=resultsDir,
profilesPath=profilesFile,
numCPUs=numCPUs)
runner.initialize()
runner.detect({'htmjava': HtmjavaDetector})
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--skipConfirmation",
help="If specified will skip the user confirmation step",
default=False,
action="store_true")
parser.add_argument("--dataDir",
default="data",
help="This holds all the label windows for the corpus.")
parser.add_argument("--resultsDir",
default="results",
help="This will hold the results after running detectors "
"on the data")
parser.add_argument("--windowsFile",
default=os.path.join("labels", "combined_windows.json"),
help="JSON file containing ground truth labels for the "
"corpus.")
parser.add_argument("-p", "--profilesFile",
default=os.path.join("config", "profiles.json"),
help="The configuration file to use while running the "
"benchmark.")
parser.add_argument("-n", "--numCPUs",
default=None,
help="The number of CPUs to use to run the "
"benchmark. If not specified all CPUs will be used.")
args = parser.parse_args()
if args.skipConfirmation or checkInputs(args):
main(args)