Exemplo n.º 1
0
def roots_interval(exp,a,b):
    roots=[]
    h=(b-a)/1000
    try:
        while(a<=b):
            f1=extract.main(exp,[a])
            f2=extract.main(exp,[a+h])
            if(f1*f2<=0 and (f1*f2)>-10):
                roots.append(a+h/2)
            else:
                if(math.fabs(f1)<0.01):
                   roots.append(a)
            a=a+h
        actual=[]
        if(len(roots)!=0):
            actual.append(roots[0])
        i=1
        count=0
        while(i<len(roots)):
            if(math.fabs(roots[i]-roots[i-1])>0.1):
               actual.append(roots[i])
               count=count+1
               i=i+1
            else:
               j=i
               sum=0
               while(i<len(roots) and math.fabs(roots[i]-roots[i-1])<0.1):
                   sum+=roots[i]
                   i=i+1
               actual[count]=(actual[count]+sum)/(i-j+1)
        return actual
    except:
        return("unexpected value experienced.Try again with a different interval")
Exemplo n.º 2
0
def main(args):
    img_paths = sorted(list_images(args['folder_images']))
    i = 1
    print('[INFO] Starting ...')
    ls = os.listdir('output/')
    ls = [item.split('.')[0] for item in ls]
    s_t = time.time()
    for path in img_paths:
        name = path.split(os.path.sep)[-1].split('.')[0]
        if name in ls:
            print('[INFO] Processed {}'.format(name))
            i += 1
            continue
        try:
            start = time.time()
            if name < 'K6171-0012':
                intro.main({'image': path, 'intro': 'True'})
            elif name == 'K6171-0012':
                intro.main({'image': path, 'intro': 'False'})
            elif name < 'K6171-0754':
                extract.main({'image': path})
            end = time.time()
            print('[INFO] processing {} - {} - {:.4f}s'.format(
                i,
                path.split(os.path.sep)[-1], end - start))
        except:
            print('[INFO] ERROR! {}'.format(path))
        i += 1
    e_t = time.time()
    print('[INFO] Finished. Total: {} images - Total time: {:.4f}s'.format(
        i - 1, e_t - s_t))
def main():

    if parser.extract:
        extract.main()

    if parser.train:
        train.main()
Exemplo n.º 4
0
def integrate(exp,downer,upper):
        if(upper=='inf'):
            upper=100000
        if(exp.isnumeric()):
            return(int(exp)*(upper-downer))
        dx=(upper-downer)/1000
        val1=cython.declare(cython.float)
        val2=cython.declare(cython.float)
        arr=[0]
        if(upper==downer):
            sum=0.0
        elif(upper>downer):
            j=downer
            sum=0.0
            while(j<upper):
                arr[0]=j
                val1=extract.main(exp,arr)
                arr[0]=j+dx
                val2=extract.main(exp,arr)
                sum+=(val1+val2)/2*dx
                j=j+dx
        else:
            j=upper
            sum=0.0
            while(j<downer):
                arr[0]=j
                val1=extract.main(exp,arr)
                arr[0]=j-dx
                val2=extract.main(exp,arr)
                sum+=(val1+val2)/2*dx
                j=j-dx
        return sum
Exemplo n.º 5
0
    def send_data_to_graphite(self):
        extract.main()
        d = os.listdir()
        delay = 1
        for files in d:
            if (("RL" in files or "TU" in files) and ".txt" in files):
                data = json.load(open(files))
                f = files[0:7]
                if f in data:
                    rc = int(data[f][3].get('rc'))
                    vst = int(data[f][3].get('vst'))
                    nmt = int(data[f][3].get('nmt'))
                    frc = int(data[f][3].get('frc'))
                    reboots = rc/((vst+1)/(3600*24))
                    upTime = (1-(nmt-vst)/nmt)*100
                    #return(f,getReboots(rc,vst),getUpTime(nmt,vst),getFilesPerDay(frc,vst))
                    print ('RLname : %s Reboot : %d Uptime : %d' % (f,reboots,upTime))

                    timestamp = int(time.time())
                    lines = [
                        'RLname.%s.UpTime %d %d' % (f, upTime, timestamp),
                        'RLname.%s.Restarts %s %d' % (f, reboots, timestamp)
                        ]

                    message = '\n'.join(lines) + '\n'
                    print(message)
                    self.sock.send(message.encode("utf-8"))
                    time.sleep(delay)
Exemplo n.º 6
0
def main():
    #Extract data from images
    target_dir = '../../Dataset/'
    if extract_data_again:
        ext.main()
    xtrain, ytrain, ytrain_label = getdata_file(target_dir+'DS2full-train.csv')
    xtest, ytest, ytest_label = getdata_file(target_dir+'DS2full-test.csv')

    #Scale Data
    scaler = pp.MinMaxScaler()
    scaler.fit(np.concatenate((xtrain,xtest)))
    xtrain = scaler.transform(xtrain)
    xtest = scaler.transform(xtest)
    original = sys.stdout
    eta = 0.1
    
    filelog=open('result_'+str(eta)+'.txt','w')
    original = sys.stdout
    sys.stdout = Tee(sys.stdout, filelog)
        
    print('##########################################')
    print('Eta:',eta)
    n_epoch = 80
    no_hidden = 30
    NeuralNet = nn.neural_network(len(xtrain[0]),[30],len(ytrain[0]))
    NeuralNet.train(xtrain, ytrain,ytrain_label,eta, n_epoch,test_while_train = True, xtest = xtest,ytest_label= ytest_label, draw_plot=True)
    eta = eta*10
    sys.stdout = original
Exemplo n.º 7
0
def main2():
    #Extract data from images
    target_dir = '../../Dataset/'
    if extract_data_again:
        ext.main()
    xtrain, ytrain, ytrain_label = getdata_file(target_dir+'DS2full-train.csv')
    xtest, ytest, ytest_label = getdata_file(target_dir+'DS2full-test.csv')
    #Scale Data
    scaler = pp.MinMaxScaler()
    scaler.fit(np.concatenate((xtrain,xtest)))
    xtrain = scaler.transform(xtrain)
    xtest = scaler.transform(xtest)
    
    
    original = sys.stdout
    eta = 0.01
    gamma = 0.01
    for i in range(5):
        filelog=open('result2_'+str(gamma)+'.txt','w')
        original = sys.stdout
        sys.stdout = Tee(sys.stdout, filelog)
            
        print('##########################################')
        print('Eta:',eta)
        print('Gamma:',gamma)
        #Set number of epochs
        n_epoch = 250

        no_hidden = 20
        NeuralNet = nn2.neural_network(len(xtrain[0]),[20],len(ytrain[0]))
        NeuralNet.train(xtrain, ytrain,ytrain_label,eta,gamma, n_epoch,test_while_train = True, xtest = xtest,ytest_label= ytest_label, draw_plot=True)
        sys.stdout = original
        gamma = gamma*10.0
