Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Plant Growth Calculator #1290

Merged
merged 7 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Calculators/Plant-Growth-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Plant Growth Predictor

## Description

The Plant Growth Predictor is a web application designed to forecast the growth rate of your houseplants. This tool considers various factors such as plant species, light, water, soil conditions, and temperature to provide accurate predictions.

## Tech Stacks

- HTML
- CSS
- JavaScript

## Features

- Select the species of your plant (Succulents, Ferns, Flowering Plants, Vegetables).
- Select the type of light condition (Full Sunlight, Partial Shade, Indirect Light).
- Enter the watering amount as a percentage of plant needs.
- Select the type of soil (Sandy, Loamy, Clay).
- Enter the ambient temperature in degrees Celsius.
- Perform the calculation and display the predicted growth rate in inches per month.

## Example

To predict the growth rate for a Tomato plant:
1. Select "Vegetables" from the plant species dropdown menu.
2. Select "Full Sunlight" from the light conditions dropdown menu (Tomato plants thrive in full sunlight).
3. Enter the watering amount, for example, 80% (Tomato plants require consistent watering).
4. Select "Loamy" from the soil type dropdown menu (Tomato plants prefer well-draining loamy soil).
5. Enter the ambient temperature, for example, 25°C (Tomato plants grow well in warm temperatures).
6. Click "Calculate Prediction" to get the predicted growth rate in inches per month.

## Screenshots


![image](https://github.com/Rakesh9100/CalcDiverse/assets/118645569/5208670c-c86e-4df5-a90a-2fdef84dd7f4)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions Calculators/Plant-Growth-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plant Growth Predictor</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Plant Growth Predictor</h1>
<form id="plant-form">
<div id="plantSpecies">
<label>Plant Species:</label>
<select id="plantType">
<option value="succulents">Succulents</option>
<option value="ferns">Ferns</option>
<option value="flowering">Flowering Plants</option>
<option value="vegetables">Vegetables</option>
</select>
</div>
<div id="lightConditions">
<label>Light Conditions:</label>
<select id="lightType">
<option value="full_sunlight">Full Sunlight</option>
<option value="partial_shade">Partial Shade</option>
<option value="indirect_light">Indirect Light</option>
</select>
</div>
<div id="watering">
<label>Plant Watering (%):</label>
<input type="number" id="wateringInput" min="0" max="100" required>
</div>
<div id="soilConditions">
<label>Soil Conditions:</label>
<select id="soilType">
<option value="sandy">Sandy</option>
<option value="loamy">Loamy</option>
<option value="clay">Clay</option>
</select>
</div>
<div id="temperature">
<label>Temperature(°C)::</label>
<input type="number" id="temperatureInput" min="-50" max="50" required>
</div>
<button type="button" onclick="calculatePrediction()">Calculate Prediction</button>
</form>
<div id="predictionResult"></div>
</div>

<script src="script.js"></script>
</body>
</html>
59 changes: 59 additions & 0 deletions Calculators/Plant-Growth-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Define factors' weights for calculation
const LIGHT_WEIGHTS = {
'full_sunlight': 1.2,
'partial_shade': 1,
'indirect_light': 0.8
};

const WATERING_WEIGHT = 0.5;

const SOIL_WEIGHTS = {
'sandy': 0.8,
'loamy': 1,
'clay': 0.9
};

// Define base growth rates for different plant species
const BASE_GROWTH_RATES = {
'succulents': 0.5,
'ferns': 0.8,
'flowering': 1,
'vegetables': 1.2
};

// Define minimum and maximum growth rates
const MIN_GROWTH_RATE = 0.1;
const MAX_GROWTH_RATE = 2;

function calculatePrediction() {
// Get input values
const plantSpecies = document.getElementById('plantType').value;
const lightCondition = document.getElementById('lightType').value;
const wateringAmount = parseFloat(document.getElementById('wateringInput').value);
const soilCondition = document.getElementById('soilType').value;
const temperature = parseFloat(document.getElementById('temperatureInput').value);

// Get base growth rate for selected plant species
const baseGrowthRate = BASE_GROWTH_RATES[plantSpecies];

// Calculate prediction based on inputs
const lightFactor = LIGHT_WEIGHTS[lightCondition];
const wateringFactor = Math.min(wateringAmount / 100, 1) * WATERING_WEIGHT;
const soilFactor = SOIL_WEIGHTS[soilCondition];

// Adjust growth rate based on temperature
let temperatureFactor = 1;
if (temperature < 10) {
temperatureFactor = 0.8;
} else if (temperature > 30) {
temperatureFactor = 0.9;
}

// Calculate growth rate
const growthRate = baseGrowthRate * ((lightFactor + wateringFactor + soilFactor + temperatureFactor) / 4 * (MAX_GROWTH_RATE - MIN_GROWTH_RATE) + MIN_GROWTH_RATE);

// Display prediction
const predictionResult = document.getElementById('predictionResult');
predictionResult.textContent = `Predicted growth rate for ${plantSpecies}: ${growthRate.toFixed(2)} inches per month`;
predictionResult.style.display = 'block';
}
74 changes: 74 additions & 0 deletions Calculators/Plant-Growth-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
body, html {
height: 100%;
margin: 0;
font-family: Arial, sans-serif;
background-image: url('assets/bg.jpg');
background-size: cover;
background-repeat: no-repeat;
}

.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
}

h1 {
text-align: center;
margin-bottom: 20px;
}

form {
background-color: rgba(255, 255, 255, 0.8);
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
width: 90%;
max-width: 400px;
}

label {
display: block;
margin-top: 10px;
}

input, select {
width: 100%;
padding: 10px;
margin-top: 5px;
border-radius: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
}

button {
display: block;
margin-top: 10px;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
width: 100%;
border-radius: 5px;
}

button:hover {
background-color: #45a049;
}

div{
margin-bottom: 1rem;
}

div label{
font-size: large;
}

#predictionResult {
margin-top: 20px;
font-size: 20px;
text-align: center;
}