forked from human-divanshu/plug-n-play-cluster
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaggregate.php
43 lines (30 loc) · 768 Bytes
/
aggregate.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
<?php
function aggregate($job){
include_once("db.php");
$sql = "Select task_file_name from tasks where job_id =".$job;
$result = query($sql);
$dir = "processed_files/".$job;
$ans = array();
foreach($result as $task){
$addr = $dir."/".$task["task_file_name"];
$file = fopen($addr,"r");
while(!feof($file)){
$line = fgets($file);
$keyval = preg_split('/\s+/', $line);
if(sizeof($keyval) > 1)
if(array_key_exists($keyval[0],$ans)){
$ans[$keyval[0]] = $ans[$keyval[0]] + $keyval[1];
}
else{
$ans[$keyval[0]] = $keyval[1];
}
}
}
$path = "processed_files/".$job."/final.txt";
$file = fopen($path, "a");
foreach($ans as $key => $val){
fwrite($file, $key." ".$val."\n");
}
fclose($file);
}
?>