-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse3.php
More file actions
318 lines (284 loc) · 10.4 KB
/
parse3.php
File metadata and controls
318 lines (284 loc) · 10.4 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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
use League\Csv\Reader;
use League\Csv\Writer;
use PragmaRX\Countries\Package\Countries;
include_once 'inc/func.php';
// Settings
$machineName = 'ifcs20';
$resultsDir = 'results/' . $machineName . '/';
$csvFile = 'src/ifcs20.csv';
$numOfAuthorColumns = 10;
// load the CSV document from a file path
$csv = Reader::createFromPath($csvFile, 'r');
$csv->setHeaderOffset(0);
$header = $csv->getHeader(); // returns the CSV header record
$records = $csv->getRecords(); // returns all the CSV records as an Iterator object
// Write Results dir
if(is_dir($resultsDir)) {
echo 'Results dir exists...' . PHP_EOL;
} else {
mkdir($resultsDir);
}
/**
* Contacts
*/
// @TODO: unknown@mail.com
$contacts = [];
//$countries = new Countries();
foreach($records as $offset => $record) {
for($i = 1; $i <= $numOfAuthorColumns; $i++) {
if($record['Email' . $i] != '') {
$contacts[] = array(
'id' => $record['Paper ID'] . $i,
'title' => $record['First Name' . $i] . ' ' . $record['Last Name' . $i],
'first' => $record['First Name' . $i],
'last' => $record['Last Name' . $i],
'email' => $record['Email' . $i],
'photo' => '',
'position' => '',
'affiliation' => $record['Contact Organization'],
'country code' => '',
'bio' => '',
'paperid' => $record['Paper ID'],
'type' => 'author',
);
}
}
// Chairs
for($i = 1; $i <= 2; $i++) {
if($record['Session Chair Last' . $i] != '') {
$contacts[] = array(
'id' => $record['Paper ID'] . '00' . $i,
'title' => $record['Session Chair First' . $i] . ' ' . $record['Session Chair Last' . $i],
'first' => $record['Session Chair First' . $i],
'last' => $record['Session Chair Last' . $i],
'email' => '',
'photo' => '',
'position' => '',
'affiliation' => $record['Session Chair Organization' . $i],
'country code' => '',
'bio' => '',
'paperid' => $record['Paper ID'],
'type' => 'chair'
);
}
}
}
// Fix unknown@mail.com email addresses
foreach($contacts as $contactKey => $contact) {
if($contact['email'] == 'unknown@mail.com') {
$uniqueContactPattern = _clean($contact['first'] . $contact['last'] . $contact['affiliation']);
// echo $uniqueContactPattern . PHP_EOL;
foreach($contacts as $contactCheck) {
$uniqueContactPatternCheck = _clean($contactCheck['first'] . $contactCheck['last'] . $contactCheck['affiliation']);
// echo $uniqueContactPatternCheck . PHP_EOL;
if($uniqueContactPattern == $uniqueContactPatternCheck && $contactCheck['email'] != 'unknown@mail.com' && $contactCheck['email'] != '') {
$contacts[$contactKey]['email'] = $contactCheck['email'];
}
}
}
}
// Write Full Contacts List
$resultsFile = $resultsDir . 'contactsFull.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile, 'w'); // file
$csvWriter->insertOne(['id','presid','first','last','email','photo','position','affiliation','country code','bio','paperid','type']); // header
$csvWriter->insertAll($contacts); // rows
// Reduce to Unique Contacts
$uniqueArray = [];
$patterns = [];
$disposedContacts = [];
//foreach($contacts as $contactKey => $contact) {
// $uniqueChairContactPattern = $contact['first'] . $contact['last'] . $contact['affiliation'];
// if(!in_array($uniqueChairContactPattern, $disposed)) {
// $disposed[$contacts[$contactKey]['id']] = array(
// 'id' => $contact['id']
// );
// $contactsUnique[] = $contact;
// } else {
// // add to disposed list
// $disposed[][] = $contact['id'];
// }
//}
$uniqueContacts = array_filter($contacts, function($contact) use (&$patterns, &$disposedContacts) {
$uniqueChairContactPattern = _clean($contact['first'] . $contact['last'] . $contact['affiliation']);
if (in_array($uniqueChairContactPattern, array_values($patterns))) {
// @TODO: Add multiple paper ids together
// print $contact['email'] . ' skipped' . PHP_EOL;
// Anytime a duplicate email is found, add it to the removed ids array
$disposedContacts[$uniqueChairContactPattern]['removed_ids'][] = $contact['id'];
return false;
} else {
// print $contact['email'] . ' added to array' . PHP_EOL;
$disposedContacts[$uniqueChairContactPattern] = ['unique_id' => $contact['id']];
$patterns[] = $uniqueChairContactPattern;
return true;
}
});
// Write disposed contacts
file_put_contents('results/' . $machineName . '/disposedContacts.json', json_encode($disposedContacts, JSON_PRETTY_PRINT));
// Write Reduced Contacts
$resultsFile = $resultsDir . 'contacts.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile); // file
$csvWriter->insertOne(['id','title','first','last','email','photo','position','affiliation','country code','bio','paperid','type']); // header
$csvWriter->insertAll($uniqueContacts); // rows
/**
* Tracks, Types, Rooms
*/
$tracks = [];
$types = [];
$rooms = [];
foreach($records as $record) {
// Tracks
if(!in_array($record['Track ID'] * 10, array_column($tracks, 'id'))) {
// Tracks get + 10 added to them to avoid decimals (hard eye roll)
$tracks[] = array(
'id' => $record['Track ID'] * 10,
'name' => $record['Track Name']
);
}
// Types
if(!in_array($record['Decision Type'], array_column($types, 'name'))) {
$types[] = array(
'id' => $record['Paper ID'],
'name' => $record['Decision Type']
);
}
}
// Write Tracks
$resultsFile = $resultsDir . 'tracks.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile, 'w');
$csvWriter->insertOne(['id','name']); // header
$csvWriter->insertAll($tracks); // rows
// Write Types
$resultsFile = $resultsDir . 'types.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile, 'w');
$csvWriter->insertOne(['id','name']); // header
$csvWriter->insertAll($types); // rows
/**
* Papers, Presentations
*/
$papers = [];
$presentations = [];
foreach($records as $record) {
// Accepted Only
if ($record['Decision'] == 'Accept') {
// Papers
$papers[] = [
'id' => $record['Paper ID'],
'title' => $record['Paper Title'],
'local file' => '',
'remote file' => '',
'link' => '',
'author ids' => '',
];
// Presentations
$presentations[] = [
'id' => $record['Paper ID'],
'title' => $record['Paper Title'],
'code' => '',
'date' => '',
'time range from' => '',
'time range to' => '',
'abstract' => $record['Abstract'],
'description' => '',
'speaker ids' => '',
'chair ids' => '',
'video embed' => '',
'paper ids' => $record['Paper ID'],
'topic ids' => '',
'type id' => _idLookup($record['Decision Type'], $types, 'name'),
'track id' => '',
'room id' => '',
'roles' => 'Attendee',
'poccontactid' => _idLookup($record['Contact Email'], $contacts, 'email'),
];
}
}
// Add Contacts to Presentations
// NOTE: This should come from Submission Webform
//foreach($presentations as $presKey => $presentation) {
// foreach($contacts as $contactKey => $contact) {
// if($presentation['id'] == $contact['paper ids']) {
// $presentations[$presKey]['speaker ids'] = $presentations[$presKey]['speaker ids'] . $contact['id'] . '||';
// }
// }
//}
// Write Presentations
$resultsFile = $resultsDir . 'presentations.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile, 'w');
$csvWriter->insertOne(['id','title','code','date','time range from','time range to','abstract','description','speaker ids','chair ids','video embed','paper ids','topic ids','type id','track id','room id','roles','poccontactid','speaker ids new']); // header
$csvWriter->insertAll($presentations); // rows
// Add Contacts to Papers
foreach($papers as $paperKey => $paper) {
foreach($contacts as $contactKey => $contact) {
if($paper['id'] == $contact['paperid']) {
if($papers[$paperKey]['author ids'] == '') {
$papers[$paperKey]['author ids'] = $contact['id'];
} else {
$papers[$paperKey]['author ids'] = $papers[$paperKey]['author ids'] . '||' . $contact['id'];
}
}
}
}
// Write Papers
$resultsFile = $resultsDir . 'papers.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile, 'w');
$csvWriter->insertOne(['id', 'title','local file','remote file','link','author ids']); // header
$csvWriter->insertAll($papers); // rows
/**
* Sessions
*/
$sessions = [];
foreach($records as $key => $record) {
// Accepted Only
if($record['Decision'] == 'Accept') {
// Sessions
if(!in_array($record['Session Name'], array_column($sessions, 'title'))) {
$sessions[$record['Session Name']] = array(
'id' => $record['Paper ID'],
'title' => $record['Session Name'],
'code' => $record['Session Code'],
'description' => '',
'length' => '',
'pres ids' => $record['Paper ID'],
'chair ids' =>
($record['Session Chair Last1'] != '' ? _idLookup($record['Session Chair Last1'], $contacts, 'last') : '') .
($record['Session Chair Last2'] != '' ? '||' . _idLookup($record['Session Chair Last2'], $contacts, 'last') : ''),
'organizer ids' => '',
'date' => date('Y-m-d', strtotime($record['Session Start Time'])),
'time range from' => date('n/j/Y G:i:s', strtotime($record['Session Start Time'])),
'time range to' => date('n/j/Y G:i:s', strtotime($record['Session End Time'])),
'type' => $record['Session Type'],
'track id' => $record['Track ID'] * 10,
'room id' => '',
);
} else {
$sessions[$record['Session Name']]['pres ids'] = $sessions[$record['Session Name']]['pres ids'] . '||' . $record['Paper ID'];
}
}
}
// Write Sessions
$resultsFile = $resultsDir . 'sessions.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile,'w');
$csvWriter->insertOne(['id','title','code','description','length','pres ids','chairs','organizer ids','date','time range from','time range to','type','track id','room id']); // header
$csvWriter->insertAll($sessions); // rows
/**
* Submission System
*/
// Write Submission Links
$resultsFile = $resultsDir . 'submission-links.csv';
fopen($resultsFile, 'w');
$csvWriter = Writer::createFromPath($resultsFile,'w');
$csvWriter->insertOne(['id','title','code']); // header
$csvWriter->insertAll($sessions); // rows