Esempio n. 1
0
import utilities

x1, y1 = utilities.form_training_data([
    105, 106, 107, 108, 169, 170, 171, 172, 209, 210, 211, 212, 278, 279, 280,
    281, 274, 275, 276, 277, 270, 271, 272, 273
], [1, 0, 0])

x2, y2 = utilities.form_training_data([
    118, 119, 120, 121, 185, 186, 187, 188, 222, 223, 224, 225, 282, 283, 284,
    285, 286, 287, 288, 289, 290, 291, 292, 293
], [1, 0, 0])

x3, y3 = utilities.form_training_data([
    130, 131, 132, 133, 197, 198, 199, 200, 234, 235, 236, 237, 294, 295, 296,
    297, 310, 309, 311, 312, 315, 316, 317, 318
], [1, 0, 0])

x_train = utilities.concatenate([x1, x2, x3])
y_train = utilities.concatenate([y1, y2, y3])
Esempio n. 2
0
from utilities import concatenate
api = MyAPI()
#X, Y = api.get_dataset(0, start_index=0,end_index=100000, nr=100000)
start_index = 1 
burst = 1000
end_index = start_index + burst
X = []
Y = []
#nr = 4051656
#nr = 430000
#nr = 7744019

while end_index <= nr:
    X_temp, Y_temp = api.get_dataset(0, start_index=start_index,end_index=end_index, nr=nr)
    if len(X_temp) > 0:
        X = concatenate(X,X_temp)
        Y = concatenate(Y,Y_temp)
    start_index = end_index + 1
    end_index = start_index + burst - 1
    if end_index > nr:
        end_index = nr
    if start_index > nr:
        end_index = nr+1

classes=list(set(Y))
Y = sorted(Y)

dist = {}
for i in range(0, len(Y)):
    try:
        dist[Y[i]] = dist[Y[i]] + 1
Esempio n. 3
0
    end_index = start_index + burst
    X = []
    Y = []
    while end_index <= nr:
        #print "start index: " + str(start_index) + " end index: " + str(end_index)
        #X_train_temp, Y_train_temp = api.get_dataset('true',psi, start_index=start_index,end_index=end_index) # training
        #X_test_temp, Y_test_temp = api.get_dataset('false',psi,start_index=start_index,end_index=end_index)
        #print len(X_train_temp[0])
        #print start_index
        #print end_index
        X_temp, Y_temp = api.get_dataset(psi,
                                         start_index=start_index,
                                         end_index=end_index,
                                         nr=nr)
        if len(X_temp) > 0:
            X = concatenate(X, X_temp)
            #print len(X_train[0])
            #print len(Y_train)
            Y = concatenate(Y, Y_temp)
            #print len(X_test)
            #print len(X_test_temp)
        #X_test = concatenate(X_test,X_test_temp)
        #print len(Y_train)
        #Y_test = concatenate(Y_test,Y_test_temp)

        start_index = end_index + 1
        end_index = start_index + burst - 1
        if end_index > nr:
            end_index = nr
        if start_index > nr:
            end_index = nr + 1
Esempio n. 4
0
    print(len(X))
    nr = len(X)
    n_training_per_cell = int(round(nr / (len(classes) - 1) / 100 * 80))
    n_test_per_cell = int(round(nr / (len(classes) - 1) / 100 * 20))

    print n_training_per_cell
    print n_test_per_cell

    X_train = []
    Y_train = []
    X_test = []
    Y_test = []
    index = 0
    while index < (nr - n_training_per_cell - n_test_per_cell):
        X_train = concatenate(X_train, X[index:index + n_training_per_cell])
        Y_train = concatenate(Y_train, Y[index:index + n_training_per_cell])
        X_test = concatenate(
            X_test, X[index + n_training_per_cell + 1:index +
                      n_training_per_cell + n_test_per_cell])
        Y_test = concatenate(
            Y_test, Y[index + n_training_per_cell + 1:index +
                      n_training_per_cell + n_test_per_cell])
        index = index + n_training_per_cell + n_test_per_cell + 1

    print len(X_train)
    print len(X_test)
    # get training
    #while end_index <= nr:
    #X_temp, Y_temp = api.get_dataset(psi, start_index=start_index,end_index=end_index, nr=nr)
    #if len(X_temp) > 0 and len(Y_temp) > 0:
def executeProductQueryViaVBScript(runtime, client, timeout=None):
	"""Query Windows products via WindowsInstaller library in vbscript.

	We use global parameters to determine whether to run the standard, slower
	WMI method to get Win32_Products, or to use the fast library method. This
	faster method requires streaming a vbscript file over the client connection
	first, before being able to run that script on the endpoint. But it has
	sub-second run times instead of anywhere between 10 seconds and 10 minutes
	to finish when doing it via Win32_Products in WMI.
	"""
	resultStdError = None
	resultProblem = None
	iterableObject = None
	sectionDemarcation = '-=-==-=-==-=-==-=-'
	p = '\''
	try:
		## Ignoring the query sent in; left in for reference only
		runtime.logger.report('  Running executeProductQuery through vbscript')
		## Build VB script to execute WMI query
		#Name,InstallLocation,Version,InstallDate,PackageName,Vendor,RegCompany,RegOwner,IdentifyingNumber,Description
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, 'Const SCRIPTVERSION = 1.2', p, ' >y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, 'set oMSI = CreateObject("WindowsInstaller.Installer")', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, 'Set Products = oMSI.ProductsEx(vbNullString, "S-1-1-0", 7,"")', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, 'Wscript.Echo "' + sectionDemarcation + '"', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, 'attributeList = Array("InstallLocation", "VersionString", "InstallDate", "PackageName", "Vendor", "RegCompany", "RegOwner", "IdentifyingNumber", "Description")', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, 'If Not Products.count = 0 Then', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '  For Each product In Products', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '    On Error Resume Next', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '    tmpName = product.InstallProperty("ProductName")', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '    If Not tmpName = "" and Not IsEmpty(tmpName) and Len(tmpName) > 0 Then', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '      Wscript.Echo tmpName', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '      For Each attribute In attributeList', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '        On Error Resume Next', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '        tmpVar = ""', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '        tmpVar = product.InstallProperty(attribute)', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '        If Not tmpVar = "" and Not IsEmpty(tmpVar) and Len(tmpVar) > 0 Then', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '          Wscript.Echo tmpVar', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '        Else', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '          Wscript.Echo "null"', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '        End If', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '      Next', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '      Wscript.Echo "' + sectionDemarcation + '"', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '    End If', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, '  Next', p, ' >>y.vbs'))
		(stdOut, stdError, hitProblem) = client.run(concatenate('echo ', p, 'End If', p, ' >>y.vbs'))
		## Execute the new script
		(vbScript, stdError, hitProblem) = client.run('cat y.vbs')
		runtime.logger.report('  File:\n {vbScript!r}', vbScript=vbScript)
		resultStdOut = None
		(resultStdOut, resultStdError, resultProblem) = client.run('cscript .\y.vbs', timeout)
		runtime.logger.report('  File:\n {resultStdOut!r}', resultStdOut=resultStdOut)
		#(stdOut, stdError, hitProblem) = client.run('del y.vbs')
		iterableObject = sectionedStringToIterableObject(resultStdOut, sectionDemarcation)

	except:
		stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])
		runtime.logger.error('Exception with discovering Windows Products from WindowsInstaller in vbscript: {stacktrace!r}', stacktrace=stacktrace)

	## end executeProductQueryViaVBScript
	return (iterableObject, resultStdError, resultProblem)