86 lines
3.7 KiB
JavaScript
86 lines
3.7 KiB
JavaScript
const fetch = require('node-fetch');
|
|
|
|
// Get number of teams from command line argument, default to 10
|
|
const numTeams = parseInt(process.argv[2]) || 10;
|
|
|
|
// Generate team names dynamically
|
|
const teamNames = [
|
|
'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota', 'Kappa',
|
|
'Lambda', 'Mu', 'Nu', 'Xi', 'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon',
|
|
'Phi', 'Chi', 'Psi', 'Omega'
|
|
];
|
|
|
|
// Generate SVG logo based on team name
|
|
function generateSVGLogo(teamName, size = 40) {
|
|
// Use team name to generate consistent colors and patterns
|
|
let hash = 0;
|
|
for (let i = 0; i < teamName.length; i++) {
|
|
hash = teamName.charCodeAt(i) + ((hash << 5) - hash);
|
|
}
|
|
|
|
const hue = hash % 360;
|
|
const saturation = 60 + (hash % 30);
|
|
const lightness = 40 + (hash % 30);
|
|
const color = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
|
|
|
// Generate secondary color
|
|
const secondaryHue = (hue + 180) % 360;
|
|
const secondaryColor = `hsl(${secondaryHue}, ${saturation}%, ${lightness}%)`;
|
|
|
|
// Choose a logo pattern based on hash
|
|
const pattern = hash % 4;
|
|
const initials = teamName.split(' ').map(w => w[0]).join('').toUpperCase().slice(0, 2);
|
|
|
|
let svgContent = '';
|
|
|
|
switch (pattern) {
|
|
case 0: // Circle with initials
|
|
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><circle cx="${size/2}" cy="${size/2}" r="${size/2}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><text x="50%" y="55%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
|
|
break;
|
|
|
|
case 1: // Square with diagonal
|
|
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><rect x="2" y="2" width="${size-4}" height="${size-4}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><line x1="0" y1="0" x2="${size}" y2="${size}" stroke="${secondaryColor}" stroke-width="3"/><text x="50%" y="55%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
|
|
break;
|
|
|
|
case 2: // Triangle
|
|
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><polygon points="${size/2},5 ${size-5},${size-5} 5,${size-5}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><text x="50%" y="60%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
|
|
break;
|
|
|
|
case 3: // Diamond
|
|
svgContent = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><polygon points="${size/2},5 ${size-5},${size/2} ${size/2},${size-5} 5,${size/2}" fill="${color}" stroke="${secondaryColor}" stroke-width="2"/><text x="50%" y="55%" text-anchor="middle" font-size="${size/3}" fill="white" font-family="Arial, sans-serif" font-weight="bold">${initials}</text></svg>`;
|
|
break;
|
|
}
|
|
|
|
return svgContent;
|
|
}
|
|
|
|
const teams = [];
|
|
for (let i = 0; i < numTeams; i++) {
|
|
const teamName = `Team ${teamNames[i]}`;
|
|
teams.push({
|
|
name: teamName,
|
|
logo: generateSVGLogo(teamName)
|
|
});
|
|
}
|
|
|
|
async function addTeams() {
|
|
for (const team of teams) {
|
|
try {
|
|
const res = await fetch('http://localhost:4000/api/teams', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ name: team.name, logo: team.logo })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok) {
|
|
console.log(`Added: ${team.name} with SVG logo`);
|
|
} else {
|
|
console.log(`Failed to add ${team.name}: ${data.error}`);
|
|
}
|
|
} catch (err) {
|
|
console.log(`Error adding ${team.name}:`, err.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
addTeams();
|