Skip to content

Commit 08661d9

Browse files
committed
Temporal stability graph
1 parent 58501b0 commit 08661d9

File tree

11 files changed

+214
-5
lines changed

11 files changed

+214
-5
lines changed

src/actions/PredictionAction.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {createPayloadForwardingAction} from './index';
2+
export const PREDICTION_LIST_REQUESTED = 'PREDICTION_LIST_REQUESTED';
3+
export const predictionListRequested = createPayloadForwardingAction(PREDICTION_LIST_REQUESTED);
4+
export const PREDICTION_LIST_RETRIEVED = 'PREDICTION_LIST_RETRIEVED';
5+
export const predictionListRetrieved = createPayloadForwardingAction(PREDICTION_LIST_RETRIEVED);
6+
export const PREDICTION_LIST_FAILED = 'PREDICTION_LIST_FAILED';
7+
export const predictionListFailed = createPayloadForwardingAction(PREDICTION_LIST_FAILED);

src/actions/ServerActions.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {limeValueListFailed, limeValueListRetrieved} from './LimeActions';
77
import {splitFailed, splitsFailed, splitsRetrieved, splitSucceeded} from './SplitActions';
88
import {modelsFailed, modelsRetrieved} from './ModelActions';
99
import {predictionFailed, predictionSucceeded, replayFailed, replaySucceeded} from './RuntimeActions';
10+
import {predictionListRetrieved, predictionListFailed} from './PredictionAction';
1011

1112
export const getJobs = () => (dispatch) => {
1213
jsonAjax(
@@ -138,3 +139,15 @@ export const getLimeValues = ({jobId, traceId}) => (dispatch) => {
138139
({error}) => dispatch(limeValueListFailed(error))
139140
);
140141
};
142+
143+
export const getPredictionValues = ({jobId, traceId}) => (dispatch) => {
144+
jsonAjax(
145+
`http://localhost:8083/api/test`,
146+
'GET',
147+
null,
148+
(predictionList) => {
149+
dispatch(predictionListRetrieved(predictionList));
150+
},
151+
({error}) => dispatch(predictionListFailed(error))
152+
);
153+
};

src/components/chart/HorizontalBarChartCard.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class HorizontalBarChartCard extends React.Component {
6464
}
6565
]
6666
};
67+
console.log(this.props.data)
68+
console.log(this.props.labels)
6769
const height = this.props.labels.length * 65;
6870
const chart = (
6971
<ReactApexChart
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import ReactApexChart from 'react-apexcharts';
4+
5+
class PredictionLineChart extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
}
9+
render() {
10+
let graph = {
11+
series: [{
12+
name: 'Value',
13+
data: this.props.data
14+
}],
15+
options: {
16+
chart: {
17+
height: 50,
18+
type: 'line',
19+
toolbar: {
20+
show: false
21+
},
22+
zoom: {
23+
enabled: false
24+
}
25+
},
26+
dataLabels: {
27+
enabled: false
28+
},
29+
stroke: {
30+
curve: 'straight'
31+
},
32+
title: {
33+
align: 'left'
34+
},
35+
grid: {
36+
row: {
37+
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
38+
opacity: 0.5
39+
},
40+
},
41+
xaxis: {
42+
categories: this.props.categories,
43+
title: {
44+
text: 'Event number',
45+
},
46+
},
47+
yaxis: {
48+
title: {
49+
text: 'Prediction value',
50+
},
51+
}
52+
}
53+
};
54+
const height = 4 * 65;
55+
const chart = (
56+
<ReactApexChart
57+
options={graph.options}
58+
series={graph.series}
59+
type="line"
60+
height={height}
61+
/>
62+
);
63+
return <div id="chart">{chart}</div>;
64+
}
65+
}
66+
PredictionLineChart.propTypes = {
67+
data: PropTypes.any.isRequired,
68+
categories: PropTypes.any.isRequired
69+
};
70+
export default PredictionLineChart;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import {Card, CardTitle, CardText} from 'react-md/lib/Cards/index';
3+
import PredictionLineChart from '../chart/PredictionLineChart';
4+
import PropTypes from 'prop-types';
5+
import {parsePredictionResultList} from '../../util/dataReducers';
6+
7+
const PredictionLineChartCard = (props) => {
8+
const predictionData = parsePredictionResultList(props.data);
9+
return <Card >
10+
<CardTitle title="Temporal Stability"></CardTitle>
11+
<CardText>
12+
{ props.traceId != '' && props.jobId != '' ?
13+
'Temporal stability result with trace id: '+ props.traceId +' and job id: '+ props.jobId: ''}
14+
</CardText>
15+
<CardText>
16+
<div className="md-cell md-cell--12">
17+
<PredictionLineChart
18+
data = {predictionData.data}
19+
categories = {predictionData.categories}/>
20+
</div>
21+
</CardText>
22+
23+
</Card>;
24+
};
25+
PredictionLineChartCard.propTypes = {
26+
data: PropTypes.any.isRequired,
27+
traceId: PropTypes.any,
28+
jobId: PropTypes.any
29+
};
30+
export default PredictionLineChartCard;

