From a8ae5adf478c797b673c7269f0d89252e11ff1e9 Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Mon, 4 Dec 2017 15:00:46 +0800 Subject: [PATCH] Reorgnize server (#43) * init logdir runs tags and scalars interface * add debug * add one mock data * add dir server * move frontend to server * optimizer python package * add mock data * add back result encode * use application/json as Response type * rm .DS_Store * update mock tags * update mock data --- .gitignore | 2 + bin/visual_dl.py | 73 ------------- setup.py => server/setup.py | 7 +- {visualdl => server/visualdl}/__init__.py | 0 .../visualdl}/frontend/.babelrc | 0 .../visualdl}/frontend/.fecsignore | 0 .../visualdl}/frontend/.fecsrc | 0 .../visualdl}/frontend/.gitignore | 0 .../visualdl}/frontend/mock/example/mock.js | 0 .../visualdl}/frontend/package.json | 0 .../visualdl}/frontend/src/App.san | 0 .../frontend/src/common/fun/downLoadCSV.js | 0 .../visualdl}/frontend/src/home/Home.san | 0 .../visualdl}/frontend/src/home/index.js | 0 .../visualdl}/frontend/src/index.js | 0 .../frontend/src/style/variables.styl | 0 .../visualdl}/frontend/template/index.html | 0 .../frontend/tool/HtmlReplacePlugin.js | 0 .../visualdl}/frontend/tool/build.js | 0 .../visualdl}/frontend/tool/dev-client.js | 0 .../visualdl}/frontend/tool/dev-server.js | 0 .../visualdl}/frontend/tool/entry.js | 0 .../visualdl}/frontend/tool/webpack.config.js | 0 .../frontend/tool/webpack.dev.config.js | 0 .../frontend/tool/webpack.prod.config.js | 0 {visualdl => server/visualdl}/log.py | 0 server/visualdl/mock/__init__.py | 0 server/visualdl/mock/data.py | 101 +++++++++++++++++ server/visualdl/mock/tags.py | 15 +++ server/visualdl/visual_dl.py | 102 ++++++++++++++++++ 30 files changed, 225 insertions(+), 75 deletions(-) delete mode 100644 bin/visual_dl.py rename setup.py => server/setup.py (50%) rename {visualdl => server/visualdl}/__init__.py (100%) rename {visualdl => server/visualdl}/frontend/.babelrc (100%) rename {visualdl => server/visualdl}/frontend/.fecsignore (100%) rename {visualdl => server/visualdl}/frontend/.fecsrc (100%) rename {visualdl => server/visualdl}/frontend/.gitignore (100%) rename {visualdl => server/visualdl}/frontend/mock/example/mock.js (100%) rename {visualdl => server/visualdl}/frontend/package.json (100%) rename {visualdl => server/visualdl}/frontend/src/App.san (100%) rename {visualdl => server/visualdl}/frontend/src/common/fun/downLoadCSV.js (100%) rename {visualdl => server/visualdl}/frontend/src/home/Home.san (100%) rename {visualdl => server/visualdl}/frontend/src/home/index.js (100%) rename {visualdl => server/visualdl}/frontend/src/index.js (100%) rename {visualdl => server/visualdl}/frontend/src/style/variables.styl (100%) rename {visualdl => server/visualdl}/frontend/template/index.html (100%) rename {visualdl => server/visualdl}/frontend/tool/HtmlReplacePlugin.js (100%) rename {visualdl => server/visualdl}/frontend/tool/build.js (100%) rename {visualdl => server/visualdl}/frontend/tool/dev-client.js (100%) rename {visualdl => server/visualdl}/frontend/tool/dev-server.js (100%) rename {visualdl => server/visualdl}/frontend/tool/entry.js (100%) rename {visualdl => server/visualdl}/frontend/tool/webpack.config.js (100%) rename {visualdl => server/visualdl}/frontend/tool/webpack.dev.config.js (100%) rename {visualdl => server/visualdl}/frontend/tool/webpack.prod.config.js (100%) rename {visualdl => server/visualdl}/log.py (100%) create mode 100644 server/visualdl/mock/__init__.py create mode 100644 server/visualdl/mock/data.py create mode 100644 server/visualdl/mock/tags.py create mode 100644 server/visualdl/visual_dl.py diff --git a/.gitignore b/.gitignore index 7bbc71c0..4f61b8cb 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,5 @@ ENV/ # mypy .mypy_cache/ + +.DS_Store diff --git a/bin/visual_dl.py b/bin/visual_dl.py deleted file mode 100644 index 7d2121a7..00000000 --- a/bin/visual_dl.py +++ /dev/null @@ -1,73 +0,0 @@ -""" entry point of visual_dl -""" -import json -import os -import sys -from optparse import OptionParser - -from flask import Flask, redirect -from flask import send_from_directory - -from visualdl.log import logger - -app = Flask(__name__, static_url_path="") - - -def option_parser(): - """ - - :return: - """ - parser = OptionParser(usage="usage: visual_dl visual_dl.py "\ - "-p port [options]") - parser.add_option( - "-p", - "--port", - default=8040, - action="store", - dest="port", - help="rest api service port") - return parser.parse_args() - - -# return data -# status, msg, data -def gen_result(status, msg): - """ - - :param status: - :param msg: - :return: - """ - result = dict() - result['status'] = status - result['msg'] = msg - result['data'] = {} - return result - - -server_path = os.path.abspath(os.path.dirname(sys.argv[0])) -static_file_path = "../visualdl/frontend/dist/" - - -@app.route('/static/') -def serve_static(filename): - return send_from_directory( - os.path.join(server_path, static_file_path), filename) - - -@app.route("/") -def index(): - return redirect('/static/index.html', code=302) - - -@app.route('/hello') -def hello(): - result = gen_result(0, "Hello, this is VisualDL!") - return json.dumps(result) - - -if __name__ == '__main__': - options, args = option_parser() - logger.info(" port=" + str(options.port)) - app.run(debug=False, host="0.0.0.0", port=options.port) diff --git a/setup.py b/server/setup.py similarity index 50% rename from setup.py rename to server/setup.py index 7865a873..6b8c71ed 100644 --- a/setup.py +++ b/server/setup.py @@ -1,10 +1,13 @@ from setuptools import setup +packages = ['visualdl', 'visualdl.frontend.dist', 'visualdl.mock'] + setup( name="visualdl", version="0.0.1", - packages=['visualdl'], + packages=packages, + package_data={'visualdl.frontend.dist': ['*', 'fonts/*']}, include_package_data=True, install_requires=['flask>=0.12.1'], url='http://www.baidu.com/', - license='Apache 2.0', ) + license='Apache 2.0') diff --git a/visualdl/__init__.py b/server/visualdl/__init__.py similarity index 100% rename from visualdl/__init__.py rename to server/visualdl/__init__.py diff --git a/visualdl/frontend/.babelrc b/server/visualdl/frontend/.babelrc similarity index 100% rename from visualdl/frontend/.babelrc rename to server/visualdl/frontend/.babelrc diff --git a/visualdl/frontend/.fecsignore b/server/visualdl/frontend/.fecsignore similarity index 100% rename from visualdl/frontend/.fecsignore rename to server/visualdl/frontend/.fecsignore diff --git a/visualdl/frontend/.fecsrc b/server/visualdl/frontend/.fecsrc similarity index 100% rename from visualdl/frontend/.fecsrc rename to server/visualdl/frontend/.fecsrc diff --git a/visualdl/frontend/.gitignore b/server/visualdl/frontend/.gitignore similarity index 100% rename from visualdl/frontend/.gitignore rename to server/visualdl/frontend/.gitignore diff --git a/visualdl/frontend/mock/example/mock.js b/server/visualdl/frontend/mock/example/mock.js similarity index 100% rename from visualdl/frontend/mock/example/mock.js rename to server/visualdl/frontend/mock/example/mock.js diff --git a/visualdl/frontend/package.json b/server/visualdl/frontend/package.json similarity index 100% rename from visualdl/frontend/package.json rename to server/visualdl/frontend/package.json diff --git a/visualdl/frontend/src/App.san b/server/visualdl/frontend/src/App.san similarity index 100% rename from visualdl/frontend/src/App.san rename to server/visualdl/frontend/src/App.san diff --git a/visualdl/frontend/src/common/fun/downLoadCSV.js b/server/visualdl/frontend/src/common/fun/downLoadCSV.js similarity index 100% rename from visualdl/frontend/src/common/fun/downLoadCSV.js rename to server/visualdl/frontend/src/common/fun/downLoadCSV.js diff --git a/visualdl/frontend/src/home/Home.san b/server/visualdl/frontend/src/home/Home.san similarity index 100% rename from visualdl/frontend/src/home/Home.san rename to server/visualdl/frontend/src/home/Home.san diff --git a/visualdl/frontend/src/home/index.js b/server/visualdl/frontend/src/home/index.js similarity index 100% rename from visualdl/frontend/src/home/index.js rename to server/visualdl/frontend/src/home/index.js diff --git a/visualdl/frontend/src/index.js b/server/visualdl/frontend/src/index.js similarity index 100% rename from visualdl/frontend/src/index.js rename to server/visualdl/frontend/src/index.js diff --git a/visualdl/frontend/src/style/variables.styl b/server/visualdl/frontend/src/style/variables.styl similarity index 100% rename from visualdl/frontend/src/style/variables.styl rename to server/visualdl/frontend/src/style/variables.styl diff --git a/visualdl/frontend/template/index.html b/server/visualdl/frontend/template/index.html similarity index 100% rename from visualdl/frontend/template/index.html rename to server/visualdl/frontend/template/index.html diff --git a/visualdl/frontend/tool/HtmlReplacePlugin.js b/server/visualdl/frontend/tool/HtmlReplacePlugin.js similarity index 100% rename from visualdl/frontend/tool/HtmlReplacePlugin.js rename to server/visualdl/frontend/tool/HtmlReplacePlugin.js diff --git a/visualdl/frontend/tool/build.js b/server/visualdl/frontend/tool/build.js similarity index 100% rename from visualdl/frontend/tool/build.js rename to server/visualdl/frontend/tool/build.js diff --git a/visualdl/frontend/tool/dev-client.js b/server/visualdl/frontend/tool/dev-client.js similarity index 100% rename from visualdl/frontend/tool/dev-client.js rename to server/visualdl/frontend/tool/dev-client.js diff --git a/visualdl/frontend/tool/dev-server.js b/server/visualdl/frontend/tool/dev-server.js similarity index 100% rename from visualdl/frontend/tool/dev-server.js rename to server/visualdl/frontend/tool/dev-server.js diff --git a/visualdl/frontend/tool/entry.js b/server/visualdl/frontend/tool/entry.js similarity index 100% rename from visualdl/frontend/tool/entry.js rename to server/visualdl/frontend/tool/entry.js diff --git a/visualdl/frontend/tool/webpack.config.js b/server/visualdl/frontend/tool/webpack.config.js similarity index 100% rename from visualdl/frontend/tool/webpack.config.js rename to server/visualdl/frontend/tool/webpack.config.js diff --git a/visualdl/frontend/tool/webpack.dev.config.js b/server/visualdl/frontend/tool/webpack.dev.config.js similarity index 100% rename from visualdl/frontend/tool/webpack.dev.config.js rename to server/visualdl/frontend/tool/webpack.dev.config.js diff --git a/visualdl/frontend/tool/webpack.prod.config.js b/server/visualdl/frontend/tool/webpack.prod.config.js similarity index 100% rename from visualdl/frontend/tool/webpack.prod.config.js rename to server/visualdl/frontend/tool/webpack.prod.config.js diff --git a/visualdl/log.py b/server/visualdl/log.py similarity index 100% rename from visualdl/log.py rename to server/visualdl/log.py diff --git a/server/visualdl/mock/__init__.py b/server/visualdl/mock/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/server/visualdl/mock/data.py b/server/visualdl/mock/data.py new file mode 100644 index 00000000..bca178f4 --- /dev/null +++ b/server/visualdl/mock/data.py @@ -0,0 +1,101 @@ +def sequence_data(): + return [[1465980660.726887, 1, 0.07000000029802322], + [1465980660.767164, 2, 0.18000000715255737], + [1465980660.799817, 3, 0.3199999928474426], + [1465980660.831853, 4, 0.33000001311302185], + [1465980660.86555, 5, 0.3400000035762787], + [1465980660.898716, 6, 0.6000000238418579], + [1465980660.930804, 7, 0.6299999952316284], + [1465980660.963156, 8, 0.6299999952316284], + [1465980660.995727, 9, 0.6299999952316284], + [1465980661.603699, 11, 0.75], + [1465980661.641232, 12, 0.7900000214576721], + [1465980661.674311, 13, 0.7099999785423279], + [1465980661.704281, 14, 0.7099999785423279], + [1465980661.737259, 15, 0.7200000286102295], + [1465980661.768047, 16, 0.75], + [1465980661.801236, 17, 0.8600000143051147], + [1465980661.832749, 18, 0.7799999713897705], + [1465980661.862822, 19, 0.8399999737739563], + [1465980662.481258, 21, 0.699999988079071], + [1465980662.521448, 22, 0.6700000166893005], + [1465980662.557197, 23, 0.7699999809265137], + [1465980662.593898, 24, 0.7900000214576721], + [1465980662.629991, 25, 0.7200000286102295], + [1465980662.671198, 26, 0.8100000023841858], + [1465980662.711186, 27, 0.7599999904632568], + [1465980662.750267, 28, 0.7799999713897705], + [1465980662.791909, 29, 0.8299999833106995], + [1465980663.47027, 31, 0.8100000023841858], + [1465980663.538732, 32, 0.8500000238418579], + [1465980663.57077, 33, 0.8600000143051147], + [1465980663.60126, 34, 0.8199999928474426], + [1465980663.631059, 35, 0.7900000214576721], + [1465980663.665972, 36, 0.7799999713897705], + [1465980663.697275, 37, 0.9100000262260437], + [1465980663.726395, 38, 0.8700000047683716], + [1465980663.760169, 39, 0.9200000166893005], + [1465980664.45205, 41, 0.8299999833106995], + [1465980664.484207, 42, 0.7599999904632568], + [1465980664.515375, 43, 0.7699999809265137], + [1465980664.547608, 44, 0.8299999833106995], + [1465980664.580122, 45, 0.949999988079071], + [1465980664.611019, 46, 0.8999999761581421], + [1465980664.642956, 47, 0.8700000047683716], + [1465980664.674636, 48, 0.8500000238418579], + [1465980664.705622, 49, 0.8899999856948853], + [1465980665.379549, 51, 0.8399999737739563], + [1465980665.422869, 52, 0.8500000238418579], + [1465980665.466136, 53, 0.8199999928474426], + [1465980665.508361, 54, 0.9300000071525574], + [1465980665.544331, 55, 0.9399999976158142], + [1465980665.589887, 56, 0.8700000047683716], + [1465980665.633466, 57, 0.9300000071525574], + [1465980665.674978, 58, 0.7799999713897705], + [1465980665.716878, 59, 0.9300000071525574], + [1465980666.653456, 61, 0.8799999952316284], + [1465980666.697294, 62, 0.9300000071525574], + [1465980666.742066, 63, 0.8700000047683716], + [1465980666.780127, 64, 0.8299999833106995], + [1465980666.818287, 65, 0.9200000166893005], + [1465980666.855386, 66, 0.9399999976158142], + [1465980666.897352, 67, 0.9300000071525574], + [1465980666.931322, 68, 0.8899999856948853], + [1465980666.96562, 69, 0.8600000143051147], + [1465980667.619625, 71, 0.8700000047683716], + [1465980667.655166, 72, 0.9200000166893005], [ + 1465980667.687101, 73, 0.8199999928474426 + ], [1465980667.720176, 74, 0.8100000023841858], + [1465980667.751985, 75, 0.8500000238418579], [ + 1465980667.785244, 76, 0.8600000143051147 + ], [1465980667.820445, 77, 0.9200000166893005], [ + 1465980667.857163, 78, 0.8899999856948853 + ], [1465980667.891868, 79, 0.8999999761581421], [ + 1465980668.56409, 81, 0.8500000238418579 + ], [1465980668.599529, 82, 0.8299999833106995], [ + 1465980668.630751, 83, 0.8500000238418579 + ], [1465980668.665135, 84, 0.8199999928474426], [ + 1465980668.697928, 85, 0.8199999928474426 + ], [1465980668.730525, 86, 0.8799999952316284], [ + 1465980668.769772, 87, 0.9200000166893005 + ], [1465980668.803344, 88, 0.8299999833106995], [ + 1465980668.834414, 89, 0.800000011920929 + ], [1465980669.814826, 91, 0.8600000143051147], [ + 1465980669.851511, 92, 0.8899999856948853 + ], [1465980669.891407, 93, 0.8799999952316284], [ + 1465980669.927507, 94, 0.9399999976158142 + ], [1465980669.968384, 95, 0.9300000071525574], [ + 1465980670.007071, 96, 0.8500000238418579 + ], [1465980670.044314, 97, 0.8500000238418579], [ + 1465980670.083472, 98, 0.9100000262260437 + ], [1465980670.214597, 99, 0.8600000143051147], [ + 1465980670.934513, 101, 0.8799999952316284 + ], [1465980670.971317, 102, 0.8700000047683716], [ + 1465980671.003626, 103, 0.8600000143051147 + ], [1465980671.037037, 104, 0.8399999737739563], [ + 1465980671.070037, 105, 0.9200000166893005 + ], [1465980671.104992, 106, 0.8600000143051147], [ + 1465980671.137882, 107, 0.8100000023841858 + ], [1465980671.173917, 108, 0.7400000095367432], [ + 1465980671.205898, 109, 0.8799999952316284 + ], [1465980671.833723, 111, 0.9100000262260437]] diff --git a/server/visualdl/mock/tags.py b/server/visualdl/mock/tags.py new file mode 100644 index 00000000..f37de69c --- /dev/null +++ b/server/visualdl/mock/tags.py @@ -0,0 +1,15 @@ +def data(): + return { + "test": { + "min/layer2/weights": { + "displayName": "min/layer2/weights", + "description": "" + } + }, + "train": { + "min/layer2/weights": { + "displayName": "min/layer2/weights", + "description": "" + } + } + } diff --git a/server/visualdl/visual_dl.py b/server/visualdl/visual_dl.py new file mode 100644 index 00000000..ec440a4e --- /dev/null +++ b/server/visualdl/visual_dl.py @@ -0,0 +1,102 @@ +""" entry point of visual_dl +""" +import json +import os +import sys +from optparse import OptionParser + +from flask import Flask, redirect +from flask import request +from flask import send_from_directory +from flask import Response + +from visualdl.log import logger +import visualdl.mock.data as mock_data +import visualdl.mock.tags as mock_tags + +app = Flask(__name__, static_url_path="") + + +def option_parser(): + """ + + :return: + """ + parser = OptionParser(usage="usage: visual_dl visual_dl.py "\ + "-p port [options]") + parser.add_option( + "-p", + "--port", + default=8040, + action="store", + dest="port", + help="rest api service port") + parser.add_option( + "--logdir", action="store", dest="logdir", help="log file directory") + return parser.parse_args() + + +options, args = option_parser() +server_path = os.path.abspath(os.path.dirname(sys.argv[0])) +static_file_path = "./frontend/dist/" +mock_data_path = "./mock_data/" + + +# return data +# status, msg, data +def gen_result(status, msg, data): + """ + :param status: + :param msg: + :return: + """ + result = dict() + result['status'] = status + result['msg'] = msg + result['data'] = data + return result + + +@app.route("/") +def index(): + return redirect('/static/index.html', code=302) + + +@app.route('/static/') +def serve_static(filename): + return send_from_directory( + os.path.join(server_path, static_file_path), filename) + + +@app.route('/data/logdir') +def logdir(): + result = gen_result(0, "", {"logdir": options.logdir}) + return Response(json.dumps(result), mimetype='application/json') + + +@app.route('/data/runs') +def runs(): + is_debug = bool(request.args.get('debug')) + result = gen_result(0, "", ["train", "test"]) + return Response(json.dumps(result), mimetype='application/json') + + +@app.route("/data/plugin/scalars/tags") +def tags(): + is_debug = bool(request.args.get('debug')) + result = gen_result(0, "", mock_tags.data()) + return Response(json.dumps(result), mimetype='application/json') + + +@app.route('/data/plugin/scalars/scalars') +def scalars(): + run = request.args.get('run') + tag = request.args.get('tag') + is_debug = bool(request.args.get('debug')) + result = gen_result(0, "", mock_data.sequence_data()) + return Response(json.dumps(result), mimetype='application/json') + + +if __name__ == '__main__': + logger.info(" port=" + str(options.port)) + app.run(debug=False, host="0.0.0.0", port=options.port) -- GitLab