Exemplo n.º 8
0
def main():
    # Get the name of the config file
    config_file = leverage_efficiency.base.get_config_filename(sys.argv)

    # Extract the data from source data folder into common format
    import extract
    extract.main(config_file)

    # Update data with most recent values (optional)
    #import update       # This doesn't connect to the rest of the pipeline yet
    #update.main(config_file)

    # Calculate derived quantities like returns for input into calculations
    import transform
    transform.main(config_file)

    # Perform leverage efficiency calculations
    import analysis
    analysis.main(config_file)

    # Create figures
    import plots
    plots.main(config_file)

    # Create exact figures used in the paper
    import paper_plots
    paper_plots.main(config_file)

    # Create figures used in the EE lecture notes
    import lecture_plots
    lecture_plots.main(config_file)
Exemplo n.º 9
0
def test_it_clears_the_database_when_reuploading_a_file():
    extract.main(['./extract.py', 'fixture/simple.xlsx'])

    extract.main(['./extract.py', 'fixture/mps.xlsx'])

    sheet1 = scraperwiki.sql.select('count(*) as n from Sheet1')
    assert_equals(sheet1[0]['n'], 308)

    sheet2 = scraperwiki.sql.select('count(*) as n from Sheet2')
    assert_equals(sheet2[0]['n'], 1073)
Exemplo n.º 10
0
def main():

    # run scrape
    extract.main()

    # run link
    link.main()

    # run make
    make.main()
Exemplo n.º 11
0
def isMonotone(exp,a,b):
    begin=min(a,b)
    end=max(a,b)
    arr=[]
    interval=(end-begin)/1000
    while(begin<=end):
        arr.append(extract.main(exp,[begin]))
        begin+=interval
    arr.sort()
    if(math.fabs(arr[0]-extract.main(exp,[begin]))<0.01 and math.fabs(arr[len(arr)-1]-extract.main(exp,[end])<0.01)):
       return True
    return False
Exemplo n.º 12
0
def integrate(exp,downer,upper):
    try:
        if(downer=='-inf'):
            downer=-300
        if(upper=='inf'):
            upper=300
        if(not('x' in exp)):
            return(float(exp)*(upper-downer))
        if(math.fabs(downer)==math.fabs(upper)):
            flag=funcType(exp,upper)
            if(flag==10):
               exp="2*("+exp+")"
               downer=0
            if(flag==-10):
               return 0
        dx=(upper-downer)/1000
        if(math.fabs(dx)<1):
               arr=[0]
               if(upper==downer):
                   sum=0.0
               elif(upper>downer):
                   j=downer
                   sum=0.0
                   while(j<upper):
                      arr[0]=j
                      val1=extract.main(exp,arr)
                      arr[0]=j+dx
                      val2=extract.main(exp,arr)
                      sum+=(val1+val2)/2*dx
                      j=j+dx
               else:
                   j=upper
                   sum=0.0
                   while(j<downer):
                      arr[0]=j
                      val1=extract.main(exp,arr)
                      arr[0]=j-dx
                      val2=extract.main(exp,arr)
                      sum+=(val1+val2)/2*dx
                      j=j-dx
               return sum
        else:
                down_lim=[downer]
                up_lim=[downer+(upper-downer)/10]
                sum=0
                for i in range(10):
                    sum+=integrate(exp,down_lim[i],up_lim[i])
                    down_lim.append(up_lim[i])
                    up_lim.append(up_lim[i]+(upper-downer)/10)
                return sum
    except:
        return("unexpected input")
Exemplo n.º 13
0
def funcType(exp,upper):
    flag=0
    for i in range(10):
        t1=random.random()*(upper)-upper
        val1=extract.main(exp,[t1])
        val2=extract.main(exp,[-1*t1])
        if(val1==val2):
            flag+=1
        elif(val1==-1*val2):
            flag-=1
        else:
            flag=0
    return flag
Exemplo n.º 14
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--crawl')
    args = parser.parse_args()

    if args.crawl == 'yes':
        c = raw_input("This will crawl the websites and will take very long time. Do you want to continue? ")

        if c == 'yes':
            crawl.crawl_trains()

    extract.main()
    transform.main()
    os.system('bash export.sh')
Exemplo n.º 15
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--crawl')
    args = parser.parse_args()

    if args.crawl == 'yes':
        c = raw_input(
            "This will crawl the websites and will take very long time. Do you want to continue? "
        )

        if c == 'yes':
            crawl.crawl_trains()

    extract.main()
    transform.main()
    os.system('bash export.sh')
Exemplo n.º 16
0
    def setUp(self):
        # Skip this test because it takes too long (>1 minute)
        # TODO: figure out how to declare a "long-running" test suite
        # and add this test to it.
        raise SkipTest()

        global SETUP_HAS_RUN

        # Subtract 1 second to help comparisons with file-modify time succeed,
        # since os.path.getmtime() is not millisecond-accurate
        self.start_time = datetime.now(UTC) - timedelta(seconds=1)
        super(TestExtract, self).setUp()
        if not SETUP_HAS_RUN:
            # Run extraction script. Warning, this takes 1 minute or more
            extract.main()
            SETUP_HAS_RUN = True
Exemplo n.º 17
0
def test_main_return_values(arguments, return_code, message, monkeypatch,
                            capsys):
    monkeypatch.setattr('extract.call_docker', lambda **_: None)
    monkeypatch.setattr('extract.sys.argv', arguments)
    monkeypatch.setattr('extract.subprocess.run', exec_stub)

    assert main() == return_code
    assert message in capsys.readouterr().err
Exemplo n.º 18
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("input", help="File of URLs to be analyzed")
    parser.add_argument("output", help="Output File")
    args = parser.parse_args()

    if args.input and args.output:
        # Update phishtank database
        print('Download and update phishtank database...')
        update_db()
        # Starts extraction
        print('Starts extraction...')
        extract.main(args.input, args.output)
        print('''
#######################################
#   Dataset generated successfully!   #
#######################################
            ''')
