Skip to content

Commit 66aa86e

Browse files
Merge pull request #1724 from rishabhchaudhary0210/main
#1144 Added Carbon FootPrint Calculator
2 parents 84cb465 + d40c9a8 commit 66aa86e

8 files changed

Lines changed: 455 additions & 1 deletion

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
9+
<link rel="stylesheet" href="./style.css">
10+
<title>Carbon FootPrint Calculator</title>
11+
</head>
12+
13+
<body>
14+
<div class="container">
15+
<h1>Carbon FootPrint Calculator</h1>
16+
<form action="" class="box bus-form">
17+
<label for="bill">Electricity Consumption : </label>
18+
<input type="text" id="bill" name="bill" placeholder="Enter Amount of Units Consumed">
19+
<label for="vehicle">Car Type (Used for Transporting Employs) : </label>
20+
<select name="vehicle" id="vehicle">
21+
<option value="petrol">Petrol</option>
22+
<option value="diesel">Diesel</option>
23+
<option value="cng">CNG</option>
24+
<option value="ev">Ev and Hybrids</option>
25+
</select>
26+
<label for="mileage">MileAge : </label>
27+
<input type="text" name="'mileage" id="mileage" placeholder="Enter MileAge of your car">
28+
<label for="distance">Distance Travelled : </label>
29+
<input type="text" id="distance" name="distance" placeholder="Enter Distance Travelled">
30+
<label for="ac">Air Condition Usage : </label>
31+
<input type="text" id="ac" name="ac" placeholder="Enter Air Condition Consumption">
32+
<span>
33+
34+
<button type="submit">Calculate</button>
35+
<a class="link" href="./index.html">Home</a>
36+
</span>
37+
</form>
38+
<div class="answer-box">
39+
40+
<h1 class="result"> </h1>
41+
<button id="btn">Calculate Again</button>
42+
</div>
43+
</div>
44+
45+
46+
<script src="./script.js"></script>
47+
</body>
48+
49+
</html>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
6+
7+
}
8+
9+
.container {
10+
height: 100vh;
11+
width: 100%;
12+
display: flex;
13+
justify-content: space-evenly;
14+
align-items: center;
15+
padding-top: 30px;
16+
background-color: rgb(0, 0, 0, 0.1);
17+
}
18+
19+
.box {
20+
font-size: 5rem;
21+
height: 200px;
22+
width: 200px;
23+
display: flex;
24+
flex-direction: column;
25+
align-items: center;
26+
justify-content: center;
27+
cursor: pointer;
28+
border-radius: 10px;
29+
transition: all 0.3s ease;
30+
background: linear-gradient(rgb(0, 0, 0, 0.5), black);
31+
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
32+
}
33+
34+
nav {
35+
position: absolute;
36+
top: 0;
37+
right: 0;
38+
height: 85px;
39+
display: flex;
40+
justify-content: center;
41+
align-items: center;
42+
width: 100%;
43+
color:white;
44+
background: linear-gradient(rgb(0, 0, 0, 0.5), rgb(107, 107, 107),rgb(83, 72, 72));
45+
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
46+
}
47+
nav h1{
48+
font-size: 2rem;
49+
word-spacing: 25px;
50+
letter-spacing: 10px;
51+
text-align: center;
52+
}
53+
54+
.box h4 {
55+
color: aliceblue;
56+
font-size: 1.7rem;
57+
margin: 15px 0;
58+
}
59+
60+
.box:hover {
61+
transform: translateY(-8px);
62+
}
63+
64+
.container a {
65+
color: aliceblue;
66+
text-decoration: none;
67+
}
68+
69+
@media screen and (max-width:900px){
70+
nav h1{
71+
font-size: 1.7rem;
72+
word-spacing: 0px;
73+
letter-spacing: 4px;
74+
}
75+
.box{
76+
width: 170px;
77+
height: 170px;
78+
font-size: 3.5rem;
79+
}
80+
}
81+
@media screen and (max-width:590px) {
82+
nav{
83+
height: 100px;
84+
}
85+
nav h1{
86+
/* font-size: 1.4rem; */
87+
word-spacing: 2px;
88+
letter-spacing: 1px;
89+
}
90+
.container{
91+
flex-direction: column;
92+
}
93+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
9+
<link rel="stylesheet" href="./index.css">
10+
<title>Document</title>
11+
</head>
12+
13+
<body>
14+
15+
<nav>
16+
<h1>CARBON FOOTPRINT CALCULATOR</h1>
17+
</nav>
18+
19+
<div class="container">
20+
<a href="./individual.html">
21+
<div class="person box">
22+
<h4>Individual</h4>
23+
<i class="fa fa-user" aria-hidden="true"></i>
24+
</div>
25+
</a>
26+
<a href="./business.html">
27+
<div class="business box">
28+
<h4>Business</h4>
29+
<i class="fa fa-building" aria-hidden="true"></i>
30+
</div>
31+
</a>
32+
</div>
33+
34+
35+
36+
<script src="./script.js"></script>
37+
</body>
38+
39+
</html>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
9+
<link rel="stylesheet" href="./style.css">
10+
<title>Carbon FootPrint Calculator</title>
11+
</head>
12+
13+
<body>
14+
15+
<div class="container">
16+
<h1>Carbon FootPrint Calculator</h1>
17+
<form action="" method="POST" class="box ind-form">
18+
<label for="bill">Electricity Consumption : </label>
19+
<input type="text" id="bill" name="bill" placeholder="Enter Amount of Units Consumed">
20+
<label for="vehicle">Car Type : </label>
21+
<select name="vehicle" id="vehicle">
22+
<option value="petrol">Petrol</option>
23+
<option value="diesel">Diesel</option>
24+
<option value="cng">CNG</option>
25+
<option value="ev">Ev and Hybrids</option>
26+
</select>
27+
<label for="mileage">MileAge : </label>
28+
<input type="text" name="mileage" id="mileage" placeholder="Enter MileAge of your car">
29+
<label for="distance">Distance Travelled : </label>
30+
<input type="text" id="distance" name="distance" placeholder="Enter Distance Travelled">
31+
<label for="ac">Air Conditioner Usage : </label>
32+
<input type="text" id="ac" name="ac" placeholder="Enter Air Condition Consumption">
33+
<label for="gas">LPG Consumption (in grams) : </label>
34+
<input type="text" id="gas" name="gas" placeholder="Enter LPG Consumption">
35+
<span>
36+
<button type="submit">Calculate</button>
37+
<a class="link" href="./index.html">Home</a>
38+
</span>
39+
</form>
40+
<div class="answer-box">
41+
42+
<h1 class="result"> </h1>
43+
<button id="btn">Calculate Again</button>
44+
</div>
45+
</div>
46+
47+
<script src="./script.js"></script>
48+
</body>
49+
50+
</html>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
const result = document.querySelector('.result');
3+
const form = document.querySelector('form');
4+
const newButton = document.querySelector('#btn');
5+
const answerBox = document.querySelector('.answer-box');
6+
7+
console.log(form)
8+
form.addEventListener('submit',(e)=>{
9+
e.preventDefault();
10+
let { bill, vehicle, mileage, distance, ac} = e.target;
11+
12+
let gas = e.target.gas;
13+
14+
let answer = calculateFootPrint(bill.value, vehicle.value, mileage.value, distance.value, ac.value, (gas) ? gas.value : null);
15+
16+
bill.value = '';
17+
vehicle.value = '';
18+
mileage.value = '';
19+
distance.value = '';
20+
ac.value = '';
21+
if(gas){
22+
gas.value = '';
23+
}
24+
answerBox.style.display = 'flex';
25+
form.style.display = 'none';
26+
result.innerHTML = "You carbon emission is: " + answer.toFixed(4);
27+
})
28+
29+
30+
newButton.addEventListener('click',()=>{
31+
// answerBox.style.display = 'none';
32+
location.reload();
33+
// form.style.display = 'block';
34+
})
35+
36+
function calculateFootPrint(bill, vehicle, mileage, distance, ac, gas){
37+
let emission = 0;
38+
39+
if (vehicle == 'petrol'){
40+
emissions_factor = 2.31;
41+
}else if (vehicle == 'diesel'){
42+
emissions_factor = 2.68;
43+
}
44+
45+
emission += (distance / mileage) * emissions_factor
46+
console.log(emission);
47+
emissions_factor2 = 0.93
48+
emission = emission + bill*emissions_factor2
49+
console.log(emission);
50+
51+
if(gas){
52+
emissions_factor3 = 2.983
53+
emission = emission + emissions_factor3*gas
54+
}
55+
56+
return emission;
57+
}
58+
59+
60+
// emission = 0
61+
// current = float(request.POST['electricity']) # In units = KWH
62+
// gas = float(request.POST['gas']) # In grams
63+
// vehicle = request.POST['vehicle'] # Car , Bus
64+
// milage = float(request.POST['mileage'])
65+
// distance =float( request.POST['distance'])
66+
// emissions_factor = 0
67+
68+
// if (vehicle == "Car"):
69+
// car_fuel = request.POST['fuel'] # Data is shared in the group
70+
// if car_fuel == 'gasoline':
71+
// emissions_factor = 2.31 # in kg CO2 per liter
72+
// elif car_fuel == 'diesel':
73+
// emissions_factor = 2.68 # in kg CO2 per liter
74+
// elif (vehicle == "Bus"):
75+
// car_fuel = request.POST['fuel'] # Data is shared in the group
76+
// emissions_factor = 0.68 # in kg CO2 per km
77+
78+
// # Fuel
79+
80+
// if vehicle == 'car':
81+
// emission = (distance / milage) * emissions_factor
82+
// elif vehicle == 'bus':
83+
// emission = distance * emissions_factor
84+
// # Electricity
85+
// emissions_factor = 0.93
86+
// emission = emission + current*emissions_factor
87+
88+
// #LPG
89+
// emissions_factor = 2.983
90+
// emission = emission + emissions_factor*gas

0 commit comments

Comments
 (0)