from collections import Counter

filename = "report_8_nonALMACAL_priority.txt"

with open(filename, 'r') as ifile:
    wordcount = Counter(ifile.read().split())

list_of_project = []

for item in wordcount:
    if len(item) == 14 and item[-1] == 'S': # project_name
        list_of_project.append([item, wordcount[item]])

sorted_project = sorted(list_of_project, key=lambda data: data[1])

print("Number of project: ", len(sorted_project))

sorted_from_large = list(reversed(sorted_project))

"""
Explanation: What is the most important project that we need to download first?
What I did is simply counting the occurance of the word (project name) in the report file
End of explanation
"""


# 15 first
for i in sorted_from_large[0:15]:
    print(i)

"""
Explanation: due to the structure of the report this number can not be used directly as a reference
e.g. maybe large occurance due to small integration and observed many time  and also it is possible only for one object in one band (like the first project in here)
I think the year of Cycle is more important due to number of antenna.
End of explanation
"""


sorted_project_year = sorted(list_of_project, key=lambda data: data[0])

sorted_from_new = list(reversed(sorted_project_year))

# 15 first
for i in sorted_from_new[0:15]:
    print(i)

"""
Explanation: Sorted based on year
End of explanation
"""


