123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- //© 2019 Dublin City University, Trinity College Dublin. All rights reserved. This material may not be reproduced, displayed, modified or distributed without the express prior written permission of the copyright holder.
- import React, { Component } from 'react';
- import {
- Modal,
- ModalHeader,
- ModalBody,
- ModalFooter,
- Button,
- Row,
- Col,
- ListGroup,
- TabContent,
- Card,
- CardBody
- } from 'reactstrap';
- import { connect } from 'react-redux';
- import { read } from '../../../services/tripleStoreAPIs/readFromTripleStore';
- import { getErrorReportForModelDefault } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForModelDefault';
- import { getErrorReportForModelProblematicTriple } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForModelProblematicTriple';
- import { getErrorReportForResource } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForResource';
- import { getErrorReportForQuad } from '../../../services/tripleStoreAPIs/sparql/problemReport/getErrorReportForQuad';
- import ListOfProblems from './ListOfProblems';
- import ResourcesFailedForProblem from './ResourcesFailedForProblem';
- import LoadingSpinner from '../loading';
- import LoadingFailed from '../loadingFailed';
- import metricExceptionMapping from '../../../config/metricKnowledgeBaseMapping';
- class ErrorReport extends Component {
- constructor(props) {
- super(props);
- this.state = {
- isloading: false,
- loadFailed: false,
- totalNumberOfTriplesWithProblem: 0,
- listOfExceptionsWithCount: [],
- listOfProblematicThings: [],
- listOfRelatedFailedMetrics:[],
- activeTab: 0
- }
- }
- toggleActiveTab = (tab) => {
- if (this.state.activeTab !== tab) {
- this.setState({
- activeTab: tab,
- listOfRelatedFailedMetrics:[]
- });
- }
- }
- componentDidMount() {
- let indexOfMetric = this.props.datasetDetailsCache[0].lastAssessmentMetrics.findIndex((assessment) => { return assessment.Metric.value === this.props.metricURI });
- if (this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport === undefined) {
- this.setState({ isloading: true }, () => {
- this.prepareErrorReportCache(indexOfMetric, this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].ProblemStructure.value.split("#")[1], this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].Metric.value.split("#")[1]).then(() => {
- this.setState(
- {
- isloading: false
- }, () => {
- if (this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport !== undefined) {
- this.prepareUI(indexOfMetric);
- }
- }
- );
- })
- });
- }
- else {
- if (this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport !== undefined) {
- this.prepareUI(indexOfMetric);
- }
- }
- }
- prepareUI = async (indexOfMetric) => {
- let totalNumberOfTriplesWithProblem = await this.prepareTotalNumberOfTriplesWithProblem(indexOfMetric);
- let listOfExceptionsWithCount = await this.prepareListOfExceptionsWithCount(indexOfMetric);
- let listOfProblematicThings = await this.prepareListOfProblematicThings(indexOfMetric);
- this.setState({
- totalNumberOfTriplesWithProblem: totalNumberOfTriplesWithProblem,
- listOfExceptionsWithCount: listOfExceptionsWithCount,
- listOfProblematicThings: listOfProblematicThings
- });
- }
- prepareTotalNumberOfTriplesWithProblem = (indexOfMetric) => {
- let exceptions = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport);
- let count = 0;
- for (let exception of exceptions) {
- count += this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].count;
- }
- return count;
- }
- prepareListOfExceptionsWithCount = (indexOfMetric) => {
- let exceptions = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport);
- let listOfExceptions = [];
- for (let exception of exceptions) {
- listOfExceptions.push({
- [exception]: this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].count
- });
- }
- return listOfExceptions;
- }
- prepareListOfProblematicThings = (indexOfMetric) => {
- let exceptions = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport);
- let listOfProblematicThings = [];
- for (let exception of exceptions) {
- let problematicThings = Object.keys(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].ProblematicThing);
- for (let problematicThing of problematicThings) {
- listOfProblematicThings.push({
- [problematicThing]: [(this.props.datasetDetailsCache[0].lastAssessmentMetrics[indexOfMetric].errorReport[exception].ProblematicThing[problematicThing].filter(resource => resource !== "")).length,exception]
- });
- }
- }
- return listOfProblematicThings;
- }
- prepareErrorReportCache = async (index, problemStrucure, metricURI) => {
- let errorReport = null;
- if (problemStrucure === "ModelContainer") {
- let functionToCall = getErrorReportForModelDefault;
- let listOfExceptions = "";
- let listOfHasExceptions = "";
- switch (metricURI) {
- case "UsageOfIncorrectDomainOrRangeDatatypesMetric":
- functionToCall = getErrorReportForModelProblematicTriple;
- break;
- default:
- functionToCall = getErrorReportForModelDefault;
- if(metricExceptionMapping.knowledgeBaseMapping[metricURI]!==undefined)
- {
- let exceptions = Object.keys(metricExceptionMapping.knowledgeBaseMapping[metricURI]).map((exception)=> "dqm-prob:"+exception);
- listOfExceptions = exceptions.join(", ") ;
- let hasExceptions = Object.keys(metricExceptionMapping.knowledgeBaseMapping[metricURI]).map((exception)=> "dqm-prob:has"+exception);
- listOfHasExceptions = hasExceptions.join(", ");
- }
- }
- if(listOfExceptions==="")
- {
- errorReport = await read(functionToCall(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value)).then((response) => {
- if (response) {
- if (response.results.bindings.length > 0) {
- return response;
- }
- }
- return null;
- });
- }
- else
- {
- errorReport = await read(functionToCall(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value, listOfExceptions, listOfHasExceptions)).then((response) => {
- if (response) {
- if (response.results.bindings.length > 0) {
- return response;
- }
- }
- return null;
- });
- }
- }
- else if (problemStrucure === "ResourceContainer") {
- errorReport = await read(getErrorReportForResource(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value)).then((response) => {
- if (response) {
- if (response.results.bindings.length > 0) {
- return response;
- }
- }
- return null;
- });
- }
- else if (problemStrucure === "QuadContainer") {
- errorReport = await read(getErrorReportForQuad(this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ProblemGraph.value, this.props.datasetDetailsCache[0].lastAssessmentMetrics[index].ObservationURI.value)).then((response) => {
- if (response) {
- if (response.results.bindings.length > 0) {
- return response;
- }
- }
- return null;
- });
- }
- if (errorReport !== null) {
- let cache = {};
- for (let error of errorReport.results.bindings) {
- let exception = error.Exception.value;
- let problematicThing = "";
- if (error.ProblematicThing !== undefined) {
- problematicThing = error.ProblematicThing.value;
- }
- let problematicThingResource = "";
- if (error.ProblematicThingResource !== undefined) {
- problematicThingResource = error.ProblematicThingResource.value;
- }
- //Exception Key doesn't exists
- if (!(exception in cache)) {
- cache[exception] = {
- count: 1,
- ProblematicThing: {
- [problematicThing]: [problematicThingResource]
- }
- };
- }
- else {
- cache[exception].count += 1;
- //Exception Key exists but problematicThing doesn't exists
- if (!(problematicThing in cache[exception].ProblematicThing)) {
- cache[exception].ProblematicThing = {
- ...cache[exception].ProblematicThing,
- [problematicThing]: [problematicThingResource]
- };
- }
- else {
- cache[exception].ProblematicThing[problematicThing].push(problematicThingResource);
- }
- }
- }
- await this.props.updateErrorReportCache(cache, Number(this.props.datasetID), index);
- }
- return;
- }
- listRelatedProblems=(listOfRelatedMetrics)=>{
- this.setState({
- listOfRelatedFailedMetrics:listOfRelatedMetrics
- });
- }
- render() {
- //console.log(this.state);
- let listOfRelatedFailedMetricsToDisplay=null;
- if(this.state.listOfRelatedFailedMetrics.length>0)
- {
- if(this.state.listOfRelatedFailedMetrics.length===1 & this.state.listOfRelatedFailedMetrics[0]==="")
- {
- //Nothing to do
- }
- else {
- listOfRelatedFailedMetricsToDisplay= this.state.listOfRelatedFailedMetrics.map((metric, index) => {
- if(metric!=="")
- {
- return <li key={index}>{metric}</li>
- }
- });
- }
- }
- return (
- <Modal isOpen={true} className="modal-dialog-centered modal-lg">
- <ModalHeader style={{ margin: 'auto' }}>Problem Report</ModalHeader>
- <ModalBody>
- <Row>
- <Col xs="4">
- <Card className="w-100" style={{overflow: 'scroll', height:'43rem'}}>
- <p className="text-center font-weight-bold">List of Problematic Instances</p>
- <ListGroup id="problemList" role="tablist" className="flex-column align-items-start">
- <ListOfProblems toggle={this.toggleActiveTab} activeTab={this.state.activeTab} listOfProblems={this.state.listOfProblematicThings} />
- </ListGroup>
- </Card>
- </Col>
- <Col xs="8">
- <Row>
- <Card className="w-100">
- <p className="text-center font-weight-bold">Problematic Instance Details</p>
- <TabContent activeTab={this.state.activeTab}>
- <ResourcesFailedForProblem listOfProblems={this.state.listOfProblematicThings} datasetID={this.props.datasetDetailsCache[0].datasetID} metricURI={this.props.metricURI} activeTab={this.state.activeTab} callBack={this.listRelatedProblems}/>
- </TabContent>
- </Card>
- </Row>
- <Row>
- <Card className="w-100" style={{overflow: 'scroll', height:'10rem'}}>
- <p className="text-center font-weight-bold">All Metric(s) failed for the selected Resource</p>
- <CardBody>
- {listOfRelatedFailedMetricsToDisplay}
- </CardBody>
- </Card>
- </Row>
- </Col>
- </Row>
- </ModalBody>
- {this.state.isloading ? <LoadingSpinner /> : null}
- <ModalFooter>
- <Button color="secondary" onClick={this.props.onCloseButtonClick}>Close</Button>
- </ModalFooter>
- </Modal>
- );
- }
- }
- const mapStateToProps = (state, ownProps) => {
- let datasetID = Number(ownProps.datasetID);
- let datasetDetails = state.datasetDetailsCache.filter((dataset) => { if (dataset.datasetID === datasetID) { return dataset; } return null; });
- return (
- {
- datasetDetailsCache: datasetDetails
- }
- );
- }
- const mapDispatchToProps = (dispatch) => {
- return ({
- updateErrorReportCache: (errorReport, datasetID, metricIndex) => { return dispatch({ type: 'UPDATE_METRIC_ERROR_REPORT_CACHE', payLoad: { errorReport: errorReport, datasetID: datasetID, metricIndex: metricIndex } }); }
- }
- );
- }
- export default connect(mapStateToProps, mapDispatchToProps)(ErrorReport);
|