-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from simonthorell/setup
Autogenerate Diagrams
- Loading branch information
Showing
10 changed files
with
179 additions
and
4 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 |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,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" | ||
} | ||
] | ||
} |
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,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') |