-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_used_ids_local.js
69 lines (58 loc) · 1.8 KB
/
load_used_ids_local.js
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
var used_ids = {};
var data = [];
String.prototype.trim_N = function()
{
return String(this).replace(/-N\d$/g, '');
};
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
var csv_format = new RegExp('([^\s]+(\\.csv)$)', 'i');
// files is a FileList of File objects. List some properties.
var output = [];
var omitted_files = [];
for (var i = 0, f; f = files[i]; i++) {
if (csv_format.test(f.name)){
let reader = new FileReader();
reader.fileName = f.name;
reader.onload = function() {
data.push(reader.result);
used_ids = convertCSVtoHash(reader.result, reader.fileName, used_ids);
}
reader.readAsText(f)
}else{
omitted_files.push(f.name)
console.log('Omitted: ' + f.name)
}
}
if(omitted_files.length > 0){
window.alert('Warning: Those non-CSV file(s) were ignored.\n\n' + omitted_files.join('\n'))
}
// for(let i=0; i<data.length;i++){
// used_ids = convertCSVtoHash(data[i], used_ids);
// }
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
function convertCSVtoHash(str, file_name, in_hash){
// console.log(file_name)
// var str = req.responseText;
var lines = str.split(/\r?\r?\n/);
// console.log(lines)
var sample_line = false;
for(var i=0; i<lines.length; i++){
tmp = lines[i];
if(tmp.startsWith('[Data]') || tmp.startsWith('[BCLConvert_Data]') ){
sample_line = true;
i++;
}else if(sample_line){
in_hash[tmp.split(',')[0].trim_N()] = file_name;
}
}
// console.log(result)
return in_hash
}
// function OnButtonClick2() {
// for(let i=0; i<data.length;i++){
// used_ids = convertCSVtoHash(data[i], used_ids);
// }
// }
const USED_IDS = used_ids