Beispiel #1
0
def load_image(request):
    img_name = 'img' + str(time.time() * 1000) + '.jpg'
    img_path = '/img/' + img_name
    dest = open(img_path, 'wb+')
    for chunk in request.FILES['image'].chunks():
        dest.write(chunk)
    dest.close()
    if request.user.is_authenticated():
        add_time = time.gmtime()
        ans = request.POST.get('ans', '')
        obj = Picture(pic_name=img_name,
                      user=request.user.username,
                      add_time=add_time,
                      vote=0,
                      ans=ans,
                      recognized='')
    else:
        add_time = time.gmtime()
        ans = request.POST.get('ans', '')
        obj = Picture(pic_name=img_name,
                      user='******',
                      add_time=add_time,
                      vote=0,
                      ans=ans,
                      recognized='')
    doc = Document()
    body = doc.createElement('body')
    doc.appendChild(body)
    thx = doc.createTextNode('Thanx!')
    doc.appendChild(thx)
    c = Client()
    c.Connect()
    c.Send(img_path)
    return HttpResponse(doc, mimetype='application/xml')
    def __init__(self, gun):
        self.gun = gun

        test_server = self.gun.get_option('test_server')
        test_port = self.gun.get_option('test_port')

        test_socket = TSocket.TSocket(test_server, test_port)
        socket = test_socket.create()
        self.transport = TTransport.TFramedTransport(socket)

        protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.client = Client(protocol)
Beispiel #3
0
from service.client import Client

# 数据组
sample = [[0, 1], [1, 0], [1, 1], [1, 2], [2, 1], [2, 2]]
# 标签组
label = [0, 0, 0, 1, 1, 1]

# 创建SVM学习器,使用默认参数。
svm = SVM()

# 训练分类器
svm.train(sample, label)

#测试分类器对新样本的分类
print(svm.classify([3, 3]))
print(svm.classify([0, 0]))
print(svm.classify([[1, 3], [0, 3], [0, 2], [0, 1]]))

# 创建服务器连接
c = Client("219.223.243.8", 8088)

# 保存分类器到服务器
c.save(svm, "test")

# 载入之前保存在服务器上的分类器
new_svm = c.load("test")

# 测试新分类器是否和之前的结果一样
print(new_svm.classify([3, 3]))
print(new_svm.classify([0, 0]))
print(new_svm.classify([[1, 3], [0, 3], [0, 2], [0, 1]]))
Beispiel #4
0
 def setUp(self):
     self.test_client = Client('mock name', 'mock last', '')
Beispiel #5
0
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.test_client = Client('mock name', 'mock last', '')

    def test_name_last_name(self):
        expected_name = 'mock name mock last'
        self.assertEqual(self.test_client.get_formatted_name(), expected_name)

    def test_name_add_preexistence(self):
        self.assertEqual(len(self.test_client.get_all_preexistence()), 0)

        self.test_client.add_preexistence('mock preexistence')
        self.assertEqual(len(self.test_client.get_all_preexistence()), 1)

        self.assertEqual(self.test_client.get_preexistence(0),
                         'mock preexistence')
        self.assertEqual(self.test_client.get_preexistence(1),
                         'There is no such preexistence')

    def test_name_remove_preexistence(self):
        self.assertEqual(len(self.test_client.get_all_preexistence()), 0)

        self.test_client.add_preexistence('mock preexistence')
        self.test_client.add_preexistence('mock preexistence 2')
        self.test_client.add_preexistence('mock preexistence 3')
        self.assertEqual(len(self.test_client.get_all_preexistence()), 3)
        self.test_client.remove_preexistence(1)
        self.assertEqual(self.test_client.get_preexistence(0),
                         'mock preexistence')
        self.assertEqual(self.test_client.get_preexistence(1),
                         'mock preexistence 3')
        self.assertEqual(self.test_client.get_preexistence(2),
                         'There is no such preexistence')
Beispiel #6
0
__author__ = 'ict'

from service.client import Client

# 测试用的变量
test = {
    1: [1, 2, 3],
    2: [1, 2, 3],
    3: [1, 2, 3],
}

