aboutsummaryrefslogtreecommitdiffstats
path: root/analysis/e1anl
diff options
context:
space:
mode:
Diffstat (limited to 'analysis/e1anl')
-rw-r--r--analysis/e1anl/Makefile27
-rw-r--r--analysis/e1anl/__pycache__/agregate.cpython-313.pycbin0 -> 3423 bytes
-rw-r--r--analysis/e1anl/__pycache__/analyze.cpython-313.pycbin0 -> 2835 bytes
-rw-r--r--analysis/e1anl/requirements.txt16
-rw-r--r--analysis/e1anl/src/__pycache__/agregate.cpython-313.pycbin0 -> 3528 bytes
-rw-r--r--analysis/e1anl/src/__pycache__/analyze.cpython-313.pycbin0 -> 2962 bytes
-rw-r--r--analysis/e1anl/src/agregate.py71
-rw-r--r--analysis/e1anl/src/analyze.py49
-rw-r--r--analysis/e1anl/src/main.py17
9 files changed, 180 insertions, 0 deletions
diff --git a/analysis/e1anl/Makefile b/analysis/e1anl/Makefile
new file mode 100644
index 0000000..7cbd4a3
--- /dev/null
+++ b/analysis/e1anl/Makefile
@@ -0,0 +1,27 @@
1# Makefile
2
3VENV_NAME=venv
4PYTHON=$(VENV_NAME)/bin/python
5SRC=src
6OUTPUT=output
7
8.PHONY: venv install run analyze clean
9
10venv:
11 python3 -m venv $(VENV_NAME)
12
13install: venv
14 $(PYTHON) -m pip install --upgrade pip
15 $(PYTHON) -m pip install -r requirements.txt
16
17run: install
18 mkdir -p $(OUTPUT)
19 $(PYTHON) $(SRC)/main.py
20
21analyze: install
22 mkdir -p $(OUTPUT)
23 $(PYTHON) $(SRC)/analyze_metrics.py
24
25clean:
26 rm -rf $(VENV_NAME)
27 rm -rf $(OUTPUT)
diff --git a/analysis/e1anl/__pycache__/agregate.cpython-313.pyc b/analysis/e1anl/__pycache__/agregate.cpython-313.pyc
new file mode 100644
index 0000000..21c7510
--- /dev/null
+++ b/analysis/e1anl/__pycache__/agregate.cpython-313.pyc
Binary files differ
diff --git a/analysis/e1anl/__pycache__/analyze.cpython-313.pyc b/analysis/e1anl/__pycache__/analyze.cpython-313.pyc
new file mode 100644
index 0000000..0b6a4ce
--- /dev/null
+++ b/analysis/e1anl/__pycache__/analyze.cpython-313.pyc
Binary files differ
diff --git a/analysis/e1anl/requirements.txt b/analysis/e1anl/requirements.txt
new file mode 100644
index 0000000..3c9cae6
--- /dev/null
+++ b/analysis/e1anl/requirements.txt
@@ -0,0 +1,16 @@
1contourpy==1.3.3
2cycler==0.12.1
3fonttools==4.59.2
4kiwisolver==1.4.9
5matplotlib==3.10.6
6numpy==2.3.2
7packaging==25.0
8paho-mqtt==2.1.0
9pandas==2.3.2
10pillow==11.3.0
11pyparsing==3.2.3
12python-dateutil==2.9.0.post0
13pytz==2025.2
14seaborn==0.13.2
15six==1.17.0
16tzdata==2025.2
diff --git a/analysis/e1anl/src/__pycache__/agregate.cpython-313.pyc b/analysis/e1anl/src/__pycache__/agregate.cpython-313.pyc
new file mode 100644
index 0000000..3a0d6cb
--- /dev/null
+++ b/analysis/e1anl/src/__pycache__/agregate.cpython-313.pyc
Binary files differ
diff --git a/analysis/e1anl/src/__pycache__/analyze.cpython-313.pyc b/analysis/e1anl/src/__pycache__/analyze.cpython-313.pyc
new file mode 100644
index 0000000..a891763
--- /dev/null
+++ b/analysis/e1anl/src/__pycache__/analyze.cpython-313.pyc
Binary files differ
diff --git a/analysis/e1anl/src/agregate.py b/analysis/e1anl/src/agregate.py
new file mode 100644
index 0000000..1054288
--- /dev/null
+++ b/analysis/e1anl/src/agregate.py
@@ -0,0 +1,71 @@
1# mqtt_receiver.py
2
3import paho.mqtt.client as mqtt
4import csv
5import time
6from datetime import datetime
7from collections import deque
8import os
9os.makedirs("output", exist_ok=True)
10
11BROKER = "192.168.1.101"
12SUB_TOPIC = "device/echo/in"
13CSV_FILE = "output/rtt_throughput_log.csv"
14WINDOW_SEC = 1
15
16msg_times = deque()
17should_stop = False # flag to stop loop externally
18
19
20def on_connect(client, userdata, flags, rc):
21 if rc == 0:
22 print("Connected to broker")
23 client.subscribe(SUB_TOPIC)
24 else:
25 print("Failed to connect, return code:", rc)
26
27
28def on_message(client, userdata, msg):
29 try:
30 payload_str = msg.payload.decode()
31 sent_ms = int(payload_str)
32 received_ms = int(time.time() * 1000)
33 rtt = received_ms - sent_ms
34 timestamp = datetime.now().isoformat()
35
36 now_sec = time.time()
37 msg_times.append(now_sec)
38 while msg_times and msg_times[0] < now_sec - WINDOW_SEC:
39 msg_times.popleft()
40 throughput = len(msg_times) / WINDOW_SEC
41
42 with open(CSV_FILE, "a", newline="") as f:
43 writer = csv.writer(f)
44 writer.writerow([timestamp, sent_ms, received_ms, rtt, throughput])
45
46 except Exception as e:
47 print("Error processing message:", e)
48
49
50def collect_data(duration_sec):
51 global should_stop
52 should_stop = False
53
54 # Start CSV log
55 with open(CSV_FILE, "w", newline="") as f:
56 writer = csv.writer(f)
57 writer.writerow(["timestamp", "sent_ms", "received_ms", "rtt_ms", "throughput_msg_per_s"])
58
59 client = mqtt.Client()
60 client.on_connect = on_connect
61 client.on_message = on_message
62 client.connect(BROKER, 1883, 60)
63
64 client.loop_start()
65 print(f"Zbieranie danych przez {duration_sec / 60:.1f} minut...")
66
67 time.sleep(duration_sec)
68
69 print("Zbieranie danych zakończone.")
70 client.loop_stop()
71 client.disconnect()
diff --git a/analysis/e1anl/src/analyze.py b/analysis/e1anl/src/analyze.py
new file mode 100644
index 0000000..6e73df3
--- /dev/null
+++ b/analysis/e1anl/src/analyze.py
@@ -0,0 +1,49 @@
1# analyze_metrics.py
2
3import pandas as pd
4import matplotlib.pyplot as plt
5import seaborn as sns
6
7import os
8os.makedirs("output", exist_ok=True)
9
10def analyze():
11 CSV_FILE = "output/rtt_throughput_log.csv"
12 df = pd.read_csv(CSV_FILE)
13
14 df['sent_ms'] = df['sent_ms'].astype(int)
15 df['received_ms'] = df['received_ms'].astype(int)
16 df['rtt_ms'] = df['rtt_ms'].astype(int)
17 df['throughput_msg_per_s'] = df['throughput_msg_per_s'].astype(float)
18
19 mean_rtt = df['rtt_ms'].mean()
20 p95_rtt = df['rtt_ms'].quantile(0.95)
21 mean_throughput = df['throughput_msg_per_s'].mean()
22
23 print(f"Średnie RTT: {mean_rtt:.2f} ms")
24 print(f"RTT 95-percentyl: {p95_rtt:.2f} ms")
25 print(f"Średni throughput: {mean_throughput:.2f} msg/s")
26
27 plt.figure(figsize=(6,4))
28 sns.barplot(x=['Variant A'], y=[mean_rtt], palette="Set2")
29 plt.title("Średnie RTT - wariant A")
30 plt.ylabel("RTT [ms]")
31 plt.tight_layout()
32 plt.savefig("output/rtt_mean_a.png")
33 plt.show()
34
35 plt.figure(figsize=(6,4))
36 sns.barplot(x=['Variant A'], y=[p95_rtt], palette="Set3")
37 plt.title("RTT 95-percentyl - wariant A")
38 plt.ylabel("RTT [ms]")
39 plt.tight_layout()
40 plt.savefig("output/rtt_p95_a.png")
41 plt.show()
42
43 plt.figure(figsize=(6,4))
44 sns.barplot(x=['Variant A'], y=[mean_throughput], palette="Set1")
45 plt.title("Średni throughput - wariant A")
46 plt.ylabel("Messages per second")
47 plt.tight_layout()
48 plt.savefig("output/throughput_a.png")
49 plt.show()
diff --git a/analysis/e1anl/src/main.py b/analysis/e1anl/src/main.py
new file mode 100644
index 0000000..b35eead
--- /dev/null
+++ b/analysis/e1anl/src/main.py
@@ -0,0 +1,17 @@
1# main.py
2
3from agregate import collect_data
4from analyze import analyze
5
6def main():
7 DURATION_HOURS = 2
8 DURATION_SECONDS = DURATION_HOURS * 3600
9
10 print("Collecting data...")
11 collect_data(DURATION_SECONDS)
12
13 print("Analyzing data...")
14 analyze()
15
16if __name__ == "__main__":
17 main()