<?php

define('BASE_PATH',realpath(__DIR__.'/../..'));

require_once BASE_PATH.'/config/autoload.php';
require_once BASE_PATH.'/config/bootstrap.php';

$db=\App\Core\Database::getInstance();

echo "CROSS CONFERENCE RESOURCE OPTIMIZER\n";

$db->exec(
"TRUNCATE TABLE cross_conference_resource_optimizer"
);

$best=
$db->query("
SELECT conference_id,overall_score
FROM conference_portfolio_intelligence
ORDER BY portfolio_rank
LIMIT 1
")->fetch(PDO::FETCH_ASSOC);

$worst=
$db->query("
SELECT conference_id,overall_score
FROM conference_portfolio_intelligence
ORDER BY portfolio_rank DESC
LIMIT 1
")->fetch(PDO::FETCH_ASSOC);

if($best && $worst){

    $score=
    round(
        ($best['overall_score'] - $worst['overall_score']),
        2
    );

    $db->prepare("
    INSERT INTO
    cross_conference_resource_optimizer
    (
        source_conference_id,
        target_conference_id,
        resource_type,
        optimization_score,
        recommendation_text
    )
    VALUES
    (
        ?,?,?,?,?
    )
    ")->execute([
        $best['conference_id'],
        $worst['conference_id'],
        'reviewer_pool',
        $score,
        'Share reviewer capacity from high-performing conference to low-performing conference'
    ]);

}

echo "DONE\n";
