forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelCard.jsx
More file actions
139 lines (132 loc) · 3.83 KB
/
Copy pathModelCard.jsx
File metadata and controls
139 lines (132 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import PropTypes from 'prop-types';
import React from 'react';
import color from '@cdo/apps/util/color';
class FeatureDetails extends React.Component {
static propTypes = {
feature: PropTypes.object,
};
render() {
const {feature} = this.props;
return (
<div>
<p style={styles.bold}>{feature.id}</p>
<p>{feature.description}</p>
<div>
Possible Values:{' '}
{!feature.values && (
<p style={styles.details}>
min: {feature.min}, max: {feature.max}
</p>
)}
{feature.values && feature.values.join(', ')}
</div>
<br />
</div>
);
}
}
export default class ModelCard extends React.Component {
static propTypes = {
model: PropTypes.object,
};
render() {
const model = this.props.model;
const metadata = model?.metadata;
const selectedFeatures = metadata?.features.map(feature => {
return feature.id;
});
return (
<div>
{model && metadata && (
<div style={styles.container}>
<h3 style={styles.header}>{metadata.name}</h3>
<div>
<span style={styles.bold}>Id: </span>
<span>{this.props.model.id}</span>
</div>
<br />
<div style={styles.subPanel}>
<div style={styles.heading}>Accuracy</div>
<p style={styles.details}>{metadata.summaryStat?.stat}%</p>
</div>
<div style={styles.subPanel}>
<div style={styles.heading}>Intended Use</div>
<p style={styles.details}>{metadata.potentialUses}</p>
</div>
<div style={styles.subPanel}>
<div style={styles.heading}>Warnings and Limitations</div>
<p style={styles.details}>{metadata.potentialMisuses}</p>
</div>
<div style={styles.subPanel}>
<div style={styles.heading}>About the Data</div>
<p style={styles.details}>
{metadata.datasetDetails?.description}
</p>
<br />
{metadata.datasetDetails?.numRows && (
<p style={styles.details}>
Dataset size: {metadata.datasetDetails?.numRows} rows
</p>
)}
</div>
<div style={styles.subPanel}>
<div style={styles.heading}>Features and Label</div>
<p style={styles.details}>
Predict {metadata.label.id} based on{' '}
{selectedFeatures.join(', ')}.
</p>
</div>
<div style={styles.subPanel}>
<div style={styles.heading}>Label</div>
<FeatureDetails feature={metadata.label} />
</div>
<div style={styles.subPanel}>
<div style={styles.heading}>Features</div>
{metadata.features.map(feature => {
return <FeatureDetails feature={feature} key={feature.id} />;
})}
</div>
</div>
)}
</div>
);
}
}
const styles = {
container: {
color: color.black,
textAlign: 'left',
backgroundColor: color.lighter_gray,
borderRadius: 5,
padding: 20,
whiteSpace: 'normal',
lineHeight: 1.5,
maxHeight: 'calc(80vh - 150px)',
overflow: 'scroll',
},
subPanel: {
backgroundColor: color.lightest_gray,
borderRadius: 5,
borderColor: color.gray,
marginBottom: 10,
padding: 10,
overflowWrap: 'break-word',
},
bold: {
fontFamily: "'Gotham 7r', sans-serif",
},
header: {
fontFamily: "'Gotham 7r', sans-serif",
marginTop: 0,
lineHeight: '20px',
},
heading: {
fontFamily: "'Gotham 7r', sans-serif",
fontSize: 14,
marginBottom: 5,
textAlign: 'center',
},
details: {
marginBottom: 0,
},
};