-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate5.3
More file actions
118 lines (92 loc) · 2.99 KB
/
template5.3
File metadata and controls
118 lines (92 loc) · 2.99 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<div>
<table>
<tr>
<td>RANK</td>
<td>NAME</td>
<td>POPRANK</td>
<td>AREARANK</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;
$popranks = [];
foreach ($populationstates as $pkey => $pval)
{
$popranks[$pkey] = $i;
$i = $i + 1;
}
//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);
$askeys = [];
$j = 1;
$arearanks = [];
foreach ($areastates as $akey => $aval)
{
$arearanks[$akey] = $j;
$j = $j + 1;
}
$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);
$finalrankdev = [];
for ($i = 0; $i < 50; $i = $i + 1)
{
$finalranks = [] //state -> final rank
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("<td>" . $arearanks[$pskeys[$i]] . "</td");
print("</tr>");
}
?>
</table>
</div>