Exemplo n.º 19
0
def test_main_return_values(arguments, return_code, message, monkeypatch,
                            capsys):
    monkeypatch.setattr(
        'extract.call_docker',
        lambda input_file, container, target, report_file, memory_limit: None)
    monkeypatch.setattr('extract.sys.argv', arguments)
    monkeypatch.setattr('extract.subprocess.run', exec_stub)

    assert main() == return_code
    assert message in capsys.readouterr().err
Exemplo n.º 20
0
 def input_num(self):
     input_window = tk.Tk()
     input_window.geometry('170x100+' + str(int(0.5 * input_window.winfo_screenwidth())) +
                   '+' + str(int(0.5 * input_window.winfo_screenheight())))
     input_window.title('输入')
     input_entry = tk.Entry(input_window, width = 15, font = ('Arial', 10))
     input_entry.place(x = 30, y = 25, anchor = 'w')
     start = tk.Button(input_window, text = '开始',
                       command = lambda : extract.main(input_entry.get(), self.extracted_name, self.show_res))
     start.place(x = 70, y = 65, anchor = 'w')
Exemplo n.º 21
0
def dirDeriv(exp,point,vector):
    dim=len(vector)
    dird=[]
    for i in range(dim):
        dird.append(CallDiff(exp,var_list[i]))
    comp=[]
    try:
        for i in range(dim):
            comp.append(extract.main(dird[i],point)*vector[i])
        return comp
    except:
        return("function not derivable")
Exemplo n.º 22
0
def differentiate(exp,x,order):
    arr=[x]
    i=1
    for i in range(1,order+1):
        if(not('x' in exp)):
            return 0
        exp=CallDiff(exp,'x')
    try:
        der=extract.main(exp,arr)
        return der
    except:
        return("function not derivable")
Exemplo n.º 23
0
def EqnSolver(exp,x0,x1):
    count=0
    try:
        while((math.fabs(x1-x0))>0.01  and count<100):
            func1=extract.main(exp,[x1])
            func0=extract.main(exp,[x0])
            if(math.fabs(func1)<0.09 and math.fabs(func0)<0.09):
                break
            x2=x1-func1*(x1-x0)/(func1-func0)
            x0,x1=x1,x2
            count=count+1
        if(count==100):
             return("please try again with better root approximation.Perhaps no roots exist")
        if(math.fabs(x1-x0)<0.1):
            if(math.fabs(func1)<0.09 and math.fabs(func0)<0.09):
                 return x1
            else:
                 return("high probability that roots don't exist")
        else:
            return("two roots were found"+str(x0)+","+str(x1))
    except:
        return("method failed.Please try again with another approximation")
Exemplo n.º 24
0
def test(text1,text2,t1,t2,text3,text4,item):
    x2=arange(t1,t2,0.01)
    y1=zeros(len(x2))
    y2=zeros(len(x2))
    z=[None]
    if item==0:
        plt.xlabel(text3)
        plt.ylabel(text4)
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            y1[i]=extract.main(text2,z)
        plot(y2,y1)
        xlabel(text3)
        ylabel(text4)
        title('f(x) vs g(x)')
        show()
    if item==1:
        xlabel(text3)
        ylabel(text4)
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            #y1[i]=extract.main(text2,z)
        plot(x2,y2)
        title('f(x) vs x')
        show()
    if item==3:
        xlabel(text3)
        ylabel(text4)
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            #y1[i]=extract.main(text2,z)
        plot(x2,y2)
        title('g(x) vs x')
        show()
    if item==2:
        xlabel(text3)
        ylabel(text4)
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            y1[i]=extract.main(text2,z)
        plot(x2,y2)
        plot(x2,y1)
        title('g(x) vs x')
        show()
Exemplo n.º 25
0
def test(text1,text2,t1,t2,text3,text4,item):
    n=50*(t2-t1)/2
    x2=linspace(t1,t2,n)
    y1=zeros(len(x2))
    y2=zeros(len(x2))
    z=[None]
    if item==0:
        plt.xlabel(text3)
        plt.ylabel(text4)
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            y1[i]=extract.main(text2,z)
        plt.figure()
        plt.plot(y1,y2)
        plt.savefig("example.png")
    if item==1:
        plt.xlabel(text3)
        plt.ylabel(text4)
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            #y1[i]=extract.main(text2,z)
        plt.figure()
        plt.plot(x2,y2)
        plt.savefig("example.png")
    if item==3:
        plt.xlabel(text3)
        plt.ylabel(text4)
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            #y1[i]=extract.main(text2,z)
        plt.figure()
        plt.plot(x2,y2)
        plt.savefig("example.png")
    if item==2:
        plt.xlabel("X axis")
        plt.ylabel("Y axis")
        for i in range(len(x2)):
            z=[x2[i]]
            y2[i]=extract.main(text1,z)
            y1[i]=extract.main(text2,z)
        plt.figure()
        plt.plot(x2,y2,label=text3)
        plt.plot(x2,y1,label=text4)
        plt.savefig("example.png")
