-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-scripts.php
More file actions
72 lines (61 loc) · 2.4 KB
/
build-scripts.php
File metadata and controls
72 lines (61 loc) · 2.4 KB
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
<?php
// Read in sitelist.csv and remove extra lines at the bottom and the header
$sites = file('sitelist.csv');
$l = count($sites);
for($i = 101; $i < $l; $i++) {
unset($sites[$i]);
}
unset($sites[0]);
$sites = array_values($sites);
$countries = array('USA' => 'US', 'Finland' => 'FI', 'Sweden' => 'SV', 'UK' => 'UK', 'Germany' => 'DE');
$industries = array('Mass media' => 'MED', 'Retail' => 'RET', 'Government' => 'GOV', 'Sports' => 'SPO');
// Explode each line and remove extra columns
$l = count($sites);
for($i = 0; $i < $l; $i++) {
$tmp = explode(',', $sites[$i]);
// unset($tmp[1]);
// unset($tmp[2]);
unset($tmp[3]);
unset($tmp[4]);
unset($tmp[5]);
unset($tmp[6]);
unset($tmp[9]);
unset($tmp[10]);
$sites[$i] = array_values($tmp);
}
// Create scripts
$scripts = array();
$check = array(array(), array(), array(), array(), array());
createScripts(1, $sites, array(0, 1, 2, 3, 4), $scripts, $check);
createScripts(2, $sites, array(1, 3, 0, 4, 2), $scripts, $check);
createScripts(3, $sites, array(2, 4, 3, 1, 0), $scripts, $check);
createScripts(4, $sites, array(3, 2, 4, 0, 1), $scripts, $check);
createScripts(5, $sites, array(4, 0, 1, 2, 3), $scripts, $check);
$checkUnique = array(array_unique($check[0]), array_unique($check[1]), array_unique($check[2]), array_unique($check[3]), array_unique($check[4]));
if(count($check[0]) != count($checkUnique[0]) ||
count($check[1]) != count($checkUnique[1]) ||
count($check[2]) != count($checkUnique[2]) ||
count($check[3]) != count($checkUnique[3]) ||
count($check[4]) != count($checkUnique[4])) {
echo "Error: not balanced scripts.\n";
}
echo "Scripts saved.\n";
foreach($scripts as $k => $v) {
$f = 'scripts/measure' . str_pad(($k + 1), 3, '0', STR_PAD_LEFT) . '.sh';
file_put_contents($f, $v);
chmod($f, 0755);
}
function createScripts($round, &$sites, $order, &$scripts, &$check) {
global $countries, $industries;
$l = count($sites);
for($i = 0; $i < $l / 5; $i++) {
$s = '';
for($j = 0; $j < 5; $j++) {
$cat = $countries[$sites[$i * 5 + $order[$j]][2]] . '-' .
$industries[$sites[$i * 5 + $order[$j]][1]];
$s .= './measure.sh ' . str_pad($i * 5 + $order[$j] + 1, 3, '0', STR_PAD_LEFT) . ' https://' . $sites[$i * 5 + $order[$j]][0] . ' ' . $round . ' ' . $cat . ' "' . $sites[$i * 5 + $order[$j]][3] . '" "' . $sites[$i * 5 + $order[$j]][4] . "\"\n";
array_push($check[$j], $sites[$i * 5 + $order[$j]][0]);
}
array_push($scripts, $s);
}
}