326 lines
11 KiB
JavaScript
326 lines
11 KiB
JavaScript
import { defineStore } from "pinia";
|
|
import moment from "moment";
|
|
import { Decimal } from 'decimal.js';
|
|
import abbreviateNumber from '@/module/abbreviateNumber.js';
|
|
import apiError from '@/module/apiError.js';
|
|
|
|
export default defineStore('conformanceStore', {
|
|
state: () => ({
|
|
conformanceLogId: null, // log 檔
|
|
conformanceFilterId: null, // filter 檔
|
|
conformanceLogTempCheckId: null, // log 檔存檔前的 check Id
|
|
conformanceFilterTempCheckId: null, // Filter 檔存檔前的 check Id
|
|
allConformanceTask: [],
|
|
allCfmSeqStart: [],
|
|
allCfmSeqEnd: [],
|
|
allProcessingTime: {},
|
|
allWaitingTime: {},
|
|
allCycleTime: {},
|
|
allConformanceTempReportData: null,
|
|
allIssueTraces: null,
|
|
allTaskSeq: null,
|
|
allCases: null,
|
|
allLoopTraces: null,
|
|
allLoopTaskSeq: null,
|
|
allLoopCases: null,
|
|
selectedRuleType: 'Have activity', // radio
|
|
selectedActivitySequence: 'Start & End', // radio
|
|
selectedMode: 'Directly follows', // radio
|
|
selectedProcessScope: 'End to end', // radio
|
|
selectedActSeqMore: 'All', // radio
|
|
selectedActSeqFromTo: 'From', // radio
|
|
infinite404: null,
|
|
isStartSelected: null, // start & end 連動先選擇 start
|
|
isEndSelected: null, // start & end 連動先選擇 end
|
|
}),
|
|
getters: {
|
|
conformanceAllTasks: state => {
|
|
return state.allConformanceTask;
|
|
},
|
|
conformanceTask: state => {
|
|
return state.allConformanceTask.map(i => i.label);
|
|
},
|
|
cfmSeqStart: state => {
|
|
return state.allCfmSeqStart;
|
|
},
|
|
cfmSeqEnd: state => {
|
|
return state.allCfmSeqEnd;
|
|
},
|
|
cfmPtEteWhole: state => {
|
|
return state.allProcessingTime.end_to_end.whole;
|
|
},
|
|
cfmPtEteStart: state => {
|
|
return state.allProcessingTime.end_to_end.starts_with;
|
|
},
|
|
cfmPtEteEnd: state => {
|
|
return state.allProcessingTime.end_to_end.ends_with;
|
|
},
|
|
cfmPtEteSE: state => {
|
|
return state.allProcessingTime.end_to_end.start_end;
|
|
},
|
|
cfmPtPStart: state => {
|
|
return state.allProcessingTime.partial.starts_with;
|
|
},
|
|
cfmPtPEnd: state => {
|
|
return state.allProcessingTime.partial.ends_with;
|
|
},
|
|
cfmPtPSE: state => {
|
|
return state.allProcessingTime.partial.start_end;
|
|
},
|
|
cfmWtEteWhole: state => {
|
|
return state.allWaitingTime.end_to_end.whole;
|
|
},
|
|
cfmWtEteStart: state => {
|
|
return state.allWaitingTime.end_to_end.starts_with;
|
|
},
|
|
cfmWtEteEnd: state => {
|
|
return state.allWaitingTime.end_to_end.ends_with;
|
|
},
|
|
cfmWtEteSE: state => {
|
|
return state.allWaitingTime.end_to_end.start_end;
|
|
},
|
|
cfmWtPStart: state => {
|
|
return state.allWaitingTime.partial.starts_with;
|
|
},
|
|
cfmWtPEnd: state => {
|
|
return state.allWaitingTime.partial.ends_with;
|
|
},
|
|
cfmWtPSE: state => {
|
|
return state.allWaitingTime.partial.start_end;
|
|
},
|
|
cfmCtEteWhole: state => {
|
|
return state.allCycleTime.end_to_end.whole;
|
|
},
|
|
cfmCtEteStart: state => {
|
|
return state.allCycleTime.end_to_end.starts_with;
|
|
},
|
|
cfmCtEteEnd: state => {
|
|
return state.allCycleTime.end_to_end.ends_with;
|
|
},
|
|
cfmCtEteSE: state => {
|
|
return state.allCycleTime.end_to_end.start_end;
|
|
},
|
|
conformanceTempReportData: state => {
|
|
return state.allConformanceTempReportData;
|
|
},
|
|
issueTraces: state => {
|
|
return state.allIssueTraces;
|
|
},
|
|
taskSeq: state => {
|
|
return state.allTaskSeq;
|
|
},
|
|
cases: state => {
|
|
if(state.allCases !== null){
|
|
const newData = state.allCases.map(c => {
|
|
c.started_at = moment(c.started_at).format('YYYY/MM/DD HH:MM');
|
|
c.completed_at = moment(c.completed_at).format('YYYY/MM/DD HH:MM');
|
|
c.facets.map(fac => {
|
|
switch(fac.type) {
|
|
case 'duration-list':
|
|
fac.value = fac.value.map(v => v !== null ? abbreviateNumber(new Decimal(v.toFixed(2))) : null);
|
|
fac.value = fac.value.join(', ');
|
|
break;
|
|
default:
|
|
break;
|
|
};
|
|
return fac;
|
|
});
|
|
c.attributes.map(att => {
|
|
switch (att.type) {
|
|
case 'date':
|
|
att.value = att.value !== null ? moment(att.value).format('YYYY/MM/DD HH:MM:ss') : null;
|
|
break;
|
|
case 'float':
|
|
att.value = att.value !== null ? new Decimal(att.value).toFixed(2) : null;
|
|
break
|
|
default:
|
|
break;
|
|
}
|
|
return att;
|
|
});
|
|
const { facets, attributes, ...rest } = c;
|
|
return { ...rest, facets, attributes };
|
|
});
|
|
return newData
|
|
};
|
|
},
|
|
loopTraces: state => {
|
|
return state.allLoopTraces;
|
|
},
|
|
loopTaskSeq: state => {
|
|
return state.allLoopTaskSeq;
|
|
},
|
|
loopCases: state => {
|
|
if(state.allLoopCases !== null){
|
|
const newData = state.allLoopCases.map(c => {
|
|
c.started_at = moment(c.started_at).format('YYYY/MM/DD HH:MM');
|
|
c.completed_at = moment(c.completed_at).format('YYYY/MM/DD HH:MM');
|
|
c.attributes.map(att => {
|
|
switch (att.type) {
|
|
case 'date':
|
|
att.value = att.value !== null ? moment(att.value).format('YYYY/MM/DD HH:MM:ss') : null;
|
|
break;
|
|
case 'float':
|
|
att.value = att.value !== null ? new Decimal(att.value).toFixed(2) : null;
|
|
break
|
|
default:
|
|
break;
|
|
}
|
|
return att;
|
|
});
|
|
return c;
|
|
});
|
|
return newData;
|
|
};
|
|
},
|
|
},
|
|
actions: {
|
|
/**
|
|
* fetch Log Conformance Parameters api for Rule Settings.
|
|
*/
|
|
async getConformanceParams() {
|
|
const logId = this.conformanceLogId;
|
|
const filterId = this.conformanceFilterId;
|
|
let api = '';
|
|
|
|
// 先判斷 filter 檔,再判斷 log 檔。
|
|
if(filterId !== null) api = `/api/filter-checks/params?filter_id=${filterId}`;
|
|
else api = `/api/log-checks/params?log_id=${logId}`;
|
|
console.log('getConformanceParams', api);
|
|
|
|
try {
|
|
const response = await this.$axios.get(api);
|
|
this.allConformanceTask = response.data.tasks;
|
|
this.allCfmSeqStart = response.data.sources;
|
|
this.allCfmSeqEnd = response.data.sinks;
|
|
this.allProcessingTime = response.data.processing_time;
|
|
this.allWaitingTime = response.data.waiting_time;
|
|
this.allCycleTime = response.data.cycle_time;
|
|
} catch(error) {
|
|
apiError(error, 'Failed to load the Conformance Parameters.');
|
|
}
|
|
},
|
|
/**
|
|
* Creates a new temporary check for a log.
|
|
*/
|
|
async addConformanceCheckId(data) {
|
|
const logId = this.conformanceLogId;
|
|
const filterId = this.conformanceFilterId;
|
|
let api = '';
|
|
|
|
// 先判斷 filter 檔,再判斷 log 檔。
|
|
if(filterId !== null) api = `/api/temp-filter-checks?filter_id=${filterId}`;
|
|
else api = `/api/temp-log-checks?log_id=${logId}`;
|
|
|
|
try {
|
|
const response = await this.$axios.post(api, data);
|
|
if(filterId !== null) this.conformanceFilterTempCheckId = response.data.id;
|
|
else this.conformanceLogTempCheckId = response.data.id;
|
|
} catch(error) {
|
|
apiError(error, 'Failed to add the Temporary Check for a file.');
|
|
}
|
|
},
|
|
/**
|
|
* Get the Temporary Log Conformance Report
|
|
*/
|
|
async getConformanceReport() {
|
|
const logTempCheckId = this.conformanceLogTempCheckId;
|
|
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
|
let api = '';
|
|
|
|
// 先判斷 filter 檔,再判斷 log 檔。
|
|
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}`;
|
|
else api = `/api/temp-log-checks/${logTempCheckId}`;
|
|
|
|
try {
|
|
const response = await this.$axios.get(api);
|
|
this.allConformanceTempReportData = response.data;
|
|
} catch(error) {
|
|
apiError(error, 'Failed to Get the Temporary Log Conformance Report.');
|
|
}
|
|
},
|
|
/**
|
|
* Get the detail of a temporary log conformance issue.
|
|
*/
|
|
async getConformanceIssue(issueNo) {
|
|
const logTempCheckId = this.conformanceLogTempCheckId;
|
|
const filterTempCheckId = this.conformanceFilterTempCheckId
|
|
let api = '';
|
|
|
|
// 先判斷 filter 檔,再判斷 log 檔。
|
|
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/issues/${issueNo}`;
|
|
else api = `/api/temp-log-checks/${logTempCheckId}/issues/${issueNo}`;
|
|
|
|
try {
|
|
const response = await this.$axios.get(api);
|
|
this.allIssueTraces = response.data.traces;
|
|
} catch(error) {
|
|
apiError(error, 'Failed to Get the detail of a temporary log conformance issue.');
|
|
};
|
|
},
|
|
/**
|
|
* Get the Trace Details of a Temporary Log Conformance lssue.
|
|
*/
|
|
async getConformanceTraceDetail(issueNo, traceId, start) {
|
|
const logTempCheckId = this.conformanceLogTempCheckId;
|
|
const filterTempCheckId = this.conformanceFilterTempCheckId
|
|
let api = '';
|
|
|
|
// 先判斷 filter 檔,再判斷 log 檔。
|
|
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
else api = `/api/temp-log-checks/${logTempCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
|
|
try {
|
|
const response = await this.$axios.get(api);
|
|
this.allTaskSeq = response.data.task_seq;
|
|
this.allCases = response.data.cases;
|
|
return response.data.cases;
|
|
} catch(error) {
|
|
if(error.response.status === 404) this.infinite404 = 404;
|
|
apiError(error, 'Failed to Get the detail of a temporary log conformance issue.');
|
|
};
|
|
},
|
|
/**
|
|
* Get the Details of a Temporary Log Conformance Loop.
|
|
*/
|
|
async getConformanceLoop(loopNo) {
|
|
const logTempCheckId = this.conformanceLogTempCheckId;
|
|
const filterTempCheckId = this.conformanceFilterTempCheckId
|
|
let api = '';
|
|
|
|
// 先判斷 filter 檔,再判斷 log 檔。
|
|
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/loops/${loopNo}`;
|
|
else api = `/api/temp-log-checks/${logTempCheckId}/loops/${loopNo}`;
|
|
|
|
try {
|
|
const response = await this.$axios.get(api);
|
|
this.allLoopTraces = response.data.traces;
|
|
} catch(error) {
|
|
apiError(error, 'Failed to Get the detail of a temporary log conformance loop.');
|
|
};
|
|
},
|
|
/**
|
|
* Get the Trace Details of a Temporary Log Conformance Loops.
|
|
*/
|
|
async getConformanceLoopsTraceDetail(loopNo, traceId, start) {
|
|
const logTempCheckId = this.conformanceLogTempCheckId;
|
|
const filterTempCheckId = this.conformanceFilterTempCheckId
|
|
let api = '';
|
|
|
|
// 先判斷 filter 檔,再判斷 log 檔。
|
|
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
else api = `/api/temp-log-checks/${logTempCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
|
|
try {
|
|
const response = await this.$axios.get(api);
|
|
this.allLoopTaskSeq = response.data.task_seq;
|
|
this.allLoopCases = response.data.cases;
|
|
return response.data.cases;
|
|
} catch(error) {
|
|
if(error.response.status === 404) this.infinite404 = 404;
|
|
apiError(error, 'Failed to Get the detail of a temporary log conformance loop.');
|
|
};
|
|
},
|
|
},
|
|
})
|