-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate5.2
More file actions
101 lines (80 loc) · 2.64 KB
/
template5.2
File metadata and controls
101 lines (80 loc) · 2.64 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
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
<div>
<table>
<tr>
<td>RANK</td>
<td>NAME</td>
<td>POPRANK</td>
</tr>
<?php
$positions = query("SELECT * FROM states WHERE 1");
$states = []; //states in alpha order
for ($i = 0; $i < 50; $i = $i + 1)
{
$states[$i] = $positions[$i]["name"];
}
/*
$mega = [];//array of "state" objects that have attributes: populationdev,areadev,tempdev
for ($i = 0; $i < 50; $i = $i + 1)
{
$mega[$states[$i]] = [
"populationdev" => abs($positions[$i]["population"] - $xpopulation),
"areadev" => abs($positions[$i]["area"] - $xarea),
"tempdev" => abs($positions[$i]["temp"] - $xtemp)
];
}
*/
$populationdev = []; //all the population devs
for ($i = 0; $i < 50; $i = $i + 1)
{
$populationdev[$i] = abs($positions[$i]["population"] - $xpopulation);
}
$populationstates = array();//state -> populationdev
for ($i = 0; $i < 50; $i = $i + 1)
{
$populationstates[$states[$i]] = $populationdev[$i];
}
asort($populationstates);//sorted by proximity to ideal
$pskeys = [];
$i = 1;
$psflipped = array_flip($populationstates);
foreach ($populationstates as $curr)
{
$pskeys[$i] = $psflipped[$curr];
$i = $i + 1;
}
$popranks = array_flip($pskeys);
//dump($popranks);
//POPRANKS is array: state -> rank
$areadev = [];
for ($i = 0; $i < 50; $i = $i + 1)
{
$areadev[$i] = abs($positions[$i]["area"] - $xarea);
}
$areastates = array();
for ($i = 0; $i < 50; $i = $i + 1)
{
$areastates[$states[$i]] = $areadev[$i];
}
asort($areastates);
$tempdev = [];
for ($i = 0; $i < 50; $i = $i + 1)
{
$tempdev[$i] = abs($positions[$i]["temp"] - $xtemp);
}
$tempstates = array();
for ($i = 0; $i < 50; $i = $i + 1)
{
$tempstates[$states[$i]] = $tempdev[$i];
}
asort($tempstates);
for($i = 1; $i < 51; $i = $i + 1)
{
print("<tr>");
print("<td>" . $i . "</td>");
print("<td>" . $pskeys[$i] . "</td>");
print("<td>" . $popranks[$pskeys[$i]] . "</td>");
print("</tr>");
}
?>
</table>
</div>