Created
December 4, 2017 22:55
-
-
Save herpiko/c2ac0e96c93bf15fe16b655d414ec7fb to your computer and use it in GitHub Desktop.
cingicanga-npwp-match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Usage : use Node 8.x, pipe the output to empty csv file. | |
| var fs = require('fs'); | |
| var async = require('async'); | |
| var byline = require('byline'); | |
| var stringSimilarity = require('string-similarity'); | |
| var sqlite3 = require('sqlite3').verbose(); | |
| var db = new sqlite3.Database('data.db'); | |
| var stream = fs.createReadStream('A2914.csv'); | |
| db.serialize(function() { | |
| stream = byline.createStream(stream); | |
| stream.on('data', function(line){ | |
| var date = line.toString().split(';')[1]; | |
| var name = line.toString().split(';')[2]; | |
| var q = 'select * from MF where birth_date=\'' + date + '\';'; | |
| //console.log(line.toString()); | |
| //console.log(date); | |
| //console.log(q); | |
| db.all(q, function(err, rows) { | |
| if (rows.length < 1) { | |
| console.log(line.toString() + ';-;-;-'); | |
| return; | |
| } | |
| var bestMatchScore = 0; | |
| var bestMatch = ""; | |
| var bestMatchNPWP = ""; | |
| async.eachSeries(rows, function(row, cb){ | |
| //console.log(row.name); | |
| var score = stringSimilarity.compareTwoStrings(name, row.name); | |
| if (bestMatchScore < score) { | |
| bestMatchScore = score; | |
| bestMatch = row.name; | |
| bestMatchNPWP = row.id; | |
| } | |
| cb(); | |
| }, function(){ | |
| console.log(line.toString() + ';' + bestMatch + ';' + bestMatchScore + ';' + bestMatchNPWP); | |
| }) | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "cingicanga-npwp-match", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "async": "^2.6.0", | |
| "byline": "^5.0.0", | |
| "csv2sql-lite": "0.0.6", | |
| "sqlite3": "^3.1.13", | |
| "string-similarity": "^1.2.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment