Commit 2385ef94 authored by ymir's avatar ymir

use GZIP common reference

parent ff80384a
......@@ -9,10 +9,12 @@ from requests import post, get, put, patch, delete
from json import dumps
from enum import Enum, unique
import sys
from neuralnetworkcommon.service import ContentType, TrainerResourceType
# contants
currentDirectory = realpath(__file__).rsplit(sep, 1)[0]
configurationFile=join(currentDirectory,"conf","neuralnetworktrainercli.conf")
extraHelpFile=join(currentDirectory,"help","neuralnetworktrainercli.sh")
GZIP = {"Content-Type": ContentType.GZIP.value}
@unique
class ActionType(Enum):
RANDOMIZE="randomize"
......@@ -30,10 +32,6 @@ class ResourceType(Enum):
TRAININGSET="trainingset"
TRAININGSESSION="trainingsession"
TRAINER="trainer"
@unique
class ContentType(Enum):
JSON = {"Content-Type": "application/json"}
GZIP = {"Content-Type": "application/gzip"}
# load configuration
configurationLoader.loadConfiguration(configurationFile)
configuration=configurationLoader.loadedConfiguration["service"]
......@@ -75,20 +73,20 @@ def loadArchive(archive):
def randomizePerceptron(dimensions,comments,archive):
URL=baseURL+"/perceptron/random"
data=dumps({"dimensions":dimensions,"comments":comments})
response = post(URL, data=data, headers=ContentType.GZIP.value)
response = post(URL, data=data, headers=GZIP)
checkresponse(response)
dumpArchive(archive, response.content)
# create
def createPerceptron(archive):
URL=baseURL+"/perceptron"
data=loadArchive(archive)
response = post(URL, data=data, headers=ContentType.GZIP.value)
response = post(URL, data=data, headers=GZIP)
checkresponse(response)
print(response.text)
# read single
def readSinglePerceptron(id,archive):
URL=baseURL+"/perceptron/"+str(id)
response = get(URL, headers=ContentType.GZIP.value)
response = get(URL, headers=GZIP)
checkresponse(response)
dumpArchive(archive, response.content)
# read all
......@@ -101,7 +99,7 @@ def readAllPerceptron():
def updatePerceptron(id,archive):
URL=baseURL+"/perceptron/"+str(id)
data=loadArchive(archive)
response = put(URL, data=data, headers=ContentType.GZIP.value)
response = put(URL, data=data, headers=GZIP)
checkresponse(response)
# patch
def patchPerceptron(id,comments):
......@@ -130,13 +128,13 @@ def deleteAllPerceptron():
def createTrainingSet(archive):
URL=baseURL+"/trainingset"
data=loadArchive(archive)
response = post(URL, data=data, headers=ContentType.GZIP.value)
response = post(URL, data=data, headers=GZIP)
checkresponse(response)
print(response.text)
# read single
def readSingleTrainingSet(id,archive):
URL=baseURL+"/trainingset/"+str(id)
response = get(URL, headers=ContentType.GZIP.value)
response = get(URL, headers=GZIP)
checkresponse(response)
dumpArchive(archive, response.content)
# read all
......@@ -149,7 +147,7 @@ def readAllTrainingSet():
def updateTrainingSet(id,archive):
URL=baseURL+"/trainingset/"+str(id)
data=loadArchive(archive)
response = put(URL, data=data, headers=ContentType.GZIP.value)
response = put(URL, data=data, headers=GZIP)
checkresponse(response)
# patch
def patchTrainingSet(id,comments):
......@@ -178,19 +176,19 @@ def deleteAllTrainingSet():
def randomizeTrainingsession(id,trainingSetId,trainingChunkSize,saveInterval,testRatio,comments,archive):
URL=baseURL+"/perceptron/"+str(id)+"/trainingsession/random"
data=dumps({"trainingSetId":trainingSetId,"trainingChunkSize":trainingChunkSize,"saveInterval":saveInterval,"testRatio":testRatio,"comments":comments})
response = post(URL, data=data, headers=ContentType.GZIP.value)
response = post(URL, data=data, headers=GZIP)
checkresponse(response)
dumpArchive(archive, response.content)
# create
def createTrainingsession(id,archive):
URL=baseURL+"/perceptron/"+str(id)+"/trainingsession"
data=loadArchive(archive)
response = post(URL, data=data, headers=ContentType.GZIP.value)
response = post(URL, data=data, headers=GZIP)
checkresponse(response)
# read single
def readSingleTrainingsession(id,archive):
URL=baseURL+"/perceptron/"+str(id)+"/trainingsession"
response = get(URL, headers=ContentType.GZIP.value)
response = get(URL, headers=GZIP)
checkresponse(response)
dumpArchive(archive, response.content)
# read all
......@@ -203,7 +201,7 @@ def readAllTrainingsession():
def updateTrainingsession(id,archive):
URL=baseURL+"/perceptron/"+str(id)+"/trainingsession"
data=loadArchive(archive)
response = put(URL, data=data, headers=ContentType.GZIP.value)
response = put(URL, data=data, headers=GZIP)
checkresponse(response)
# patch
def patchTrainingsession(id,trainingChunkSize,saveInterval,comments):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment