-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtr.install
215 lines (208 loc) · 7.27 KB
/
qtr.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
<?php
/**
* @file
* qtr instll
*
*/
function qtr_schema() {
$schema['qtr_item_types'] = array(
'description' => 'Stores the list of available items for computing QTR',
'fields' => array(
'item_type' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'description' => 'Alphanumeric id for a QTR type',
),
'reference_table' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'description' => 'The reference table for the item type, E.g. node or comments',
),
'description' => array(
'type' => 'varchar',
'length' => 256,
'description' => 'The description of the QTR action',
),
),
'primary key' => array('item_type'),
);
$schema['qtr_action_types'] = array(
'description' => 'Stores the list of available actions for computing QTR',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'primary identifier',
),
'action' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'description' => 'Alphanumeric id for a QTR action',
),
'weight' => array(
'type' => 'float',
'unsigned' => FALSE,
'not null' => TRUE,
'description' => 'QTR weight of this action',
),
'description' => array(
'type' => 'varchar',
'length' => 256,
'description' => 'The description of the QTR action',
),
),
'primary key' => array('id'),
);
$schema['qtr_actions'] = array(
'description' => 'Stores information of users interaction with items (e.g. news)',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'primary identifier',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The user id from the users table',
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The item id from the table referenced in the qtr_item_types table',
),
'action_type' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The action type id from the qtr_actions table',
),
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'The time at which the action took place',
),
),
'primary key' => array('id'),
'foreign keys' => array(
'qtr_actions_user_fkey' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'qtr_actions_action_type_fkey' => array(
'table' => 'qtr_action_types',
'columns' => array('action_type' => 'id'),
),
),
'indexes' => array(
'qtr_user' => array('uid'),
'qtr_action_type' => array('action_type'),
'qtr_time' => array('timestamp'),
),
);
$schema['qtr_reputation'] = array(
'description' => 'Stores the average QTR REPUTATION for a user ',
'fields' => array(
'uid' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'description' => 'Alphanumeric id for a QTR action',
),
'reputation' => array(
'type' => 'float',
'not null' => TRUE,
'description' => 'The description of the QTR action',
),
'rank' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The reputation of the user',
),
'percentile' => array(
'type' => 'float',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The percentile of the user',
),
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'The time at which the QTR is calculated',
),
),
'primary key' => array('uid', 'timestamp'),
);
$schema['qtr_quality'] = array(
'description' => 'Stores the results of the computation of the QTR',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The item id from the table referenced in the qtr_item_types table',
),
'quality' => array(
'type' => 'float',
'not null' => TRUE,
'description' => 'The QTR QUALITY of an item',
),
),
'primary key' => array('nid'),
'indexes' => array(
'qtr_quality' => array('quality'),
),
);
$schema['qtr_trust'] = array(
'description' => 'Stores the results of the computation of the QTR',
'fields' => array(
'uid1' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The user id from the users table',
),
'uid2' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The user id from the users table',
),
'trust' => array(
'type' => 'float',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The value for the QTR TRUST of user1 towards user2',
),
),
'primary key' => array('uid1', 'uid2'),
);
return $schema;
}
function qtr_install() {
qtr_add_actiontype('vote', 1);
qtr_add_actiontype('download', 0.1);
qtr_add_actiontype('view', 0.05);
$query = db_select('votingapi_vote', 'q');
$results = $query->fields('q')->execute()->fetchAll();
if ($results) {
foreach ($results as $result) {
if ($result->tag == 'plus1_node_vote' && $result->value>0)
db_insert('qtr_actions')->fields(array('uid' => $result->uid, 'nid' => $result->entity_id, 'action_type' => 1, 'timestamp' => $result->timestamp))->execute();
}
}
$result = array();
foreach (node_type_get_types() as $type => $type_obj) {
$result[] = array('item_type' => $type);
variable_set('popular_block_' . $type, $type);
}
qtr_update_itemtype($result);
}