src/components/explanation/post_hoc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const PostHocExplanation = (props) => {
1414
labels = {props.limeValueList.labels}/>;
1515
return <Card className="md-block-centered">
1616
<CardTitle title="Graphs"/>
17+
<CardText>
18+
{!props.isLimeValuesLoaded ? 'Lime result with trace id: '+ props.traceId +' is loading. Please wait...' :
19+
'Lime result with trace id: '+ props.traceId}
20+
</CardText>
1721
{!props.isLimeValuesLoaded ? <CircularProgress id="query-indeterminate-progress"/> : null}
1822
<CardText>
1923
<div className="md-cell md-cell--12" key="1">
@@ -29,6 +33,7 @@ PostHocExplanation.propTypes = {
2933
limeValueList: PropTypes.any.isRequired,
3034
isLimeValuesLoaded: PropTypes.bool.isRequired,
3135
fetchState: fetchStatePropType,
36+
traceId: PropTypes.any
3237

3338
};
3439
export default PostHocExplanation;

src/middlewares/ServerMiddleware.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
getTraceList,
1111
postSplit,
1212
postTraining,
13-
getLimeValues
13+
getLimeValues,
14+
getPredictionValues
1415
} from '../actions/ServerActions';
1516
import {JOB_DELETE_REQUESTED, JOBS_REQUESTED, TRAINING_SUBMITTED} from '../actions/JobActions';
1617
import {TRACE_LIST_REQUESTED} from '../actions/TraceActions';
@@ -19,6 +20,7 @@ import {LIME_VALUE_LIST_REQUESTED} from '../actions/LimeActions';
1920
import {SPLIT_SUBMITTED, SPLITS_REQUESTED} from '../actions/SplitActions';
2021
import {MODELS_REQUESTED} from '../actions/ModelActions';
2122
import {PREDICTION_SUBMITTED, REPLAY_SUBMITTED} from '../actions/RuntimeActions';
23+
import { PREDICTION_LIST_REQUESTED } from '../actions/PredictionAction';
2224

2325
const ACTION_TYPE_TO_SERVER_ACTION = {
2426
[JOBS_REQUESTED]: getJobs,
@@ -32,7 +34,8 @@ const ACTION_TYPE_TO_SERVER_ACTION = {
3234
[REPLAY_SUBMITTED]: postReplay,
3335
[MODELS_REQUESTED]: getModels,
3436
[JOB_DELETE_REQUESTED]: deleteJob,
35-
[LIME_VALUE_LIST_REQUESTED]: getLimeValues
37+
[LIME_VALUE_LIST_REQUESTED]: getLimeValues,
38+
[PREDICTION_LIST_REQUESTED]: getPredictionValues,
3639

3740
};
3841

src/reducers/Predictions.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
PREDICTION_LIST_REQUESTED,
3+
PREDICTION_LIST_RETRIEVED,
4+
PREDICTION_LIST_FAILED,
5+
} from '../actions/PredictionAction';
6+
7+
const initialState = {
8+
fetchState: {inFlight: false},
9+
predictionList: {},
10+
isPredictionsLoaded: true
11+
};
12+
13+
const predictions = (state = initialState, action) => {
14+
switch (action.type) {
15+
case PREDICTION_LIST_REQUESTED: {
16+
return {
17+
...state,
18+
fetchState: {inFlight: true},
19+
isPredictionsLoaded: false,
20+
21+
};
22+
}
23+
24+
case PREDICTION_LIST_RETRIEVED: {
25+
const predictionList = action.payload;
26+
return {
27+
...state,
28+
fetchState: {inFlight: false},
29+
predictionList,
30+
isPredictionsLoaded: true
31+
};
32+
}
33+
34+
case PREDICTION_LIST_FAILED: {
35+
const predictionList = initialState.predictionList;
36+
return {
37+
...state,
38+
fetchState: {inFlight: false, error: action.payload},
39+
predictionList,
40+
isPredictionsLoaded: true
41+
};
42+
}
43+
default:
44+
return state;
45+
}
46+
}
47+
;
48+
49+
export default predictions;

src/reducers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import splits from './Splits';
77
import models from './Models';
88
import traces from './Traces';
99
import lime from './Lime';
10+
import predictions from './Predictions';
1011

1112

1213
export default combineReducers({
@@ -17,5 +18,6 @@ export default combineReducers({
1718
training,
1819
splits,
1920
traces,
20-
lime
21+
lime,
22+
predictions
2123
});

src/util/dataReducers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ export const parseLimeResult = (limeValueList) => {
283283
return ({labels: labels, values: values});
284284
};
285285

286+
export const parsePredictionResultList = (predictionList) => {
287+
let data = [];
288+
let keys = Object.keys(predictionList);
289+
290+
if (keys != null) {
291+
for (let j = 0; j < keys.length; j++) {
292+
data.push(predictionList[keys[j]]);
293+
}
294+
}
295+
return ({data: data, categories: keys});
296+
};
297+
286298
export const getTraceAttributes = (traceList, selectedTrace) =>{
287299
let i=0;
288300
if (traceList === undefined) {

0 commit comments

Comments
 (0)