-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-timer-multiple.ts
More file actions
114 lines (94 loc) · 3.57 KB
/
Copy pathsample-timer-multiple.ts
File metadata and controls
114 lines (94 loc) · 3.57 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Sample timer multiple times with exact timestamps
* This script should be run to collect synchronized samples
*/
import 'dotenv/config'
import { existsSync, readFileSync, writeFileSync } from 'fs'
import { join } from 'path'
function parseTimer(timerStr: string): number {
const parts = timerStr.trim().split(/\s*:\s*/)
if (parts.length !== 3) {
throw new Error(`Invalid timer format: ${timerStr}`)
}
const hours = parseInt(parts[0], 10)
const minutes = parseInt(parts[1], 10)
const seconds = parseInt(parts[2], 10)
return hours * 3600 + minutes * 60 + seconds
}
interface Sample {
timer: string
timestamp: number
timerSeconds: number
unlockTime: number
}
async function main() {
console.log('📊 Collecting timer samples with synchronized timestamps\n')
console.log('This script needs to be run with timer values from the website.\n')
console.log('For each sample, record: [timer string, exact timestamp when read]\n')
// We need to manually input samples or use a better method
// For now, let's create a script that can be called with timer values
const args = process.argv.slice(2)
if (args.length === 0) {
console.log('Usage: Provide timer values as arguments')
console.log('Example: tsx src/sample-timer-multiple.ts "00:36:26" "00:36:25" "00:36:23"')
console.log('\nOr use the browser to collect samples with exact timestamps')
process.exit(1)
}
const samples: Sample[] = []
const now = Date.now()
// Collect samples - each arg is a timer value, timestamp is when we read it
for (let i = 0; i < args.length; i++) {
const timerStr = args[i]
const timestamp = now + (i * 1000) // Approximate - in real use, record exact time
try {
const timerSeconds = parseTimer(timerStr)
const unlockTime = timestamp + (timerSeconds * 1000)
samples.push({
timer: timerStr,
timestamp,
timerSeconds,
unlockTime
})
console.log(`Sample ${i + 1}: ${timerStr} → unlock: ${new Date(unlockTime).toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' })}`)
} catch (error: any) {
console.error(`Error parsing ${timerStr}: ${error.message}`)
}
}
if (samples.length === 0) {
console.error('No valid samples')
process.exit(1)
}
// Calculate mean
const meanUnlockTime = samples.reduce((sum, s) => sum + s.unlockTime, 0) / samples.length
const unlockTimes = samples.map(s => s.unlockTime)
const minTime = Math.min(...unlockTimes)
const maxTime = Math.max(...unlockTimes)
const range = maxTime - minTime
const meanDate = new Date(meanUnlockTime)
const meanHHMMSS = meanDate.toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
})
console.log(`\n📈 Statistics:`)
console.log(` Samples: ${samples.length}`)
console.log(` Range: ${(range / 1000).toFixed(3)}s`)
console.log(`\n⏰ Mean Unlock Time: ${meanHHMMSS}`)
// Update .env
const envPath = join(process.cwd(), '.env')
if (existsSync(envPath)) {
let envContent = readFileSync(envPath, 'utf8')
if (envContent.match(/^EXPECTED_UNLOCK_TIME=/m)) {
envContent = envContent.replace(/^EXPECTED_UNLOCK_TIME=.*$/m, `EXPECTED_UNLOCK_TIME=${meanHHMMSS}`)
} else {
envContent += `\nEXPECTED_UNLOCK_TIME=${meanHHMMSS}\n`
}
writeFileSync(envPath, envContent, 'utf8')
console.log(`\n✅ Updated .env with EXPECTED_UNLOCK_TIME=${meanHHMMSS}`)
}
}
main().catch(error => {
console.error('Fatal error:', error)
process.exit(1)
})