← back to Handbag Auth Nextjs
auction-viewer/generate-test-data.js
154 lines
const Database = require('better-sqlite3');
const path = require('path');
const crypto = require('crypto');
const DB_PATH = path.join(__dirname, '..', 'data', 'auction-history', 'auctions.db');
const brands = [
"Hermes Birkin", "Hermes Kelly", "Chanel Classic Flap", "Chanel Boy", "Chanel 19",
"Louis Vuitton Neverfull", "Louis Vuitton Speedy", "Dior Lady Dior", "Dior Saddle",
"Gucci Dionysus", "Gucci Marmont", "Prada Galleria", "Bottega Veneta Cassette",
"Celine Luggage", "Saint Laurent Kate", "Balenciaga City", "Fendi Baguette"
];
const auctionHouses = [
"Christie's", "Sotheby's", "Heritage Auctions", "Bonhams", "Phillips"
];
const colors = [
"Black", "Brown", "Beige", "Navy", "Red", "Pink", "White", "Gray", "Blue", "Green"
];
const materials = [
"Leather", "Canvas", "Suede", "Exotic Skin", "Patent Leather"
];
function randomElement(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generateAuctionId() {
return 'LA-' + crypto.randomBytes(6).toString('hex').toUpperCase();
}
function generateDataHash(data) {
const hash_string = `${data.auction_id}:${data.title}:${data.current_price}`;
return crypto.createHash('md5').update(hash_string).digest('hex');
}
function generateAuction() {
const brand = randomElement(brands);
const color = randomElement(colors);
const material = randomElement(materials);
const size = randomInt(20, 40);
const title = `${brand} ${color} ${material} ${size}cm`;
const auction_house = randomElement(auctionHouses);
// Generate realistic prices
const basePrice = randomInt(1000, 50000);
const estimate_low = Math.round(basePrice * (1 + Math.random() * 0.5));
const estimate_high = Math.round(estimate_low * (1.2 + Math.random() * 0.5));
const current_price = Math.round(estimate_low * (0.5 + Math.random() * 0.8));
const auction_id = generateAuctionId();
const lot_number = `LOT-${randomInt(100, 999)}`;
const url = `https://www.liveauctioneers.com/item/${auction_id}`;
// Random date in the last 30 days
const daysAgo = randomInt(0, 30);
const end_date = new Date();
end_date.setDate(end_date.getDate() - daysAgo);
const data = {
auction_id,
title,
auction_house,
current_price,
estimate_low,
estimate_high,
end_date: end_date.toISOString().split('T')[0],
lot_number,
url,
search_term: brand
};
data.data_hash = generateDataHash(data);
return data;
}
function generateTestData(count = 100) {
console.log(`Generating ${count} test auction records...`);
const db = new Database(DB_PATH);
const insert = db.prepare(`
INSERT OR IGNORE INTO auctions
(auction_id, title, auction_house, current_price, estimate_low,
estimate_high, end_date, lot_number, url, search_term, data_hash)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`);
let inserted = 0;
db.transaction(() => {
for (let i = 0; i < count; i++) {
const auction = generateAuction();
const result = insert.run(
auction.auction_id,
auction.title,
auction.auction_house,
auction.current_price,
auction.estimate_low,
auction.estimate_high,
auction.end_date,
auction.lot_number,
auction.url,
auction.search_term,
auction.data_hash
);
if (result.changes > 0) {
inserted++;
}
}
})();
console.log(`✓ Generated ${inserted} auction records`);
// Show statistics
const stats = db.prepare(`
SELECT
COUNT(*) as total,
COUNT(DISTINCT search_term) as brands,
COUNT(DISTINCT auction_house) as houses,
ROUND(AVG(current_price), 2) as avg_price,
MIN(current_price) as min_price,
MAX(current_price) as max_price
FROM auctions
`).get();
console.log('\nDatabase Statistics:');
console.log('===================');
console.log(`Total Auctions: ${stats.total}`);
console.log(`Unique Brands: ${stats.brands}`);
console.log(`Auction Houses: ${stats.houses}`);
console.log(`Avg Price: $${stats.avg_price}`);
console.log(`Price Range: $${stats.min_price} - $${stats.max_price}`);
db.close();
}
if (require.main === module) {
const count = parseInt(process.argv[2]) || 100;
generateTestData(count);
}
module.exports = generateTestData;