181 lines
6.7 KiB
PHP
181 lines
6.7 KiB
PHP
<?php
|
|
$message = "";
|
|
$gas_amount = "0";
|
|
$gas_country = "";
|
|
|
|
//
|
|
|
|
if (isset($_POST) && !empty($_POST['gas_amount'])) {
|
|
//$message = "post was detected";
|
|
$gas_amount = GetPostVar("gas_amount");
|
|
$gas_country = GetPostVar("gas_country", 'US');
|
|
$gas_number = GetPostVar("gas_number");
|
|
|
|
$emisson = getEmissionModel($gas_amount, $gas_number, $gas_country);
|
|
|
|
// you can attach your calls here
|
|
$message = "Gas Amount $=" . $gas_amount . " Country = " . $gas_country;
|
|
$message1 = " Estimated total CO2 emissions per re-fuel =" . $emisson[0];
|
|
$message2 = " Estimated CO2 emissions per month =" . $emisson[1];
|
|
$message3 = " Estimated CO2 emissions per week =" . $emisson[2];
|
|
}
|
|
|
|
function getEmissionModel($gas_amount, $gas_number, $gas_country = 'US') {
|
|
|
|
// GAS MODEL ASSUMPTIONS
|
|
|
|
$average_car_CO2_emissions = 168;
|
|
$average_distance_travelled_pre_litre_of_petrol_km = 13;
|
|
$average_price_per_litre_USD = 1.07;
|
|
if ('SG' == $gas_country) {
|
|
$average_price_per_litre_USD = 1.39;
|
|
}
|
|
|
|
|
|
$estimated_litres_of_fuel_purchased_litres = $gas_amount / $average_price_per_litre_USD;
|
|
$estimated_distance_travelled_per_re_fuel_km = $estimated_litres_of_fuel_purchased_litres * $average_distance_travelled_pre_litre_of_petrol_km;
|
|
|
|
$estimated_total_CO2_emissions_per_refuel = $estimated_distance_travelled_per_re_fuel_km * $average_car_CO2_emissions;
|
|
$estimated_CO2_emissions_per_month = $estimated_total_CO2_emissions_per_refuel * $gas_number;
|
|
$estimated_CO2_emissions_per_week = $estimated_CO2_emissions_per_month * 12 / 52;
|
|
|
|
|
|
$data = [];
|
|
|
|
$data[0] = $estimated_total_CO2_emissions_per_refuel;
|
|
$data[1] = $estimated_CO2_emissions_per_month;
|
|
$data[2] = $estimated_CO2_emissions_per_week;
|
|
|
|
return $data;
|
|
}
|
|
|
|
/*
|
|
*
|
|
CREATE TABLE emission_gas_model (
|
|
id SERIAL,
|
|
country varchar(2) UNIQUE REFERENCES country(code),
|
|
avrg_car_CO2_emissions INT DEFAULT 0,
|
|
avrg_dist_travel_pre_litre INT DEFAULT 0,
|
|
avrg_price_per_litre FLOAT DEFAULT 0,
|
|
created timestamp without time zone DEFAULT now(),
|
|
updated timestamp without time zone DEFAULT now(),
|
|
primary key(id)
|
|
);
|
|
|
|
INSERT INTO emission_gas_model(country,avrg_car_CO2_emissions,avrg_dist_travel_pre_litre,avrg_price_per_litre)
|
|
VALUES('US',168,13,1.07);
|
|
|
|
INSERT INTO emission_gas_model(country,avrg_car_CO2_emissions,avrg_dist_travel_pre_litre,avrg_price_per_litre)
|
|
VALUES('SG',168,13,1.39);
|
|
*/
|
|
//print_r($_POST);
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Gas Model Test</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="jumbotron text-center">
|
|
<h1>Test Gas Emission Model</h1>
|
|
<p>Reference Emission Model - <a href="https://docs.google.com/spreadsheets/d/1c93ZRl_XXViCvkP6NN2tXXvwbG25TWhlRqKX11Ezrw4/edit#gid=328549878">https://docs.google.com/spreadsheets/d/1c93ZRl_XXViCvkP6NN2tXXvwbG25TWhlRqKX11Ezrw4/edit#gid=328549878</a> </p>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-sm-4">
|
|
<h3>Technical Description</h3>
|
|
<p> This interface uses the model to calculate the emission my gas purchase</p>
|
|
<p>The function prepared should be used where the model is needed in data generation </p>
|
|
</div>
|
|
<div class="col-sm-8">
|
|
<h3>Find Ride</h3>
|
|
<form method='post' action="#">
|
|
|
|
<table class="table table-striped">
|
|
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">Amount</th>
|
|
<td>
|
|
|
|
<input type="text" class="form-control" name="gas_amount" value="<?= $gas_amount ?>" placeholder="Enter Start Address" aria-label="Enter Start Address" aria-describedby="basic-addon2" >
|
|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">Number of Refill</th>
|
|
<td>
|
|
<select class="form-control" name="gas_number">
|
|
<option value="1">1</option>
|
|
<option value="2">2</option>
|
|
<option value="3">3</option>
|
|
<option value="4">4</option>
|
|
</select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
<th scope="row">Country</th>
|
|
<td>
|
|
<select class="form-control" name="gas_country">
|
|
<option value="">Select Country</option>
|
|
<option value="US">United States</option>
|
|
<option value="SG">Singapore</option>
|
|
</select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"></th>
|
|
<td style="text-align: right;"><button type="submit" name="foo" class="btn btn-info">Submit</button></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
<div class="row">
|
|
<h2><?= $message ?></h2><br><p>
|
|
|
|
</div>
|
|
<div class="row">
|
|
|
|
<h2><?= $message1 ?></h2><br><p>
|
|
|
|
</div>
|
|
<div class="row">
|
|
|
|
<h2><?= $message2 ?></h2><br><p>
|
|
|
|
</div>
|
|
<div class="row">
|
|
|
|
<h2><?= $message3 ?></h2><br>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|
|
|
|
<?php
|
|
|
|
function GetPostVar($name, $sDefault = "") {
|
|
global $_GET, $_POST;
|
|
return (isset($_POST[$name])) ? strip_tags($_POST[$name]) : ((isset($_GET[$name])) ? strip_tags($_GET[$name]) : $sDefault);
|
|
}
|
|
?>
|