-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from jjikky/feat/generate-test-data
Feat/generate test data
- Loading branch information
Showing
5 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,4 +131,6 @@ dist | |
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
.pnp.* | ||
|
||
scripts/data/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require('fs'); | ||
|
||
function generateRandomId() { | ||
return Array(24) | ||
.fill(0) | ||
.map(() => Math.floor(Math.random() * 16).toString(16)) | ||
.join(''); | ||
} | ||
|
||
function generateRandomNickname(index) { | ||
return `user${index}`; | ||
} | ||
|
||
function generateUser(index) { | ||
const now = new Date().toISOString(); | ||
return { | ||
_id: { $oid: generateRandomId() }, | ||
deletedAt: null, | ||
nickname: generateRandomNickname(index), | ||
email: `user${index}@example.com`, | ||
password: '$2b$10$NWhqlRrE5W0YMHlnaBi.CODbFjPZzvgT5G993eKoziVzrhH3M6KNC', | ||
role: 'user', | ||
snsId: null, | ||
provider: null, | ||
recentSearches: [], | ||
requests: [], | ||
createdAt: { $date: now }, | ||
updatedAt: { $date: now }, | ||
__v: 0, | ||
}; | ||
} | ||
|
||
function generateUsers(count) { | ||
const users = []; | ||
for (let i = 0; i < count; i++) { | ||
users.push(generateUser(i)); | ||
} | ||
return users; | ||
} | ||
|
||
async function generateAndSaveData(totalCount) { | ||
const userData = generateUsers(totalCount); | ||
const fileName = './scripts/data/test-users-data.json'; | ||
fs.writeFileSync(fileName, JSON.stringify(userData, null, 2)); | ||
|
||
console.log('✅ 10000개의 유저 데이터가 생성되었습니다.'); | ||
console.log('📁 파일 위치: users.json'); | ||
} | ||
|
||
generateAndSaveData(10000).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const fs = require('fs'); | ||
|
||
const prefixes = ['A', 'Ab', 'Ac', 'Ad', 'Af', 'Ag', 'Al', 'Am', 'An', 'Ap', 'Ar', 'As', 'At', 'Au']; | ||
const middles = ['sync', 'pi', 'data', 'net', 'web', 'cloud', 'tech', 'dev', 'sys', 'log']; | ||
const suffixes = ['Service', 'API', 'Hub', 'Lab', 'Flow', 'Base', 'Core', 'Plus', 'Pro', 'Box']; | ||
|
||
function generateRandomWord(index) { | ||
const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; | ||
const middle = middles[Math.floor(Math.random() * middles.length)]; | ||
const suffix = suffixes[Math.floor(Math.random() * suffixes.length)]; | ||
return `${prefix}${middle}${suffix}${index}`; | ||
} | ||
|
||
function* generateWordBatch(totalCount, batchSize = 1000) { | ||
for (let i = 0; i < totalCount; i += batchSize) { | ||
const batch = []; | ||
const currentBatchSize = Math.min(batchSize, totalCount - i); | ||
|
||
for (let j = 0; j < currentBatchSize; j++) { | ||
const word = generateRandomWord(i + j); | ||
batch.push({ | ||
word, | ||
awkPron: `어색한_${word}`, | ||
comPron: `일반적인_${word}`, | ||
info: `${word}에 대한 설명입니다. (테스트 데이터 ${i + j + 1})`, | ||
suggestedBy: 'admin', | ||
freq: Math.floor(Math.random() * 100), | ||
}); | ||
} | ||
yield batch; | ||
} | ||
} | ||
|
||
async function generateAndSaveData(totalCount) { | ||
console.time('Data Generation'); | ||
const fileName = './scripts/data/test-words-data.json'; | ||
const batchSize = 1000; | ||
let currentBatch = 1; | ||
const totalBatches = Math.ceil(totalCount / batchSize); | ||
|
||
fs.writeFileSync(fileName, '[\n', 'utf8'); | ||
|
||
for (const batch of generateWordBatch(totalCount, batchSize)) { | ||
console.log(`처리 중: ${currentBatch}/${totalBatches} 배치`); | ||
|
||
const batchData = batch.map((item) => JSON.stringify(item)).join(',\n'); | ||
fs.appendFileSync(fileName, currentBatch === 1 ? batchData : ',\n' + batchData, 'utf8'); | ||
|
||
currentBatch++; | ||
} | ||
|
||
fs.appendFileSync(fileName, '\n]', 'utf8'); | ||
|
||
console.log(`✅ ${totalCount}개의 테스트 데이터 생성 완료!`); | ||
console.log(`📁 파일 위치: ${fileName}`); | ||
} | ||
|
||
generateAndSaveData(100000).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters