-
Notifications
You must be signed in to change notification settings - Fork 0
/
radon_statistics.py
155 lines (131 loc) · 5.87 KB
/
radon_statistics.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
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
import pandas as pd
import glob, os
def getListofExcelFiles(DirectoryPath, ext):
'''
Returns a list of files with specific extension stored in the given folder.
Parameters:
DirectoryPath (str): Path to folder
ext (str): extension of files, e.g. 'xls'
Returns:
ListofExcelFiles (list of str): List of files with specific extension with full path
'''
ListofExcelFiles = []
for file in glob.iglob(DirectoryPath+'/**/*', recursive=True):
if file.endswith(ext):
ListofExcelFiles.append(file)
return ListofExcelFiles
def printList(DirectoryPath, title, list):
'''
Prints and writes to txt file total number of items in the list.
Prints and writes to txt file all items in the list.
Parameters:
DirectoryPath (str): Path to folder where file with results will be stored
title (str): Title of file with results
list (list of str): list of strings
'''
i = 1
filename = DirectoryPath + title + ".txt"
file = open(filename, "w")
file.write("TOTAL NUMBER: " + str(len(list)) + "\n\n")
print("TOTAL NUMBER: " + str(len(list)) + "\n\n")
for item in list:
file.write(str(i) + '. ' + item + '\n')
print(str(i) + '. ' + item)
i += 1
file.close()
return
def schoolsStatistics(ListofExcelFiles, DirectoryPath):
'''
Makes statistics of benchmark participants from Excel files. In Excel files first sheet, called "Informacje Ogólne"
containes detailed data about participants: School's Name, City, Teacher's Name, List of Students (names).
Prints list of schools, teachers and students participated in the benchmark.
Use .xls files.
Function uses printList() function
Parameters:
ListofExcelFiles (list of str): List of .xls files with full path
DirectoryPath (str): Path to folder where file with results will be stored
'''
ListofSchools = []
ListofTeachers = []
ListofStudents = []
for file in ListofExcelFiles:
general_info_sheet = pd.read_excel(file, sheet_name="Informacje ogólne")
#print(general_info_sheet)
school = general_info_sheet.at[1,"Unnamed: 2"]
city = general_info_sheet.at[2,"Unnamed: 2"]
school_full = school + " - " + city
ListofSchools.append(str(school_full))
teacher = general_info_sheet.at[4,"Unnamed: 2"]
ListofTeachers.append(str(teacher))
students = general_info_sheet.loc[6:,['Unnamed: 2']].values.tolist()
students_flat_list = [item for sublist in students for item in sublist]
ListofStudents.extend(students_flat_list)
ListofStudents = [item for item in ListofStudents if "Prosimy" not in item]
ListofSchools = list(set(ListofSchools))
ListofTeachers = list(set(ListofTeachers))
print("\n")
printList(DirectoryPath, title="lista_szkol", list=ListofSchools)
print("\n")
printList(DirectoryPath, title="lista_nauczycieli", list=ListofTeachers)
print("\n")
printList(DirectoryPath, title="lista_uczniow", list=ListofStudents)
print("\n")
#print(ListofSchools)
#print("\n")
#print(ListofTeachers)
#print("\n")
#print(ListofStudents)
#STATISTICS:
print("STATISTICS:")
print("Number of Schools: " + str(len(ListofSchools)))
print("Number of Teachers: " + str(len(ListofTeachers)))
print("Number of Students: " + str(len(ListofStudents)))
print("Number of Excel files: " + str(len(ListofExcelFiles)))
return
def generateGroups(DirectoryPath, ListofExcelFiles):
'''
Generates information about every group of students paricipated in the banchmark and writes it to 'groups.txt' file.
Information about gruop consists of: number o gruop, school's name, city, teacher and list of students.
Use .xls files.
Parameters:
ListofExcelFiles (list of str): List of .xls files with full path
DirectoryPath (str): Path to folder where 'groups.txt' file will be stored
'''
listOfGroups = []
for file in ListofExcelFiles:
dict_with_data = {}
file_name = os.path.basename(file)
id = int(file_name[0:2])
dict_with_data['id'] = id
#------------------------------------------------------
#general info
general_info_sheet = pd.read_excel(file, sheet_name="Informacje ogólne")
school = general_info_sheet.at[1,"Unnamed: 2"]
city = general_info_sheet.at[2,"Unnamed: 2"]
school_full = school + " - " + city
dict_with_data['school'] = school_full
teacher = general_info_sheet.at[4,"Unnamed: 2"]
dict_with_data['teacher'] = teacher
students = general_info_sheet.loc[6:,['Unnamed: 2']].values.tolist()
students_flat_list = [item for sublist in students for item in sublist]
dict_with_data['students'] = students_flat_list
listOfGroups.append(dict_with_data)
data = pd.DataFrame(listOfGroups)
file = open(DirectoryPath + "groups.txt","w+")
file.write("BENCHMARK, LISTA GRUP \n\n")
n_index = data.index
for i in n_index:
file.write(str(i) + " -- " + str(data.loc[i]['school']) + "\n")
file.write("Opiekun grupy: " + str(data.loc[i]['teacher']) + "\n")
file.write("Uczniowie: ")
for i in data.loc[i]['students']:
file.write(str(i) + ", ")
file.write("\n\n")
file.close()
return
DirectoryPath = "E:\\A-- FUNDACJA\\PROJEKTY\\Szkolna Radonowa Mapa Polski\\Benchmark\\"
ListofExcelFiles = getListofExcelFiles(DirectoryPath, 'xls')
#print(ListofExcelFiles)
#print("\n")
schoolsStatistics(ListofExcelFiles, DirectoryPath)
generateGroups(DirectoryPath, ListofExcelFiles)