function rec_transfer_import_results in Recommender API 6.3
Same name and namespace in other branches
- 7.4 rec_transfer/rec_transfer.module \rec_transfer_import_results()
- 7.5 rec_transfer/rec_transfer.module \rec_transfer_import_results()
1 call to rec_transfer_import_results()
- rec_transfer_download in rec_transfer/
rec_transfer.module
File
- rec_transfer/
rec_transfer.module, line 278 - This is the module file for Recommender Data Transfer
Code
function rec_transfer_import_results($what, $command_id, $recommender_id) {
$apikey = variable_get('rec_transfer_apikey', '');
if ($what == 'similarity') {
$table = '{recommender_similarity}';
$suffix = 'simi';
}
else {
if ($what == 'prediction') {
$table = '{recommender_prediction}';
$suffix = 'pred';
}
else {
assert(FALSE);
}
}
$download_file = "{$apikey}-{$command_id}.{$suffix}";
$save_file = variable_get('file_temporary_path', file_directory_temp()) . '/' . $download_file;
$download_success = rec_transfer_download_results($download_file, $save_file);
if ($download_success) {
// FIXME: if new data import fails, we'll need to re-import old data.
// also, perhaps need to think about incremental update. then we don't want to delete old data.
db_query("DELETE FROM {$table} WHERE app_id=%d", $recommender_id);
$fp = fopen($save_file, 'r');
while (($row = fgetcsv($fp)) !== FALSE) {
db_query("INSERT INTO {$table}(app_id, source_eid, target_eid, score, updated) VALUES(%d, %d, %d, %f, %d)", $recommender_id, $row[0], $row[1], $row[2], $row[3]);
}
fclose($fp);
return TRUE;
}
else {
return FALSE;
}
}