-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
102 lines (87 loc) · 3.7 KB
/
main.py
File metadata and controls
102 lines (87 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pandas as pd
def load_data(filepath):
"""CSV oder SQL-Daten einlesen."""
# Beispiel: pd.read_csv(filepath)
# Hier als Platzhalter:
df = pd.read_csv(filepath)
return df
def process_timeline(df):
"""Verarbeitet die Timeline-Daten, gruppiert nach 'ident' und 'timestamp'."""
# Nach ident und timestamp sortieren
df = df.sort_values(['ident', 'timestamp'])
# Gruppiere nach ident, position_latitude, position_longitude
grouped = df.groupby(['ident', 'position_latitude', 'position_longitude', 'ble_receiver_ident'])
results = []
for (ident, lat, lon, receiver), group in grouped:
start_time = group['timestamp'].min()
end_time = group['timestamp'].max()
max_rssi = group['ble_beacon_rssi'].max()
min_rssi = group['ble_beacon_rssi'].min()
mean_rssi = group['ble_beacon_rssi'].mean()
results.append({
'ident': ident,
'from': start_time,
'to': end_time,
'position_latitude': lat,
'position_longitude': lon,
'ble_receiver_ident': receiver,
'max_rssi': max_rssi,
'min_rssi': min_rssi,
'mean_rssi': mean_rssi
})
return pd.DataFrame(results)
def show_timeline_on_map(df, output_html="timeline_map.html"):
import folium
import itertools
timeline = process_timeline(df)
center_lat = df['position_latitude'].mean()
center_lon = df['position_longitude'].mean()
m = folium.Map(location=[center_lat, center_lon], zoom_start=15)
color_list = [
"red", "blue", "green", "orange", "purple", "darkred", "lightred",
"beige", "darkblue", "darkgreen", "cadetblue", "darkpurple", "white",
"pink", "lightblue", "lightgreen", "gray", "black", "lightgray"
]
color_cycle = itertools.cycle(color_list)
ident_colors = {}
for ident, group in df.groupby('ident'):
color = next(color_cycle)
ident_colors[ident] = color
group = group.sort_values('timestamp')
coords = list(zip(group['position_latitude'], group['position_longitude']))
layer_name = f'<span style="color:{color};">●</span> {ident}'
layer = folium.FeatureGroup(name=layer_name, show=False)
if len(coords) > 1:
folium.PolyLine(coords, color=color, weight=2.5, opacity=0.7, tooltip=ident).add_to(layer)
# Marker für jede Koordinate mit zusammengefasstem Zeitraum, RSSI-Statistiken und receiver_ident
coord_groups = timeline[timeline['ident'] == ident].groupby(['position_latitude', 'position_longitude', 'ble_receiver_ident'])
for (lat, lon, receiver), coord_group in coord_groups:
row = coord_group.iloc[0]
popup_html = (
f"<b>{ident}</b><br>"
f"<b>Koordinate:</b> {lat}, {lon}<br>"
f"<b>Receiver:</b> {receiver}<br><br>"
f"<b>Zeitraum:</b> {row['from']} bis {row['to']}<br>"
f"max_rssi: {row['max_rssi']}<br>"
f"min_rssi: {row['min_rssi']}<br>"
f"mean_rssi: {row['mean_rssi']:.2f}<br>"
)
folium.Marker(
[lat, lon],
icon=folium.Icon(color=color),
popup=folium.Popup(popup_html, max_width=300)
).add_to(layer)
layer.add_to(m)
folium.LayerControl(collapsed=False).add_to(m)
m.save(output_html)
print("HTML Datei wurde generiert.")
def main():
"""Hauptfunktion zum Ausführen des Skripts."""
# Datei einlesen
df = load_data('data.csv')
# Timeline-Berechnung und Ausgabe im Terminal entfernen
# print(timeline)
# Karte anzeigen
show_timeline_on_map(df)
if __name__ == "__main__":
main()