diff --git a/build_wheel.bat b/build_wheel.bat index 5acff78f..b2b46732 100644 --- a/build_wheel.bat +++ b/build_wheel.bat @@ -1,5 +1,6 @@ rem "Before building the wheels, please make sure you have setup-up the environment." rem "for python 3.6/3.7 we need vs++14" +python maro/utils/dashboard/package_data.py pip install -r maro/simulator/requirements.build.txt diff --git a/examples/ecr/q_learning/common/dqn.py b/examples/ecr/q_learning/common/dqn.py index 88f41645..2e01f4df 100644 --- a/examples/ecr/q_learning/common/dqn.py +++ b/examples/ecr/q_learning/common/dqn.py @@ -180,7 +180,6 @@ class DQN(object): for q_values in q_values_batch: for i in range(len(q_values)): scalars = {self._policy_net.name: q_values[i].item()} - scalars[str(i)] = q_values[i].item() self._dashboard.upload_q_value(scalars, current_ep, i) return False, q_values_batch.max(1)[1][0].item() diff --git a/maro/cli/maro.py b/maro/cli/maro.py index 3d75d9b2..3a88f8d6 100644 --- a/maro/cli/maro.py +++ b/maro/cli/maro.py @@ -11,6 +11,7 @@ import os import io import platform import yaml +import subprocess from requests import get from maro.simulator.utils.common import get_available_envs @@ -61,8 +62,8 @@ def main(): parser = argparse.ArgumentParser("maro cli interface") parser.add_argument("--envs", action="store_true", help="Show available environment settings") - parser.add_argument("--dashboard", nargs='?', choices=['unzip', 'start', 'stop', 'no_action'], default='no_action', const='unzip', metavar='ACTION', - help="default or 'unzip' to extract dashboard resources to current folder. 'start' to start dashboard service. 'stop' to stop dashboard service.") + parser.add_argument("--dashboard", nargs='?', choices=['unzip', 'start', 'stop', 'no_action', 'build'], default='no_action', const='unzip', metavar='ACTION', + help="default or 'unzip' to extract dashboard resources to current folder. 'start' to start dashboard service. 'stop' to stop dashboard service. 'build' to build docker for dashboard service.") args = parser.parse_args() @@ -79,8 +80,11 @@ def main(): stop_dashboard() elif args.dashboard == 'no_action': pass + elif args.dashboard == 'build': + print('build') + build_dashboard() else: - print("default or 'unzip' to extract dashboard resources to current folder.\n'start' to start dashboard service.\n'stop' to stop dashboard service.") + print("default or 'unzip' to extract dashboard resources to current folder. 'start' to start dashboard service. 'stop' to stop dashboard service. 'build' to build docker for dashboard service.") def ext_dashboard(): @@ -131,11 +135,11 @@ def start_dashboard(): print(f"Dashboard files not found, aborting...") return if not platform.system() == 'Windows': - os.popen( + os.system( 'mkdir -p ./data/grafana;CURRENT_UID=$(id -u):$(id -g) docker-compose up&') else: - os.popen( - 'powershell.exe -windowstyle hidden "Set-Item -Path Env:CURRENT_UID -Value [Environment]::UserName; docker-compose up"') + subprocess.Popen( + 'powershell.exe -windowstyle hidden "docker-compose up"', shell=True, start_new_session=True) localhosts = [] localhosts.append('localhost') @@ -191,3 +195,34 @@ def stop_dashboard(): os.popen('docker-compose down') else: os.popen('powershell.exe -windowstyle hidden "docker-compose down"') + + + +def build_dashboard(): + ''' + Build docker for dashboard service + + Args: + None. + + Returns: + None. + ''' + + print('Try to build docker for dashboard service.') + cwd = os.getcwd() + all_files_exist = True + for path in ['config', 'panels', 'provisioning', 'templates', 'docker-compose.yml', 'Dockerfile']: + tar_path = os.path.join(cwd, path) + if not os.path.exists(tar_path): + print(f"{tar_path} not found") + all_files_exist = False + if not all_files_exist: + print(f"Dashboard files not found, aborting...") + return + if not platform.system() == 'Windows': + os.system( + 'docker-compose build --no-cache') + else: + subprocess.Popen( + 'powershell.exe -windowstyle hidden "docker-compose build --no-cache"', shell=True, start_new_session=True) diff --git a/maro/utils/dashboard/dashboard_resource/Dockerfile b/maro/utils/dashboard/dashboard_resource/Dockerfile index 297f3fe4..119c67a5 100644 --- a/maro/utils/dashboard/dashboard_resource/Dockerfile +++ b/maro/utils/dashboard/dashboard_resource/Dockerfile @@ -5,8 +5,8 @@ WORKDIR /panels COPY ./panels/line_chart ./line_chart COPY ./panels/heatmap_chart ./heatmap_chart -RUN cd /panels/line_chart; yarn install --pure-lockfile; yarn run build; rm -rf node_modules -RUN cd /panels/heatmap_chart; yarn install --pure-lockfile; yarn run build; rm -rf node_modules +RUN cd /panels/line_chart; yarn install --pure-lockfile; yarn run dev; yarn run build; rm -rf node_modules +RUN cd /panels/heatmap_chart; yarn install --pure-lockfile; yarn run dev; yarn run build; rm -rf node_modules FROM grafana/grafana:6.5.2 diff --git a/maro/utils/dashboard/dashboard_resource/panels/line_chart/src/linechart_ctrl.ts b/maro/utils/dashboard/dashboard_resource/panels/line_chart/src/linechart_ctrl.ts index 72880691..ddb9e322 100644 --- a/maro/utils/dashboard/dashboard_resource/panels/line_chart/src/linechart_ctrl.ts +++ b/maro/utils/dashboard/dashboard_resource/panels/line_chart/src/linechart_ctrl.ts @@ -164,6 +164,16 @@ class LineChartCtrl extends MetricsPanelCtrl { .key((d: any) => { return d.x; }) + .sortKeys((a: any, b: any) => { + const nA = Number(a); + const nB = Number(b); + if (isNaN(nA) || isNaN(nB)) { + return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; + } + else { + return nA < nB ? -1 : nA > nB ? 1 : nA >= nB ? 0 : NaN; + } + }) .entries(dataSeries); const groupedData: any[] = []; for (let j = 0; j < groupedSeries.length; j++) {