-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_table_content_generation_summary.php
237 lines (199 loc) · 9.2 KB
/
gen_table_content_generation_summary.php
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
229
230
231
232
233
234
235
236
237
<?php
# This script generates the table: "Table3.9 - Content Generation Summary"
# Usage: php gen_table_content_generation_summary.php > out_content_generation_summary
# This script generates a csv file which needs to be formatted into the final table: http://vox.hubzero.org/report/ncnreport/2013
# Set parameters between 'TODO-Begin' and 'TODO-End'
# ---------------------------------------------------------------------------------------------------------
require_once('/var/www/tmp/metrics_ncnreport/hub_parameters.php');
require_once('/opt/hubzero/bin/metrics/includes/db_connect.php');
require_once('/opt/hubzero/bin/metrics/includes/func_misc.php');
$db_hub = db_connect('db_hub');
$cumulative = 1;
# ---------------------------------------------------------------------------------------------------------
# TODO-Begin
## List of Resource Types used in this report
// Tools: 7
// Learning Modules: 4
// Online Presentations: 1
// Courses: 6
// Workshops: 2
// Animations: 5
// Publications: 3
// Downloads: 9
// Notes: 10
// Teaching Materials: 39
// Non-Interative Educational Material: ?
// Non Interactive documents: ?
$res_types = array(7,4,1,6,2,5,3,9,10,39);
## List of Tags used in this report
// Tutorials: 25
// Research Seminars: 27
// Serial Tools: 226
// Parallel Tools: 227
$res_tags = array(226,227,25,27);
# TODO-End
# ---------------------------------------------------------------------------------------------------------
print "\n,Pre-NCN,Year 1,Year 2,Year 3,Year 4,Year 5,Year 6,Year 7,Year 8, Year 9, Year 10, Year 11, Year 12, Year 13, Year 14, Year 15, Year 16, Year 17, Year 18, Last 12 Months, Year 19 (partial), Cummulative\n";
foreach($res_types as $type) {
$sql = 'SELECT type FROM nanohub.jos_resource_types where id='.$type;
$result = mysql_query($sql, $db_hub);
if($result) {
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_row($result)) {
$res_type=$row[0];
}
}
} else {
echo mysql_error($db_hub)." while executing ".$sql."\n";
die;
}
print "\n".$res_type."\n";
# Special Case used in 2007 report
// remove published=1 for punch tools
/*
if ($type == 7) {
$published = " AND res.published < 2 ";
} else {
$published = " AND res.published=1 ";
}*/
$published = " AND res.published=1 ";
# Total
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res WHERE res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND res.type="'.$type.'" ';
compute_years($db_hub, "Total", $statement,1);
print "\n";
# NCN Purdue
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid AND res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND objtags.tbl="resources" AND res.type="'.$type.'" ';
compute_years($db_hub, "NCN Purdue", $statement);
print "\n";
/*
# NCN Other
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid '.$published.' AND res.access!=1 AND res.access!=4 AND res.standalone=1 AND objtags.tbl="resources" AND res.type="'.$type.'" ';
compute_years($db_hub, "NCN Other", $statement);
print "\n";
*/
# Outside NCN
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid AND res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND objtags.tbl="resources" AND res.type="'.$type.'" ';
compute_years($db_hub, "Outside NCN", $statement);
print "\n";
}
// -------
// All "and more" Resources
print "\nTotal 'and more' Content\n";
# Special Case used in 2007 report
#$published = " AND res.published < 2 ";
$published = " AND res.published = 1 ";
# Total
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res WHERE res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND res.type <> 7';
compute_years($db_hub, "Total", $statement,1);
print "\n";
# NCN Purdue
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid AND res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND objtags.tbl="resources" AND res.type <> 7 ';
compute_years($db_hub, "NCN Purdue", $statement);
print "\n";
/*
# NCN Other
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid '.$published.' AND res.access!=1 AND res.access!=4 AND res.standalone=1 AND objtags.tbl="resources" AND res.type <> 7';
compute_years($db_hub, "NCN Other", $statement);
print "\n";
*/
# Outside NCN
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid AND res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND objtags.tbl="resources" AND res.type <> 7';
compute_years($db_hub, "Outside NCN", $statement);
print "\n\n";
// -------
// All Resources
print "Total Resources\n";
#$published = " AND res.published < 2 ";
$published = " AND res.published = 1 ";
# Total
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res WHERE res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1';
compute_years($db_hub, "Total", $statement,1);
print "\n";
# NCN Purdue
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid AND res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND objtags.tbl="resources" ';
compute_years($db_hub, "NCN Purdue", $statement);
print "\n";
/*
# NCN Other
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid '.$published.' AND res.access!=1 AND res.access!=4 AND res.standalone=1 AND objtags.tbl="resources" ';
compute_years($db_hub, "NCN Other", $statement);
print "\n";
*/
# Outside NCN
$statement = 'SELECT COUNT(DISTINCT(res.id)) FROM nanohub.jos_resources AS res, nanohub.jos_tags_object AS objtags WHERE res.id=objtags.objectid AND res.access!=1 AND res.access!=4 '.$published.' AND res.standalone=1 AND objtags.tbl="resources" ';
compute_years($db_hub, "Outside NCN", $statement);
print "\n\n";
db_close($db_hub);
// -------
function compute_years($db_hub, $label, $statement, $total=0){
global $cumulative, $report_db;
print $label.",";
$sql = 'SELECT period, startdate, enddate FROM '.$report_db.'.report_periods order by enddate ASC';
print "sql: ".$sql;
$result = mysql_query($sql, $db_hub);
if($result) {
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_row($result)) {
$period = $row[0];
$startdate = $row[1];
if ($cumulative)
$startdate = '2000-01-01';
$enddate = $row[2];
if (!$total) {
$tags = '';
$tags = get_ncn_participation($db_hub, $period, $label);
$sql_ = $statement.' AND res.publish_up > "'.$startdate.'" AND res.publish_up < "'.$enddate.'" AND objtags.tagid IN ('.$tags.')';
} else {
$sql_ = $statement.' AND res.publish_up > "'.$startdate.'" AND res.publish_up < "'.$enddate.'"';
}
$result_ = mysql_query($sql_, $db_hub);
if($result_) {
if(mysql_num_rows($result_) > 0) {
while($row_ = mysql_fetch_row($result_)) {
$items = $row_[0];
}
}
} else {
echo mysql_error($db_hub)." while executing ".$sql_."\n";
die;
}
if ($items) {
print $items.",";
} else {
print ",";
}
}
}
} else {
echo mysql_error($db_hub)." while executing ".$sql."\n";
die;
}
}
function get_ncn_participation ($db_hub, $period, $label) {
global $report_db;
$tag_list = '';
if ($label == "NCN Purdue") {
$sql = 'SELECT tagid FROM '.$report_db.'.report_ncn_tags WHERE report_tag IN (SELECT report_tag FROM '.$report_db.'.report_ncn_participation WHERE inside = 1 AND report_tag = "ncn_purdue" AND period = "'.$period.'")';
} else if ($label == "NCN Other") {
$sql = 'SELECT tagid FROM '.$report_db.'.report_ncn_tags WHERE report_tag IN (SELECT report_tag FROM '.$report_db.'.report_ncn_participation WHERE inside = 1 AND report_tag <> "ncn_purdue" AND period = "'.$period.'")';
} else if ($label == "Outside NCN") {
// $sql = 'SELECT tagid FROM '.$report_db.'.report_ncn_tags WHERE report_tag IN (SELECT report_tag FROM '.$report_db.'.report_ncn_participation WHERE report_tag <> "ncn_purdue" AND period = "'.$period.'")';
$sql = 'SELECT tagid FROM '.$report_db.'.report_ncn_tags WHERE report_tag IN (SELECT report_tag FROM '.$report_db.'.report_ncn_participation WHERE report_tag = "ncn_outside" AND period = "'.$period.'")';
} else {
return;
}
$result = mysql_query($sql, $db_hub);
if($result) {
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_row($result)) {
$tag_list .= $row[0].',';
}
}
} else {
echo mysql_error($db_hub)." while executing ".$sql."\n";
die;
}
$tag_list = rtrim($tag_list, ',');
return $tag_list;
}
?>