|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
import { groupBy } from '../../utils/commons';
|
|
|
|
|
|
|
|
|
|
export const datePartOptions = [
|
|
|
|
|
{ label: '日', value: 'day' },
|
|
|
|
@ -126,10 +127,32 @@ export const resultDataCb = (dataRaw, dateGroup, { data1, data2 }, fieldMapper,
|
|
|
|
|
dateRange: ele.dateRange,
|
|
|
|
|
dateGroup: ele[fieldMapper.dateKey],
|
|
|
|
|
}));
|
|
|
|
|
const useKeys = parseData1.map((ele) => ele[fieldMapper.dateKey]);
|
|
|
|
|
const reindexData2 = parseData2.map((ele, index) => ({ ...ele, [fieldMapper.dateKey]: useKeys[index] || `_${ele[fieldMapper.dateKey]}`, dateKey: ele.dateKey }));
|
|
|
|
|
const retData = [].concat(parseData1, reindexData2 );
|
|
|
|
|
const data1KeyMapped = parseData1.reduce((r, v) => {
|
|
|
|
|
const _k = v[fieldMapper.dateKey];
|
|
|
|
|
const allDate0 = moment.min([...new Set((r[_k] || []).concat(moment(v.dateRange[0])))]);
|
|
|
|
|
r[_k] = [allDate0];
|
|
|
|
|
return r;
|
|
|
|
|
}, {});
|
|
|
|
|
const data1KeyMappedStr = Object.keys(data1KeyMapped).reduce((r, v) => ({...r, [v]: data1KeyMapped[v][0].format('YYYY-MM-DD')}), {});
|
|
|
|
|
const data2KeyMapped = parseData2.reduce((r, v) => {
|
|
|
|
|
const _k = v[fieldMapper.dateKey];
|
|
|
|
|
const allDate0 = moment.min([...new Set((r[_k] || []).concat(moment(v.dateRange[0])))]);
|
|
|
|
|
r[_k] = [allDate0];
|
|
|
|
|
return r;
|
|
|
|
|
}, {});
|
|
|
|
|
const data2KeyMappedStr = Object.keys(data2KeyMapped).reduce((r, v) => ({...r, [v]: data2KeyMapped[v][0].format('YYYY-MM-DD')}), {});
|
|
|
|
|
const groupBykeyD1 = Object.keys(groupBy(parseData1, ele => ele[fieldMapper.dateKey]));
|
|
|
|
|
const groupBykeyD2 = Object.keys(groupBy(parseData2, ele => ele[fieldMapper.dateKey]));
|
|
|
|
|
const keyMapped = {
|
|
|
|
|
...groupBykeyD2.reduce((obj, k, i) => ({...obj, [k]: groupBykeyD1[i] || k}), {})
|
|
|
|
|
};
|
|
|
|
|
const reindexData2 = parseData2.map((ele, index) => ({
|
|
|
|
|
...ele,
|
|
|
|
|
[fieldMapper.dateKey]: keyMapped[ele[fieldMapper.dateKey]],
|
|
|
|
|
dateKey: ele.dateKey,
|
|
|
|
|
}));
|
|
|
|
|
const retData = [].concat(parseData1, reindexData2 ).map(ele => ({...ele, [fieldMapper.dateKey]: data1KeyMappedStr[ele[fieldMapper.dateKey]] || data2KeyMappedStr[ele[fieldMapper.dateKey]]}));
|
|
|
|
|
const avg1 = parse1.avgVal;
|
|
|
|
|
// console.log('callback', dateGroup, retData);
|
|
|
|
|
// console.log('callback', dateGroup, retData, data1KeyMappedStr, data2KeyMappedStr);
|
|
|
|
|
cb(dateGroup, retData, avg1);
|
|
|
|
|
};
|
|
|
|
|