Skip to content

Commit

Permalink
Added maintenance scripts for cache databases.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan.ramseyer committed Dec 12, 2018
1 parent cf38aae commit 1c01279
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 0 deletions.
81 changes: 81 additions & 0 deletions glm_cells-cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const sqlite3 = require('sqlite3');
const path = require('path');
const util = require('util');
const ociDb = new sqlite3.Database(path.join(__dirname, 'oci_cells.sqlite'), sqlite3.OPEN_READONLY);
const mlsDb = new sqlite3.Database(path.join(__dirname, 'mls_cells.sqlite'), sqlite3.OPEN_READONLY);
const glmDb = new sqlite3.Database(path.join(__dirname, 'glm_cells.sqlite'), sqlite3.OPEN_READWRITE);

var numProcessedEntries = 0;

glmDb.each("SELECT mcc, mnc, lac, cellid FROM cells", function(err, glmRow) {
if (err) {
console.error('Error querying Google GLM MMAP cache database');
return;
} else {
numProcessedEntries++;
ociDb.get('SELECT lat, lon, range FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: glmRow.mcc,
2: glmRow.mnc,
3: glmRow.lac,
4: glmRow.cellid
}, function(err, row) {
if (err) {
console.error('Error querying OpenCellId database');
return;
}

if (typeof row != 'undefined') {
glmDb.run('DELETE FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: glmRow.mcc,
2: glmRow.mnc,
3: glmRow.lac,
4: glmRow.cellid
}, function(err) {
if (err) {
console.error('Error removing entry in Google GLM MMAP cache database');
return;
} else {
console.log(util.format('Removed %d %d %d %d because already in OpenCellId database', glmRow.mcc, glmRow.mnc, glmRow.lac, glmRow.cellid));
return;
}
});
} else {
mlsDb.get('SELECT lat, lon, range FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: glmRow.mcc,
2: glmRow.mnc,
3: glmRow.lac,
4: glmRow.cellid
}, function(err, row) {
if (err) {
console.error('Error querying Mozilla Location Service database');
return;
}

if (typeof row != 'undefined') {
glmDb.run('DELETE FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: glmRow.mcc,
2: glmRow.mnc,
3: glmRow.lac,
4: glmRow.cellid
}, function(err) {
if (err) {
console.error('Error removing entry in Google GLM MMAP cache database');
return;
} else {
console.log(util.format('Removed %d %d %d %d because already in Mozilla Location Service database', glmRow.mcc, glmRow.mnc, glmRow.lac, glmRow.cellid));
return;
}
});
}
});
}
});
}
});

process.on('exit', function() {
ociDb.close();
mlsDb.close();
glmDb.close();
console.log(util.format('Processed entries: %d', numProcessedEntries));
});
132 changes: 132 additions & 0 deletions uwl_cells_cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
const sqlite3 = require('sqlite3');
const path = require('path');
const util = require('util');
const request = require(path.join(__dirname,'./request.js'));
const ociDb = new sqlite3.Database(path.join(__dirname, 'oci_cells.sqlite'), sqlite3.OPEN_READONLY);
const mlsDb = new sqlite3.Database(path.join(__dirname, 'mls_cells.sqlite'), sqlite3.OPEN_READONLY);
const glmDb = new sqlite3.Database(path.join(__dirname, 'glm_cells.sqlite'), sqlite3.OPEN_READONLY);
const uwlDb = new sqlite3.Database(path.join(__dirname, 'uwl_cells.sqlite'), sqlite3.OPEN_READWRITE);

var numProcessedEntries = 0;

uwlDb.each("SELECT mcc, mnc, lac, cellid FROM cells", function(err, uwlRow) {
if (err) {
console.error('Error querying OpenCellId cache database');
return;
} else {
numProcessedEntries++;
ociDb.get('SELECT lat, lon, range FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: uwlRow.mcc,
2: uwlRow.mnc,
3: uwlRow.lac,
4: uwlRow.cellid
}, function(err, row) {
if (err) {
console.error('Error querying OpenCellId database');
return;
}

if (typeof row != 'undefined') {
uwlDb.run('DELETE FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: uwlRow.mcc,
2: uwlRow.mnc,
3: uwlRow.lac,
4: uwlRow.cellid
}, function(err) {
if (err) {
console.error('Error removing entry in OpenCellId cache database');
return;
} else {
console.log(util.format('Removed %d %d %d %d because already in OpenCellId database', uwlRow.mcc, uwlRow.mnc, uwlRow.lac, uwlRow.cellid));
return;
}
});
} else {
mlsDb.get('SELECT lat, lon, range FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: uwlRow.mcc,
2: uwlRow.mnc,
3: uwlRow.lac,
4: uwlRow.cellid
}, function(err, row) {
if (err) {
console.error('Error querying Mozilla Location Service database');
return;
}

if (typeof row != 'undefined') {
uwlDb.run('DELETE FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: uwlRow.mcc,
2: uwlRow.mnc,
3: uwlRow.lac,
4: uwlRow.cellid
}, function(err) {
if (err) {
console.error('Error removing entry in OpenCellId cache database');
return;
} else {
console.log(util.format('Removed %d %d %d %d because already in Mozilla Location Service database', uwlRow.mcc, uwlRow.mnc, uwlRow.lac, uwlRow.cellid));
return;
}
});
} else {
glmDb.get('SELECT lat, lon, range FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: uwlRow.mcc,
2: uwlRow.mnc,
3: uwlRow.lac,
4: uwlRow.cellid
}, function(err, row) {
if (err) {
console.error('Error querying Google GLM MMAP database');
return;
}

if (typeof row != 'undefined') {
console.log(util.format('Entry %d %d %d %d already in Google GLM MMAP cache database', uwlRow.mcc, uwlRow.mnc, uwlRow.lac, uwlRow.cellid));
uwlDb.run('DELETE FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: uwlRow.mcc,
2: uwlRow.mnc,
3: uwlRow.lac,
4: uwlRow.cellid
}, function(err) {
if (err) {
console.error('Error removing entry in OpenCellId cache database');
return;
} else {
console.log(util.format('Removed %d %d %d %d because already in Google GLM MMAP cache database', uwlRow.mcc, uwlRow.mnc, uwlRow.lac, uwlRow.cellid));
return;
}
});
} else {
request.glm(uwlRow.mcc,uwlRow.mnc,uwlRow.lac,uwlRow.cellid).then(coords => {
uwlDb.run('DELETE FROM cells WHERE mcc = ? AND mnc = ? AND lac = ? AND cellid = ?', {
1: uwlRow.mcc,
2: uwlRow.mnc,
3: uwlRow.lac,
4: uwlRow.cellid
}, function(err) {
if (err) {
console.error('Error removing entry in OpenCellId cache database');
return;
} else {
console.log(util.format('Removed %d %d %d %d because already in Google GLM MMAP online service', uwlRow.mcc, uwlRow.mnc, uwlRow.lac, uwlRow.cellid));
return;
}
});
}).catch(err => {
});
}
});
}
});
}
});
}
});

process.on('exit', function() {
ociDb.close();
mlsDb.close();
glmDb.close();
uwlDb.close();
console.log(util.format('Processed entries: %d', numProcessedEntries));
});

0 comments on commit 1c01279

Please sign in to comment.