Exemplo n.º 26
0
def optimize_min(exp, dim, arrmin, arrmax):
    flag = -1
    count = 0
    while count < 50:
        count = count + 1
        if flag == 0 or flag == -1:
            points = [] * (dim + 1)
            values = []
            for i in range(dim + 1):
                points.append([0] * (dim))
                temp = [] * (dim)
                for j in range(dim):
                    temp.append(arrmin[j] + (arrmax[j] - arrmin[j]) * random.random())
                points[i] = temp
                values.append(extract.main(exp, points[i]))
                points[i] = numpy.array(points[i])
            values = numpy.array(values)
        index = values.argsort()
        temp = points
        for i in range(dim + 1):
            points[i] = temp[index[i]]
        values.sort()
        if math.fabs((values[dim] - values[0]) / values[0]) < 0.01:
            break
        if True in (points[dim] - points[0]) < numpy.array([0.05] * (dim)) and True in (
            points[dim] - points[0]
        ) > numpy.array([-0.05] * (dim)):
            break
        x0 = numpy.array([0] * dim)
        for i in range(dim):
            x0 = x0 + points[dim]
        x0 = x0 / dim
        xr = numpy.array([0] * (dim))
        xr = 2 * x0 - points[dim]
        if extract.main(exp, xr) < values[dim] and extract.main(exp, xr) >= values[0]:
            gr = xr >= numpy.array(arrmin)
            sm = xr <= numpy.array(arrmax)
            if False in gr or False in sm:
                flag = 0
                continue
            points[dim] = xr
            values[dim] = extract.main(exp, xr)
            flag = 1
            continue
        elif extract.main(exp, xr) < values[0]:
            xe = 2 * xr - x0
            gr = xr >= numpy.array(arrmin)
            sm = xr <= numpy.array(arrmax)
            if False in gr or False in sm:
                flag = 0
                continue
            if extract.main(exp, xe) < extract.main(exp, xr):
                points[dim] = xe
                values[dim] = extract.main(exp, xe)
                flag = 1
                continue
            else:
                points[dim] = xr
                values[dim] = extract.main(exp, xr)
                flag = 1
                continue
        else:
            xc = 0.5 * xr + 0.5 * x0
            gr = xr >= numpy.array(arrmin)
            sm = xr <= numpy.array(arrmax)
            if False in gr or False in sm:
                flag = 0
                continue
            if extract.main(exp, xc) < extract.main(exp, xr):
                points[dim] = xc
                values[dim] = extract.main(exp, xc)
                flag = 1
                continue
            elif extract.main(exp, xr) > values[dim]:
                xc = 0.5 * values[dim] + 0.5 * x0
                if extract.main(exp, xc) < values[dim]:
                    points[dim] = xc
                    values[dim] = extract.main(exp, xc)
                    flag = 1
                    continue
                else:
                    for i in range(1, dim + 1):
                        points[i] = 0.5 * points[0] + 0.5 * points[i]
                        values[i] = extract.main(exp, points[i])
                        flag = 1
    if math.fabs((values[dim] - values[0]) / values[0]) < 0.01:
        return values[0]
    if True in (points[dim] - points[0]) < ([0.05] * (dim)) and True in (points[dim] - points[0]) > ([-0.05] * (dim)):
        return min(values)
    return min(values)
Exemplo n.º 27
0
def main():
    embed.main()
    extract.main()
    evaluate.main()
Exemplo n.º 28
0
import eval
import extract

if __name__ == '__main__':
    extract.main('data/Corpus.DEV.txt', 'data/Corpus.TRAIN.txt',
                 'data/TRAIN.annotations', 'output.dev.txt')
    eval.main('data/DEV.annotations', 'output.dev.txt')
Exemplo n.º 29
0
    while choice != 5:
        print('\nMenu:')
        print(
            '1 -> Create Dataset.\n2 -> Classify using kNN.\n3 -> Classify using MNB.\n4 -> Exit.'
        )
        choice = int(input('Enter your choice: '))

        if choice == 1:
            # Create Dataset
            reply = input(
                'Do you want get emails from your email account? (y/n): '
            )[0].lower()
            if reply == 'n':
                dataset_name = input(
                    'Enter the name of existing dataset folder: ')
                ex.main(dataset_name)
            elif reply == 'y':
                usr = input('Email: ')
                pwd = getpass('Password: '******'Enter a name for your dataset: ')
                    if platform.system() == 'Windows':
                        dataset_path = current_path + dataset_name + "\\"
                    elif platform.system() == 'Linux':
                        dataset_path = current_path + dataset_name + "/"
                    if not os.path.exists(dataset_path):
                        os.mkdir(dataset_path)

                    print('Your Folders:')
Exemplo n.º 30
0
	if platform.system() == 'Windows':
		current_path = os.path.dirname(os.path.abspath(__file__)) + "\\"
	elif platform.system() == 'Linux':	
		current_path = os.path.dirname(os.path.abspath(__file__)) + "/"
	choice = 0
	while choice != 5:
		print('\nMenu:')
		print('1 -> Create Dataset.\n2 -> Classify using kNN.\n3 -> Classify using MNB.\n4 -> Exit.')
		choice = int(input('Enter your choice: '))
		
		if choice == 1:
			# Create Dataset
			reply = input('Do you want get emails from your email account? (y/n): ')[0].lower()
			if reply == 'n':
				dataset_name = input('Enter the name of existing dataset folder: ')
				ex.main(dataset_name)
			elif reply == 'y':
				usr = input('Email: ')
				pwd = getpass('Password: '******'Enter a name for your dataset: ')
					if platform.system() == 'Windows':
						dataset_path = current_path + dataset_name + "\\"
					elif platform.system() == 'Linux':
						dataset_path = current_path + dataset_name + "/"
					if not os.path.exists(dataset_path):
						os.mkdir(dataset_path)

					print('Your Folders:')
Exemplo n.º 31
0
def main():
  usage = "Usage: vcfPytools.py [tool] [options]\n\n" + \
          "Available tools:\n" + \
          "  annotate:\n\tAnnotate the vcf file with membership in other vcf files.\n" + \
          "  extract:\n\tExtract vcf records from a region.\n" + \
          "  filter:\n\tFilter the vcf file.\n" + \
          "  indel:\n\tIndel manipulation tools.\n" + \
          "  intersect:\n\tGenerate the intersection of two vcf files.\n" + \
          "  merge:\n\tMerge a list of vcf files.\n" + \
          "  multi:\n\tFind the intersections and unique fractions of multiple vcf files.\n" + \
          "  sort:\n\tSort a vcf file.\n" + \
          "  stats:\n\tGenerate statistics from a vcf file.\n" + \
          "  union:\n\tGenerate the union of two vcf files.\n" + \
          "  unique:\n\tGenerate the unique fraction from two vcf files.\n" + \
          "  validate:\n\tValidate the input vcf file.\n\n" + \
          "vcfPytools.py [tool] --help for information on a specific tool."

# Determine the requested tool.

  if len(sys.argv) > 1:
    tool = sys.argv[1]
  else:
    print >> sys.stderr, usage
    exit(1)

  if tool == "annotate":
    import annotate
    success = annotate.main()
  elif tool == "extract":
    import extract
    success = extract.main()
  elif tool == "filter":
    import filter
    success = filter.main()
  elif tool == "intersect":
    import intersect
    success = intersect.main()
  elif tool == "indel":
    import indel
    success = indel.main()
  elif tool == "multi":
    import multi
    success = multi.main()
  elif tool == "merge":
    import merge
    success = merge.main()
  elif tool == "sort":
    import sort
    success = sort.main()
  elif tool == "stats":
    import stats
    success = stats.main()
  elif tool == "union":
    import union
    success = union.main()
  elif tool == "unique":
    import unique
    success = unique.main()
  elif tool == "test":
    import test
    success = test.main()
  elif tool == "validate":
    import validate
    success = validate.main()
  elif tool == "--help" or tool == "-h" or tool == "?":
    print >> sys.stderr, usage
  else:
    print >> sys.stderr, "Unknown tool: ",tool
    print >> sys.stderr, "\n", usage
    exit(1)

