-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMission_Status_Record.py
110 lines (86 loc) · 4.26 KB
/
Mission_Status_Record.py
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
import csv
import os
from tabulate import tabulate
import App_Parameters as app_params
class Mission_Status_Recorder():
def __init__(self, mission_name, mission_datetime, mission_downlink_time):
self.image_status_record = []
self.mission_name = mission_name
self.mission_start_time = mission_datetime
self.mission_downlink_time = mission_downlink_time
self.has_failure = False
self.table_header = ['#', 'Downlink Status', 'Reed Solomon Decode Status', 'Unzip + Base64 Decode Status']
def create_new_record(self, image_count):
self.image_status_record.append(
{'#': image_count, 'Downlink Status': "FAILED", 'Reed Solomon Decode Status': "FAILED",
'Unzip + Base64 Decode Status': "FAILED"})
def update_downlink_status(self, image_count, is_success):
idx = image_count - 1
if is_success:
self.image_status_record[idx].update({'Downlink Status': "SUCCESS"})
else:
self.image_status_record[idx].update({'Downlink Status': "FAILED"})
self.has_failure = True
def update_rs_decode_status(self, image_count, is_success):
idx = image_count - 1
if is_success:
self.image_status_record[idx].update({'Reed Solomon Decode Status': "SUCCESS"})
else:
self.image_status_record[idx].update({'Reed Solomon Decode Status': "FAILED"})
self.has_failure = True
def update_unzip_base64_decode_status(self, image_count, is_success):
idx = image_count - 1
if is_success:
self.image_status_record[idx].update({'Unzip + Base64 Decode Status': "SUCCESS"})
else:
self.image_status_record[idx].update({'Unzip + Base64 Decode Status': "FAILED"})
self.has_failure = True
def create_mission_status_log(self):
table_values = [list(x.values()) for x in self.image_status_record]
# If mission has timeout and failed
if len(table_values) == 0:
# Set failure flag to indicate record fail
self.has_failure = True
with open(f"{app_params.GROUND_STN_MISSION_FOLDER_PATH}/{self.mission_name}/{self.mission_name}_status.txt", 'w') as status_log:
to_print = ""
status = [["Mission Name", self.mission_name],
["Mission Start time", self.mission_start_time],
["Mission Downlink time", self.mission_downlink_time]]
to_print += tabulate(status, tablefmt="pretty")
to_print += '\n'
to_print += 'Mission Status:\n'
to_print += 'MISSION FAILED - TIMEOUT'
status_log.write(to_print)
status_log.close()
else:
# Create the log file
with open(f"{app_params.GROUND_STN_MISSION_FOLDER_PATH}/{self.mission_name}/{self.mission_name}_status.txt", 'w') as status_log:
to_print = ""
status = [["Mission Name", self.mission_name],
["Mission Start time", self.mission_start_time],
["Mission Downlink time", self.mission_downlink_time]]
to_print += tabulate(status, tablefmt="pretty")
to_print += '\n'
to_print += 'Mission Status:\n'
to_print += tabulate(table_values, headers=self.table_header, tablefmt="pretty")
status_log.write(to_print)
status_log.close()
def update_overall_mission_status_log(self, mission_name):
header = "Mission Name,Mission Status\n"
# TODO: Need to run overall check again for failure
# Check overall status - success or failure
outcome = ""
if self.has_failure == True:
outcome = "FAIL"
else:
outcome = "SUCCESS"
print(f"Mission outcome: {outcome}")
# Create csv file if not already created
if not os.path.exists(app_params.GROUND_STN_MISSION_LOG_FILEPATH):
f = open(app_params.GROUND_STN_MISSION_LOG_FILEPATH, "w")
f.write(header)
f.close()
# Append to csv
with open(app_params.GROUND_STN_MISSION_LOG_FILEPATH, "a") as log:
log.write(f"{mission_name},{outcome}\n")
log.close()