-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #873 from BenakDeepak/main
*Queue Visualization Enhancement*
- Loading branch information
Showing
6 changed files
with
582 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Visualizing Tools | ||
|
||
# 🎯 Goal | ||
|
||
The primary objective of this project is to explain the implementation, visualization, and analysis of various queue data structures, including Dequeue, Linear Queue, Priority Queue, and Queue in Two Stacks. The project focuses on providing an interactive experience where users can input data and observe the behavior of these data structures through visual representation. | ||
|
||
# 🧵 Dataset / Input | ||
|
||
This project does not rely on a predefined dataset. Instead, it takes user input in the following formats: | ||
1. **File Upload:** Users can upload a file containing the input data. Ensure that the input file format is described below. | ||
2. **Manual Entry:** Users can manually input data. | ||
|
||
### File Format Requirements: | ||
- **File1:** Accepts input in CSV format, containing fields such as `operation`, `value`, and so on. | ||
- **File2:** Requires JSON format, with key fields such as `operation` and `priority`. | ||
- **File3:** Describes the operations in the format `<operation>: <value>`. | ||
- **File4:** Takes file types or formats and expects the following fields: `operation_type`, `data`. | ||
|
||
**Example Input:** | ||
- **Manual Input Format Example:** | ||
```plaintext | ||
operation: enqueue | ||
value: 10 | ||
``` | ||
- **File Input Example:** | ||
```csv | ||
operation,value | ||
enqueue,10 | ||
dequeue, | ||
enqueue,20 | ||
``` | ||
# 🧾 Description | ||
This project provides a web-based platform developed using Streamlit that allows users to interact with the system through manual input or file uploads. The tool implements specific functionalities for Dequeue, Linear Queue, Priority Queue, and Queue in Two Stacks, enabling users to visualize operations in real-time. | ||
### Features: | ||
- **Real-time visualization** of queue operations based on user input. | ||
- **Multiple input modes:** manual and file-based. | ||
- **Dynamic operations** that are applied step-by-step to the input data, allowing users to see how elements are added or removed from the queues. | ||
# 🧮 What I Had Done! | ||
1. Developed an interactive web interface using Streamlit. | ||
2. Implemented features for file uploading and manual input handling for various queue operations. | ||
3. Visualized the queue operations (enqueue, dequeue, etc.) in real-time. | ||
4. Provided feedback on every step of the process, illustrating how each queue type behaves with different operations. | ||
5. Output examples based on the input data. | ||
### Sample Output (based on the project): | ||
- After processing the input, the system generates visualizations or outputs relevant to the queue operations. For example: | ||
- **Queue Visualization Output:** | ||
```plaintext | ||
[10] -> [20] (for a linear queue) | ||
``` | ||
- **Processed Data Output:** | ||
```plaintext | ||
operation: dequeue | ||
result: 10 | ||
``` | ||
# 📚 Libraries Needed | ||
To run this project, install the following libraries: | ||
- **streamlit:** for building the web interface. | ||
- **matplotlib** (or other visualization libraries as per your needs). | ||
- **Any other dependencies needed by your project.** | ||
Install them using: | ||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Requirements File (requirements.txt): | ||
```plaintext | ||
streamlit | ||
matplotlib | ||
``` | ||
|
||
# 📊 Exploratory Data Analysis Results | ||
No EDA is required as the project is based on user inputs. However, real-time graphical outputs or visual representations of the queue operations provide insights into how each queue type operates based on user inputs. | ||
|
||
### 📈 Performance of the Algorithms | ||
Since the project focuses on various queue algorithms, no accuracy metrics are required. Performance can be verified based on the correct execution of: | ||
- Enqueue and dequeue operations for each queue type. | ||
- Visualization of the current state of each queue after operations are performed. | ||
|
||
# 📢 Conclusion | ||
The project effectively demonstrates how to process user inputs and visualize queue operations in real-time. The system allows for dynamic interaction through both manual entry and file upload, offering flexibility in how users interact with different queue data structures. | ||
|
||
# ✒️ Your Signature | ||
Benak Deepak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
import streamlit as st | ||
|
||
# Helper function to display the queue in a box-like format | ||
def display_queue_as_boxes(queue, front=None, rear=None): | ||
box_representation = "" | ||
for i, item in enumerate(queue): | ||
label = "" | ||
if i == front: | ||
label = "**Front**" | ||
elif i == rear: | ||
label = "**Rear**" | ||
box_representation += f"| {label} {item} |" | ||
return box_representation | ||
|
||
### Linear Queue ### | ||
class LinearQueue: | ||
def __init__(self, max_size): | ||
self.queue = [] | ||
self.max_size = max_size | ||
|
||
def is_empty(self): | ||
return len(self.queue) == 0 | ||
|
||
def is_full(self): | ||
return len(self.queue) == self.max_size | ||
|
||
def enqueue(self, item): | ||
if self.is_full(): | ||
st.warning("Linear queue is full.") | ||
else: | ||
self.queue.append(item) | ||
|
||
def dequeue(self): | ||
if self.is_empty(): | ||
st.warning("Linear queue is empty.") | ||
else: | ||
return self.queue.pop(0) | ||
|
||
def display_queue(self): | ||
return self.queue | ||
|
||
### Dequeue (Double-ended Queue) ### | ||
class Dequeue: | ||
def __init__(self, max_size): | ||
self.queue = [] | ||
self.max_size = max_size | ||
|
||
def is_empty(self): | ||
return len(self.queue) == 0 | ||
|
||
def is_full(self): | ||
return len(self.queue) == self.max_size | ||
|
||
def add_front(self, item): | ||
if self.is_full(): | ||
st.warning("Dequeue is full.") | ||
else: | ||
self.queue.insert(0, item) | ||
|
||
def add_rear(self, item): | ||
if self.is_full(): | ||
st.warning("Dequeue is full.") | ||
else: | ||
self.queue.append(item) | ||
|
||
def remove_front(self): | ||
if self.is_empty(): | ||
st.warning("Dequeue is empty.") | ||
else: | ||
return self.queue.pop(0) | ||
|
||
def remove_rear(self): | ||
if self.is_empty(): | ||
st.warning("Dequeue is empty.") | ||
else: | ||
return self.queue.pop() | ||
|
||
def display_queue(self): | ||
return self.queue | ||
|
||
### Priority Queue ### | ||
class PriorityQueue: | ||
def __init__(self): | ||
self.queue = [] | ||
|
||
def enqueue(self, item): | ||
self.queue.append(item) | ||
self.queue.sort() # Sorts the queue after each insertion | ||
|
||
def dequeue(self): | ||
if len(self.queue) == 0: | ||
st.warning("Priority queue is empty.") | ||
else: | ||
return self.queue.pop(0) # Pops the highest priority element | ||
|
||
def display_queue(self): | ||
return self.queue | ||
|
||
### Queue Using Two Stacks ### | ||
class QueueTwoStacks: | ||
def __init__(self): | ||
self.stack1 = [] | ||
self.stack2 = [] | ||
|
||
def enqueue(self, item): | ||
self.stack1.append(item) | ||
|
||
def dequeue(self): | ||
if len(self.stack2) == 0: | ||
if len(self.stack1) == 0: | ||
st.warning("Queue using two stacks is empty.") | ||
while len(self.stack1) > 0: | ||
self.stack2.append(self.stack1.pop()) | ||
return self.stack2.pop() | ||
|
||
def display_queue(self): | ||
return self.stack2[::-1] + self.stack1 # Stack 2 reversed + Stack 1 | ||
|
||
|
||
# Streamlit UI | ||
st.title("Different Types of Queues with Box-like Display") | ||
|
||
# Queue type selection | ||
queue_type = st.selectbox("Select the type of queue", ("Linear Queue", "Dequeue", "Priority Queue", "Queue Using Two Stacks")) | ||
|
||
# Queue size input (for applicable queues) | ||
if queue_type in ["Linear Queue", "Dequeue"]: | ||
max_size = st.number_input("Enter the size of the queue:", min_value=3, max_value=10, value=5, step=1) | ||
|
||
# Initialize queues based on selection | ||
if "queue_state" not in st.session_state: | ||
if queue_type == "Linear Queue": | ||
st.session_state.queue_state = LinearQueue(max_size) | ||
elif queue_type == "Dequeue": | ||
st.session_state.queue_state = Dequeue(max_size) | ||
elif queue_type == "Priority Queue": | ||
st.session_state.queue_state = PriorityQueue() | ||
elif queue_type == "Queue Using Two Stacks": | ||
st.session_state.queue_state = QueueTwoStacks() | ||
|
||
# Operations based on the selected queue type | ||
if queue_type == "Linear Queue": | ||
option = st.selectbox("Choose an operation", ("None", "Enqueue", "Dequeue", "Display")) | ||
|
||
if option == "Enqueue": | ||
item = st.number_input("Enter item to enqueue:", min_value=0, value=1) | ||
if st.button("Enqueue Item"): | ||
st.session_state.queue_state.enqueue(item) | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Dequeue": | ||
if st.button("Dequeue Item"): | ||
st.session_state.queue_state.dequeue() | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Display": | ||
if st.button("Show Queue"): | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
elif queue_type == "Dequeue": | ||
option = st.selectbox("Choose an operation", ("None", "Add to Front", "Add to Rear", "Remove from Front", "Remove from Rear", "Display")) | ||
|
||
if option == "Add to Front": | ||
item = st.number_input("Enter item to add to front:", min_value=0, value=1) | ||
if st.button("Add to Front"): | ||
st.session_state.queue_state.add_front(item) | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Add to Rear": | ||
item = st.number_input("Enter item to add to rear:", min_value=0, value=1) | ||
if st.button("Add to Rear"): | ||
st.session_state.queue_state.add_rear(item) | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Remove from Front": | ||
if st.button("Remove from Front"): | ||
st.session_state.queue_state.remove_front() | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Remove from Rear": | ||
if st.button("Remove from Rear"): | ||
st.session_state.queue_state.remove_rear() | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Display": | ||
if st.button("Show Queue"): | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
elif queue_type == "Priority Queue": | ||
option = st.selectbox("Choose an operation", ("None", "Enqueue", "Dequeue", "Display")) | ||
|
||
if option == "Enqueue": | ||
item = st.number_input("Enter item to enqueue:", min_value=0, value=1) | ||
if st.button("Enqueue Item"): | ||
st.session_state.queue_state.enqueue(item) | ||
st.write("Current Queue (sorted):", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Dequeue": | ||
if st.button("Dequeue Item"): | ||
st.session_state.queue_state.dequeue() | ||
st.write("Current Queue (sorted):", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Display": | ||
if st.button("Show Queue"): | ||
st.write("Current Queue (sorted):", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
elif queue_type == "Queue Using Two Stacks": | ||
option = st.selectbox("Choose an operation", ("None", "Enqueue", "Dequeue", "Display")) | ||
|
||
if option == "Enqueue": | ||
item = st.number_input("Enter item to enqueue:", min_value=0, value=1) | ||
if st.button("Enqueue Item"): | ||
st.session_state.queue_state.enqueue(item) | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Dequeue": | ||
if st.button("Dequeue Item"): | ||
st.session_state.queue_state.dequeue() | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) | ||
|
||
if option == "Display": | ||
if st.button("Show Queue"): | ||
st.write("Current Queue:", display_queue_as_boxes(st.session_state.queue_state.display_queue())) |
Oops, something went wrong.