# If program completed properly, terminate.

  if success == 0: exit(0)
Exemplo n.º 32
0
def multiDimensionInteg(exp,dim,down,up):
    minarr=[None]*dim
    maxarr=[None]*dim
    res=0.0
    pro=1.0
    j=0
    flag_down=[]
    flag_up=[]
    while(j<dim):
        flag_down.append(0)
        flag_up.append(0)
        k=j-1
        while(k>=0):
            if(var_list[k] in str(up[j])):
                flag_up[j]=1
            if(var_list[k] in str(down[j])):
                flag_down[j]=1
            k=k-1
        if(flag_up[j]==0 and flag_down[j]==0):
            minarr[j],maxarr[j]=float(down[j]),float(up[j])
        elif(flag_up[j]==1 and flag_down[j]==0):
            temp1=(Max(up[j],j,minarr[0:j],maxarr[0:j]))
            temp2=(Min(up[j],j,minarr[0:j],maxarr[0:j]))
            temp3=float(down[j])
            if(temp1>=temp3):
                maxarr[j]=temp1
            else:
                maxarr[j]=temp3
            if(temp2<=temp3):
                minarr[j]=temp2
            else:
                minarr[j]=temp3
        elif(flag_up[j]==0 and flag_down[j]==1):
            temp1=(Max(down[j],j,minarr[0:j],maxarr[0:j]))
            temp2=(Min(down[j],j,minarr[0:j],maxarr[0:j]))
            temp3=float(up[j])
            if(temp1>=temp3):
                maxarr[j]=temp1
            else:
                maxarr[j]=temp3
            if(temp2<=temp3):
                minarr[j]=temp2
            else:
                minarr[j]=temp3         
        else:
            temp1=(Max(up[j],j,minarr[0:j],maxarr[0:j]))
            temp2=(Min(up[j],j,minarr[0:j],maxarr[0:j]))
            temp3=(Max(down[j],j,minarr[0:j],maxarr[0:j]))
            temp4=(Min(down[j],j,minarr[0:j],maxarr[0:j]))
            if(temp1>=temp3):
                maxarr[j]=temp1
            else:
                maxarr[j]=temp3
            if(temp2<=temp4):
                minarr[j]=temp2
            else:
                minarr[j]=temp4
        j=j+1
    if(minarr[0]>maxarr[0]):
        minarr[0],maxarr[0]=maxarr[0],minarr[0]
    try:
        
        for i in range(1000):
            arr=[]
            j=0
            while(j<dim):
                arr.append((maxarr[j]-minarr[j])*random.random()+minarr[j])
                j=j+1
            f1=extract.main(exp,arr)
            flag=1
            for k in range(dim):
                temp1=extract.main(down[k],arr[0:k])
                temp2=extract.main(up[k],arr[0:k])
                if(not((arr[k]<temp1 and arr[k]>temp2) or (arr[k]>temp1 and arr[k]<temp2))):
                    flag=0
                if(temp1>temp2):
                    flag=-1*flag
            
            res+=f1*flag
        res/=1000
        for i in range(dim):
            res*=(maxarr[i]-minarr[i])
        return res
    except:
        return("unexpected input")
Exemplo n.º 33
0
        console.setLevel(logging.CRITICAL)

    # Set a format which is simpler for console use
    formatter = logging.Formatter('%(message)s')
    # Tell the handler to use this format
    console.setFormatter(formatter)
    # Add the handler to the root logger
    logging.getLogger('').addHandler(console)

    # Create a logger
    log = logging.getLogger(__name__)

    #
    # RUN SELECTED COMMAND
    #
    if cliArgs.command == "simulate":
        # Run simulate.py
        simulate.main(cliArgs)

    elif cliArgs.command == "list":
        # Run list.py
        list.main()

    elif cliArgs.command == "convert":
        # Run convert.py
        convert.main(cliArgs)

    elif cliArgs.command == "extract":
        # Run extract.py
        extract.main(cliArgs)
def test_it_returns_error_json():
    rawOutput = extract.main(['./extract.py','fixture/empty-header-cells.csv'])
    output = json.loads(rawOutput)
    assert("errorType" in output)
    assert_equals(output["errorType"],"NullHeaderError")
