<?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 "CONFERENCE KPI OPTIMIZATION\n";

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

$rows=
$db->query("
SELECT *
FROM conference_health_metrics
")->fetchAll(PDO::FETCH_ASSOC);

foreach($rows as $r){

    $current=
    (float)$r['overall_health_score'];

    $target=85;

    $gap=
    round($target-$current,2);

    if($gap<0){
        $gap=0;
    }

    $db->prepare("
    INSERT INTO conference_kpi_optimization
    (
        conference_id,
        kpi_name,
        current_value,
        target_value,
        improvement_gap,
        recommendation
    )
    VALUES
    (
        ?,?,?,?,?,?
    )
    ")->execute([
        $r['conference_id'],
        'Conference Health',
        $current,
        $target,
        $gap,
        'Improve reviewer quality, track balance and workflow efficiency'
    ]);

}

echo "DONE\n";
