<?php

include "db.class.php";

// $db = new db();


// function calculate_horizontal_cylinder_volume($radius_mm, $depth_mm, $tank_length_mm)
// {
//     // Convert measurements to meters
//     $radius = $radius_mm / 1000; // Convert millimeters to meters
//     $depth = $depth_mm / 1000; // Convert millimeters to meters
//     $tank_length = $tank_length_mm / 1000; // Convert millimeters to meters

//     // Calculate the angle of the segment
//     $theta = acos((($radius - $depth) / $radius));

//     // Calculate the volume of the fluid
//     $volume_fluid = $theta * pow($radius, 2) * $tank_length;

//     // Calculate the total volume of the tank
//     $volume_total = M_PI * pow($radius, 2) * $tank_length;

//     // Convert volumes to liters
//     $volume_fluid_liters = $volume_fluid * 1000; // Convert cubic meters to liters
//     $volume_total_liters = $volume_total * 1000; // Convert cubic meters to liters

//     // Calculate the percentage of the tank filled
//     $percentage_filled = ($volume_fluid_liters / $volume_total_liters) * 100;

//     return array(
//         'fluid_volume_liters' => $volume_fluid_liters,
//         'total_volume_liters' => $volume_total_liters,
//         'percentage_filled' => $percentage_filled
//     );
// }



// $res = $db->exec_query('tanks', ['*'], '', '', '', '', "record_id = 1");
// $data = $res->fetch_assoc();

// $res_2 = $db->exec_query('tank_level_log', ['*'], '', '', '', '', "tank_id = 1", "ORDER BY record_id DESC ");
// $data_2 = $res_2->fetch_assoc();
// echo "<br> Dis:".$data_2['distance'];

// // Example usage:
// echo  "<br> Rad:".$radius_mm = $data['radius_mm']; // replace with your value in millimeters
// // echo  "<br> fluid Height:".$height_mm = ($data['radius_mm'] * 2) - 10 - $data_2['distance']; // replace with your value in millimeters
// echo "<br> Tank Legnth:".$tank_length_mm = $data['length_mm']; // replace with your value in millimeters
// echo "<br> Height :".$height_mm = $data['radius_mm'] * 2 - $data_2['distance'];

// $volumes = calculate_horizontal_cylinder_volume($radius_mm,$height_mm,$tank_length_mm);

// echo "<br> Volume of fluid in the tank: " . $volumes['fluid_volume_liters'] . " Liters<br>";
// echo "<br> Total volume of the tank: " . $volumes['total_volume_liters'] . " Liters<br>";
// echo ($volumes['fluid_volume_liters'] / $volumes['total_volume_liters']) * 100;
// echo "<br>";

// function calculate_horizontal_oval_tank_volume($radius1_mm, $radius2_mm, $depth_mm, $tank_length_mm)
// {
//     // Convert measurements to meters
//     $radius1 = $radius1_mm / 1000; // Convert millimeters to meters
//     $radius2 = $radius2_mm / 1000; // Convert millimeters to meters
//     $depth = $depth_mm / 1000; // Convert millimeters to meters
//     $tank_length = $tank_length_mm / 1000; // Convert millimeters to meters

//     // Calculate the angle of the segment
//     $theta = acos((($radius1 - $depth) / $radius1));

//     // Calculate the volume of the fluid
//     $volume_fluid = ($theta * $radius1 * $radius2) * $tank_length;

//     // Convert volume to liters
//     $volume_fluid_liters = $volume_fluid * 1000; // Convert cubic meters to liters

//     // Calculate the total volume of the tank
//     $volume_total = (M_PI * $radius1 * $radius2) * $tank_length;

//     // Convert volumes to liters
//     $volume_total_liters = $volume_total * 1000; // Convert cubic meters to liters

//     // Calculate the percentage of the tank filled
//     $percentage_filled = ($volume_fluid_liters / $volume_total_liters) * 100;

//     return array(
//         'fluid_volume_liters' => $volume_fluid_liters,
//         'total_volume_liters' => $volume_total_liters,
//         'percentage_filled' => $percentage_filled
//     );
// }



$db = new db();

// $res = $db->exec_query('fuel_movement',['*']);
// while($row = $res->fetch_assoc()){


//     $db->Update('fuel_movement',['asset_id'],["1_".$row['asset_id']],"record_id = {$row['record_id']}");

// }


// var_dump(calculate_horizontal_oval_tank_volume(612.5,390,390,1230));