提交 b632c19f 编写于 作者: S superjom

image service ready

fix most bugs

waiting for frontend to fix interfaces
上级 401e139b
...@@ -21,6 +21,18 @@ def get_scalar_tags(storage, mode): ...@@ -21,6 +21,18 @@ def get_scalar_tags(storage, mode):
return result return result
def get_scalar(storage, mode, tag):
reader = storage.as_mode(mode)
scalar = reader.scalar(tag)
records = scalar.records()
ids = scalar.ids()
timestamps = scalar.timestamps()
result = zip(timestamps, ids, records)
return result
def get_image_tags(storage, mode): def get_image_tags(storage, mode):
result = {} result = {}
...@@ -31,16 +43,17 @@ def get_image_tags(storage, mode): ...@@ -31,16 +43,17 @@ def get_image_tags(storage, mode):
result[mode] = {} result[mode] = {}
for tag in reader.tags('image'): for tag in reader.tags('image'):
image = reader.image(tag) image = reader.image(tag)
if image.num_samples() == 1: if image.num_samples() <= 1:
result[mode][tag] = { result[mode][tag] = {
'displayName': mage.caption(), 'displayName': image.caption(),
'description': "", 'description': "",
'samples': 1, 'samples': 1,
} }
else: else:
for i in xrange(image.num_samples()): for i in xrange(image.num_samples()):
result[mode][tag + '/%d' % i] = { caption = tag + '/%d' % i
'displayName': image.caption(), result[mode][caption] = {
'displayName': caption,
'description': "", 'description': "",
'samples': 1, 'samples': 1,
} }
...@@ -51,6 +64,7 @@ def get_image_tag_steps(storage, mode, tag): ...@@ -51,6 +64,7 @@ def get_image_tag_steps(storage, mode, tag):
# remove suffix '/x' # remove suffix '/x'
res = re.search(r".*/([0-9]+$)", tag) res = re.search(r".*/([0-9]+$)", tag)
step_index = 0 step_index = 0
origin_tag = tag
if res: if res:
tag = tag[:tag.rfind('/')] tag = tag[:tag.rfind('/')]
step_index = int(res.groups()[0]) step_index = int(res.groups()[0])
...@@ -65,7 +79,7 @@ def get_image_tag_steps(storage, mode, tag): ...@@ -65,7 +79,7 @@ def get_image_tag_steps(storage, mode, tag):
query = urllib.urlencode({ query = urllib.urlencode({
'sample': 0, 'sample': 0,
'index': i, 'index': i,
'tag': tag, 'tag': origin_tag,
'run': mode, 'run': mode,
}) })
res.append({ res.append({
......
...@@ -2,5 +2,7 @@ ...@@ -2,5 +2,7 @@
set -ex set -ex
export PYTHONPATH="$(pwd)/..:/home/superjom/project/VisualDL/build/visualdl/logic:/home/superjom/project/VisualDL/visualdl/python" export PYTHONPATH="$(pwd)/..:/home/superjom/project/VisualDL/build/visualdl/logic:/home/superjom/project/VisualDL/visualdl/python"
export FLASK_APP=visual_dl.py
export FLASK_DEBUG=1
python visual_dl.py --logdir ./tmp/mock --host 172.23.233.68 python visual_dl.py --logdir ./tmp/mock --host 172.23.233.68 --port 8041
...@@ -95,7 +95,8 @@ def runs(): ...@@ -95,7 +95,8 @@ def runs():
@app.route("/data/plugin/scalars/tags") @app.route("/data/plugin/scalars/tags")
def tags(): def scalar_tags():
mode = request.args.get('mode')
is_debug = bool(request.args.get('debug')) is_debug = bool(request.args.get('debug'))
if is_debug: if is_debug:
result = mock_tags.data() result = mock_tags.data()
...@@ -107,7 +108,8 @@ def tags(): ...@@ -107,7 +108,8 @@ def tags():
@app.route("/data/plugin/images/tags") @app.route("/data/plugin/images/tags")
def tags(): def image_tags():
mode = request.args.get('mode')
result = lib.get_image_tags(storage, mode) result = lib.get_image_tags(storage, mode)
print 'tags', result print 'tags', result
result = gen_result(0, "", result) result = gen_result(0, "", result)
...@@ -120,39 +122,33 @@ def scalars(): ...@@ -120,39 +122,33 @@ def scalars():
tag = request.args.get('tag') tag = request.args.get('tag')
is_debug = bool(request.args.get('debug')) is_debug = bool(request.args.get('debug'))
if is_debug: if is_debug:
result = gen_result(0, "", mock_data.sequence_data()) result = mock_data.sequence_data()
else: else:
reader = storage.as_mode(run) result = lib.get_scalar(storage, run, tag)
scalar = reader.scalar(tag)
records = scalar.records()
ids = scalar.ids()
timestamps = scalar.timestamps()
result = zip(timestamps, ids, records)
result = gen_result(0, "", result)
result = gen_result(0, "", result)
return Response(json.dumps(result), mimetype='application/json') return Response(json.dumps(result), mimetype='application/json')
@app.route('/data/plugin/images/images') @app.route('/data/plugin/images/images')
def images(): def images():
run = request.args.get('run') mode = request.args.get('run')
tag = request.args.get('tag') #tag = request.args.get('tag')
tag = request.args.get('displayName')
res = lib.gen_image_tag_steps(storage, mode, tag) result = lib.get_image_tag_steps(storage, mode, tag)
return Response(json.dumps(result), mimetype='application/json') return Response(json.dumps(result), mimetype='application/json')
@app.route('/data/plugin/images/individualImage') @app.route('/data/plugin/images/individualImage')
def individual_image(): def individual_image():
run = request.args.get('run') mode = request.args.get('run')
tag = request.args.get('tag') # include a index tag = request.args.get('tag') # include a index
index = request.args.get('index') # index of step step_index = request.args.get('index') # index of step
offset = 0 offset = 0
imagefile = lib.get_invididual_image(storage, mode, tag) imagefile = lib.get_invididual_image(storage, mode, tag, step_)
response = send_file( response = send_file(
imagefile, as_attachment=True, attachment_filename='img.png') imagefile, as_attachment=True, attachment_filename='img.png')
return response return response
...@@ -160,4 +156,4 @@ def individual_image(): ...@@ -160,4 +156,4 @@ def individual_image():
if __name__ == '__main__': if __name__ == '__main__':
logger.info(" port=" + str(options.port)) logger.info(" port=" + str(options.port))
app.run(debug=False, host=options.host, port=options.port) app.run(debug=True, host=options.host, port=options.port)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册