Commit ab0d859e by AlasdairSwan

Grade table data progressing

parent 21f65404
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
const exGrades = [
{
"assignment_type":"Exam",
"total_possible":6.0,
"total_earned":3.0
},
{
"assignment_type":"Homework",
"total_possible":5.0,
"total_earned":4.0
},
{
"assignment_type":"Homework",
"total_possible":11.0,
"total_earned":0.0
}
];
class GradeTable extends React.Component {
constructor(props) {
super(props);
}
getTableGroup(type) {
const {data} = this.props;
const groupData = data.filter(value => {
if (value['assignment_type'] === type) {
return value;
}
});
const multipleAssessments = groupData.length > 1;
const rows = groupData.map(({assignment_type, total_possible, total_earned}, index) => {
const label = multipleAssessments ? `${assignment_type} ${index + 1}` : assignment_type;
return (
<tr key={index}>
<td>{label}</td>
<td>{total_possible}/{total_possible}</td>
<td>{total_earned}/{total_possible}</td>
</tr>
);
});
return <tbody>{rows}</tbody>;
}
render() {
const {assignmentTypes} = this.props;
return (
<table className="table">
<thead className="table-head">
<tr>
<th>Assessment</th>
<th>You</th>
<th>Passing</th>
</tr>
</thead>
{assignmentTypes.map(type => this.getTableGroup(type))}
</table>
)
}
};
GradeTable.propTypes = {
data: PropTypes.array.isRequired
}
export default GradeTable;
...@@ -5,42 +5,41 @@ import React from 'react'; ...@@ -5,42 +5,41 @@ import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import CircleChart from './CircleChart'; import CircleChart from './CircleChart';
import CircleChartLegend from './CircleChartLegend'; import CircleChartLegend from './CircleChartLegend';
import Table from './Table'; import GradeTable from './GradeTable';
export function LearnerAnalyticsDashboard(props) { export function LearnerAnalyticsDashboard(props) {
console.log('props: ', props); console.log('props: ', props);
const {grading_policy} = props; const {grading_policy, grades} = props;
const gradeBreakdown = grading_policy.GRADER.map(({type, weight}, index) => { const gradeBreakdown = grading_policy.GRADER.map(({type, weight}, index) => {
return { return {
value: weight, value: weight,
label: type, label: type,
sliceIndex: index + 1 sliceIndex: index + 1
} }
}).sort((a, b) => a.value > b.value); }).sort((a, b) => a.value < b.value);
// const data = [
// { const exGrades = [
// color: '#386F77', {
// value: 0.50, "assignment_type":"Exam",
// label: 'Chucky' "total_possible":6.0,
// }, "total_earned":3.0
// { },
// color: '#1ABC9C', {
// value: 0.25, "assignment_type":"Homework",
// label: 'Michael Myers' "total_possible":5.0,
// }, "total_earned":4.0
// { },
// color: '#92C9D3', {
// value: 0.3, "assignment_type":"Homework",
// label: 'Freddy Krueger' "total_possible":11.0,
// }, "total_earned":0.0
// { }
// color: '#73bde7', ];
// value: 0.15,
// label: 'Jason Vorhees' // Get a list of assignment types minus duplicates
// } const assignmentTypes = [...new Set(gradeBreakdown.map(value => value['label']))];
// ];
const tableHeadings = ['Assessment', 'Passing', 'You'];
const tableData = [ const tableData = [
{ {
label: 'Problem Set 1', label: 'Problem Set 1',
...@@ -83,10 +82,16 @@ console.log('props: ', props); ...@@ -83,10 +82,16 @@ console.log('props: ', props);
<h3>Graded Assessments</h3> <h3>Graded Assessments</h3>
<div className="graded-assessments-wrapper"> <div className="graded-assessments-wrapper">
<Table headings={tableHeadings} data={tableData} /> <GradeTable assignmentTypes={assignmentTypes} data={exGrades} />
<p className="footnote">*Calculated based on current average</p> <p className="footnote">*Calculated based on current average</p>
</div> </div>
</div> </div>
<div className="discussions-group">
<h2>Discussions</h2>
</div>
<div className="timing-group">
<h2>Timing</h2>
</div>
</div> </div>
); );
} }
......
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
class Table extends React.Component {
constructor(props) {
super(props);
this.getTableHead = this.getTableHead.bind(this);
}
getTableBody() {
const {data} = this.props;
const rows = data.map(({label, user, passing, total}, index) => {
return (
<tr key={index}>
<td>{label}</td>
<td>{user}/{total}</td>
<td>{passing}/{total}</td>
</tr>
);
});
return <tbody>{rows}</tbody>;
}
getTableHead() {
const {headings} = this.props;
const html = headings.map((title, index) => <th key={index}>{title}</th>);
return (
<thead className="table-head">
<tr>
{html}
</tr>
</thead>
);
}
render() {
return (
<table className="table">
<colgroup>
<col />
<col span="2"/>
<col />
</colgroup>
{this.getTableHead()}
{this.getTableBody()}
</table>
)
}
};
Table.propTypes = {
headings: PropTypes.array.isRequired,
data: PropTypes.array.isRequired
}
export default Table;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment