-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
93 lines (70 loc) · 3 KB
/
index.php
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
<?php
require_once 'includes/functions.php'; // functions needed to run the webpage
include 'includes/header.php'; //* Header - contains opening body HTML tags, <head> section
?>
<?php
$directory = opendir('data');
while (($file = readdir($directory))) {
#Exlude '.' and '..' name of directory
if (!($file == '.' || $file == '..')){
#Check the extension of the file, exlude one with different then .txt
$fileExtension = pathinfo($file);
$fileExtension = $fileExtension['extension']; #Extract extension of the file
if (!($fileExtension == 'txt')) {
continue;
}
##
$lines = file('data/'.$file);
#Check if file is empty or it contains only whitespaces:
if((empty($lines) || ctype_space($lines[0]))){
echo '<p id="emptyFile"> Error - file: '.$file.' is empty or contains whitespaces only</p>';
continue;
}
echo '<div id="file">
<p> Module header data:</p><br>
<div class="data">
<p>File name: '. $file.'</p>';
#Print header data:
$header = printModuleHeaderData($lines[0]); #function returns multiple value in array
foreach ($header as $data) { #printing out data from the function
echo $data;
}
echo '</div>
<br><p>Student ID and marked data read from the file:</p><br>
<div class="data">';
$validStudents = array(); #Array will be updated in the function to print out only vailable students
$marksToAnalyse = array(); #Array will be updated in the function to pass to mmmr() function
$errorCount = 0; #Global variable updated in function to return how many errors of students data occured
#Print all student ID's and check if they are valid
for ($currentLine=1; $currentLine < count($lines) ; $currentLine++) {
echo is_valid_id_mark($lines[$currentLine]);
}
#echo '<p>Array count:'.$validStudents[1].'</p>';
#echo '<p>Array count:'.$marksToAnalyse[1].'</p>';
echo '</div>
<br><p>ID\'s and module marks to be included:</p><br>
<div class="data">';
foreach ($validStudents as $student) {
echo '<p>'.$student.'</p>';
}
echo '</div>
<br><p>Statistical Analysis of module marks:</p><br>
<div class="data">
<p>Mean: '.mmmr($marksToAnalyse).'</p>
<p>Mode: '.mmmr($marksToAnalyse, 'mode').'</p>
<p>Range: '.mmmr($marksToAnalyse, 'range').'</p>
<br>
<p># of students: '.count($marksToAnalyse).'</p>
</div>
<br><p>Grade Distribution of module marks:</p><br>
<div class="data">.'
.gradeDistribution($marksToAnalyse, $errorCount).'
</div>';
echo'</div>'; #closing tag for each file
}
}
closedir($directory);
?>
<?php
include 'includes/footer.php' // Footer - contains closing body HTML tags
?>