-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMission Comparison.py
97 lines (86 loc) · 3.15 KB
/
Mission Comparison.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
import os
datafileList = []
missionList = []
activeMissions = []
failedMissions = []
abortedMissions = []
offeredMissions = []
declinedMissions = []
completedMissions = []
# Filter a string to only what's between double quotes
def filterToQuotes(s):
q1 = s.find('"')
q2 = s.find('"', q1 + 1)
return s[q1+1:q2]
# Create a list of all data files
def listDatafiles(directory):
global datafileList
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
if os.path.isfile(f):
if f.endswith('.txt'):
datafileList.append(f)
else:
listDatafiles(f)
# Find all the mission nodes in a datafile
def listMissionsInFile(f):
global missionList
file = open(f)
for line in file:
if line.startswith('mission'):
missionName = filterToQuotes(line)
missionList.append(missionName)
# Parse save file looking for missions of all kinds
def listMissionsByStatus(f):
global activeMissions
global failedMissions
global abortedMissions
global offeredMissions
global declinedMissions
global completedMissions
file = open(f)
search = False
for line in file:
if line == 'conditions\n' and not search:
search = True
elif not line.startswith('\t') and search:
search = False
if search:
condition = filterToQuotes(line)
if condition.endswith(': active'):
activeMissions.append(condition[0:-8])
elif condition.endswith(': failed'):
failedMissions.append(condition[0:-8])
elif condition.endswith(': aborted'):
abortedMissions.append(condition[0:-9])
elif condition.endswith(': offered'):
offeredMissions.append(condition[0:-9])
elif condition.endswith(': declined'):
declinedMissions.append(condition[0:-10])
elif condition.endswith(': done'):
completedMissions.append(condition[0:-5])
# Check if a value is not in a list
def notIn(a, l):
if a in l:
return False
return True
# Run the script
dataDir = input('Path to datafile directory: ')
listDatafiles(dataDir)
for file in datafileList:
listMissionsInFile(file)
print('Data file crawling complete!')
savefile = input('Path to save file: ')
listMissionsByStatus(savefile)
print('Save file crawling complete!')
# Print the final report
print('\nThere were %s missions in the files loaded (missionList).' % len(missionList))
print('\nYou have completed %s of them (completedMissions).' % len(completedMissions))
print('You have %s currently active (activeMissions).' % len(activeMissions))
print('You have failed %s of them (failedMissions).' % len(failedMissions))
print('You have aborted %s of them (abortedMissions).' % len(abortedMissions))
print('You have been offered %s of them (offeredMissions).' % len(offeredMissions))
print('You have declined %s of them (declinedMissions).' % len(declinedMissions))
print('\nThe following missions are still incomplete:')
incomplete = list(filter(lambda a: notIn(a, completedMissions), missionList))
print(incomplete)