-
Notifications
You must be signed in to change notification settings - Fork 0
/
subModule.js
85 lines (73 loc) · 2.63 KB
/
subModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
export function calculateAveragePressure(path) {
if (!path.length) return 0;
const totalPressure = path.reduce((sum, point) => sum + point.pressure, 0);
return totalPressure / path.length;
}
export function calculateMedianPressure(_points) {
if (!_points.length) return 0;
const pressures = _points.map(point => point.pressure).sort((a, b) => a - b);
const mid = Math.floor(pressures.length / 2);
if (pressures.length % 2 === 0) {
return (pressures[mid - 1] + pressures[mid]) / 2;
} else {
return pressures[mid];
}
}
export function calcConfidenceOfPathsOnPage(pathArray){
let confidence = 0;
pathArray.forEach(path => {
if(path.type != null && path.type == 'path'){
if(getPathLength(path.points) > 50 && getMedianPressure(path.points) >= 0.9){
confidence+=2;
} else if(getPathLength(path.points) > 10 && getMedianPressure(path.points) >= 0.9){
confidence++;
} else if(getPathLength(path.points) > 10 && getMedianPressure(path.points) >= 0.8){
confidence+=0.5;
}
}
});
return confidence;
}
function getPathLength(points) {
if (points.length < 2) return 0;
let length = 0;
for (let i = 1; i < points.length; i++) {
const dx = points[i].x - points[i - 1].x;
const dy = points[i].y - points[i - 1].y;
length += Math.sqrt(dx * dx + dy * dy);
}
return length;
}
function getMedianPressure(points) {
if (points.length === 0) return 0;
const pressures = points.map(point => point.pressure).sort((a, b) => a - b);
const middle = Math.floor(pressures.length / 2);
if (pressures.length % 2 === 0) {
return (pressures[middle - 1] + pressures[middle]) / 2;
} else {
return pressures[middle];
}
}
export function extractUUID(_url) {
console.log(_url);
console.log(_url.length);
if(_url.length < 50) return null;
try {
// URLオブジェクトを作成
let urlObj = new URL(_url);
// URLパス全体とクエリパラメータを含む文字列を取得
let fullPath = urlObj.pathname + urlObj.search;
// UUIDの正規表現
let uuidRegex = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/;
// 正規表現にマッチする部分を抽出
let match = fullPath.match(uuidRegex);
if (match) {
return match[0];
} else {
throw new Error("Invalid UUID format");
}
} catch (error) {
console.error("Invalid URL or UUID format:", error);
return null;
}
}