import { h, Component } from 'preact' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import Group from '../common/group.component' import Param from '../common/param.component' import * as systemActions from './system.actions' import * as taskActions from '../task/task.actions' const cpu_test_task = { activity: 'cpu', module: 'test', dataset: 'test', epochs: 1, opt: {} } const gpu_test_task = { activity: 'gpu', module: 'test', dataset: 'test', epochs: 1, opt: {} } const live_test_task = { activity: 'live', module: 'test', dataset: 'test', epochs: 1, opt: {} } class System extends Component { constructor(props){ super() } componentDidUpdate(){ console.log(this._screen.scrollHeight, this._screen.scrollTop, this._screen.offsetHeight) if (this._screen.scrollHeight > this._screen.scrollTop - this._screen.offsetHeight + 100) { this._screen.scrollTop = this._screen.scrollHeight } } render(){ const { site, server, relay, runner, rpc, actions } = this.props return (

{site.name} System

{server.status} {server.error && {server.error.message} } {relay.status} {rpc.status} {this.renderStatus(runner.cpu)} {this.renderStatus(runner.gpu)}
{this.renderCommandOutput()}
) } renderStatus(processor){ if (!processor) { return 'unknown' } if (processor.status === 'IDLE') { return 'idle' } const task = processor.task return task.activity + ' ' + task.module } renderCommandOutput(){ const { cmd, stdout, stderr } = this.props let output if (cmd.loading) { output = 'Loading: ' + cmd.name } else if (cmd.loaded) { if (cmd.error) { output = 'Error: ' + cmd.name + '\n\n' + JSON.stringify(cmd.error, null, 2) } else { output = cmd.stdout if (cmd.stderr) { output += '\n\n_________________________________\n\n' output += cmd.stderr } } } else { output = stdout if (stderr.length) { output += '\n\n_________________________________\n\n' output += stderr } } return (
this._screen = ref} className='screen'>{output}
) } } const mapStateToProps = state => ({ ...state.system }) const mapDispatchToProps = (dispatch, ownProps) => ({ actions: { system: bindActionCreators(systemActions, dispatch), task: bindActionCreators(taskActions, dispatch), }, }) export default connect(mapStateToProps, mapDispatchToProps)(System)