Exemplo n.º 35
0
Arquivo: CAS.py Projeto: mridulv/CAS
    def answer(self,event):
        f=open("data.txt",'w')
        t1=self.tc.GetValue()
        t2=self.tc2.GetValue()
        self.imp.Append(t1)
        f.write(t1+'\n')
        self.imp.Append(t2)
        f.write(t2+'\n')
        print self.k
        if self.k<=5 and self.k>=0:                                                          # matrices (part 1)
            text=self.tc.GetValue()
            print(text)
            a=self.conv(text)
            text2=self.tc2.GetValue()
            print(text2)
            b=self.conv(text2)
            if self.k==0:
              try:
                    ans=matrix(a)+matrix(b)
                    ans=str(ans)
                    self.text12.SetValue(ans)
              except:
                ans='Either of the matrix is not given in the correct format' 
                self.text12.SetValue(ans)
            if self.k==1:
              try:
                ans=matrix(a)-matrix(b)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='Either of the matrix is not given in the correct format' 
                self.text12.SetValue(ans)
            if self.k==2:
              try:
                ans=dot(matrix(a),matrix(b))
                ans=str(ans)                                         
                self.text12.SetValue(ans)
              except:
                ans='Either of the matrix is not given in the correct format' 
                self.text12.SetValue(ans)
            if self.k==3:
              try:
               if determinant.determinant(a)!=0:   
                v=matrix(a).I
                ans=dot(v,matrix(b))
                ans=str(ans)
                self.text12.SetValue(ans)
               elif determinant.determinant(a)==0:
                ans='Given an invertible matrix'
                self.text12.SetValue(ans)  
              except:
                ans='Either of the matrix is not given in the correct format' 
                self.text12.SetValue(ans)  
            if self.k==4:
              try:  
               if determinant.determinant(a)!=0:
                ans=matrix(a).I
                ans=str(ans)
                self.text12.SetValue(ans)
               elif determinant.determinant(a)==0:
                ans='The matrix is not invertible'
                self.text12.SetValue(ans)
              except:
                ans='The matrix is not given inthe correct format'
                self.text12.SetValue(ans)  
            if self.k==5:
               try: 
                c=determinant.determinant(a)
                ans=str(c)
                self.text12.SetValue(ans)
               except:
                ans='The matrix given is not in the correct format'
                self.text12.SetValue(ans)
                
        if self.k>5 and self.k<=14 :
            self.text2.SetLabel('')
            text=self.tc.GetValue()                                                # matrices (part 2)
            print(text)
            a=self.conv(text)
            if self.k==6:
              try:
                a=matrix(a)
                m=rank(a)
                m=str(m)
                self.text12.SetValue(m)
              except:
                m='The given input is not in the correct format'
                self.text12.SetValue(m)
            if self.k==7:
              try:
                c=matrix(a)
                ans=gauss.test(c,len(a))
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not in the correct format'
                self.text12.SetValue(ans)
            if self.k==8:
              try:
                l,u,d=ludecomposition.test(a)
                ans='l is ',l,'u is',u,'and d is',d
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not in the correct format'
                self.text12.SetValue(ans)
            if self.k==9:
              try:
                ans=matrix(a).T
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not in the correct format'
                self.text12.SetValue(ans)  
            if self.k==10:
              try:
                a=matrix(a)
                ans1,ans2=qr_decomposition.test(text)
                ans='Q is ',ans1,'R is ',ans2,'in QR decomposition'
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==11:
              try:
                ans=qr_decomposition2.test(text)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)  
            if self.k==12:
              try:
                ans=eigen.test(text)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is incorrect'
                self.text12.SetValue(ans)

        if self.k>=16 and self.k<20:                                            # differential calculus
            text2=self.tc2.GetValue()
            text=self.tc.GetValue()
            if self.k==16:
              try:
                b=self.conv(text2)
                print b[0],b[1]
                ans=symbolic.differentiate(text,float(b[0]),int(b[1]))
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='please check the input that you have given'
                self.text12.SetValue(ans)
            if self.k==17:
              try:
                ans=symbolic.CallDiff(text,text2)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==18:
              try:
                b=self.conv(text2)
                ans=symbolic.dirDeriv(text,b[0],b[1])
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==19:
              try:
                ans=symbolic.Laplacian(text)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
                
        if self.k>=21 and self.k<=25:                                                    # polynomials
            text=self.tc.GetValue()
            text2=self.tc2.GetValue()
            Poly=Polynomial()
            if self.k==21:
              try:
                ans=Poly.addPolynomial(text,text2)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==22:
              try:
                ans=Poly.subtractPolynomial(text,text2)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==23:
              try:
                ans=Poly.MultiplyPolynomial(text,text2)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==24:
              try:
                ans=Poly.dividePolynomial(text,text2)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==25:
              try:
                self.tc2.SetValue('')
                ans=rootpoly(text)
                ans=str(ans)                                                           # karna hain
                self.text12.SetValue(ans)
              except:
                ans='he choice not selected'
                self.text12.SetValue(ans)
        if self.k>=27 and self.k<=30:                                                    # integral calculus
            text=self.tc.GetValue()
            text2=self.tc2.GetValue()                                               
            print(text2)

            if self.k==27:
              try:
                b=self.conv(text2)
                lower=[None]*len(b)
                upper=[None]*len(b)
                ans=symbolic.integrate(text,b[0],b[1])
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==28:
              try:
                b=self.conv3(text2)
                print 'mridul',b
                lower=[None]*len(b)
                upper=[None]*len(b)
                for i in range(len(b)):
                    lower[i]=b[i][0]
                    upper[i]=b[i][1]
                print 'mridul',lower,upper
                ans=symbolic.multiDimensionInteg(text,len(b),lower,upper)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==29:
              try:
                b=self.conv(text2)
                lower=[None]*len(b)
                upper=[None]*len(b)
                if len(b)==6:
                    ans=diffeqn.solveDiffEqn4(text,b[:len(b)-2],b[len(b)-2],b[len(b)-1])                        # the first element b[len(b)-1] is the point where the f(x) has to be calculated  and the rest are the initial conditions
                if len(b)==5:
                    ans=diffeqn.solveDiffEqn3(text,b[:len(b)-2],b[len(b)-2],b[len(b)-1])
                if len(b)==4:
                    ans=diffeqn.solveDiffEqn2(text,b[:len(b)-2],b[len(b)-2],b[len(b)-1])                        # the first element b[0] is the point where the f(x) has to be calculated  and the rest are the initial conditions
                if len(b)==3:
                    ans=diffeqn.solveDiffEqn1(text,b[:len(b)-2],b[len(b)-2],b[len(b)-1])
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not in not in the standard format demanded by CAS'
                self.text12.SetValue(ans)
            if self.k==30:
              try:
                b=self.conv3(text2)
                lower=[None]*len(b)
                upper=[None]*len(b)
                print b
                ans=diffeqn.LaplaceEqn(text,b[0],b[2],b[1],b[3])                                        
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
        if self.k>=37 and self.k<=44:                                             # statistics the data points  
            text=self.tc.GetValue()
            print(text)
            b=self.conv(text)
            lower=[None]*len(b)
            middle=[None]*len(b)
            upper=[None]*len(b)
            if self.k==37:
              try:
                text2=self.tc2.GetValue()
                for i in range(len(b)):
                    lower[i]=b[i][0]
                    upper[i]=b[i][1]
                ans=regression.LeastSquare(int(text2),lower,upper)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct format'
                self.text12.SetValue(ans)
            if self.k==38:
              try:
                for i in range(len(b)):
                    lower[i]=b[i][0]
                    middle[i]=b[i][1]
                    upper[i]=b[i][2]
                ans=regression.PlaneFit(lower,middle,upper)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==39:
              try:
                for i in range(len(b)):
                    lower[i]=b[i][0]
                    upper[i]=b[i][1]
                ans=regression.ExponentialCurve(lower,upper)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==40:
              try:
                for i in range(len(b)):
                    lower[i]=b[i][0]
                    upper[i]=b[i][1]
                ans=regression.LogarithmicCurve(lower,upper)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==41:
              try:
                ans=regression.SplineInterpolation(b)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==42:
              try:
                for i in range(len(b)):
                    lower[i]=b[i][0]
                    upper[i]=b[i][1]
                ans=regression.SpearsmanCoff(lower,upper)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==43:
              try:
                for i in range(len(b)):
                    lower[i]=b[i][0]
                    upper[i]=b[i][1]
                ans=regression.Pearson(lower,upper)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==44:
              try:
                ans=regression.tau(b)
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)  
        if self.k>=32 and self.k<=36:                                        # playing with Fourier
             text=self.tc.GetValue()
             print (text)
             if self.k==32:
              try:
                text2=self.tc2.GetValue()
                b=self.conv(text2)
                ans=SinCoeff(text,b[0],b[1],b[2])
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
             if self.k==33:
              try:
                text2=self.tc2.GetValue()
                b=self.conv(text2)
                ans=CosCoeff(text,b[0],b[1],b[2])
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
             if self.k==34:
              try:
                text2=self.tc2.GetValue()
                b=self.conv(text2)
                ans=FourierCoeff(text,b[0],b[1],b[2])
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
             if self.k==35:
              try:
                b=self.conv2(text)
                ans=discreteFourier(b,len(b))
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
             if self.k==36:
              try:
                b=self.conv2(text)
                ans=inverseVal(b,len(b))
                ans=str(ans)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
                
        if self.k>=46 and self.k<=47:                                        # optimization
             text=self.tc.GetValue()
             print (text)
             text2=self.tc2.GetValue()
             b=self.conv(text2)
             lower=[None]*len(b)
             upper=[None]*len(b)
             for i in range(len(b)):
                    lower[i]=b[i][0]
                    upper[i]=b[i][1]
             if self.k==46:
              try:
                m=symbolic.Max(text,len(b),lower,upper)
                ans=str(m)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
             if self.k==47:
              try:
                m=symbolic.Min(text,len(b),lower,upper)
                ans=str(m)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
                

        if self.k>=49:                                                      #evaluating expression
            text=self.tc.GetValue()
            print (text)
            text2=self.tc2.GetValue()
            b=self.conv(text2)
            if self.k==49:
              try:
                m=symbolic.roots_interval(text,b[0],b[1])
                ans=str(m)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==50:
              try:
                m=symbolic.EqnSolver(text,b[0],b[1])
                ans=str(m)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
            if self.k==51:
              try:
                m=extract.main(text,b)
                ans=str(m)
                self.text12.SetValue(ans)
              except:
                ans='The given input is not correct'
                self.text12.SetValue(ans)
        t3=self.text12.GetValue()
        self.imp.Append(t3)
        f.write(t3+'\n')
        f.close()
Exemplo n.º 36
0
def main():
    usage = "Usage: vcfPytools.py [tool] [options]\n\n" + \
            "Available tools:\n" + \
            "  annotate:\n\tAnnotate the vcf file with membership in other vcf files.\n" + \
            "  extract:\n\tExtract vcf records from a region.\n" + \
            "  filter:\n\tFilter the vcf file.\n" + \
            "  indel:\n\tIndel manipulation tools.\n" + \
            "  intersect:\n\tGenerate the intersection of two vcf files.\n" + \
            "  merge:\n\tMerge a list of vcf files.\n" + \
            "  multi:\n\tFind the intersections and unique fractions of multiple vcf files.\n" + \
            "  sort:\n\tSort a vcf file.\n" + \
            "  stats:\n\tGenerate statistics from a vcf file.\n" + \
            "  union:\n\tGenerate the union of two vcf files.\n" + \
            "  unique:\n\tGenerate the unique fraction from two vcf files.\n" + \
            "  validate:\n\tValidate the input vcf file.\n\n" + \
            "vcfPytools.py [tool] --help for information on a specific tool."

    # Determine the requested tool.

    if len(sys.argv) > 1:
        tool = sys.argv[1]
    else:
        print >> sys.stderr, usage
        exit(1)

    if tool == "annotate":
        import annotate
        success = annotate.main()
    elif tool == "extract":
        import extract
        success = extract.main()
    elif tool == "filter":
        import filter
        success = filter.main()
    elif tool == "intersect":
        import intersect
        success = intersect.main()
    elif tool == "indel":
        import indel
        success = indel.main()
    elif tool == "multi":
        import multi
        success = multi.main()
    elif tool == "merge":
        import merge
        success = merge.main()
    elif tool == "sort":
        import sort
        success = sort.main()
    elif tool == "stats":
        import stats
        success = stats.main()
    elif tool == "union":
        import union
        success = union.main()
    elif tool == "unique":
        import unique
        success = unique.main()
    elif tool == "test":
        import test
        success = test.main()
    elif tool == "validate":
        import validate
        success = validate.main()
    elif tool == "--help" or tool == "-h" or tool == "?":
        print >> sys.stderr, usage
    else:
        print >> sys.stderr, "Unknown tool: ", tool
        print >> sys.stderr, "\n", usage
        exit(1)


# If program completed properly, terminate.

    if success == 0: exit(0)
Exemplo n.º 37
0
def test_it_logs_progress_to_a_text_file():
    extract.main(['./extract.py','fixture/simple.xls'])
    with open('log.txt', 'r') as f:
        assert("STARTED" in f.read())
Exemplo n.º 38
0
import traceback
import time

import extract
import read_csv
import write_csv
import read_lines
import processsing

if __name__ == "__main__":
    print("_" * 50)
    print("Start script 'time_reporting.py'")
    try:
        dir, csv_list = extract.main()
        files = read_csv.main(csv_list)
        datas = read_lines.main(files, csv_list)
        datas_transformed = processsing.main(datas)
        write_csv.main(dir, datas_transformed)
        print("Finish script 'time_reporting.py'")
    except:
        traceback.print_exc()
    time.sleep(24 * 60 * 60)
def test_it_returns_success_json():
    rawOutput = extract.main(['./extract.py', 'fixture/simple.xls'])
    output = json.loads(rawOutput)
    assert ("errorType" in output)
    assert_equals(output["errorType"], None)
def test_it_returns_error_json():
    rawOutput = extract.main(
        ['./extract.py', 'fixture/empty-header-cells.csv'])
    output = json.loads(rawOutput)
    assert ("errorType" in output)
    assert_equals(output["errorType"], "NullHeaderError")
Exemplo n.º 41
0
import sys
import extract as ex
import eval as ev

train_file, annotation_file, output_file = sys.argv[1:]

