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 liveActions from '../live/live.actions'
import * as queueActions from '../queue/queue.actions'
import * as authActions from '../auth/auth.actions'
import * as i18n from '../i18n'
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: {}
}
const wait_test_task = {
activity: 'wait',
module: 'test',
dataset: 'test',
epochs: 1,
opt: {}
}
const fruits = ["apple","pear","orange","strawberry"]
function choice(a){ return a[Math.floor(Math.random()*a.length)]}
class System extends Component {
constructor(props){
super()
}
componentDidUpdate(){
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, user } = 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)}
{i18n.languages.map(language => (
))}
{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 => ({
user: state.auth.user,
...state.system,
...state.live,
})
const mapDispatchToProps = (dispatch, ownProps) => ({
actions: {
auth: bindActionCreators(authActions, dispatch),
system: bindActionCreators(systemActions, dispatch),
queue: bindActionCreators(queueActions, dispatch),
live: bindActionCreators(liveActions, dispatch),
},
})
export default connect(mapStateToProps, mapDispatchToProps)(System)