コード例 #1
0
ファイル: hello.py プロジェクト: vc13/project
def hello():
	if request.method == 'POST':
		print "Got Request"
		file = request.files['file']
		file.save('hello.wav')
		init(mp3_file = 'hello.wav')
		return send_file('hello.png', mimetype='image/png')
	else:
		return "Get World"
コード例 #2
0
ファイル: test_io_redirection.py プロジェクト: odivlad/psh
# -*- coding: utf-8 -*-

"""Tests I/O redirection."""

from __future__ import unicode_literals

import logging
import sys
import tempfile

import psys
from psh import sh, File, Program, STDOUT, STDERR, DEVNULL

import test
test.init(globals())


def test_command_with_redirection(test):
    """Tests command arguments representation."""

    process = sh.echo("test", _stdout=STDERR)
    assert str(process) == "echo test >&2"
    assert bytes(process) == psys.b(str(process))

    process = sh.echo("test", _stdout=File("/tmp/test.path"))
    assert str(process) == "echo test > /tmp/test.path"
    assert bytes(process) == psys.b(str(process))

    process = sh.echo("test", _stderr=File("/tmp/test.path"))
    assert str(process) == "echo test 2> /tmp/test.path"
    assert bytes(process) == psys.b(str(process))
コード例 #3
0
ファイル: test_general.py プロジェクト: KonishchevDmitry/psh
from __future__ import unicode_literals

import signal
import time

import pytest

import psh
import psys

from psh import sh
from pcore import bytes, str

import test
test.init(globals())


def test_command_arguments(test):
    """Tests command argument parsing."""

    process = sh.test()
    assert process.command() == ["test"]
    assert str(process) == "test"
    assert bytes(process) == psys.b(str(process))

    process = sh.complex_command_name()
    assert process.command() == ["complex-command-name"]
    assert str(process) == "complex-command-name"
    assert bytes(process) == psys.b(str(process))
コード例 #4
0
        self.bitmapData = bitmapData

    def _getOriginalWidth(self):
        return self.bitmapData.width

    def _getOriginalHeight(self):
        return self.bitmapData.height

    def _loopDraw(self, c):
        bmpd = self.bitmapData
        c.drawImage(0, 0, bmpd.image, bmpd.x, bmpd.y, bmpd.width, bmpd.height)


from test import init, addChild


def main():
    loader = Loader()
    loader.load("1.bmp")
    bmpd = BitmapData(loader.content)
    bmp = Bitmap(bmpd)
    addChild(bmp)

    bmp.x = 80
    bmp.y = 100
    bmp.rotation = -20
    bmp.alpha = 0.8


init(30, "Display An Image", 800, 600, main)
コード例 #5
0
#Author: stephon
#Time: 11.15

import os
import cv2
import codecs
from test import init, predict
import time
import Levenshtein
import numpy as np
from preproc import preprocess2

debug = False
t = time.time()
checkpoint = "./model/basemodel48.h5"  #model: 36; 48的比较好, 达到98.22%; 去除一些倾斜比较严重的,准确率应该可以上到99%;
basemodel = init(0, 0.2, checkpoint)  #last 1.2s
print(
    "init time is: {}".format(time.time() - t)
)  #按需分配,则模型只需要占用1172-1095 = 77M ~ 80M;  正常运行,占用显存大小:2571 - 1095 = 1471M左右;
#exit()

test_file = "./truth_test.txt"
all_num = 0
right_num = 0
item_right_num = 0
wrong_images = []
w = codecs.open("result.txt", 'w', 'utf-8')

with codecs.open(test_file, 'r', 'utf-8') as r:
    alllines = r.readlines()
    for oneline in alllines:
コード例 #6
0
ファイル: test.py プロジェクト: BGCAV/util
#!/usr/bin/python
import sys, test

if len(sys.argv) > 1:
	test.init(sys.argv)
else:
	print("nothing to do")
