Skip to content

Commit

Permalink
Merge pull request #5 from maubreville/master
Browse files Browse the repository at this point in the history
Changes to the I/F in EXACT (see PR)
  • Loading branch information
ChristianMarzahl authored Mar 27, 2023
2 parents f798122 + ac0ef81 commit 444f1b8
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 99 deletions.
43 changes: 14 additions & 29 deletions exact_sync/exact_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import re
import sys
from functools import partial
import threading
import queue
from tqdm import tqdm
from requests_toolbelt.multipart import encoder

Expand All @@ -33,23 +31,13 @@ def dict(self) -> dict:

class ExactManager():

def __init__(self, username:str=None, password:str=None, serverurl:str=None, logfile=sys.stdout, loglevel:int=1, statusqueue:queue.Queue=None):
def __init__(self, username:str=None, password:str=None, serverurl:str=None, logfile=sys.stdout, loglevel:int=1):
self.username = username
self.password = password
self.serverurl = serverurl if serverurl[-1]=='/' else serverurl+'/'
self.statusqueue = statusqueue
self.progress_denominator = 1
self.progress_offset = 0
self.set_progress_properties(1,0)
self.multi_threaded=True
self.num_threads=10
if (self.multi_threaded):
self.jobqueue = queue.Queue()
self.resultQueue = queue.Queue()
self.workers={}
for k in range(self.num_threads):
self.workers[k] = threading.Thread(target=self.queueWorker, daemon=True)
self.workers[k].start()

self.logfile = logfile
self.loglevel = loglevel
Expand All @@ -67,32 +55,16 @@ def log(self,level, *args):
logmsg=' '.join([str(x) for x in args])
if level>=self.loglevel:
self.logfile.write( '%s ' % str(datetime.datetime.now()) + logmsg +'\n')
if (self.statusqueue is not None) and (level>1):
self.statusqueue.put((1, logmsg))

def progress(self, value:float, callback:callable=None):
value=value/self.progress_denominator+self.offset
if (self.statusqueue is not None):
self.statusqueue.put((0, value*100 if value<1 else -1))
if (callback is not None):
callback(value*100)

def set_progress_properties(self, denominator:float, offset:float):
self.progress_denominator=float(denominator)
self.offset=float(offset)

def queueWorker(self):
while (True):
status, newjob, context = self.jobqueue.get()
if (status==-1):
# print('Stopping worker')
break
ret = newjob()
self.resultQueue.put((ret, context))

def terminate(self):
for k in range(self.num_threads):
self.jobqueue.put((-1,0,0))

def create_progressbar(self, e:encoder.MultipartEncoder):