ex.main(train_file, output_file)
ev.main(annotation_file, output_file)
Exemplo n.º 42
0
def LaplaceEqn(g,boundary,boundary1,pts,pt):
    for i in range(len(pts)):
        pts[i]=int(pts[i])
    #print(pts)
    pt[0]=float(pt[0])
    pt[1]=float(pt[1])
   # print(pt)
    m=int(math.fabs(int(pts[0]/1)))
    n=int(math.fabs(int(pts[1]/1)))
    t1=1
    t2=1
    A=[0]*((m-1)*(n-1))
    for i in range((m-1)*(n-1)):
        A[i]=[0]*((m-1)*(n-1))
    D=[0]*(m-1)
    I=[0]*(m-1)
    for i in range(m-1):
        D[i]=[0]*(m-1)
        I[i]=[0]*(m-1)
        for j in range(m-1):
            if(i==j):
                D[i][j]=4
                I[i][j]=-1
            elif(math.fabs(i-j)==1):
                D[i][j]=-1
    i=0
    while(i<((m-1)*(n-1))):
        j=0
        while(j<((m-1)*(n-1))):
            MatrixFill(A,i,j,D,I,m-1)
            j+=(m-1)
        i+=(m-1)
    val=[]
    if(pts[0]<0):
        t1=-1
    if(pts[1]<0):
        t2=-1
    y_cor=1*t2
    for i in range(n-1):
        x_cor=1*t1
        for j in range(m-1):
            if(math.fabs(x_cor)==1 and math.fabs(y_cor)==1):
                val.append(extract.main(boundary[0],[x_cor,y_cor])+extract.main(boundary[1],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            elif((x_cor)==(pts[0]-1*t1) and (y_cor)==(pts[1]-1*t2)):
                val.append(extract.main(boundary1[0],[x_cor,y_cor])+extract.main(boundary1[1],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            elif((x_cor)==(pts[0]-1*t1) and math.fabs(y_cor)==1):
                val.append(extract.main(boundary1[0],[x_cor,y_cor])+extract.main(boundary[1],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            elif((y_cor)==(pts[1]-1*t2) and math.fabs(x_cor)==1):
                val.append(extract.main(boundary[0],[x_cor,y_cor])+extract.main(boundary1[1],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            elif(math.fabs(x_cor)==1):
                val.append(extract.main(boundary[1],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            elif(math.fabs(y_cor)==1):
                val.append(extract.main(boundary[0],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            elif((x_cor)==(pts[0]-1*t1)):
                val.append(extract.main(boundary1[1],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            elif((y_cor)==(pts[1]-1*t2)):
                val.append(extract.main(boundary1[0],[x_cor,y_cor])-extract.main(g,[x_cor,y_cor])*(math.pow(1,2)))
            else:
                val.append(extract.main(g,[x_cor,y_cor])*(math.pow(1,2))*-1)
            x_cor+=1*t1
        y_cor+=1*t2
    A=matrix(A)
    val=matrix(val)
    u=(A.I)*(val.T)
    u.tolist()
    x1=int(pt[0])
    y1=int(pt[1])
    w1=max(1-math.sqrt((x1-pt[0])**2+(y1-pt[1])**2),0)
    w2=max(1-math.sqrt((x1+t1-pt[0])**2+(y1-pt[1])**2),0)
    w3=max(1-math.sqrt((x1-pt[0])**2+(y1+t2-pt[1])**2),0)
    w4=max(1-math.sqrt((x1+t1-pt[0])**2+(y1+t2-pt[1])**2),0)
    if(x1!=0 and y1!=0):
        u1=u[math.fabs(x1)-1+(m-1)*(math.fabs(y1)-1)]
    else:
        if(x1==0):
            u1=extract.main(boundary[1],[x1,y1])
        elif(y1==0):
            u1=extract.main(boundary[0],[x1,y1])
    if(y1!=0 and x1!=pts[0]-t1):
        u2=u[math.fabs(x1)+(m-1)*(math.fabs(y1)-1)]
    else:
        if(y1==0):
            u2=extract.main(boundary[0],[x1,y1])
        elif(x1==pts[0]-t1):
            u2=extract.main(boundary1[1],[x1,y1])
    if(x1!=0 and y1!=pts[1]-t2):
        u3=u[math.fabs(x1)-1+(m-1)*(math.fabs(y1))]
    else:
        if(x1==0):
            u3=extract.main(boundary[1],[x1,y1])
        elif(y1==pts[1]-t2):
            u3=extract.main(boundary1[1],[x1,y1])
    if(x1!=pts[0]-t1 and y1!=pts[1]-t2):
       u4=u[math.fabs(x1)+(m-1)*(math.fabs(y1))]
    else:
       if(x1==pts[0]-t1):
            u4=extract.main(boundary1[1],[x1,y1])
       elif(y1==pts[1]-t2):
            u4=extract.main(boundary1[1],[x1,y1]) 
    u_final=(w1*u1+w2*u2+w3*u3+w4*u4)/(w1+w2+w3+w4)
    return(u_final)
Exemplo n.º 43
0
def test_it_logs_stack_traces():
    extract.main(['./extract.py','fixture/empty-header-cells.csv'])
    with open('log.txt', 'r') as f:
        logOutput = f.read()
        assert('Traceback (most recent call last):' in logOutput)
        assert('NullHeaderError' in logOutput)
Exemplo n.º 44
0
def extract(text=None, filename=None):
    from extract import main
    if filename:
        with open(filename) as f:
            text = f.read()
    print(main(text))
Exemplo n.º 45
0
def test_it_clears_the_log_before_each_run():
    extract.main(['./extract.py','fixture/simple.xls'])
    with open('log.txt', 'r') as f:
        assert_equals(f.read().count('STARTED'), 1)
Exemplo n.º 46
0
import cv2
import os
import numpy as np
import extract

e = extract.main()
print(e)
a0 = e[0][0]
a1 = e[0][1]
b0 = e[1][0]
b1 = e[1][1]
c0 = e[2][0]
c1 = e[2][1]
cv2.destroyAllWindows()
rgb = np.zeros((100, 512, 3), np.uint8)

lower_range = np.zeros((100, 512, 3), np.uint8)

upper_range = np.zeros((100, 512, 3), np.uint8)
draw = np.zeros((480, 640, 3), np.uint8)

cap = cv2.VideoCapture(0)


def nothing(x):
    pass


cv2.namedWindow('control & lower_range')

cv2.createTrackbar('r', 'control & lower_range', 0, 255, nothing)
def test_it_returns_success_json():
    rawOutput = extract.main(['./extract.py','fixture/simple.xls'])
    output = json.loads(rawOutput)
    assert("errorType" in output)
    assert_equals(output["errorType"],None)