change 使用权重值百分比作为 normalize method
This commit is contained in:
@@ -27,17 +27,17 @@ export default async function handler(
|
|||||||
} = JSON.parse(jsonStr);
|
} = JSON.parse(jsonStr);
|
||||||
|
|
||||||
// Normalization
|
// Normalization
|
||||||
// 使用 标准分数 算法 z = (x - mean) / std
|
// 使用 权重值 / 权重值之和
|
||||||
const { selections } = json;
|
const { selections } = json;
|
||||||
const nums = Object.values(selections);
|
const nums = Object.values(selections);
|
||||||
const mean = nums.reduce((a, b) => a + b) / nums.length;
|
const sum = nums.reduce((a, b) => a + b);
|
||||||
|
const mean = sum / nums.length;
|
||||||
const std = Math.sqrt(
|
const std = Math.sqrt(
|
||||||
nums.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) /
|
nums.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) /
|
||||||
nums.length
|
nums.length
|
||||||
);
|
);
|
||||||
const normalizedNums = nums.map((x) => (std === 0 ? 0 : (x - mean) / std));
|
|
||||||
for (const index in selections) {
|
for (const index in selections) {
|
||||||
selections[index] = std === 0 ? 0 : (selections[index] - mean) / std;
|
selections[index] = selections[index] / sum;
|
||||||
}
|
}
|
||||||
users[json.user] = selections;
|
users[json.user] = selections;
|
||||||
}
|
}
|
||||||
@@ -99,6 +99,10 @@ export default async function handler(
|
|||||||
sortedHoursCount.sort((a, b) => a[1] - b[1]);
|
sortedHoursCount.sort((a, b) => a[1] - b[1]);
|
||||||
console.log("sortedHoursCount", sortedHoursCount);
|
console.log("sortedHoursCount", sortedHoursCount);
|
||||||
console.log("sortedHoursCount.length", sortedHoursCount.length);
|
console.log("sortedHoursCount.length", sortedHoursCount.length);
|
||||||
|
console.log(
|
||||||
|
"user.length === sorted.length",
|
||||||
|
Object.keys(users).length === sortedHoursCount.length
|
||||||
|
);
|
||||||
|
|
||||||
res.status(200).json(resp);
|
res.status(200).json(resp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ const ReportPage = () => {
|
|||||||
const getReport = async () => {
|
const getReport = async () => {
|
||||||
const resp = await fetch("/api/html").then((resp) => resp.json());
|
const resp = await fetch("/api/html").then((resp) => resp.json());
|
||||||
ref.current.innerHTML = resp.html;
|
ref.current.innerHTML = resp.html;
|
||||||
const json: Record<string, string> = await fetch("/api/tool").then(
|
const json: Record<string, string> = await fetch("/api/tool").then((resp) =>
|
||||||
(resp) => resp.json()
|
resp.json()
|
||||||
);
|
);
|
||||||
const table = ref.current.children[0];
|
const table = ref.current.children[0];
|
||||||
const tbody = table.children[table.children.length - 1];
|
const tbody = table.children[table.children.length - 1];
|
||||||
@@ -47,4 +47,4 @@ const ReportPage = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ReportPage;
|
export default ReportPage;
|
||||||
|
|||||||
Reference in New Issue
Block a user