Skip to content

Commit

Permalink
Merge pull request #13 from simonthorell/setup
Browse files Browse the repository at this point in the history
Autogenerate Diagrams
  • Loading branch information
simonthorell authored Feb 8, 2024
2 parents 2e53c12 + f97fb91 commit 3960bfa
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 4 deletions.
61 changes: 58 additions & 3 deletions .github/workflows/convert-to-pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
# Install any dependencies if needed
- name: Checkout PR Head Branch
uses: actions/checkout@v4
Expand All @@ -46,9 +45,65 @@ jobs:
git commit -m "Update REPORT.md with latest protocols" || echo "No changes to REPORT.md."
git push origin ${{ github.head_ref }}
generate-diagrams:
name: Generate Diagrams
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 'pypy3.9' # Adjust Python version as necessary

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install matplotlib
- name: Checkout PR Head Branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0 # Fetch all history for .Git based projects

- name: Checkout to Git Feature Branch
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git fetch origin ${{ github.head_ref }}
git checkout ${{ github.head_ref }}
- name: Remove Outdated Diagrams
run: |
if [ -d "./images" ]; then
git rm -r ./images/protocols_datarate.png
git rm -r ./images/protocols_frequency.png
git rm -r ./images/protocols_range.png
git commit -m "Remove existing pdfs folder"
git push origin ${{ github.head_ref }}
else
echo "images folder does not exist, skipping removal."
fi
- name: Generate Diagrams
run: |
if [ ! -d "./images" ]; then
mkdir images
else
echo "images folder already exists, skipping creation."
fi
python ./scripts/create_diagram.py
- name: Set up Git and Commit Changes
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add images/
git commit -m "Created diagrams and saved to images-folder" || echo "No diagrams to create"
git push origin ${{ github.head_ref }}
convert-to-pdf: # Second job: Convert REPORT.md to PDF
name: Convert to PDF
needs: merge-markdown-files
needs: [merge-markdown-files, generate-diagrams]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -77,7 +132,7 @@ jobs:
with:
input_dir: docs
output_dir: pdfs
images_dir: docs/images
images_dir: images
image_import: ./images
build_html: false # Set true to also add HTML files to the output directory

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Wireless IoT Protocol Report

This repo is a setup to enable collaboration work in the same report using markdown formatting.
The CI pipeline is setup to automatically merge the markdown-files and generate a PDF once making a pull request to the main branch.
The CI pipeline is setup to automatically create diagrams using python matplotlib, merge the markdown-files and then generate a PDF once making a pull request to the main branch.

## Usage
1) Clone this repo:
Expand Down
5 changes: 5 additions & 0 deletions docs/REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ Some text...
3) List item
<br><br>

## Diagrams
![Range](./images/protocols_range.png)
![Data Rate](./images/protocols_datarate.png)
![Frequency](./images/protocols_frequency.png)

### Protocol Summaries

- **WiFi** emerges as the go-to choice for high-bandwidth applications requiring internet access,
Expand Down
5 changes: 5 additions & 0 deletions docs/REPORT.stub
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Milad Isho Saeb and Abdihakim Abdisamad Roble.
{NFC}
<br><br>

## Diagrams
![Range](./images/protocols_range.png)
![Data Rate](./images/protocols_datarate.png)
![Frequency](./images/protocols_frequency.png)

### Protocol Summaries

- **WiFi** emerges as the go-to choice for high-bandwidth applications requiring internet access,
Expand Down
Binary file added images/protocols_datarate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/protocols_frequency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/protocols_range.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pdfs/REPORT.pdf
Binary file not shown.
22 changes: 22 additions & 0 deletions protocols_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"protocols": [
{
"name": "Bluetooth",
"frequency": "2.4 GHz",
"range": "10-100 meters",
"dataRate": "1-3 Mbps"
},
{
"name": "Zigbee",
"frequency": "2.4 GHz",
"range": "10-100 meters",
"dataRate": "250 Kbps"
},
{
"name": "WiFi",
"frequency": "2.4 GHz, 5 GHz",
"range": "50 meters",
"dataRate": "54 Mbps - 1.3 Gbps"
}
]
}
88 changes: 88 additions & 0 deletions scripts/create_diagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
import matplotlib.pyplot as plt

# Assuming the JSON data is loaded from 'protocols_data.json'
with open('protocols_data.json', 'r') as file:
data = json.load(file)

protocols = [protocol['name'] for protocol in data['protocols']]

# Process ranges (assuming meters are specified and ranges may be given)
range_values = []
for protocol in data['protocols']:
range_str = protocol['range']
# Extract numbers, assuming ' meters' is always present
if '-' in range_str:
min_range, max_range = [int(val.split(' ')[0]) for val in range_str.split('-')]
range_values.append((min_range + max_range) / 2)
else:
range_values.append(int(range_str.split(' ')[0]))

# Process frequencies (count occurrence of each frequency)
frequency_counts = {}
for protocol in data['protocols']:
freqs = protocol['frequency'].split(', ')
for freq in freqs:
if freq not in frequency_counts:
frequency_counts[freq] = 0
frequency_counts[freq] += 1

# Process data rates (convert all to Mbps)
# Function to convert data rate to Mbps
def convert_to_mbps(data_rate_str):
converted_rates = []
rates = data_rate_str.split('-')
for rate in rates:
parts = rate.strip().split(' ')
if len(parts) == 2:
# If the rate includes both a number and a unit
number, unit = parts
number = float(number)
if 'Kbps' in unit:
number /= 1000 # Convert Kbps to Mbps
elif 'Gbps' in unit:
number *= 1000 # Convert Gbps to Mbps
elif len(parts) == 1 and parts[0].isdigit():
# If the rate is just a number (assuming Mbps by default)
number = float(parts[0])
else:
# Handle unexpected formats or log an error
print(f"Unexpected data rate format: '{rate}'")
number = 0 # Default or error value; adjust as needed

converted_rates.append(number)

return max(converted_rates)

# Updated part for processing data rates
data_rate_values = [convert_to_mbps(protocol['dataRate']) for protocol in data['protocols']]

# Plotting Range
plt.figure(figsize=(10, 6))
plt.bar(protocols, range_values, color='skyblue')
plt.xlabel('Protocol')
plt.ylabel('Average Range (meters)')
plt.title('Range of Different IoT Wireless Protocols')
plt.xticks(rotation=45)
plt.tight_layout()
plt.savefig('images/protocols_range.png')

# Plotting Frequency Usage
plt.figure(figsize=(10, 6))
plt.bar(frequency_counts.keys(), frequency_counts.values(), color='lightgreen')
plt.xlabel('Frequency')
plt.ylabel('Number of Protocols')
plt.title('Frequency Usage across IoT Wireless Protocols')
plt.xticks(rotation=45)
plt.tight_layout()
plt.savefig('images/protocols_frequency.png')

# Plotting Data Rate
plt.figure(figsize=(10, 6))
plt.bar(protocols, data_rate_values, color='lightcoral')
plt.xlabel('Protocol')
plt.ylabel('Max Data Rate (Mbps)')
plt.title('Data Rate Comparison across IoT Wireless Protocols')
plt.xticks(rotation=45)
plt.tight_layout()
plt.savefig('images/protocols_datarate.png')

0 comments on commit 3960bfa

Please sign in to comment.