Commit fb950ee3 by Leo Zheng

Debug,修改了eventDataStrategy使其不再修改数据

parent 15340644
...@@ -29,33 +29,9 @@ export class allEventDataStrategy extends abstractDataStrategyMid { ...@@ -29,33 +29,9 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
* @returns 事件的数据。 * @returns 事件的数据。
*/ */
execute(): any { execute(): any {
let eventData = this.extractor.getData(allEventDataStrategy.fileName, allEventDataStrategy.sheetName); const eventData = this.extractor.getData(allEventDataStrategy.fileName, allEventDataStrategy.sheetName);
this.removeUnusedColumns(eventData); const formattedData = this.formatDataForFrontend(eventData);
return this.formatDataForFrontend(eventData); return formattedData;
}
/**
* 移除数据中前端不使用的列
* @param data - 从数据源提取的数据
*/
private removeUnusedColumns(data: any) {
data.forEach(row => {
// Initialize missing relevant columns with a default value
allEventDataStrategy.RELEVANTINFO.forEach(key => {
if (!(key in row)) {
row[key] = null; // You can set this to any default value you prefer
}
});
Object.keys(row).forEach(key => {
if (!allEventDataStrategy.RELEVANTINFO.includes(key)) {
delete row[key];
}
if (typeof row[key] === 'number') {
row[key] = excelSerialToJSDate(row[key]);
}
});
});
} }
/** /**
...@@ -66,19 +42,17 @@ export class allEventDataStrategy extends abstractDataStrategyMid { ...@@ -66,19 +42,17 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
private formatDataForFrontend(data: any): any { private formatDataForFrontend(data: any): any {
return data.map(row => { return data.map(row => {
let formattedRow: { [key: string]: any } = {}; let formattedRow: { [key: string]: any } = {};
Object.keys(row).forEach(key => {
allEventDataStrategy.RELEVANTINFO.forEach(key => {
const translatedKey = allEventDataStrategy.KEY_MAP[key]; const translatedKey = allEventDataStrategy.KEY_MAP[key];
let value = row[key]; let value = row[key];
// Format date if key is one of the date fields // Format date if key is one of the date fields
if (['creationTime', 'dispositionTime', 'dispositionCompletionTime', 'closureTime'].includes(translatedKey) && value) { if (['创建时间', '处置时间', '处置完成时间', '办结时间'].includes(key) && value) {
value = new Date(value).toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-').replace(',', ''); value = new Date(value).toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-').replace(',', '');
} }
// Only add non-null values to the formatted row formattedRow[translatedKey] = value !== undefined ? value : null;
if (value !== null) {
formattedRow[translatedKey] = value;
}
}); });
// Add detail section with all time fields and their corresponding statuses // Add detail section with all time fields and their corresponding statuses
...@@ -94,43 +68,36 @@ export class allEventDataStrategy extends abstractDataStrategyMid { ...@@ -94,43 +68,36 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
* @returns 详细信息部分 * @returns 详细信息部分
*/ */
private constructDetailSection(row: { [key: string]: any }): any { private constructDetailSection(row: { [key: string]: any }): any {
const details: any = {}; const details: any = [];
if (row.creationTime) { if (row.creationTime) {
details.creationTime = { details.push({
time: row.creationTime, time: row.creationTime,
status: '待调度' status: '待调度'
}; });
} }
if (row.dispositionTime) { if (row.dispositionTime) {
details.dispositionTime = { details.push({
time: row.dispositionTime, time: row.dispositionTime,
status: '处置中' status: '处置中'
}; });
} }
if (row.dispositionCompletionTime) { if (row.dispositionCompletionTime) {
details.dispositionCompletionTime = { details.push({
time: row.dispositionCompletionTime, time: row.dispositionCompletionTime,
status: '已处置' status: '已处置'
}; });
} }
if (row.closureTime) { if (row.closureTime) {
details.closureTime = { details.push({
time: row.closureTime, time: row.closureTime,
status: '已办结' status: '已办结'
}; });
} }
// Remove any null detail fields return details;
Object.keys(details).forEach(key => {
if (details[key].time === null) {
delete details[key];
}
});
return Object.values(details);
} }
} }
...@@ -65,16 +65,13 @@ export abstract class abstractDataStrategyRight implements dataStrategy { ...@@ -65,16 +65,13 @@ export abstract class abstractDataStrategyRight implements dataStrategy {
return eventCount; return eventCount;
} }
/**
* 统计事件列表中每个事件的数量。
* @param list - 事件名称列表。
* @param target - 目标事件名称。
* @param data - 数据源。
* @param year - 指定年份 ("thisyear" or "lastyear").
* @returns 事件计数映射。
*/
/** /**
* getListCount 方法的更新版本,添加了零替换逻辑 * 统计事件列表中每个事件的数量。
* @param list - 事件名称列表。
* @param target - 目标事件名称。
* @param data - 数据源。
* @param year - 指定年份 ("thisyear" or "lastyear").
* @returns 事件计数映射。
*/ */
protected getListCount(list: string[], target: string, data: any, year: string) { protected getListCount(list: string[], target: string, data: any, year: string) {
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
...@@ -86,11 +83,9 @@ protected getListCount(list: string[], target: string, data: any, year: string) ...@@ -86,11 +83,9 @@ protected getListCount(list: string[], target: string, data: any, year: string)
let rowDate: any = 0; let rowDate: any = 0;
if (typeof (row['创建时间']) == "number") { if (typeof (row['创建时间']) == "number") {
rowDate = excelSerialToJSDate(row['创建时间']); rowDate = excelSerialToJSDate(row['创建时间']);
// console.log("from if", row['创建时间']);
} }
else { else {
rowDate = row['创建时间']; rowDate = row['创建时间'];
// console.log(rowDate);
} }
const rowYear = rowDate.getFullYear(); const rowYear = rowDate.getFullYear();
if (rowYear == targetYear) { if (rowYear == targetYear) {
...@@ -111,9 +106,44 @@ protected getListCount(list: string[], target: string, data: any, year: string) ...@@ -111,9 +106,44 @@ protected getListCount(list: string[], target: string, data: any, year: string)
count.set(key, Math.floor(Math.random() * 10) + 1); // Random number between 1 and 10 count.set(key, Math.floor(Math.random() * 10) + 1); // Random number between 1 and 10
}); });
} }
console.log(allCountsZero ? "randomly generating" : "excel data");
return count; return count;
} }
/**
* 统计事件列表中每个事件的数量。
* @param list - 事件名称列表。
* @param target - 目标事件名称。
* @param data - 数据源。
* @param year - 指定年份 ("thisyear" or "lastyear").
* @returns 事件计数映射。
*/
protected getListCountSorted(list: string[], target: string, data: any, year: string) {
// data = data.slice(0, 5);
const currentYear = new Date().getFullYear();
const targetYear = year === 'thisyear' ? currentYear : currentYear - 1;
const count = this.registerItems(list);
data.forEach(row => {
let rowDate: any = 0;
if (typeof (row['创建时间']) == "number") {
rowDate = excelSerialToJSDate(row['创建时间']);
}
else {
rowDate = row['创建时间'];
}
const rowYear = rowDate.getFullYear();
if (rowYear == targetYear) {
count.set(row[target], (count.get(row[target]) || 0) + 1);
}
});
const sortedCount = Array.from(count.entries()).sort((a, b) => b[1] - a[1]);
const sortedCountMap = new Map(sortedCount);
console.log(sortedCount);
return sortedCountMap;
}
} }
...@@ -27,6 +27,6 @@ export class eventSrcStrategy extends abstractDataStrategyRight { ...@@ -27,6 +27,6 @@ export class eventSrcStrategy extends abstractDataStrategyRight {
const target = '事件来源'; const target = '事件来源';
// 获取指定年份的事件来源统计,并转换为对象 // 获取指定年份的事件来源统计,并转换为对象
return mapToObj(this.getListCount(sourceList, target, this.eventData, params.query.year), "source", "count"); return mapToObj(this.getListCountSorted(sourceList, target, this.eventData, params.query.year), "source", "count");
} }
} }
\ No newline at end of file
...@@ -46,11 +46,9 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight { ...@@ -46,11 +46,9 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
let rowDate: any = 0; let rowDate: any = 0;
if (typeof (row['创建时间']) == "number") { if (typeof (row['创建时间']) == "number") {
rowDate = excelSerialToJSDate(row['创建时间']); rowDate = excelSerialToJSDate(row['创建时间']);
console.log("from if", row['创建时间']);
} }
else { else {
rowDate = row['创建时间']; rowDate = row['创建时间'];
console.log(rowDate);
} }
let rowYear = 0; let rowYear = 0;
if (!isNaN(rowDate.getTime())) { if (!isNaN(rowDate.getTime())) {
...@@ -58,10 +56,7 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight { ...@@ -58,10 +56,7 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
rowYear = rowDate.getFullYear(); rowYear = rowDate.getFullYear();
} catch (e) { } catch (e) {
rowYear = 0; rowYear = 0;
console.log('Error getting year:', e);
} }
} else {
// console.log('Invalid Date:', rawDate.getTime());
} }
if (rowYear == targetYear) { if (rowYear == targetYear) {
......
...@@ -27,6 +27,6 @@ export class gridEventCountStrategy extends abstractDataStrategyRight { ...@@ -27,6 +27,6 @@ export class gridEventCountStrategy extends abstractDataStrategyRight {
const target = '网格名称'; const target = '网格名称';
// 获取指定年份的网格事件数量统计,并转换为对象 // 获取指定年份的网格事件数量统计,并转换为对象
return mapToObj(this.getListCount(gridList, target, this.eventData, params.query.year), "gridname", "count"); return mapToObj(this.getListCountSorted(gridList, target, this.eventData, params.query.year), "gridname", "count");
} }
} }
\ No newline at end of file
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