-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoclustering.install
228 lines (208 loc) · 6.87 KB
/
geoclustering.install
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
function geoclustering_schema()
{
/****************************************/
/***** *****/
/***** geoclustering_clusters table *****/
/***** *****/
/****************************************/
module_load_include('inc','geo','includes/geo.api');
$geo=geo_load(array('name' => 'geoclustering_clusters'));
$fields=array(
'cluster_id' => array(
'description' => 'Primary key; required by Views, ' .
'unnecessary for anything else',
'type' => 'serial',
'not null' => TRUE,
),
'params_hash' => array(
'description' => 'Hash of parameters of the tree where ' .
'this cluster belongs to',
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
),
'level' => array(
'description' => 'Level in a tree of clusters',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'size' => 'small',
),
'idx' => array(
'description' => 'Cluster idx, which (in combination with ' .
'level) identifies the geographical region ' .
'of the cluster',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'nr_of_nodes' => array(
'description' => 'Number of nodes in this cluster',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'min_nid' => array(
'description' => 'Minimum Node ID of nodes in this cluster',
'type' => 'int',
),
'summed_fields' => array(
'description' => 'Summed data fields from nodes ' .
'in this cluster',
'type' => 'text',
'not null' => TRUE,
),
);
if (method_exists($geo,'sqlFieldDefinition')) {
$fields=array_merge($fields,$geo->sqlFieldDefinition('coords'));
$fields['coords']['not null']=TRUE;
}
return array(
'geoclustering_clusters' => array(
'description' => 'Stores clusters for Geoclustering module',
'fields' => $fields,
'primary key' => array('cluster_id'),
'unique keys' => array('idx_index' =>
array('params_hash','level','idx')),
),
/*******************************************/
/***** *****/
/***** geoclustering_tree_params table *****/
/***** *****/
/*******************************************/
'geoclustering_tree_params' => array(
'description' => 'Stores settings for each clustering tree',
'export' => array(
'key' => 'name',
'default hook' => 'geoclustering_tree_params',
),
'fields' => array(
'name' => array(
'description' => 'Machine-readable unique tree name',
'type' => 'varchar', // MySQL forbids indexed TEXT fields
'length' => 64,
'not null' => TRUE,
),
'description' => array(
'description' => 'Human-readable description of the tree',
'type' => 'text',
),
'geofield_name' => array(
'description' => 'CCK field name that stores Node ' .
'coordinates for nodes that match node_conditions. ' .
'Geoclustering takes its input data from ' .
'these fields',
'type' => 'text',
'not null' => TRUE,
),
'maxlevel' => array(
'description' => 'Number of cluster tree levels ' .
'Geoclustering should build. Higher values ' .
'mean more detailed clusters, but need more ' .
'server horsepower. Default is 27 which means ' .
'ca 2x2km clusters in the bottom of tree; ' .
'increasing it by one halves the cluster area ' .
'(to 1.4x1.4km), decreasing by one ' .
'doubles the area (2.8x2.8km). Minimum is 0, ' .
'which means a single cluster covering ' .
'all Earth.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 27,
),
'node_conditions' => array(
'description' => 'PHP array of field_name => ' .
'required_value mappings that specify ' .
'requirements that a Node must meet in order ' .
'to be included in this cluster tree. ' .
'field_name can be a {node} table field ' .
"('type', 'status', ...) or a CCK field name " .
"(e.g. 'field_myfield'). Multiple requirements " .
"are ANDed. Example: array('type' => 'mytype', " .
"'status' => 1, 'field_placemark_type' => " .
"'school').",
'type' => 'text',
'serialize' => TRUE,
),
'summed_field_names' => array(
'description' => 'PHP array of CCK field names of ' .
'numeric fields of input nodes. These fields ' .
'are replicated from input nodes to ' .
'clusters, so that values for each cluster ' .
'are sums of values of its child nodes. ' .
'Cluster fields have same types as node ' .
'fields, thus for integer fields overflow ' .
'could happen. Example: ' .
"array('field_population', 'field_area').",
'type' => 'text',
'serialize' => TRUE,
),
),
'primary key' => array('name'),
),
/**********************************************/
/***** *****/
/***** geoclustering_uptodate_trees table *****/
/***** *****/
/**********************************************/
'geoclustering_uptodate_trees' => array(
'description' => "Stores params_hash'es for trees that are " .
"up to date in {geoclustering_clusters} table",
'fields' => array(
'params_hash' => array(
'description' => 'Hash of parameters of the tree',
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
),
),
'primary key' => array('params_hash'),
),
);
}
function geoclustering_install()
{
module_load_include('inc','geo','includes/geo.api');
$geo=geo_sql_load();
$geo->setTitle('geoclustering_clusters');
$geo->setName('geoclustering_clusters');
$geo->setSRID(4326);
$geo->setGeoType(GEO_TYPE_POINT);
$geo->setTableName('geoclustering_clusters');
$geo->setColumnName('coords');
geo_save($geo);
drupal_install_schema('geoclustering');
$geo->setIndexed(TRUE,TRUE);
}
function geoclustering_uninstall()
{
drupal_uninstall_schema('geoclustering');
module_load_include('inc','geo','includes/geo.api');
geo_delete(geo_load(array('name' => 'geoclustering_clusters')));
}
function geoclustering_requirements($phase)
{
$requirements=array();
if ($phase == 'runtime') {
$req=array('title' => t('Geoclustering dataset configured ' .
'in {geo} table'));
if (db_result(db_query("SELECT COUNT(*) from {geo} " .
"WHERE name='geoclustering_clusters'"))) {
$req['severity']=REQUIREMENT_OK;
$req['value']=t('Yes');
}
else {
$req['severity']=REQUIREMENT_ERROR;
$req['value']=t('No');
$req['description']=t("Geo dataset %name does " .
"exist in {geo} table. To fix this, you can try " .
"disabling and then re-enabling Geoclustering module.",
array('%name' => 'geoclustering_clusters'));
}
$requirements['geoclustering_geo']=$req;
}
return $requirements;
}
?>