class SampleScore(ScorePlug): datadigestDir = str(Settings.SETTINGS.get("score", "datadigestDir")) pyPath = "-Dpython.path=" + str(datadigestDir) jythonExe = "./score/JythonBI.py" # data_file = "./score/models/out_sample.csv" data_file = "./score/models/blah.csv" model_file = "./score/models/Skaion_model.bn5" outs = ["OUTCOME"] thrus = ["OUTCOME"] outOfInterest = "outcome_malicious" def run(self, inputObject): self.csv = CSV(self.data_file) self.csv.writeRow(self.csv.format(inputObject)) self.csv.__del__() # subprocess.call(["jython", pyPath, jythonExe, data_file, model_file, str(outs), str(thrus)]) results = subprocess.Popen(["jython", self.pyPath, self.jythonExe, self.data_file, self.model_file, str(self.outs), str(self.thrus)], \ stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0] # print results buff = StringIO.StringIO(results) header = buff.readline().rstrip('\n').split(',') pos = header.index(self.outOfInterest) # print header for line in buff: d = line.rstrip('\n').split(',') #TODO: Find a better way to avoid last line with just \n if len(d) > 1: print "Predicted %s = %s" % (self.outOfInterest, str(d[pos]))
class SampleScore(ScorePlug): datadigestDir = str(Settings.SETTINGS.get("score","datadigestDir")) pyPath = "-Dpython.path=" + str(datadigestDir) jythonExe = "./score/JythonBI.py" # data_file = "./score/models/out_sample.csv" data_file = "./score/models/blah.csv" model_file = "./score/models/Skaion_model.bn5" outs = ["OUTCOME"] thrus = ["OUTCOME"] outOfInterest = "outcome_malicious" def run(self,inputObject): self.csv = CSV(self.data_file) self.csv.writeRow(self.csv.format(inputObject)) self.csv.__del__() # subprocess.call(["jython", pyPath, jythonExe, data_file, model_file, str(outs), str(thrus)]) results = subprocess.Popen(["jython", self.pyPath, self.jythonExe, self.data_file, self.model_file, str(self.outs), str(self.thrus)], \ stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0] # print results buff = StringIO.StringIO(results) header = buff.readline().rstrip('\n').split(',') pos = header.index(self.outOfInterest) # print header for line in buff: d = line.rstrip('\n').split(',') #TODO: Find a better way to avoid last line with just \n if len(d) > 1: print "Predicted %s = %s" %(self.outOfInterest, str(d[pos]))
class ContinentBasedSimilarityModel(ScorePlug): def __init__(self): self.data_file = "./score/models/blah.csv" self.inf_file = "./score/models/blahInf.csv" #self.model_file = "./score/models/Skaion_model.bn5" self.model_file = "./score/models/Geo 5b5 AS Query Using NoA Binning All Parts.bn5" self.outs = ["bytes_sent", "continent", "dst_port", "ip_proto", "netmask", "pkts_sent", "src_port", "tcp_flag_ACK", "tcp_flag_FIN", "tcp_flag_PSH", "tcp_flag_RST", "tcp_flag_SYN", "tcp_flag_URG"] self.thrus = self.outs # TODO: Move this to ScorePlug, Complains 'module' not iterable def createCSV(self, inputObject): self.csv = CSV(self.data_file) self.csv.writeRow(self.csv.format(inputObject)) self.csv.__del__() # close file def getResults(self): results = subprocess.Popen(["jython", ScorePlug.pyPath, ScorePlug.jythonExe, self.data_file, self.model_file, str(self.outs), str(self.thrus)], \ stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0] return results def run(self,inputObject): self.runBatchInference(inputObject) self.createCSV(inputObject) results = self.getResults() #print results f = open(self.inf_file, "w") f.write(results) f.close() realResults = subprocess.Popen(["Rscript", "./score/similarityscore.R", self.inf_file, self.model_file], \ stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0] print "AS Model Similarity Score = %s " %(str(realResults).strip()) print "Observed actual value is %s" %str(inputObject.continent)
def run(self, inputObject): self.csv = CSV(self.data_file) self.csv.writeRow(self.csv.format(inputObject)) self.csv.__del__() # subprocess.call(["jython", pyPath, jythonExe, data_file, model_file, str(outs), str(thrus)]) results = subprocess.Popen(["jython", self.pyPath, self.jythonExe, self.data_file, self.model_file, str(self.outs), str(self.thrus)], \ stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0] # print results buff = StringIO.StringIO(results) header = buff.readline().rstrip('\n').split(',') pos = header.index(self.outOfInterest) # print header for line in buff: d = line.rstrip('\n').split(',') #TODO: Find a better way to avoid last line with just \n if len(d) > 1: print "Predicted %s = %s" % (self.outOfInterest, str(d[pos]))
def run(self,inputObject): self.csv = CSV(self.data_file) self.csv.writeRow(self.csv.format(inputObject)) self.csv.__del__() # subprocess.call(["jython", pyPath, jythonExe, data_file, model_file, str(outs), str(thrus)]) results = subprocess.Popen(["jython", self.pyPath, self.jythonExe, self.data_file, self.model_file, str(self.outs), str(self.thrus)], \ stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0] # print results buff = StringIO.StringIO(results) header = buff.readline().rstrip('\n').split(',') pos = header.index(self.outOfInterest) # print header for line in buff: d = line.rstrip('\n').split(',') #TODO: Find a better way to avoid last line with just \n if len(d) > 1: print "Predicted %s = %s" %(self.outOfInterest, str(d[pos]))
def createCSV(self, inputObject): self.csv = CSV(self.data_file) self.csv.writeRow(self.csv.format(inputObject)) self.csv.__del__() # close file