-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_data.py
More file actions
482 lines (386 loc) · 15.7 KB
/
sample_data.py
File metadata and controls
482 lines (386 loc) · 15.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#!/usr/bin/env python3
"""
Vessel Maintenance AI System - Sample Data Generator
This script generates realistic sample data for testing and demonstrating
the vessel maintenance AI system. It creates various types of maintenance
records, sensor alerts, and incident reports that showcase the system's
classification and analysis capabilities.
The script sends test documents to the running API server and displays
the AI analysis results, providing a comprehensive demonstration of
the system's features.
Usage:
python sample_data.py
Requirements:
- The main application server must be running on localhost:8000
- The requests library must be installed
Author: Fusionpact Technologies Inc.
Date: 2025-07-18
Version: 1.0.0
License: MIT License
Copyright (c) 2025 Fusionpact Technologies Inc.
Licensed under the MIT License. See LICENSE file for details.
"""
import requests
import json
import time
import random
from datetime import datetime, timedelta
# Configuration
API_BASE_URL = "http://localhost:8000"
DEMO_DELAY = 2 # Seconds between requests for better demonstration
# Sample vessel maintenance records demonstrating different classification types
MAINTENANCE_RECORDS = [
"""
Vessel ID: MV-ATLANTIC-001
Date: 2024-01-15
Main Engine Maintenance Report:
During routine inspection of main engine, discovered oil leak from cylinder head gasket.
Engine temperature readings showing 5-degree increase over normal operating range.
Oil pressure maintaining within acceptable limits but showing gradual decline over past week.
Recommended immediate replacement of gasket and full system pressure test.
Crew: Chief Engineer Martinez, Assistant Engineer Thompson
Equipment: Caterpillar 3516C Marine Engine
""",
"""
Vessel ID: MV-PACIFIC-STAR
Date: 2024-01-20
CRITICAL NAVIGATION SYSTEM FAILURE:
GPS primary unit has completely failed during night watch.
Backup GPS showing intermittent signal loss.
Radar system functioning but showing reduced range accuracy.
Ship currently navigating using compass and paper charts.
IMMEDIATE ASSISTANCE REQUIRED - Position uncertainty in heavy traffic area.
Bridge Officer: Captain Rodriguez
Location: 45°N 35°W (approximate)
""",
"""
Vessel ID: MV-CARGO-MASTER
Date: 2024-01-25
Environmental Incident Report:
During fuel transfer operations in port, approximately 150 liters of marine diesel
spilled into harbor waters due to hose connection failure.
Spill containment booms deployed immediately.
Coast Guard and port authority notified as per MARPOL regulations.
Environmental cleanup crew dispatched.
This constitutes a breach of environmental compliance protocols.
Full investigation and corrective measures required.
Environmental Officer: Sarah Johnson
Port: Rotterdam
""",
"""
Vessel ID: MV-OCEAN-BREEZE
Date: 2024-01-30
Routine Maintenance Schedule:
Weekly inspection completed on all safety equipment.
Life jackets - 48 units inspected, 3 require replacement
Fire extinguishers - all pressure levels normal
Emergency lighting - 2 units need battery replacement
Scheduled for next port call maintenance:
- Air filter replacement (due in 50 hours)
- Oil change (due in 75 hours)
- Pump bearing lubrication
Maintenance Supervisor: Mike Chen
""",
"""
Vessel ID: MV-NORDIC-WIND
Date: 2024-02-05
Safety Violation Incident:
Crew member found working on deck without proper personal protective equipment.
No safety harness used while working near rail in rough sea conditions.
Incident occurred during cargo securing operations.
Immediate safety briefing conducted for all deck crew.
Written warning issued to crew member.
All safety protocols must be strictly enforced.
Safety Officer: David Wilson
""",
"""
Vessel ID: MV-FUEL-EFFICIENT
Date: 2024-02-10
Fuel Efficiency Alert:
Fuel consumption has increased by 15% over past voyage compared to normal operations.
Current consumption: 45 tons/day (normal: 39 tons/day)
Possible causes:
- Hull fouling (last cleaning 8 months ago)
- Engine performance degradation
- Adverse weather conditions
Recommend hull inspection and engine tuning during next dry dock.
Consider speed optimization for remaining voyage.
Chief Engineer: Anna Petrov
""",
"""
Vessel ID: MV-SENSOR-WATCH
Date: 2024-02-15
Sensor Anomaly Alert:
Temperature sensors in engine room showing unusual readings:
- Sensor A1: 95°C (normal: 75°C)
- Sensor B2: Temperature fluctuating between 65-85°C
- Cooling water pressure: 4.2 bar (normal: 5.5 bar)
Manual temperature checks confirm elevated readings.
Cooling system efficiency appears compromised.
Recommend immediate cooling system inspection and pump check.
Watch Engineer: Tom Anderson
""",
"""
Vessel ID: MV-STORM-RIDER
Date: 2024-02-20
Severe Weather Incident Report:
Vessel encountered Force 9 gale conditions with 12-meter waves.
During heavy rolling, cargo containers shifted causing:
- Minor damage to container guides on deck
- Loose lashing requiring immediate attention
- Bridge window cracked from wave impact
All crew accounted for and safe.
Speed reduced to 8 knots for safety.
ETA delayed by 6 hours.
Master: Captain Lisa Chang
Position: 52°N 15°W
""",
"""
Vessel ID: MV-MAINTENANCE-MASTER
Date: 2024-02-25
Preventive Maintenance Completion Report:
Monthly maintenance schedule completed successfully:
✓ Engine oil analysis - results within normal parameters
✓ Fuel filters replaced - 3 primary, 2 secondary
✓ Steering gear lubrication completed
✓ Emergency generator tested - 30-minute full load test passed
✓ Fire suppression system inspection completed
Next scheduled maintenance: March 25, 2024
Chief Engineer: Roberto Silva
""",
"""
Vessel ID: MV-TECH-INNOVATION
Date: 2024-03-01
Equipment Malfunction Report:
Autopilot system experiencing intermittent failures.
System disconnects randomly every 2-3 hours requiring manual steering.
Gyrocompass readings appear stable.
Preliminary diagnosis suggests software corruption or sensor malfunction.
Manual steering capabilities confirmed operational.
Recommend technical support consultation at next port.
Navigation Officer: Emma Thompson
"""
]
def print_banner():
"""Display the application banner and introduction."""
print("\n" + "="*80)
print("🚢 VESSEL MAINTENANCE AI SYSTEM - SAMPLE DATA DEMONSTRATION")
print("="*80)
print("\nThis demonstration will process various types of vessel maintenance")
print("documents to showcase the AI system's classification capabilities.")
print("\nDocument types included:")
print("• Critical Equipment Failures")
print("• Navigational Hazard Alerts")
print("• Environmental Compliance Breaches")
print("• Routine Maintenance Records")
print("• Safety Violation Reports")
print("• Fuel Efficiency Alerts")
print("• Sensor Anomaly Alerts")
print("• Incident Reports")
print("\n" + "-"*80)
def check_server_availability():
"""
Check if the API server is running and accessible.
Returns:
bool: True if server is accessible, False otherwise
"""
try:
response = requests.get(f"{API_BASE_URL}/health", timeout=5)
if response.status_code == 200:
print("✅ API server is running and accessible")
return True
else:
print(f"❌ API server returned status code: {response.status_code}")
return False
except requests.exceptions.RequestException as e:
print(f"❌ Unable to connect to API server: {e}")
print("Please ensure the server is running on localhost:8000")
return False
def process_document(text, vessel_id=None, document_type=None):
"""
Process a single document through the API.
Args:
text (str): Document text to process
vessel_id (str, optional): Vessel identifier
document_type (str, optional): Type of document
Returns:
dict: API response or None if failed
"""
try:
payload = {
"text": text,
"vessel_id": vessel_id,
"document_type": document_type
}
response = requests.post(
f"{API_BASE_URL}/process/text",
json=payload,
timeout=30
)
if response.status_code == 200:
return response.json()
else:
print(f"❌ Error processing document: {response.status_code}")
print(f" Response: {response.text}")
return None
except requests.exceptions.RequestException as e:
print(f"❌ Network error: {e}")
return None
def display_result(result, index):
"""
Display the processing result in a formatted manner.
Args:
result (dict): Processing result from the API
index (int): Document index for numbering
"""
if not result:
return
print(f"\n📋 DOCUMENT {index + 1} ANALYSIS RESULTS:")
print("-" * 50)
# Basic information
print(f"🏷️ Classification: {result.get('classification', 'Unknown')}")
print(f"🚨 Priority: {result.get('priority', 'Unknown')}")
print(f"📊 Confidence: {result.get('confidence_score', 0):.2%}")
print(f"📄 Document Type: {result.get('document_type', 'Unknown')}")
# Summary and details
print(f"\n📝 Summary:")
print(f" {result.get('summary', 'No summary available')}")
# Risk assessment
print(f"\n⚠️ Risk Assessment:")
print(f" {result.get('risk_assessment', 'No risk assessment available')}")
# Keywords
keywords = result.get('keywords', [])
if keywords:
print(f"\n🔑 Key Terms: {', '.join(keywords[:8])}{'...' if len(keywords) > 8 else ''}")
# Entities
entities = result.get('entities', {})
if entities:
print(f"\n🔍 Extracted Entities:")
for entity_type, entity_list in entities.items():
if entity_list:
print(f" {entity_type.title()}: {', '.join(entity_list[:3])}{'...' if len(entity_list) > 3 else ''}")
# Recommended actions
recommendations = result.get('recommended_actions', [])
if recommendations:
print(f"\n💡 Recommended Actions:")
for i, action in enumerate(recommendations[:5], 1):
print(f" {i}. {action}")
if len(recommendations) > 5:
print(f" ... and {len(recommendations) - 5} more actions")
print("\n" + "="*60)
def get_analytics():
"""
Retrieve and display system analytics.
Returns:
dict: Analytics data or None if failed
"""
try:
response = requests.get(f"{API_BASE_URL}/analytics", timeout=10)
if response.status_code == 200:
return response.json()
else:
print(f"❌ Error getting analytics: {response.status_code}")
return None
except requests.exceptions.RequestException as e:
print(f"❌ Network error getting analytics: {e}")
return None
def display_analytics(analytics):
"""
Display system analytics in a formatted manner.
Args:
analytics (dict): Analytics data from the API
"""
if not analytics:
return
print("\n" + "="*80)
print("📊 SYSTEM ANALYTICS SUMMARY")
print("="*80)
# Overall statistics
print(f"📈 Total Documents Processed: {analytics.get('total_processed', 0)}")
print(f"🚨 Critical Alerts: {analytics.get('critical_alerts', 0)}")
# Classification breakdown
classification_breakdown = analytics.get('classification_breakdown', {})
if classification_breakdown:
print(f"\n🏷️ Classification Breakdown:")
for classification, count in classification_breakdown.items():
print(f" • {classification}: {count}")
# Priority breakdown
priority_breakdown = analytics.get('priority_breakdown', {})
if priority_breakdown:
print(f"\n🚨 Priority Level Distribution:")
for priority, count in priority_breakdown.items():
print(f" • {priority}: {count}")
# Recent trends
recent_trends = analytics.get('recent_trends', [])
if recent_trends:
print(f"\n📅 Recent Activity (Last 7 Days):")
for trend in recent_trends[:7]:
date = trend.get('date', 'Unknown')
count = trend.get('count', 0)
print(f" • {date}: {count} documents")
print("\n" + "="*80)
def main():
"""
Main function to run the sample data demonstration.
This function orchestrates the entire demonstration process including
server checks, document processing, and analytics display.
"""
# Display introduction
print_banner()
# Check if server is running
if not check_server_availability():
print("\n❌ Cannot proceed without server connection.")
print("Please start the server with: python app.py")
return
# Process sample documents
print(f"\n🔄 Processing {len(MAINTENANCE_RECORDS)} sample documents...")
print("(Processing with 2-second delays for demonstration purposes)")
successful_processes = 0
for i, document in enumerate(MAINTENANCE_RECORDS):
print(f"\n⏳ Processing document {i + 1}/{len(MAINTENANCE_RECORDS)}...")
# Extract vessel ID from document if available
vessel_id = None
lines = document.strip().split('\n')
for line in lines:
if 'Vessel ID:' in line:
vessel_id = line.split('Vessel ID:')[1].strip()
break
# Process the document
result = process_document(
text=document,
vessel_id=vessel_id,
document_type="Sample Data"
)
if result:
display_result(result, i)
successful_processes += 1
else:
print(f"❌ Failed to process document {i + 1}")
# Add delay for demonstration purposes
if i < len(MAINTENANCE_RECORDS) - 1:
time.sleep(DEMO_DELAY)
# Display summary
print(f"\n✅ Successfully processed {successful_processes}/{len(MAINTENANCE_RECORDS)} documents")
# Get and display analytics
print("\n⏳ Generating analytics summary...")
analytics = get_analytics()
display_analytics(analytics)
# Final message
print("\n🎉 DEMONSTRATION COMPLETE!")
print("\nThe Vessel Maintenance AI System has successfully processed various")
print("types of maritime documents and provided intelligent classifications")
print("and actionable recommendations.")
print("\n💡 Next steps:")
print("• Visit http://localhost:8000 for the web interface")
print("• View analytics at http://localhost:8000/analytics")
print("• Check system health at http://localhost:8000/health")
print("• Review processing history at http://localhost:8000/history")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\n⏹️ Demonstration interrupted by user.")
print("Thank you for testing the Vessel Maintenance AI System!")
except Exception as e:
print(f"\n❌ Unexpected error during demonstration: {e}")
print("Please check the server logs for more details.")