v17
This commit is contained in:
parent
9f71e36542
commit
c0f0a02ee2
99
generate_activity.php
Normal file
99
generate_activity.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
function generateActivity($pdo) {
|
||||
echo "Starting to generate matches, swipes, and notifications...\n";
|
||||
|
||||
$stmt = $pdo->query("SELECT id, role, full_name FROM users WHERE role IN ('founder', 'investor')");
|
||||
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$founders = array_values(array_filter($users, fn($u) => $u['role'] === 'founder'));
|
||||
$investors = array_values(array_filter($users, fn($u) => $u['role'] === 'investor'));
|
||||
|
||||
if (count($founders) < 2 || count($investors) < 2) {
|
||||
echo "Not enough users found. Please run seed_data.php first.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
echo "Found " . count($founders) . " founders and " . count($investors) . " investors.\n";
|
||||
|
||||
$swipeStmt = $pdo->prepare("INSERT IGNORE INTO swipes (swiper_id, swiped_id, direction, created_at) VALUES (?, ?, ?, NOW())");
|
||||
$matchStmt = $pdo->prepare("INSERT IGNORE INTO matches (user1_id, user2_id, status, created_at) VALUES (?, ?, 'active', NOW())");
|
||||
$msgStmt = $pdo->prepare("INSERT INTO messages (sender_id, receiver_id, content, created_at) VALUES (?, ?, ?, NOW())");
|
||||
$notifStmt = $pdo->prepare("INSERT INTO notifications (user_id, content, created_at) VALUES (?, ?, NOW())");
|
||||
|
||||
// 1. Investor-Founder matches
|
||||
foreach ($investors as $investor) {
|
||||
$numSwipes = rand(3, 5);
|
||||
$founderKeys = array_rand($founders, min($numSwipes, count($founders)));
|
||||
$targetIndices = is_array($founderKeys) ? $founderKeys : [$founderKeys];
|
||||
|
||||
foreach ($targetIndices as $founderIdx) {
|
||||
$founder = $founders[$founderIdx];
|
||||
|
||||
// Investor likes founder
|
||||
$swipeStmt->execute([$investor['id'], $founder['id'], 'like']);
|
||||
|
||||
// 40% chance founder likes back
|
||||
if (rand(1, 10) <= 4) {
|
||||
$swipeStmt->execute([$founder['id'], $investor['id'], 'like']);
|
||||
|
||||
$u1 = min($investor['id'], $founder['id']);
|
||||
$u2 = max($investor['id'], $founder['id']);
|
||||
$matchStmt->execute([$u1, $u2]);
|
||||
|
||||
// Notifications
|
||||
$notifStmt->execute([$investor['id'], "You have a new match with {$founder['full_name']}!"]);
|
||||
$notifStmt->execute([$founder['id'], "You have a new match with {$investor['full_name']}!"]);
|
||||
|
||||
// Message
|
||||
$msgStmt->execute([
|
||||
$investor['id'],
|
||||
$founder['id'],
|
||||
"Hi {$founder['full_name']}! I'm impressed by your startup's mission. Let's talk!"
|
||||
]);
|
||||
echo "Match: {$investor['full_name']} <-> {$founder['full_name']}\n";
|
||||
} else {
|
||||
echo "Swipe: {$investor['full_name']} liked {$founder['full_name']}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Founder-Founder matches
|
||||
foreach ($founders as $index => $founder) {
|
||||
$otherFounders = $founders;
|
||||
unset($otherFounders[$index]);
|
||||
$otherFounders = array_values($otherFounders);
|
||||
|
||||
$numSwipes = rand(1, 2);
|
||||
$otherKeys = array_rand($otherFounders, min($numSwipes, count($otherFounders)));
|
||||
$targetIndices = is_array($otherKeys) ? $otherKeys : [$otherKeys];
|
||||
|
||||
foreach ($targetIndices as $idx) {
|
||||
$other = $otherFounders[$idx];
|
||||
$swipeStmt->execute([$founder['id'], $other['id'], 'like']);
|
||||
|
||||
// 30% chance they match
|
||||
if (rand(1, 10) <= 3) {
|
||||
$swipeStmt->execute([$other['id'], $founder['id'], 'like']);
|
||||
$u1 = min($founder['id'], $other['id']);
|
||||
$u2 = max($founder['id'], $other['id']);
|
||||
$matchStmt->execute([$u1, $u2]);
|
||||
|
||||
$notifStmt->execute([$founder['id'], "New co-founder match with {$other['full_name']}!"]);
|
||||
$notifStmt->execute([$other['id'], "New co-founder match with {$founder['full_name']}!"]);
|
||||
|
||||
echo "Co-founder Match: {$founder['full_name']} <-> {$other['full_name']}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Finished generating initial activity.\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
generateActivity($pdo);
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user