Skip to content

Commit 3a51f52

Browse files
committed
Fix bugs in tour
1 parent 962415a commit 3a51f52

File tree

6 files changed

+113
-76
lines changed

6 files changed

+113
-76
lines changed

main/static/main/js/input.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ function populateTargetDropdown(columns) {
253253

254254
// Ensure the select dropdown is styled correctly for Bootstrap 5
255255
targetSelect.classList.add('form-select'); // Updated class for Bootstrap 5
256+
tour3();
256257
}
257258

258259
function clearFile(event) {
@@ -538,3 +539,44 @@ function activateBuildButton() {
538539
$('#build-btn-div1').removeClass('d-none');
539540
$('#build-btn-div2').addClass('d-none');
540541
}
542+
543+
// Tour 3: Started after uploading a dataset in KNN, if the user is on the tour
544+
function tour3() {
545+
if (localStorage.getItem('knn_tour3') === 'start') {
546+
localStorage.setItem('knn_tour3', 'end');
547+
introJs().setOptions({
548+
steps: [
549+
{
550+
intro: "Great! Now you need to select the features and target variable. For the Iris dataset, we have 4 features and 1 target variable.",
551+
},
552+
{
553+
element: document.querySelector('#features-div'),
554+
intro: "Select the features of the Iris flower you want to use to predict the species. Let's predict the species based on the sepal length (SepalLengthCm) and sepal width (SepalWidthCm).",
555+
},
556+
{
557+
element: document.querySelector('#target-div'),
558+
intro: "For the Iris dataset, it's the 'Species' column that you want to predict. Select 'Species' as the target variable.",
559+
},
560+
{
561+
element: document.querySelector('#n_neighbors'),
562+
intro: "A hyperparameter is a parameter whose value is set before the learning process begins. KNN has a hyperparameter called 'n_neighbors', which is the number of neighbors to consider when classifying a data point. Let's set it as 5.",
563+
},
564+
{
565+
element: document.querySelector('#canvas-1'),
566+
intro: "This is a heatmap of the Iris dataset. It shows the correlation between each pair of features. The darker the color, the higher the correlation.",
567+
},
568+
{
569+
element: document.querySelector('#canvas-2'),
570+
intro: "This is a scatter plot of the Iris dataset. It shows the relationship between a pair of features. You can select the features you want to plot on the X and Y axes to visualize the data.",
571+
},
572+
{
573+
element: document.querySelector('#build-btn'),
574+
intro: "Finally, click 'Build' to train the KNN model.",
575+
},
576+
],
577+
}).start();
578+
document.querySelector('#build-btn'),addEventListener('click', function() {
579+
localStorage.setItem('knn_results', 'start'); // Set the next tour to start
580+
});
581+
}
582+
}

main/static/main/js/main.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ async function makePrediction(event) {
5454
const data = await response.json();
5555
predictionResult.classList.add('alert-success');
5656
predictionResult.innerHTML = target + ": " + data.predictions;
57+
58+
// If the user is in the platform tour, continue the tour
59+
predTour();
5760
} catch (error) {
5861
predictionResult.classList.add('alert-danger');
5962
predictionResult.innerHTML = error.message;
@@ -293,3 +296,32 @@ var bubblyButtons = document.getElementsByClassName("bubbly-button");
293296
for (var i = 0; i < bubblyButtons.length; i++) {
294297
bubblyButtons[i].addEventListener('click', animateButton, false);
295298
}
299+
300+
// Platform tour continues after making a prediction in KNN
301+
function predTour() {
302+
if (localStorage.getItem('prediction') !== 'start') return;
303+
localStorage.setItem('prediction', 'end');
304+
introJs().setOptions({
305+
steps: [
306+
{
307+
element: document.querySelector('#prediction-result'),
308+
intro: "Great job! The model has generated the predicted values based on the input features you provided. This is the class in which the data point you entered belongs to.",
309+
},
310+
{
311+
element: document.querySelector('.table-responsive'),
312+
intro: "The table below shows the actual and predicted values for some test data. You can compare the predicted values with the actual values to understand the model's performance.",
313+
},
314+
{
315+
element: document.querySelector('.download-model'),
316+
intro: "You can download the trained model (as a .pkl file) by clicking the button below. This saved model can be used to make predictions anytime, and it can be deployed in production systems.",
317+
},
318+
{
319+
element: document.querySelector('.view-code-btn'),
320+
intro: "Here, you can view a sample Python code snippet that demonstrates how to train a KNN model using the scikit-learn library. You can replace the example dataset with your own data to train a custom model.",
321+
},
322+
{
323+
intro: "That's it! You have completed the tour of the platform. 12 more algorithms are waiting for you to explore. Don't forget to check out the preprocessing and visualization tools as well. Happy learning!",
324+
}
325+
],
326+
}).start();
327+
}

main/templates/main/algorithms.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h1 class="display-3 m-2 title">{{ type }}</h1>
3838
);
3939

4040
document.addEventListener('DOMContentLoaded', function() {
41-
if (localStorage.getItem('algo') !== 'true' && localStorage.getItem('tour') == 'true' && '{{ type }}' == 'Classification') {
41+
if (localStorage.getItem('algo') === 'start' && localStorage.getItem('tour') == 'true' && '{{ type }}' == 'Classification') {
4242
localStorage.setItem('algo', 'true'); // Mark as visited
4343
introJs().setOptions({
4444
steps: [

main/templates/main/index.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ <h6 class="card-subtitle mb-2 text-muted">Supervised Learning</h6>
229229
</p>
230230
</div>
231231
<div class="last mt-auto">
232-
<a href={% url 'classification' %} class="">Go →</a>
232+
<a href={% url 'classification' %} class="" id="classification-link">Go →</a>
233233
</div>
234234
</div>
235235
</div>
@@ -360,7 +360,8 @@ <h5>Preprocessing</h5>
360360
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
361361
<script>
362362
function homeTour() {
363-
localStorage.setItem('tour', 'true');
363+
localStorage.setItem('tour', 'true'); // Indicate that the user has started the tour
364+
localStorage.setItem('visited', 'true'); // Prevents the notification from showing again
364365
introJs().setOptions({
365366
steps: [
366367
{
@@ -386,12 +387,13 @@ <h5>Preprocessing</h5>
386387
]
387388
}).start();
388389
}
390+
// Show a notification asking the user to start the tour of the platform
389391
document.addEventListener('DOMContentLoaded', function() {
390-
// Check if the user has visited the site before
392+
// Check if the user has denied the tour before by closing the notification
391393
if (localStorage.getItem('visited') === 'true') {
392394
return;
393395
}
394-
// Start the intro.js tour
396+
// Start the notification after 1 second
395397
setTimeout(function() {
396398
showNotification({
397399
title: "Welcome to Expert System!",
@@ -401,7 +403,15 @@ <h5>Preprocessing</h5>
401403
onDismiss: () => localStorage.setItem('visited', 'true'),
402404
});
403405
}, 1000);
404-
});
406+
407+
// Initialize Classification Tour if the user is navigating to it
408+
document.querySelector('#classification-link').addEventListener('click', function() {
409+
if (localStorage.getItem('algo') !== 'true' && localStorage.getItem('tour') == 'true') {
410+
localStorage.setItem('algo', 'start');
411+
}
412+
});
413+
});
414+
405415

406416
$(document).ready(function() {
407417
$('.fade-in').fadeIn(500);

main/templates/main/input.html

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ <h2 class="accordion-header" id="headingOne">
214214
<script src="https://d3js.org/d3.v4.js"></script>
215215
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
216216
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
217-
<script src={% static "main/js/input.js" %}></script>
218217
<script>
219218
document.addEventListener('DOMContentLoaded', function() {
220219
if (localStorage.getItem('knn') === 'start' && document.querySelector('.dataset-selection')) {
221-
localStorage.setItem('knn', 'true'); // Mark as visited
220+
localStorage.setItem('knn', 'true');
221+
222+
// First tour: Introduction to the dataset selection
222223
introJs().setOptions({
223224
steps: [
224225
{
@@ -228,58 +229,35 @@ <h2 class="accordion-header" id="headingOne">
228229
element: document.querySelector('.dataset-selection-preload'),
229230
intro: "Click here to see available datasets for classification.",
230231
},
231-
{
232-
element: document.querySelector('#preloaded-div'),
233-
intro: "Go for the 'Iris' dataset. It's a classic!",
234-
},
235-
{
236-
element: document.querySelector('#upload-btn'),
237-
intro: "Click 'Next' to proceed.",
238-
},
239232
],
240233
}).start();
241-
document.querySelector('#upload-btn').addEventListener('click', function() {
242-
// End the previous tour
243-
introJs().exit();
244-
// Start the next tour after the info is populated by js
245-
if (document.querySelector('#features-div').classList.contains('d-none')) {
234+
235+
// Tour 2: Selecting a dataset
236+
document.querySelector('.dataset-selection-preload').addEventListener('click', function() {
237+
introJs().exit(); // End the previous tour
238+
setTimeout(() => {
246239
introJs().setOptions({
247240
steps: [
248241
{
249-
intro: "Great! Now you need to select the features and target variable. For the Iris dataset, we have 4 features and 1 target variable.",
250-
},
251-
{
252-
element: document.querySelector('#features-div'),
253-
intro: "Select the features of the Iris flower you want to use to predict the species. Let's predict the species based on the sepal length (SepalLengthCm) and sepal width (SepalWidthCm).",
254-
},
255-
{
256-
element: document.querySelector('#target-div'),
257-
intro: "For the Iris dataset, it's the 'Species' column that you want to predict. Select 'Species' as the target variable.",
242+
element: document.querySelector('#preloaded-div'),
243+
intro: "Go for the 'Iris' dataset. It contains 150 samples of Iris flowers with 4 features: sepal length, sepal width, petal length, and petal width.",
258244
},
259245
{
260-
element: document.querySelector('#n_neighbors'),
261-
intro: "A hyperparameter is a parameter whose value is set before the learning process begins. KNN has a hyperparameter called 'n_neighbors', which is the number of neighbors to consider when classifying a data point. Let's set it as 5.",
262-
},
263-
{
264-
element: document.querySelector('#canvas-1'),
265-
intro: "This is a heatmap of the Iris dataset. It shows the correlation between each pair of features. The darker the color, the higher the correlation.",
266-
},
267-
{
268-
element: document.querySelector('#canvas-2'),
269-
intro: "This is a scatter plot of the Iris dataset. It shows the relationship between a pair of features. You can select the features you want to plot on the X and Y axes to visualize the data.",
270-
},
271-
{
272-
element: document.querySelector('#build-btn'),
273-
intro: "Finally, click 'Build' to train the KNN model.",
246+
element: document.querySelector('#upload-btn'),
247+
intro: "Click 'Next' to proceed.",
274248
},
275249
],
276250
}).start();
277-
document.querySelector('#build-btn'),addEventListener('click', function() {
278-
localStorage.setItem('knn_results', 'start');
279-
});
280-
}
251+
}, 500); // Delay the start of the next tour, to ensure the component is rendered
252+
});
253+
254+
document.querySelector('#upload-btn').addEventListener('click', function() {
255+
introJs().exit();
256+
localStorage.setItem('knn_tour3', 'start');
257+
// The tour3 will be called in the input.js file
281258
});
282259
}
283260
});
284261
</script>
262+
<script src={% static "main/js/input.js" %}></script>
285263
{% endblock %}

main/templates/main/knn.html

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,39 +145,14 @@ <h3 class="m-2" id="predict-title">Predict</h3>
145145
},
146146
{
147147
element: document.querySelector('.pred-right'),
148-
intro: "You can use this trained model to generate predictions based on the input features you provide. Enter some values for each feature and click 'Predict'.",
148+
intro: "You can use this trained model to generate predictions based on the input features you provide. Enter some values for each feature (e.g. SepalLengthCm = 4, SepalWidthCm = 2) and click 'Predict'.",
149149
},
150150
],
151151
}).start();
152152
document.querySelector('.predict-btn').addEventListener('click', function() {
153153
introJs().exit();
154-
// Ensure that the prediciton result is displayed before the next step
155-
if (document.querySelector('#prediction-result').classList.contains('d-none')) {
156-
document.querySelector('.predict-btn').click();
157-
}
158-
introJs().setOptions({
159-
steps: [
160-
{
161-
element: document.querySelector('#prediction-result'),
162-
intro: "Great job! The model has generated the predicted values based on the input features you provided. This is the class in which the data point you entered belongs to.",
163-
},
164-
{
165-
element: document.querySelector('.table-responsive'),
166-
intro: "The table below shows the actual and predicted values for some test data. You can compare the predicted values with the actual values to understand the model's performance.",
167-
},
168-
{
169-
element: document.querySelector('.download-model'),
170-
intro: "You can download the trained model (as a .pkl file) by clicking the button below. This saved model can be used to make predictions anytime, and it can be deployed in production systems.",
171-
},
172-
{
173-
element: document.querySelector('.view-code-btn'),
174-
intro: "Here, you can view a sample Python code snippet that demonstrates how to train a KNN model using the scikit-learn library. You can replace the example dataset with your own data to train a custom model.",
175-
},
176-
{
177-
intro: "That's it! You have completed the tour of the platform. 12 more algorithms are waiting for you to explore. Don't forget to check out the preprocessing and visualization tools as well. Happy learning!",
178-
}
179-
],
180-
}).start();
154+
localStorage.setItem('prediction', 'start');
155+
// predTour will be called in the
181156
});
182157
}
183158
});

0 commit comments

Comments
 (0)