Yahoo Maps are a bit rubbish, so I looked for a way to easily pull together a map I don't dislike using.
The map's here; the original data's here; and the Yahoo pipe between is here.
This map is a handy reference to the Victorian state government's public register of convictions for food safety offences. It's also a nice example of how cloud services can be integrated and mixed, and matched - Yahoo does provide a map interface to this data, but their maps are terrible.
View Larger Map
The bits of the IT world that apply to me right now. Blogged in the hope that someone (even me) will find them useful.
Showing posts with label parser. Show all posts
Showing posts with label parser. Show all posts
Tuesday, July 02, 2013
Monday, October 17, 2011
CSV parser in JavaScript
I wanted a JavaScript based CSV parser. I couldn't find a good one (that would allow multi-character delimiters, and text qualifiers), so I wrote it. The textToArray function should run under any js implementation; but the demonstration of it is written for a ringojs environment.
Call textToArray with a line of delimited text, and the delimiter and text qualifier you're expecting to find; it will give back an array of the elements it finds.
Call textToArray with a line of delimited text, and the delimiter and text qualifier you're expecting to find; it will give back an array of the elements it finds.
var textToArray = function (txtLine, del, txtQual) {
"use strict";
var datArr = [], newStr = "";
while (txtLine.length > 0) {
if (txtLine.substr(0, txtQual.length) === txtQual) {
// get quoted block
newStr = txtLine.substr(0, txtQual.length + txtLine.indexOf(txtQual, txtQual.length));
datArr.push(newStr.substr(txtQual.length, newStr.length - txtQual.length * 2));
}
else {
// get data block
if (txtLine.indexOf(del) !== -1) {
newStr = txtLine.substr(0, txtLine.indexOf(del));
} else {
newStr = txtLine;
}
datArr.push(newStr);
}
txtLine = txtLine.substr(newStr.length + del.length, txtLine.length);
}
return datArr;
};
var fs = require('fs');
var con = require('console');
var del = ";;";
var txtQual = "\"\""; // a pair of quotes.
var file = fs.open('D:/ringojs-0.8/test.txt');
var line = "";
for (line in file) {
con.log(textToArray(line, del, txtQual).join("---"));
}
Subscribe to:
Posts (Atom)