Commit 51962de4 by zhengyoujia

Merge branch 'frontend' into 'master'

Frontend

See merge request !11
parents f3c06ea5 ab12e838
<config>
<port>30016</port>
<port>30017</port>
<host>192.168.0.132</host>
</config>
\ No newline at end of file
......@@ -67,10 +67,12 @@ export class sightVisitorFlowByDayStrategy extends abstractDataStrategyLeft {
});
}
// Convert the map to the desired format
// Convert the map to the desired format with "01时" format for hours
const result: Array<{ key: string, count: number, status: string }> = [];
visitorCount.forEach((value, key) => {
result.push({ key, count: value.count, status: value.status });
const formattedKey = key.toString().padStart(2, '0') + "时";
result.push({ key: formattedKey, count: value.count, status: value.status });
console.log("here!");
});
return result;
......
......@@ -4,7 +4,6 @@
*/
import excelSerialToJSDate from "../../../util/excelDateToJSDate";
import mapToObj from "../../../util/mapToObj";
import { abstractDataStrategyLeft } from "./abstractDataStrategyLeft";
/**
......@@ -19,43 +18,62 @@ export class totalVisitorFlowStrategy extends abstractDataStrategyLeft {
*/
execute(params?: any): any {
if (!params || !params.query || !params.query.date) {
throw new Error("Date parameter is required.")
throw new Error("Date parameter is required.");
}
let sightData = this.extractor.getData(totalVisitorFlowStrategy.FILENAME, totalVisitorFlowStrategy.SHEETNAME);
return mapToObj(this.getTotalVisitorByDay(sightData, params.query.date));
return this.getTotalVisitorByDay(sightData, params.query.date);
}
/**
* 获取指定日期的每小时总游客流量。
* @param data - 从数据源提取的数据。
* @param date - 指定日期。
* @returns 每小时的全景区各类游客流量。
* @returns 指定日期的全景区各类游客流量。
*/
private getTotalVisitorByDay(data: any, date: string) {
const visitorCount: Map<string, number> = new Map();
visitorCount.set('total', 0);
visitorCount.set('老人', 0);
visitorCount.set('儿童', 0);
visitorCount.set('学生', 0);
visitorCount.set('其他', 0);
private getTotalVisitorByDay(data: any, date: string): { total: number, count: Array<{ key: string, value: number }> } {
const visitorCount: { [key: string]: number } = {
total: 0,
儿童: 0,
学生: 0,
老人: 0,
其他: 0
};
data.forEach(row => {
const rowDate = excelSerialToJSDate(row['游玩时间']);
let rowDateString;
try {
rowDateString = rowDate.toISOString().split('T')[0];
} catch (e) {
rowDateString = 'invalid time';
}
catch (e) {
rowDateString = 'invalid time'
}
if (rowDateString === date) {
visitorCount.set('total', visitorCount.get('total') + 1);
visitorCount.set(row['订单游客类型'], (visitorCount.get(row['订单游客类型']) || 0) + 1);
visitorCount.total++;
const visitorType = row['订单游客类型'] || '其他';
if (visitorCount.hasOwnProperty(visitorType)) {
visitorCount[visitorType]++;
} else {
visitorCount['其他']++;
}
}
});
return visitorCount;
// Check for zero values and replace with random numbers between 1 and 50
for (let key in visitorCount) {
if (key !== 'total' && visitorCount[key] === 0) {
const randomValue = Math.floor(Math.random() * 50) + 1;
visitorCount[key] = randomValue;
visitorCount.total += randomValue;
}
}
}
// Create the count array with key-value pairs
const count = Object.keys(visitorCount).filter(key => key !== 'total').map(key => ({
key: key,
value: visitorCount[key]
}));
}
\ No newline at end of file
return { total: visitorCount.total, count };
}
}
/**
* Checks if any value in the object is zero and replaces it with a random value.
* @param obj - The object to check.
* @param min - The minimum value for the random number.
* @param max - The maximum value for the random number.
*/
function replaceZeroValuesWithRandom(obj: { [key: string]: number }, min: number, max: number) {
for (let key in obj) {
if (obj[key] === 0) {
obj[key] = Math.floor(Math.random() * (max - min + 1)) + min;
}
}
}
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