# 创建一个到服务器的连接
c = Client("219.223.243.8", 8088)

# 测试对变量的各种存取操作
print(c.save(test, "test"))

print(c.load("test"))

print(c.list())

print(c.remove("test"))

print(c.load("test"))

print(c.list())

# 关闭连接
c.close()
Beispiel #7
0
# 数据组
sample = [[0, 1], [1, 0], [1, 1], [1, 2], [2, 1], [2, 2]]
# 标签组
label = [0, 0, 0, 1, 1, 1]
# k值
k = 3

# 创建k近邻学习器,使用欧几里得距离。
knn = KNN(k)

# 训练分类器
knn.train(sample, label)

# 测试分类器对新样本的分类
print(knn.classify([3, 3]))
print(knn.classify([0, 0]))
print(knn.classify([[1, 3], [0, 3]]))

# 创建服务器连接
c = Client("219.223.243.8", 8088)

# 保存分类器到服务器
c.save(knn, "test-knn")

# 载入之前保存在服务器上的分类器
new_knn = c.load("test-knn")

# 测试新分类器是否和之前的结果一样
print(new_knn.classify([3, 3]))
print(new_knn.classify([0, 0]))
print(new_knn.classify([[1, 3], [0, 3]]))
Beispiel #8
0
          "-" * size_len + "-+-" + "-" * lock_len + "-+")
    for name, attr in var_dict.items():
        size_str = normal_size(attr[size_offset])
        print("| " + str(name) + " " * (name_len - len(str(name))), end="")
        print(" | " + str(attr[type_offset]) + " " *
              (type_len - len(str(attr[type_offset]))),
              end="")
        print(" | " + str(size_str) + " " * (size_len - len(size_str)), end="")
        print(" | " + str(attr[lock_offset]) + " " *
              (lock_len - len(str(attr[lock_offset]))) + " |")
    print("+-" + "-" * name_len + "-+-" + "-" * type_len + "-+-" +
          "-" * size_len + "-+-" + "-" * lock_len + "-+")


if __name__ == "__main__":
    c = Client("219.223.243.8", 10555)
    while True:
        var = c.list()
        print_list(var)
        cmd = input(">>> ")
        tmp_list = cmd.split(" ")
        cmd_list = []
        for one_cmd in tmp_list:
            if len(one_cmd) != 0:
                cmd_list.append(one_cmd)
        if len(cmd_list) == 0:
            continue
        start_time = time.time()
        try:
            if cmd_list[0] == "print":
                if len(cmd_list) != 2:
Beispiel #9
0
    print("| " + name_title + " " * (name_len - len(name_title)), end="")
    print(" | " + type_title + " " * (type_len - len(type_title)), end="")
    print(" | " + size_title + " " * (size_len - len(size_title)), end="")
    print(" | " + lock_title + " " * (lock_len - len(lock_title)) + " |")
    print("+-" + "-" * name_len + "-+-" + "-" * type_len + "-+-" + "-" * size_len + "-+-" + "-" * lock_len + "-+")
    for name, attr in var_dict.items():
        size_str = normal_size(attr[size_offset])
        print("| " + str(name) + " " * (name_len - len(str(name))), end="")
        print(" | " + str(attr[type_offset]) + " " * (type_len - len(str(attr[type_offset]))), end="")
        print(" | " + str(size_str) + " " * (size_len - len(size_str)), end="")
        print(" | " + str(attr[lock_offset]) + " " * (lock_len - len(str(attr[lock_offset]))) + " |")
    print("+-" + "-" * name_len + "-+-" + "-" * type_len + "-+-" + "-" * size_len + "-+-" + "-" * lock_len + "-+")


if __name__ == "__main__":
    c = Client("219.223.243.8", 10555)
    while True:
        var = c.list()
        print_list(var)
        cmd = input(">>> ")
        tmp_list = cmd.split(" ")
        cmd_list = []
        for one_cmd in tmp_list:
            if len(one_cmd) != 0:
                cmd_list.append(one_cmd)
        if len(cmd_list) == 0:
            continue
        start_time = time.time()
        try:
            if cmd_list[0] == "print":
                if len(cmd_list) != 2: