Initial commit of step-competition project
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
81
sample-data.js
Normal file
81
sample-data.js
Normal file
@@ -0,0 +1,81 @@
|
||||
// Sample data script to populate the database with test data
|
||||
// Run with: node sample-data.js
|
||||
|
||||
const { initializeDatabase, runQuery } = require('./src/database');
|
||||
|
||||
async function populateSampleData() {
|
||||
console.log('Initializing database...');
|
||||
initializeDatabase();
|
||||
|
||||
// Wait a bit for database to initialize
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
try {
|
||||
// Create teams
|
||||
console.log('Creating teams...');
|
||||
const team1 = await runQuery('INSERT INTO teams (name) VALUES (?)', ['Team Velocity']);
|
||||
const team2 = await runQuery('INSERT INTO teams (name) VALUES (?)', ['Team Momentum']);
|
||||
const team3 = await runQuery('INSERT INTO teams (name) VALUES (?)', ['Team Endurance']);
|
||||
|
||||
console.log('Teams created!');
|
||||
|
||||
// Create participants
|
||||
console.log('Creating participants...');
|
||||
const participants = [
|
||||
// Team Velocity
|
||||
{ name: 'Alice Johnson', email: 'alice@example.com', team_id: team1.id },
|
||||
{ name: 'Bob Smith', email: 'bob@example.com', team_id: team1.id },
|
||||
{ name: 'Carol Williams', email: 'carol@example.com', team_id: team1.id },
|
||||
// Team Momentum
|
||||
{ name: 'David Brown', email: 'david@example.com', team_id: team2.id },
|
||||
{ name: 'Eve Davis', email: 'eve@example.com', team_id: team2.id },
|
||||
{ name: 'Frank Miller', email: 'frank@example.com', team_id: team2.id },
|
||||
// Team Endurance
|
||||
{ name: 'Grace Wilson', email: 'grace@example.com', team_id: team3.id },
|
||||
{ name: 'Henry Moore', email: 'henry@example.com', team_id: team3.id },
|
||||
{ name: 'Iris Taylor', email: 'iris@example.com', team_id: team3.id },
|
||||
];
|
||||
|
||||
const participantIds = [];
|
||||
for (const p of participants) {
|
||||
const result = await runQuery(
|
||||
'INSERT INTO participants (name, email, team_id) VALUES (?, ?, ?)',
|
||||
[p.name, p.email, p.team_id]
|
||||
);
|
||||
participantIds.push(result.id);
|
||||
}
|
||||
|
||||
console.log('Participants created!');
|
||||
|
||||
// Create sample step entries for the past week
|
||||
console.log('Creating sample step entries...');
|
||||
const today = new Date();
|
||||
|
||||
for (let dayOffset = 0; dayOffset < 7; dayOffset++) {
|
||||
const date = new Date(today);
|
||||
date.setDate(date.getDate() - dayOffset);
|
||||
const dateStr = date.toISOString().split('T')[0];
|
||||
|
||||
for (const participantId of participantIds) {
|
||||
// Random steps between 5000 and 15000
|
||||
const steps = Math.floor(Math.random() * 10000) + 5000;
|
||||
|
||||
await runQuery(
|
||||
'INSERT INTO daily_steps (participant_id, date, steps) VALUES (?, ?, ?)',
|
||||
[participantId, dateStr, steps]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Sample data created successfully!');
|
||||
console.log('\nYou can now start the app with: npm start');
|
||||
console.log('Then visit: http://localhost:3060');
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('Error creating sample data:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
populateSampleData();
|
||||
Reference in New Issue
Block a user