rajkhanke commited on
Commit
8508900
·
verified ·
1 Parent(s): 3223c7e

Upload 5 files

Browse files
static/alarn_tune.mp3 ADDED
Binary file (229 kB). View file
 
static/images/irrigation_image.jpeg ADDED
templates/index.html ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Smart Irrigation System</title>
7
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
8
+ <style>
9
+ body {
10
+ background-color: #f0f8f5;
11
+ }
12
+ .container {
13
+ background-color: #ffffff;
14
+ border-radius: 10px;
15
+ margin-top: 50px;
16
+ padding: 30px;
17
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
18
+ border: 2px solid green;
19
+ margin-bottom: 20px; /* Add bottom margin here */
20
+ }
21
+ h1 {
22
+ color: green;
23
+ text-align: center;
24
+ font-weight: bold;
25
+ }
26
+ .left-box, .right-box {
27
+ padding: 20px;
28
+ }
29
+ .form-group label {
30
+ font-weight: bold;
31
+ }
32
+ .form-control, .form-control-file {
33
+ border: 2px solid green;
34
+ border-radius: 5px;
35
+ }
36
+ #image-preview {
37
+ display: block;
38
+ margin: 10px auto; /* Centering the image */
39
+ width: 100px; /* Size of the preview */
40
+ height: 100px; /* Size of the preview */
41
+ border-radius: 5px;
42
+ object-fit: cover;
43
+ border: 2px solid green; /* Optional: Border around the preview */
44
+ }
45
+ #weather-box {
46
+ margin-top: 20px;
47
+ padding: 15px;
48
+ background-color: #e0f8e0;
49
+ border-radius: 8px;
50
+ border: 2px solid green;
51
+ }
52
+ #decorative-image {
53
+ display: block;
54
+ width: 100%;
55
+ height: 100%;
56
+ object-fit: cover;
57
+ border-radius: 10px;
58
+ }
59
+ </style>
60
+ </head>
61
+ <body>
62
+ <div class="container">
63
+ <h1>Smart Irrigation System</h1>
64
+ <form method="POST" action="/" enctype="multipart/form-data">
65
+ <div class="row">
66
+ <!-- Left side: Input Fields -->
67
+ <div class="col-md-7 left-box">
68
+
69
+ <!-- Crop Type Dropdown -->
70
+ <div class="form-group">
71
+ <label for="crop_type">Select Crop Type</label>
72
+ <select class="form-control" id="crop_type" name="crop_type" required>
73
+ <option value="">--Select Crop Type--</option>
74
+ {% for crop, value in crop_types.items() %}
75
+ <option value="{{ crop }}" {% if crop == crop_type %}selected{% endif %}>{{ crop }}</option>
76
+ {% endfor %}
77
+ </select>
78
+ </div>
79
+
80
+ <!-- Crop Age Input -->
81
+ <div class="form-group">
82
+ <label for="crop_age">Enter Crop Age (in days)</label>
83
+ <input type="number" class="form-control" id="crop_age" name="crop_age" value="{{ crop_age }}" required>
84
+ </div>
85
+
86
+ <!-- Region Dropdown -->
87
+ <div class="form-group">
88
+ <label for="region">Select Region</label>
89
+ <select class="form-control" id="region" name="region" required>
90
+ <option value="">--Select Region--</option>
91
+ {% for region, value in regions.items() %}
92
+ <option value="{{ region }}" {% if region == region %}selected{% endif %}>{{ region }}</option>
93
+ {% endfor %}
94
+ </select>
95
+ </div>
96
+
97
+ <!-- Irrigation Type Dropdown -->
98
+ <div class="form-group">
99
+ <label for="irrigation_type">Select Irrigation Type</label>
100
+ <select class="form-control" id="irrigation_type" name="irrigation_type" required>
101
+ <option value="">--Select Irrigation Type--</option>
102
+ {% for irrigation, value in irrigation_types.items() %}
103
+ <option value="{{ irrigation }}" {% if irrigation == irrigation_type %}selected{% endif %}>{{ irrigation }}</option>
104
+ {% endfor %}
105
+ </select>
106
+ </div>
107
+
108
+ <!-- Weather Data Section -->
109
+ <div class="form-group">
110
+ <label for="city">Enter Your City for Weather</label>
111
+ <input type="text" class="form-control" id="city" name="city" value="{{ city }}">
112
+ <button type="submit" name="fetch_weather" class="btn btn-success mt-2">Fetch Weather Data</button>
113
+ </div>
114
+
115
+ <!-- Display weather data -->
116
+ {% if temperature %}
117
+ <div id="weather-box">
118
+ <p><strong>Weather Description:</strong> {{ weather_desc }}</p>
119
+ <p><strong>Temperature:</strong> {{ temperature }} °C</p>
120
+ <p><strong>Humidity:</strong> {{ humidity }}%</p>
121
+ <p><strong>Pressure:</strong> {{ pressure }} hPa</p>
122
+ </div>
123
+ {% endif %}
124
+ <div class="form-group">
125
+ <label for="soil_moisture">Upload Soil Moisture Data (CSV)</label>
126
+ <input type="file" class="form-control-file" id="soil_moisture" name="soil_moisture" accept=".csv" required>
127
+ </div>
128
+ <div class="form-group">
129
+ <label for="soil_image">Upload Soil Image</label>
130
+ <input type="file" class="form-control-file" id="soil_image" name="soil_image" accept="image/*" onchange="previewImage(event)">
131
+ </div>
132
+
133
+ <!-- Image Preview Section -->
134
+ <img id="image-preview" src="{{ soil_image_url }}" alt="Image Preview" style="display: {% if soil_image_url %}block{% else %}none{% endif %};">
135
+
136
+ {% if predicted_soil_type %}
137
+ <div class="form-group">
138
+ <label for="predicted_soil_type"><strong>Predicted Soil Type:</strong></label>
139
+ <input type="text" class="form-control" id="predicted_soil_type" value="{{ soil_label }}" readonly>
140
+ </div>
141
+ {% endif %}
142
+ </div>
143
+
144
+ <!-- Right side: Static Image Decoration -->
145
+ <div class="col-md-5 right-box text-center">
146
+ <img id="decorative-image" src="static/images/irrigation_image.jpeg" alt="Decorative Irrigation Image">
147
+ </div>
148
+ </div>
149
+
150
+ <button type="submit" name="predict" class="btn btn-primary btn-block">Predict Pump Status</button>
151
+ </form>
152
+ </div>
153
+
154
+ <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
155
+ <script>
156
+ // Preview uploaded image
157
+ function previewImage(event) {
158
+ const [file] = event.target.files;
159
+ const preview = document.getElementById('image-preview');
160
+ if (file) {
161
+ preview.src = URL.createObjectURL(file);
162
+ preview.style.display = 'block'; // Show the image preview
163
+ } else {
164
+ preview.style.display = 'none'; // Hide if no file is selected
165
+ }
166
+ }
167
+ </script>
168
+ </body>
169
+ </html>
templates/predict.html ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Pump Prediction</title>
7
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
8
+ <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
9
+ <style>
10
+ body {
11
+ background-color: #f0f8f5;
12
+ }
13
+ .container {
14
+ background-color: #ffffff;
15
+ border-radius: 10px;
16
+ margin-top: 100px;
17
+ padding: 30px;
18
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
19
+ position: relative;
20
+ }
21
+ .status {
22
+ font-size: 24px;
23
+ font-weight: bold;
24
+ margin-bottom: 20px;
25
+ }
26
+ .status.on {
27
+ color: green;
28
+ border: 2px solid green;
29
+ padding: 10px;
30
+ display: inline-block;
31
+ border-radius: 5px;
32
+ }
33
+ .status.off {
34
+ color: red;
35
+ border: 2px solid red;
36
+ padding: 10px;
37
+ display: inline-block;
38
+ border-radius: 5px;
39
+ }
40
+ h2 {
41
+ color: green;
42
+ font-weight: bold;
43
+ text-align: center;
44
+ }
45
+ #time-counter {
46
+ position: absolute;
47
+ top: 60px;
48
+ right: 20px;
49
+ font-size: 1.5rem;
50
+ color: brown; /* Brown color for the time counter */
51
+ }
52
+ /* Center-align and highlight the gauge chart */
53
+ #gauge-container {
54
+ text-align: center;
55
+ padding: 20px;
56
+ }
57
+ #gauge {
58
+ margin-left : 60px;
59
+ display: inline-block;
60
+ width: 650px;
61
+ height: 450px;
62
+ border: 2px solid #4CAF50; /* Highlight with green border */
63
+ border-radius: 10px;
64
+ padding: 10px;
65
+ }
66
+ </style>
67
+ <script>
68
+ let alertSound = new Audio('{{ url_for("static", filename="alarn_tune.mp3") }}');
69
+
70
+ function playAlertSound() {
71
+ alertSound.currentTime = 0;
72
+ alertSound.play().catch(error => console.error("Error playing sound:", error));
73
+ }
74
+
75
+ function fetchPumpStatus() {
76
+ fetch('/update_pump_status')
77
+ .then(response => response.json())
78
+ .then(data => {
79
+ const statusElement = document.getElementById('pumpStatus');
80
+ statusElement.innerHTML = 'Pump Status: ' + data.pump_status;
81
+ statusElement.className = data.pump_status === 'On' ? 'status on' : 'status off';
82
+
83
+ if (data.pump_status === 'Off') {
84
+ console.log("Pump status is Off. Playing alert sound.");
85
+ playAlertSound();
86
+ }
87
+ })
88
+ .catch(err => console.error("Error fetching pump status:", err));
89
+ }
90
+
91
+ function fetchGraphData() {
92
+ fetch('/update_graph')
93
+ .then(response => response.json())
94
+ .then(data => {
95
+ const time = data.map((_, index) => index + 1);
96
+ const soilMoisture = data.map(entry => entry[0]);
97
+ const pumpStatus = data.map(entry => entry[1]);
98
+
99
+ // Update Gauge chart with soil moisture
100
+ const currentSoilMoisture = soilMoisture[soilMoisture.length - 1];
101
+ updateGaugeChart(currentSoilMoisture);
102
+
103
+ // Pump Status vs. Time
104
+ const binaryPumpStatus = pumpStatus.map(status => status);
105
+ const trace1 = {
106
+ x: time,
107
+ y: binaryPumpStatus,
108
+ mode: 'lines+markers',
109
+ type: 'scatter',
110
+ name: 'Pump Status',
111
+ line: { color: 'blue' },
112
+ };
113
+
114
+ const layout1 = {
115
+ title: 'Pump Status (On/Off) vs. Time',
116
+ xaxis: { title: 'Time (s)' },
117
+ yaxis: { title: 'Pump Status', tickvals: [-1, 1], ticktext: ['Off', 'On'], range: [-1.5, 1.5] },
118
+ showlegend: true
119
+ };
120
+
121
+ Plotly.newPlot('graph1', [trace1], layout1);
122
+
123
+ // Soil Moisture vs. Time
124
+ const trace2 = {
125
+ x: time,
126
+ y: soilMoisture,
127
+ mode: 'lines+markers',
128
+ type: 'scatter',
129
+ name: 'Soil Moisture',
130
+ line: { color: 'green' },
131
+ };
132
+
133
+ const layout2 = {
134
+ title: 'Soil Moisture vs. Time',
135
+ xaxis: { title: 'Time (s)' },
136
+ yaxis: { title: 'Soil Moisture' },
137
+ showlegend: true
138
+ };
139
+
140
+ Plotly.newPlot('graph2', [trace2], layout2);
141
+
142
+ // Combined Graph for Soil Moisture vs. Pump Status
143
+ const trace3 = {
144
+ x: soilMoisture,
145
+ y: binaryPumpStatus,
146
+ mode: 'lines',
147
+ type: 'scatter',
148
+ name: 'Pump Status',
149
+ line: { color: 'blue' },
150
+ };
151
+
152
+ const layout3 = {
153
+ title: 'Pump Status and Soil Moisture',
154
+ xaxis: { title: 'Soil Moisture' },
155
+ yaxis: { title: 'Pump Status', tickvals: [-1, 1], ticktext: ['Off', 'On'], range: [-1.5, 1.5] },
156
+ showlegend: true
157
+ };
158
+
159
+ Plotly.newPlot('graph3', [trace3], layout3);
160
+
161
+ // Histogram for Soil Moisture
162
+ const trace4 = {
163
+ x: soilMoisture,
164
+ type: 'histogram',
165
+ };
166
+
167
+ const layout4 = {
168
+ title: 'Histogram of Soil Moisture',
169
+ xaxis: { title: 'Soil Moisture' },
170
+ yaxis: { title: 'Frequency' }
171
+ };
172
+
173
+ Plotly.newPlot('graph4', [trace4], layout4);
174
+ })
175
+ .catch(err => console.error("Error fetching graph data:", err));
176
+ }
177
+
178
+ // Function to update the gauge chart
179
+ function updateGaugeChart(value) {
180
+ const data = [
181
+ {
182
+ type: "indicator",
183
+ mode: "gauge+number+delta",
184
+ value: value,
185
+ title: { text: "Soil Moisture", font: { size: 24 } },
186
+ gauge: {
187
+ axis: { range: [0, 100] },
188
+ steps: [
189
+ { range: [0, 30], color: "red" },
190
+ { range: [30, 60], color: "yellow" },
191
+ { range: [60, 100], color: "green" }
192
+ ],
193
+ threshold: {
194
+ line: { color: "black", width: 4 },
195
+ thickness: 0.75,
196
+ value: value
197
+ }
198
+ }
199
+ }
200
+ ];
201
+
202
+ const layout = {
203
+ width: 600,
204
+ height: 400,
205
+ margin: { t: 0, b: 0 }
206
+ };
207
+
208
+ Plotly.newPlot('gauge', data, layout);
209
+ }
210
+
211
+ // Time counter functionality
212
+ let timeCounter = 0;
213
+ function updateTimeCounter() {
214
+ timeCounter++;
215
+ document.getElementById('time-counter').innerText = `Time: ${timeCounter} seconds`;
216
+ }
217
+
218
+ // Set intervals for data fetching and time counting
219
+ setInterval(fetchPumpStatus, 2000); // Update every 2 seconds
220
+ setInterval(fetchGraphData, 2000); // Update every 2 seconds
221
+ setInterval(updateTimeCounter, 1000); // Update time counter every second
222
+
223
+ document.addEventListener('click', () => {
224
+ alertSound.load(); // Load the sound on user interaction
225
+ });
226
+ </script>
227
+ </head>
228
+ <body>
229
+ <div class="container">
230
+ <h2>Pump & Irrigation Status Prediction</h2>
231
+ <div id="pumpStatus" class="status {{ 'on' if pump_status == 'On' else 'off' }}">
232
+ Pump Status: {{ pump_status }}
233
+ </div>
234
+ <div id="time-counter">Time: 0 seconds</div>
235
+
236
+ <!-- Soil Moisture Gauge Chart with center alignment and highlight -->
237
+ <div id="gauge-container">
238
+ <div id="gauge"></div>
239
+ </div>
240
+
241
+ <div id="graph1" style="width:100%; height:400px;"></div>
242
+ <div id="graph2" style="width:100%; height:400px;"></div>
243
+ <div id="graph3" style="width:100%; height:400px;"></div>
244
+ <div id="graph4" style="width:100%; height:400px;"></div>
245
+ </div>
246
+ </body>
247
+ </html>
templates/sample.html ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Random Value Beep</title>
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ text-align: center;
12
+ margin-top: 50px;
13
+ }
14
+ button {
15
+ padding: 10px 20px;
16
+ font-size: 16px;
17
+ cursor: pointer;
18
+ }
19
+ </style>
20
+ </head>
21
+ <body>
22
+
23
+ <h1>Random Value Checker</h1>
24
+ <button id="generateButton">Generate Random Value</button>
25
+ <p id="result"></p>
26
+
27
+ <audio id="beepSound" src="/alarn_tune.mp3"></audio>
28
+
29
+ <script>
30
+ document.getElementById("generateButton").onclick = function() {
31
+ // Generate a random value between 0 and 20
32
+ var randomValue = Math.floor(Math.random() * 21);
33
+ document.getElementById("result").innerText = "Generated Value: " + randomValue;
34
+
35
+ // Check if the random value is greater than 10
36
+ if (randomValue > 10) {
37
+ document.getElementById("beepSound").play();
38
+ }
39
+ }
40
+ </script>
41
+ </body>
42
+ </html>