// define the sql file path
if ($_POST['num_package'] != NULL) {
    $cur_model = $_SESSION['cur_model'] = $_POST['num_package'];
} elseif ($_POST['num_package'] == NULL && $_SESSION['cur_model'] == NULL) {
    $cur_model = $_SESSION[cur_model];
} else {
    $cur_model = $_SESSION[cur_model];
}
// baseline sql file path
if ($cur_model == $_SESSION['Model'][0]) {
    $sql_file = "ENERGYPLUS/idf/{$cur_model}/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
} else {
    // eem sql file path
    $sql_file = "eem/{$_SESSION['user_dir']}/Output/{$cur_model}.sql";
}
$eeb = new EEB_SQLITE3("{$sql_file}");
$e_vals = $eeb->getValuesByMonthly('END USE ENERGY CONSUMPTION ELECTRICITY MONTHLY', 'Meter', '', '%');
$ng_vals = $eeb->getValuesByMonthly('END USE ENERGY CONSUMPTION NATURAL GAS MONTHLY', 'Meter', '', '%');
// echo $eeb->getFilePath();
function printRow($row)
{
    foreach ($row as $v) {
        if ($v >= 0) {
            echo "<td> {$v} </td>";
        } else {
            echo "<td> 0.0 </td>";
        }
    }
}
function printMonthlyData($row)
{
// define the sql file path
if ($_POST['num_package'] != NULL) {
    $cur_model = $_SESSION['cur_model'] = $_POST['num_package'];
} elseif ($_POST['num_package'] == NULL && $_SESSION['cur_model'] == NULL) {
    $cur_model = $_SESSION[cur_model];
} else {
    $cur_model = $_SESSION[cur_model];
}
// baseline sql file path
if ($cur_model == $_SESSION['Model'][0]) {
    $sql_file = "ENERGYPLUS/idf/{$cur_model}/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
} else {
    // eem sql file path
    $sql_file = "eem/{$_SESSION['user_dir']}/Output/{$cur_model}.sql";
}
$eeb = new EEB_SQLITE3("{$sql_file}");
if ($_GET['for'] == '' && $_GET['table'] == '') {
    $_SESSION['for'] = '1ST FLOOR-MIDDLE';
    $_SESSION['table'] = 'Estimated Cooling Peak Load Components';
} else {
    if ($_GET['for'] == '') {
    } else {
        $_SESSION['for'] = $_GET['for'];
    }
    if ($_GET['table'] == '') {
    } else {
        $_SESSION['table'] = $_GET['table'];
    }
}
$load_vals = $eeb->getValuesByColumn('ZoneComponentLoadSummary', $_SESSION['for'], $_SESSION['table'], '%');
$zone = $eeb->getReportForStrings('ZoneComponentLoadSummary');
// define the sql file path
if ($_POST['num_package'] != NULL) {
    $cur_model = $_SESSION['cur_model'] = $_POST['num_package'];
} elseif ($_POST['num_package'] == NULL && $_SESSION['cur_model'] == NULL) {
    $cur_model = $_SESSION[cur_model];
} else {
    $cur_model = $_SESSION[cur_model];
}
// baseline sql file path
if ($cur_model == $_SESSION['Model'][0]) {
    $sql_file = "ENERGYPLUS/idf/{$cur_model}/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
} else {
    // eem sql file path
    $sql_file = "eem/{$_SESSION['user_dir']}/Output/{$cur_model}.sql";
}
$eeb = new EEB_SQLITE3("{$sql_file}");
$total_vals = $eeb->getValues('AnnualBuildingUtilityPerformanceSummary', 'Entire Facility', 'Site and Source Energy', '%');
$site_vals = $eeb->getValues('AnnualBuildingUtilityPerformanceSummary', 'Entire Facility', 'End Uses', 'kBtu');
$source_vals = $eeb->getValues('SourceEnergyEndUseComponentsSummary', 'Entire Facility', 'Source Energy End Use Components Summary', 'kBtu');
$area_vals = $eeb->getValues('AnnualBuildingUtilityPerformanceSummary', 'Entire Facility', 'Building Area', '%');
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>EEB Hub Simulation Tools: Comprehensive</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
// go to eeb_rb folder
$cmd = "runenergyplus eem_{$version}.idf /usr/local/EnergyPlus-8-0-0/WeatherData/USA_PA_Philadelphia.Intl.AP.724080_TMY3.epw";
$run = shell_exec($cmd);
# run the simulation
# add the new version EEM model to the list
$_SESSION['Model'][$version] = "eem_{$version}";
// udpate the latest version
$cur_model = "eem_{$version}";
//assign the current model
// baseline energy cost
$baselineCost = $_SESSION['newCost'][0];
// the current year from 1 to 10
$current_yr = ++$_SESSION['current_yr'];
// add a new energy simulation cost
$sql_file = "Output/{$cur_model}.sql";
$eeb = new EEB_SQLITE3("{$sql_file}");
$electric_tariff = $eeb->getValues('Tariff Report', 'BLDG101_ELECTRIC_RATE', 'Categories', '%');
$gas_tariff = $eeb->getValues('Tariff Report', 'BLDG101_GAS_RATE', 'Categories', '%');
$newCost = $_SESSION['newCost'][$current_yr] = round($electric_tariff['Total (~~$~~)'][Sum] + $gas_tariff['Total (~~$~~)'][Sum], 2);
$_SESSION['cur_model'] = "eem_{$version}";
// add a new installation cost
if ($addAirEconCost) {
    // get the air economizer data from Fans report table
    $fans = $eeb->getValues('EquipmentSummary', 'Entire Facility', 'Fans', '%');
    $airEconUnit = 0.5;
    // air economizer unit ($/CFM)
    $measureCost = $fans['FAN VARIABLE VOLUME 1']['Max Air Flow Rate'] * $airEconUnit;
    $installationCost += $measureCost;
}
if ($addCondensingBoilerCost) {
    // get the water boiler data from Central Plant report table
// define the sql file path
if ($_POST['num_package'] != NULL) {
    $cur_model = $_SESSION['cur_model'] = $_POST['num_package'];
} elseif ($_POST['num_package'] == NULL && $_SESSION['cur_model'] == NULL) {
    $cur_model = $_SESSION[cur_model];
} else {
    $cur_model = $_SESSION[cur_model];
}
// baseline sql file path
if ($cur_model == $_SESSION['Model'][0]) {
    $sql_file = "ENERGYPLUS/idf/{$cur_model}/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
} else {
    // eem sql file path
    $sql_file = "eem/{$_SESSION['user_dir']}/Output/{$cur_model}.sql";
}
$eeb = new EEB_SQLITE3("{$sql_file}");
$electric_tariff = $eeb->getValues('Tariff Report', 'BLDG101_ELECTRIC_RATE', 'Categories', '%');
$gas_tariff = $eeb->getValues('Tariff Report', 'BLDG101_GAS_RATE', 'Categories', '%');
function printRow($Row)
{
    foreach ($Row as $r) {
        if ($r > 0) {
            echo "<td> {$r} </td>";
        } else {
            echo "<td> 0.0 </td>";
        }
    }
}
function getRowData($Row)
{
    echo '[';
    $sql_file3 = "eem/{$user_dir}/Output/{$_POST[Model][3]}.sql";
} else {
    $sql_file3 = "ENERGYPLUS/idf/{$_SESSION[Model][0]}/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
}
/*
$sql_file1="eem/{$user_dir0}{$_POST['Model'][0]}.idf/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
$sql_file2="eem/{$user_dir1}{$_POST['Model'][1]}.idf/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
$sql_file3="eem/{$user_dir2}{$_POST['Model'][2]}.idf/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
$sql_file4="eem/{$user_dir3}{$_POST['Model'][3]}.idf/EnergyPlusPreProcess/EnergyPlus-0/eplusout.sql";
*/
$sql_file = "eem/{$user_dir}/Output/{$_SESSION['cur_model']}.sql";
#$eeb = new EEB_SQLITE3('php/modified_V8_V720.sql');
$baseline = new EEB_SQLITE3("./{$sql_file0}");
$eem1 = new EEB_SQLITE3("./{$sql_file1}");
$eem2 = new EEB_SQLITE3("./{$sql_file2}");
$eem3 = new EEB_SQLITE3("./{$sql_file3}");
# Baseline data
$base_e_vals = $baseline->getValuesByCategory('END USE ENERGY CONSUMPTION ELECTRICITY MONTHLY', 'Meter', '', '%');
$baseline_value[Jan] = array_sum($base_e_vals["January"]);
$baseline_value[Feb] = array_sum($base_e_vals["February"]);
$baseline_value[Mar] = array_sum($base_e_vals["March"]);
$baseline_value[Apr] = array_sum($base_e_vals["April"]);
$baseline_value[May] = array_sum($base_e_vals["May"]);
$baseline_value[Jun] = array_sum($base_e_vals["June"]);
$baseline_value[Jul] = array_sum($base_e_vals["July"]);
$baseline_value[Aug] = array_sum($base_e_vals["August"]);
$baseline_value[Sep] = array_sum($base_e_vals["September"]);
$baseline_value[Oct] = array_sum($base_e_vals["October"]);
$baseline_value[Nov] = array_sum($base_e_vals["November"]);
$baseline_value[Dec] = array_sum($base_e_vals["December"]);
$baseline_data = "[" . convertToDataString($baseline_value, NULL, NULL, NULL) . "]";