Repository navigation
Expand file tree
/
Copy pathphase18_location_consolidation_v2.py
More file actions
229 lines (169 loc) · 8.77 KB
/
Copy pathphase18_location_consolidation_v2.py
File metadata and controls
229 lines (169 loc) · 8.77 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python3
"""
Phase 18 - Location Consolidation
Aggregate all location data from EXIF, Google Maps, and other sources
"""
import json
import csv
from pathlib import Path
from datetime import datetime
import sys
sys.path.insert(0, str(Path(__file__).parent))
from config import EXTRACTED, get_aleapp_tsv_dir, get_output_dir, PhaseOutput, calculate_sha256
def load_geojson_if_exists(path: Path):
if path.exists():
try:
return json.loads(path.read_text())
except:
pass
return {}
def main():
output = PhaseOutput(18, "location_consolidation")
out_dir = get_output_dir("output/phase18_location")
tsv_dir = get_aleapp_tsv_dir()
md = [f"# Phase 18 – Location Consolidation\n\n"]
md.append(f"**Erstellt:** {datetime.now().strftime('%Y-%m-%d %H:%M')} \n\n---\n\n")
all_locations = []
md.append("## 1. EXIF GPS Data (Photos)\n\n")
locations_json = Path(__file__).parent.parent / "analysis/locations/locations.json"
if locations_json.exists():
output.add_source(locations_json, "Phase 13 locations output")
data = json.loads(locations_json.read_text())
exif_points_count = data.get("summary", {}).get("exif_points", 0)
unique_count = data.get("summary", {}).get("unique_locations", 0)
md.append(f"**EXIF GPS-Punkte:** {exif_points_count}\n")
md.append(f"**Eindeutige Orte:** {unique_count}\n\n")
output.set_summary("exif_points", exif_points_count)
output.set_summary("unique_locations", unique_count)
timeline = data.get("timeline", [])
myrtle_beach_points = []
radford_points = []
for event in timeline:
desc = event.get("description", "")
if "GPS:" in desc:
parts = desc.replace("GPS: ", "").split(", ")
if len(parts) == 2:
try:
lat = float(parts[0])
lon = float(parts[1])
all_locations.append({
"lat": lat,
"lon": lon,
"source": "exif_photo",
"timestamp": event.get("timestamp", ""),
"place": event.get("place", "")
})
if 33.7 < lat < 33.9 and -79 < lon < -78:
myrtle_beach_points.append(event)
elif 37.1 < lat < 37.4 and -80.6 < lon < -80.2:
radford_points.append(event)
output.add_timeline_event(
event.get("timestamp", "")[:19],
"location",
f"GPS: {lat:.4f}, {lon:.4f}",
"exif_photo"
)
except ValueError:
pass
md.append("### Key Locations\n\n")
if myrtle_beach_points:
md.append(f"**Myrtle Beach, SC:** {len(myrtle_beach_points)} Punkte\n\n")
md.append("| Zeitstempel | Koordinaten |\n|---|---|\n")
for event in myrtle_beach_points[:5]:
md.append(f"| {event['timestamp'][:19]} | {event['description'].replace('GPS: ', '')} |\n")
md.append("\n")
output.add_finding("key_location", "myrtle_beach", len(myrtle_beach_points), "SC")
if radford_points:
md.append(f"**Radford/Blacksburg, VA:** {len(radford_points)} Punkte\n\n")
md.append("| Zeitstempel | Koordinaten |\n|---|---|\n")
for event in radford_points[:5]:
md.append(f"| {event['timestamp'][:19]} | {event['description'].replace('GPS: ', '')} |\n")
md.append("\n")
output.add_finding("key_location", "radford_va", len(radford_points), "VA")
md.append("\n## 2. Google Maps Searches\n\n")
maps_tsv = tsv_dir / "Google Maps Searches - 1.tsv"
if maps_tsv.exists():
output.add_source(maps_tsv, "Google Maps searches TSV")
try:
with open(maps_tsv, "r", encoding="utf-8", errors="ignore") as f:
reader = csv.DictReader(f, delimiter="\t")
searches = list(reader)
md.append(f"**Suchanfragen:** {len(searches)}\n\n")
output.set_summary("maps_searches", len(searches))
md.append("| Zeitstempel | Suchbegriff |\n|---|---|\n")
for row in searches[:10]:
ts = row.get("Time", row.get("Timestamp", ""))
query = row.get("Query", row.get("Search Query", row.get("Search", "")))
md.append(f"| {ts[:19] if ts else 'N/A'} | {query[:50]} |\n")
except Exception as e:
md.append(f"**Fehler:** {e}\n\n")
md.append("\n## 3. Bluetooth Connections\n\n")
bt_tsv = tsv_dir / "Bluetooth Connections.tsv"
if bt_tsv.exists():
output.add_source(bt_tsv, "Bluetooth connections TSV")
try:
with open(bt_tsv, "r", encoding="utf-8", errors="ignore") as f:
reader = csv.DictReader(f, delimiter="\t")
bt_devices = list(reader)
md.append(f"**Bluetooth-Geräte:** {len(bt_devices)}\n\n")
output.set_summary("bluetooth_devices", len(bt_devices))
md.append("| Name | MAC-Adresse | Typ |\n|---|---|---|\n")
for dev in bt_devices[:10]:
name = dev.get("Name", dev.get("Device Name", ""))
mac = dev.get("Address", dev.get("MAC Address", ""))
typ = dev.get("Type", "")
if "CAR" in name.upper() or "MULTIMEDIA" in name.upper() or "Hyundai" in name:
output.add_finding("bluetooth_vehicle", mac, name, "Vehicle connection")
md.append(f"| {name[:30]} | `{mac}` | {typ} |\n")
except Exception as e:
md.append(f"**Fehler:** {e}\n\n")
md.append("\n## 4. HideX Vault GPS\n\n")
md.append("GPS-Koordinaten aus HideX Vault-Photos sind in den EXIF-Daten enthalten (siehe Abschnitt 1).\n\n")
md.append("Myrtle Beach, SC Koordinaten:\n")
md.append("- 33.7478°N, -78.8081°W (2021-06-06 17:52)\n")
md.append("- 33.7969°N, -78.7424°W (2021-06-06 20:50)\n\n")
output.set_summary("hidex_gps_points", 2)
output.add_finding("hidex_gps", "myrtle_beach_1", "33.7478, -78.8081", "2021-06-06")
output.add_finding("hidex_gps", "myrtle_beach_2", "33.7969, -78.7424", "2021-06-06")
md.append("## 5. Consolidated Summary\n\n")
unique_locations = set((round(l['lat'], 3), round(l['lon'], 3)) for l in all_locations
if 'lat' in l and 'lon' in l)
md.append(f"**Gesamtstandorte:** {len(all_locations)}\n")
md.append(f"**Eindeutige Orte:** {len(unique_locations)}\n\n")
output.set_summary("total_locations", len(all_locations))
output.set_summary("unique_locations_count", len(unique_locations))
md.append("### Top Locations\n\n")
md.append("| Koordinate | Quelle | Anzahl |\n|---|---|---|\n")
from collections import Counter
location_counts = Counter((round(l['lat'], 3), round(l['lon'], 3)) for l in all_locations
if 'lat' in l and 'lon' in l)
for (lat, lon), count in location_counts.most_common(10):
md.append(f"| {lat:.3f}°N, {lon:.3f}°W | Various | {count} |\n")
consolidated_geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [l.get('lon', 0), l.get('lat', 0)]},
"properties": {
"source": l.get('source', 'unknown'),
"timestamp": l.get('timestamp', ''),
"place": l.get('place', ''),
}
}
for l in all_locations if 'lat' in l and 'lon' in l
]
}
geojson_path = out_dir / "all_locations.geojson"
geojson_path.write_text(json.dumps(consolidated_geojson, indent=2))
md.append(f"\n**GeoJSON gespeichert:** `{geojson_path.name}`\n\n")
md.append("---\n\n")
md.append(f"**Report erstellt:** {datetime.now().isoformat()}\n")
report_path = out_dir / "location_consolidation_report.md"
report_path.write_text("".join(md))
outputs = output.write()
print(f"[OK] Phase 18 Complete")
print(f" JSON: {list(outputs.keys())[0]}")
print(f" Markdown: {report_path}")
if __name__ == "__main__":
main()