Пример #1
0
def test():
    callback = request.GET.get('callback')
    classifier_name = request.GET.get('classifier_name')
    classifier_dump = request.GET.get('classifier')
    collection_id = request.GET.get('collection_id')
    print("Params :")
    print(classifier_name)
    features_train, labels_train = wtf.getArrays(collection_id)
    clf = pickle.loads(classifier_dump)
    preditions, accuracy, recall, precision = classifier.test(clf = clf, features = features_train, labels = labels_train)
    print("Test :")
    print("accuracy" + accuracy)
    print("precision" + precision)
    print("recall" + recall)
    data1 = test_data_to_send(classifier_id, 0, " ", precision, accuracy, recall)
    post.send("http://localhost:8080/dataprocessing/rest-api","/result_test_classifier","",data1)

    return '{0}({1})'.format(callback, {'a':1, 'b':2})
Пример #2
0
def test():
    callback = request.GET.get('callback')
    classifier_name = request.GET.get('classifier_name')
    classifier_dump = request.GET.get('classifier')
    collection_id = request.GET.get('collection_id')
    print("Params :")
    print(classifier_name)
    features_train, labels_train = wtf.getArrays(collection_id)
    clf = pickle.loads(classifier_dump)
    preditions, accuracy, recall, precision = classifier.test(
        clf=clf, features=features_train, labels=labels_train)
    print("Test :")
    print("accuracy" + accuracy)
    print("precision" + precision)
    print("recall" + recall)
    data1 = test_data_to_send(classifier_id, 0, " ", precision, accuracy,
                              recall)
    post.send("http://localhost:8080/dataprocessing/rest-api",
              "/result_test_classifier", "", data1)

    return '{0}({1})'.format(callback, {'a': 1, 'b': 2})
Пример #3
0
def clientThread(clientSocket, address):

    doc_type = ''
    while True:

        msg = recvall(clientSocket)
        msg_data = msg.split('\r\n\r\n'.encode())
        headers = msg_data[0]

        try:
            header = headers.decode()
        except UnicodeDecodeError:
            pass

        try:
            pieces = header.split('\n')
        except AttributeError:
            pass

        if len(msg) != 0:
            if len(pieces) > 0:
                request = pieces[0].split(' ')

            #GET request
            if request[0] == 'GET':
                for line in pieces:
                    header = line.split(':')
                    if header[0] == 'Accept-Encoding':
                        encoding = header[1].strip()
                        break
                    else:
                        encoding = ''

                if request[1].find('.png') == -1 and request[1].find(
                        '.jpg') == -1:
                    response_html = GET.get(pieces, address)

                    try:
                        if ((encoding == 'zlib' or encoding == 'gzip')
                                and response_html.find('404') < 0
                                and response_html.find('406') < 0):
                            clientSocket.sendall(response_html)
                        else:
                            clientSocket.sendall(response_html.encode())

                    except (TypeError, BrokenPipeError):
                        try:
                            clientSocket.sendall(response_html)
                        except TypeError:
                            clientSocket.sendall(response_html.encode())

                else:
                    try:
                        response_html, response_image = GET.get(
                            pieces, address)
                        try:
                            clientSocket.sendall(response_html.encode() +
                                                 response_image)
                        except BrokenPipeError:
                            pass

                    except ValueError:
                        response_html = GET.get(pieces, address)
                        try:
                            clientSocket.sendall(response_html.encode())
                        except BrokenPipeError:
                            pass

            #HEAD request
            elif request[0] == 'HEAD':
                response_html = HEAD.head(pieces, address)
                clientSocket.sendall(response_html.encode())

            #DELETE request
            elif request[0] == 'DELETE':
                if request[1].find('.png') == -1 and request[1].find(
                        '.jpg') == -1:
                    response_html = DELETE.delete(pieces, address)
                    try:
                        clientSocket.sendall(response_html.encode())
                    except BrokenPipeError:
                        pass

                else:
                    try:
                        response_html, response_image = DELETE.delete(
                            pieces, address)
                        try:
                            clientSocket.sendall(response_html.encode() +
                                                 response_image)
                        except BrokenPipeError:
                            pass

                    except ValueError:
                        response_html = DELETE.delete(pieces, address)
                        try:
                            clientSocket.sendall(response_html.encode())
                        except BrokenPipeError:
                            pass

            elif request[0] == 'PUT':
                for line in pieces:
                    header = line.split(':')
                    if header[0] == 'Content-Type':
                        doc_type = header[1]
                        break

                if doc_type.find('html') >= 0 or doc_type.find('plain') >= 0:
                    payload = msg_data[1].decode()
                    response_html = PUT.put(pieces, address, payload)
                    try:
                        clientSocket.sendall(response_html.encode())
                    except BrokenPipeError:
                        pass

                else:
                    try:
                        payload = msg_data[1]
                    except IndexError:
                        pass

                    try:
                        response_html, response_image = PUT.put(
                            pieces, address, payload)
                        try:
                            clientSocket.sendall(response_html.encode() +
                                                 response_image)
                        except BrokenPipeError:
                            pass

                    except ValueError:
                        response_html = PUT.put(pieces, address, '')
                        try:
                            clientSocket.sendall(response_html.encode())
                        except BrokenPipeError:
                            pass

            elif request[0] == 'POST':

                payload = msg_data[1].decode()
                response_html = POST.post(pieces, address, payload)
                try:
                    clientSocket.sendall(response_html.encode())
                except BrokenPipeError:
                    pass
            try:
                clientSocket.shutdown(socket.SHUT_RDWR)
            except OSError:
                #Transport endpoint not connected
                pass
        else:
            clientSocket.close()
            remove(clientSocket)
            break
Пример #4
0
def preds_to_send(questionId, documentId, value, range):
    data ={
        "userId" : "2",
        "questionId" : questionId,
        "documentId" : documentId,
        "value" : value,
        "range" : range,
    }
    return data

def test_data_to_send(classifierId, vectoriziedDocumentCollectionId, parameter, precision, accuracy, recall):
    data ={
        "classifierId" : classifierId,
        "vectoriziedDocumentCollectionId" : vectoriziedDocumentCollectionId,
        "parameter" : parameter,
        "precision" : precision,
        "accuracy" : accuracy,
        "recall" : recall
    }
    return data


data1 = test_data_to_send(1, 1, 1)
post.send("http://localhost:8080/dataprocessing/rest-api/resultTestClassifiers",data1)

data2 = preds_to_send(2, 2, -5, 5)
post.send("http://localhost:8080/dataprocessing/rest-api/annotations",data2)

data3 = classfier_to_send(2, 2, 1)
put.send("http://localhost:8080/dataprocessing/rest-api/classifiers/",id,data3)