Expand Down Expand Up @@ -197,6 +169,19 @@ def create_annotation(self, image_id:int, annotationtype_id:int, vector:list, la
else:
self.log(10,'Unable to create annotation, message was: '+ret)
raise ExactProcessError('Unable to create annotation')

def submit_job(self, image_id:int, plugin_id:int):
data = {
'image_id': image_id,
'plugin_id' : plugin_id,
}

status, ret = self.post('processing/api/plugin_job/create/', data=json.dumps(data), headers={'content-type':'application/json'})
if status==201:
return ret
else:
self.log(10,'Unable to create plugin job, message was: '+ret)
raise ExactProcessError('Unable to create plugin job')

def upload_image_to_imageset(self, imageset_id:int, filename:str) -> bool:
e = encoder.MultipartEncoder(fields={'files[]': (os.path.basename(filename), open(filename, 'rb'), 'application/octet-stream')})
Expand Down
110 changes: 61 additions & 49 deletions exact_sync/v1/api/processing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from exact_sync.v1.api_client import ApiClient


class ProcessingApi(PaginationBaseAPI):
"""NOTE: This class is auto generated by the swagger code generator program.
Expand Down Expand Up @@ -84,7 +83,7 @@ def create_plugin_with_http_info(self, **kwargs): # noqa: E501
returns the request thread.
"""

all_params = [ 'id', 'name', 'author', 'contact', 'abouturl', 'icon', 'products', 'results'] # noqa: E501
all_params = [ 'id', 'name', 'author', 'package', 'contact', 'abouturl', 'icon', 'products', 'results'] # noqa: E501
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
Expand All @@ -110,30 +109,15 @@ def create_plugin_with_http_info(self, **kwargs): # noqa: E501

form_params = []
local_var_files = {}

if 'id' in params:
form_params.append(('id', params['id'])) # noqa: E501
if 'name' in params:
form_params.append(('name', params['name'])) # noqa: E501
if 'author' in params:
form_params.append(('author', params['author'])) # noqa: E501
if 'contact' in params:
form_params.append(('contact', params['contact'])) # noqa: E501
if 'abouturl' in params:
form_params.append(('abouturl', params['abouturl'])) # noqa: E501
if 'icon' in params:
local_var_files['icon'] = params['icon'] # noqa: E501
if 'products' in params:
form_params.append(('products', params['products'])) # noqa: E501
collection_formats['products'] = 'multi' # noqa: E501
if 'results' in params:
form_params.append(('results', params['results'])) # noqa: E501
collection_formats['results'] = 'multi' # noqa: E501
if 'id' in params:
form_params.append(('id', params['id'])) # noqa: E501
if 'name' in params:
form_params.append(('name', params['name'])) # noqa: E501
if 'author' in params:
form_params.append(('author', params['author'])) # noqa: E501
if 'package' in params:
form_params.append(('package', params['package'])) # noqa: E501
if 'contact' in params:
form_params.append(('contact', params['contact'])) # noqa: E501
if 'abouturl' in params:
Expand All @@ -147,9 +131,8 @@ def create_plugin_with_http_info(self, **kwargs): # noqa: E501
form_params.append(('results', params['results'])) # noqa: E501
collection_formats['results'] = 'multi' # noqa: E501

body_params = None
if 'body' in params:
body_params = params['body']
body_params = {}

# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501
Expand Down Expand Up @@ -220,6 +203,7 @@ def create_plugin_job_with_http_info(self, **kwargs): # noqa: E501
:param int id:
:param int creator:
:param int plugin:
:param int image:
:param datetime created_time:
:param datetime eta_time:
:param float processing_complete:
Expand All @@ -230,7 +214,7 @@ def create_plugin_job_with_http_info(self, **kwargs): # noqa: E501
returns the request thread.
"""

all_params = ['id', 'creator', 'plugin', 'created_time', 'eta_time', 'processing_complete', 'updated_time', 'result'] # noqa: E501
all_params = ['id', 'body'] # noqa: E501
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
Expand All @@ -256,27 +240,12 @@ def create_plugin_job_with_http_info(self, **kwargs): # noqa: E501

form_params = []
local_var_files = {}
if 'id' in params:
form_params.append(('id', params['id'])) # noqa: E501
if 'creator' in params:
form_params.append(('creator', params['creator'])) # noqa: E501
if 'plugin' in params:
form_params.append(('plugin', params['plugin'])) # noqa: E501
if 'created_time' in params:
form_params.append(('created_time', params['created_time'])) # noqa: E501
if 'eta_time' in params:
form_params.append(('eta_time', params['eta_time'])) # noqa: E501
if 'processing_complete' in params:
form_params.append(('processing_complete', params['processing_complete'])) # noqa: E501
if 'updated_time' in params:
form_params.append(('updated_time', params['updated_time'])) # noqa: E501
if 'result' in params:
form_params.append(('result', params['result'])) # noqa: E501

body_params = None
if 'body' in params:
body_params = params['body']
# HTTP header `Accept`

# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501

Expand All @@ -287,6 +256,8 @@ def create_plugin_job_with_http_info(self, **kwargs): # noqa: E501
# Authentication setting
auth_settings = ['basicAuth'] # noqa: E501

print('Running query with: ',{'path_params':path_params,'query_params':query_params, 'body_params':body_params, 'post_params':form_params})

return self.api_client.call_api(
'/api/v1/processing/pluginjobs/', 'POST',
path_params,
Expand Down Expand Up @@ -487,6 +458,8 @@ def create_plugin_result_annotation_with_http_info(self, **kwargs): # noqa: E50
form_params.append(('meta_data', params['meta_data'])) # noqa: E501
if 'vector' in params:
form_params.append(('vector', params['vector'])) # noqa: E501
if 'score' in params:
form_params.append(('score', params['score'])) # noqa: E501
if 'unique_identifier' in params:
form_params.append(('unique_identifier', params['unique_identifier'])) # noqa: E501
if 'generated' in params:
Expand Down Expand Up @@ -719,6 +692,8 @@ def create_plugin_result_entry_with_http_info(self, **kwargs): # noqa: E501
form_params.append(('name', params['name'])) # noqa: E501
if 'visible' in params:
form_params.append(('visible', params['visible'])) # noqa: E501
if 'default_threshold' in params:
form_params.append(('default_threshold', params['default_threshold'])) # noqa: E501
if 'annotation_results' in params:
form_params.append(('annotation_results', params['annotation_results'])) # noqa: E501
collection_formats['annotation_results'] = 'multi' # noqa: E501
Expand Down Expand Up @@ -1135,6 +1110,7 @@ def partial_update_plugin_result_annotation_with_http_info(self, id, **kwargs):
'pluginresultentry',
'meta_data',
'vector',
'score',
'unique_identifier',
'image',
'time'] # noqa: E501
Expand Down Expand Up @@ -1367,6 +1343,7 @@ def partial_update_plugin_result_entry_with_http_info(self, id, **kwargs): # no
'created_time',
'name',
'visible',
'default_threshold',
'annotation_results',
'bitmap_results'] # noqa: E501
all_params.append('async_req')
Expand Down Expand Up @@ -1476,6 +1453,9 @@ def list_plugin_jobs_with_http_info(self, **kwargs): # noqa: E501
"""

all_params = ['limit', 'offset'] # noqa: E501
all_params.append('image_id')
all_params.append('user_id')
all_params.append('plugin_id')
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
Expand All @@ -1495,11 +1475,20 @@ def list_plugin_jobs_with_http_info(self, **kwargs): # noqa: E501

path_params = {}

query_params = []
query_params = {}
if 'limit' in params:
query_params.append(('limit', params['limit'])) # noqa: E501
query_params['limit'] = params['limit']
#.append(('limit', params['limit'])) # noqa: E501
if 'offset' in params:
query_params.append(('offset', params['offset'])) # noqa: E501
query_params['offset'] = params['offset']
if 'user_id' in params:
query_params['user_id'] = params['user_id']
if 'plugin_id' in params:
query_params['plugin_id'] = params['plugin_id']
if 'image_id' in params:
query_params['image_id'] = params['image_id']

# query_params.append(('offset', params['offset'])) # noqa: E501

header_params = {}

Expand Down Expand Up @@ -1542,6 +1531,8 @@ def list_plugin_result_annotations(self, **kwargs): # noqa: E501
:param async_req bool
:param int limit: Number of results to return per page.
:param int offset: The initial index from which to return the results.
:param int pluginresultentry: id of the plugin result
:param int image: id of the image
:return: PluginResultAnnotations
If the method is called asynchronously,
returns the request thread.
Expand All @@ -1565,13 +1556,16 @@ def list_plugin_result_annotations_with_http_info(self, **kwargs): # noqa: E501
:param async_req bool
:param int limit: Number of results to return per page.
:param int offset: The initial index from which to return the results.
:param int plugin_result_id: id of the plugin result
:return: PluginResultAnnotations
If the method is called asynchronously,
returns the request thread.
"""

all_params = ['limit', 'offset'] # noqa: E501
all_params = ['limit', 'offset','omit'] # noqa: E501
all_params.append('async_req')
all_params.append('image')
all_params.append('pluginresultentry')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
Expand All @@ -1595,6 +1589,12 @@ def list_plugin_result_annotations_with_http_info(self, **kwargs): # noqa: E501
query_params.append(('limit', params['limit'])) # noqa: E501
if 'offset' in params:
query_params.append(('offset', params['offset'])) # noqa: E501
if 'omit' in params:
query_params.append(('omit', params['omit'])) # noqa: E501
if 'image' in params:
query_params.append(('image', params['image'])) # noqa: E501
if 'pluginresultentry' in params:
query_params.append(('pluginresultentry', params['pluginresultentry'])) # noqa: E501

header_params = {}

Expand Down Expand Up @@ -1858,6 +1858,7 @@ def list_plugin_result_entrys_with_http_info(self, **kwargs): # noqa: E501
all_params = ['limit', 'offset'] # noqa: E501
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('pluginresult')
all_params.append('_preload_content')
all_params.append('_request_timeout')

Expand All @@ -1880,6 +1881,8 @@ def list_plugin_result_entrys_with_http_info(self, **kwargs): # noqa: E501
query_params.append(('limit', params['limit'])) # noqa: E501
if 'offset' in params:
query_params.append(('offset', params['offset'])) # noqa: E501
if 'pluginresult' in params:
query_params.append(('pluginresult', params['pluginresult'])) # noqa: E501

header_params = {}

Expand Down Expand Up @@ -1951,6 +1954,9 @@ def list_plugin_results_with_http_info(self, **kwargs): # noqa: E501
"""

all_params = ['limit', 'offset'] # noqa: E501
all_params.append('job_id')
all_params.append('image_id')
all_params.append('plugin_id')
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
Expand All @@ -1973,6 +1979,12 @@ def list_plugin_results_with_http_info(self, **kwargs): # noqa: E501
query_params = []
if 'limit' in params:
query_params.append(('limit', params['limit'])) # noqa: E501
if 'image_id' in params:
query_params.append(('image_id', params['image_id'])) # noqa: E501
if 'plugin_id' in params:
query_params.append(('plugin_id', params['plugin_id'])) # noqa: E501
if 'job_id' in params:
query_params.append(('job_id', params['job_id'])) # noqa: E501
if 'offset' in params:
query_params.append(('offset', params['offset'])) # noqa: E501

Expand Down Expand Up @@ -3407,7 +3419,7 @@ def retrieve_plugin_job_with_http_info(self, id, **kwargs): # noqa: E501
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

def retrieve_plugin_result(self, id, **kwargs): # noqa: E501
def retrieve_plugin_result(self, **kwargs): # noqa: E501
"""retrieve_plugin_result # noqa: E501
API endpoint that allows PluginResultss to be viewed or edited. # noqa: E501
Expand All @@ -3424,12 +3436,12 @@ def retrieve_plugin_result(self, id, **kwargs): # noqa: E501
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async_req'):
return self.retrieve_plugin_result_with_http_info(id, **kwargs) # noqa: E501
return self.retrieve_plugin_result_with_http_info(**kwargs) # noqa: E501
else:
(data) = self.retrieve_plugin_result_with_http_info(id, **kwargs) # noqa: E501
(data) = self.retrieve_plugin_result_with_http_info(**kwargs) # noqa: E501
return data

def retrieve_plugin_result_with_http_info(self, id, **kwargs): # noqa: E501
def retrieve_plugin_result_with_http_info(self, **kwargs): # noqa: E501
"""retrieve_plugin_result # noqa: E501
API endpoint that allows PluginResultss to be viewed or edited. # noqa: E501
Expand Down
Loading

0 comments on commit 444f1b8

Please sign in to comment.