コード例 #7
0
ファイル: main.py プロジェクト: BehzadBozorgtabar/LTS5_FER
        # Prepare TCNN extractor
        print("Prepare TCNN extractor")
        conv1_1_weigths = get_conv_1_1_weights(vggCustom_weights_path)
        tcnn_bottom = create_tcnn_bottom(vggCustom_weights_path,
                                         conv1_1_weigths)
        tcnn_extractor = tcnn_bottom.predict
        img_size = 224

    elif tcnn_type == 'squeezenet':
        tcnn_model = load_model(squeezenet_tcnn_model_path)

        # Prepare TCNN extractor
        print("Prepare TCNN extractor")
        conv1_weights = get_conv1_weights(squeezeNetCustom_weights_path)
        tcnn_bottom = create_squeezenet_tcnn_bottom(
            squeezeNetCustom_weights_path, conv1_weights)
        tcnn_extractor = tcnn_bottom.predict
        img_size = 227

    client = init(mqttHost="test.mosquitto.org", client_name="JSON", port=1883)
    K.get_session().run(tf.global_variables_initializer())
    prediction(tcnn_model,
               phrnn_model,
               tcnn_extractor,
               test_file,
               client,
               img_size=img_size,
               tcnn_type=tcnn_type,
               phrnn_type="landmarks")
コード例 #8
0
from test import init,check,convert2label
import time
model,w_model=init()
count=0
sql=0
xss=0
normal=0
start=time.time()
for line in open('data/test_normal.txt','r'):
    if len(line):
        count+=1
        checked=check(model,w_model,line)
        print(checked)
        if checked==0:
            normal+=1
        elif checked==1:
            sql+=1
        else :
            xss+=1
end=time.time()
print("normal %f"%(normal/count)," xss:",xss," sql:",sql)
print("sql %f"%(sql/count)," normal:",normal," xss:",xss)
print("xss %f"%(xss/count)," sql:",sql," normal:",normal)
print("cost time is "+str(end-start)+"s")
コード例 #9
0
ファイル: cross_check.py プロジェクト: yanshuyuan/classify
        for file_ix in xrange(len(filelist)):
            if file_ix % group_num == group_ix:
                test_filelist.append(filelist[file_ix])
                test_filenum += 1
            else:
                train_filelist.append(filelist[file_ix])
                train_filenum += 1

        train.count(frompath, train_filenum, train_filelist)
        train.CHI(train_filenum)
        result_file = "tmp%s.dat" % group_ix

        train.create_train(topath, train_filenum, train_filelist, result_file)

        test.init()
        test.read_train("tmp/", result_file)

        rate_dict = test.test_by_filelist("train/", test_filelist)

        fp.write("Group %s:\n" % group_ix)

        group_classify = 0
        group_fact = 0
        group_error = 0
        group_total = 0
        for subject in rate_dict.keys():
            if not total_rate.has_key(subject):
                total_rate[subject] = {"classify": 0, "fact": 0, "error": 0, "total": 0}

            group_classify += rate_dict[subject]["classify"]
コード例 #10
0
ファイル: web_api.py プロジェクト: seher0/mt
from bottle import route, run
import json
from test import init, load_model, predict

config, max_sent_len, vocab, inv_label_vocab = init()

session, model = load_model(config)

@route('/getEntities/<sent>')
def index(sent):
    from bottle import response

    #try:
    output = predict (session, model, vocab, inv_label_vocab, max_sent_len, sent)

    response.content_type = 'application/json'
    ''' 
    Check if this is a good or bad response. 
    '''
    return json.dumps(output)
    #except ValueError:
    #    print "Error"
    #    return ''


run(host='localhost', port=7760, reloader=True)
コード例 #11
0
        for file_ix in xrange(len(filelist)):
            if file_ix % group_num == group_ix:
                test_filelist.append(filelist[file_ix])
                test_filenum += 1
            else:
                train_filelist.append(filelist[file_ix])
                train_filenum += 1

        train.count(frompath, train_filenum, train_filelist)
        train.CHI(train_filenum)
        result_file = 'tmp%s.dat' % group_ix

        train.create_train(topath, train_filenum, train_filelist, result_file)

        test.init()
        test.read_train('tmp/', result_file)

        rate_dict = test.test_by_filelist('train/', test_filelist)

        fp.write('Group %s:\n' % group_ix)

        group_classify = 0
        group_fact = 0
        group_error = 0
        group_total = 0
        for subject in rate_dict.keys():
            if not total_rate.has_key(subject):
                total_rate[subject] = {
                    'classify': 0,
                    'fact': 0,
コード例 #12
0
def c(k):

    test.init()  #通过调用函数来在test变量空间里面操作a

    test.add(k)
コード例 #13
0
    def test(self):
        SCENARIO("Testing cdp logic")

        for cycle_i in range(1, 200):

            ##################################
            COMMENT(f"Cycle {cycle_i}")

            try:
                transfer(eosio_token, buck, user1, "100000000.0000 EOS", "")
            except:
                pass

            destroy(buck)
            maketime(buck, 0)
            update(buck, 1)

            transfer(eosio_token, user1, buck, "100000000.0000 EOS", "deposit")

            initial_funds = fundbalance(buck, user1)

            # mature rex
            test.init()
            maketime(buck, test.time)
            update(buck, test.price)

            ##################################
            COMMENT("Open CDP")

            for cdp in sorted(test.table, key=lambda x: int(x.id)):
                ccr = int(0 if cdp.cd > 999999 else cdp.cd)
                open(buck, user1, ccr, cdp.acr, asset(cdp.collateral, "REX"))

            ##################################
            COMMENT("Initial matching")

            self.compare(buck, test.table)

            ##################################
            COMMENT("Start rounds")

            rounds = 20
            for round_i in range(1, rounds):
                print("\n\n\n\n")
                COMMENT(f"Round {round_i} / {rounds} of cycle {cycle_i}")

                # actions
                result = test.run_round(balance(buck, user1) * 10000)
                round_time = result[0]
                actions = result[1]

                if len(actions) == 0:
                    COMMENT("No actions were performed")
                else:
                    for action in actions:
                        if action[0][0] == "reparam":
                            cdp = action[0][1]
                            col = asset(action[0][2], "REX")
                            debt = asset(action[0][3], "BUCK")

                            # print("reparam", col, debt)
                            if action[1] == False:
                                assertRaises(
                                    self, lambda: reparam(
                                        buck, user1, cdp, debt, col))
                            else:
                                reparam(buck, user1, cdp, debt, col)

                        elif action[0][0] == "acr":
                            cdp = action[0][1]
                            acr = action[0][2]

                            if action[1] == False:
                                assertRaises(
                                    self,
                                    lambda: changeacr(buck, user1, cdp, acr))
                            else:
                                changeacr(buck, user1, cdp, acr)

                        elif action[0][0] == "redeem":

                            quantity = asset(action[0][1], "BUCK")

                            if action[1] == False:
                                balance(buck, user1)
                                assertRaises(
                                    self,
                                    lambda: redeem(buck, user1, quantity))
                            else:
                                redeem(buck, user1, quantity)

                maketime(buck, round_time)
                update(buck, test.price, 3)

                ##################################
                COMMENT(f"Matching after round {round_i}")

                # match cdps
                self.compare(buck, test.table)

                # match taxes
                taxation = table(buck, "taxation")
                self.assertAlmostEqual(unpack(test.IDP),
                                       amount(taxation["insurance_pool"]), 3,
                                       "insurance pools don't match")
                self.assertAlmostEqual(unpack(test.TEC),
                                       unpack(taxation["total_excess"]), 0,
                                       "total excesses don't match")
                self.assertAlmostEqual(unpack(test.CIT),
                                       amount(taxation["collected_excess"]), 0,
                                       "collected insurances don't match")
                # self.assertAlmostEqual(unpack(test.AEC), unpack(taxation["aggregated_excess"]), 0, "aggregated excesses don't match") # uint128 doesn't parse
                print("+ Matched insurance pools")

                # match buck supply
                supply = amount(table(buck, "stat", "BUCK", element="supply"))
                user_balance = balance(buck, "user1")
                scruge_balance = balance(buck, "equityscruge")
                collected_savings = amount(taxation["collected_savings"])
                savings_pool = amount(taxation["savings_pool"])
                locked_in_requests = self.get_locked_in_requests_tokens()
                circulation = scruge_balance + user_balance + collected_savings + savings_pool + locked_in_requests
                self.assertAlmostEqual(supply, circulation, 4,
                                       "supply doesn't match total buck")
                print("+ Matched buck supply")

                # match funds + collateral
                total_collateral = 0
                for cdp in test.table:
                    total_collateral += cdp.collateral / 10000

                insurance_pool = amount(taxation["insurance_pool"])
                collected_insurance = amount(taxation["collected_excess"])
                scruge_funds = fundbalance(buck, "scrugescruge")
                current_balance = fundbalance(buck, "user1")
                calculated_funds = insurance_pool + scruge_funds + total_collateral + current_balance + collected_insurance
                self.assertAlmostEqual(initial_funds, calculated_funds, 3,
                                       "total funds don't match")
                print("+ Matched rex supply")

                ##################################
                COMMENT(
                    f"Round {round_i} / {rounds} of cycle {cycle_i} complete.")
コード例 #14
0
ファイル: __init__.py プロジェクト: niklaskorz/hyperbukkit
def init(bottle, webapp):
    test.init(bottle, webapp)