ingests to lmdb
parent
b5d6662b66
commit
34ff197320
@ -0,0 +1,2 @@
|
|||||||
|
*.lmdb
|
||||||
|
*.lmdb-lock
|
@ -1,16 +1,80 @@
|
|||||||
import { open } from 'npm:lmdb';
|
import { open } from 'npm:lmdb';
|
||||||
import { CsvParseStream } from 'https://deno.land/std@0.184.0/csv/mod.ts';
|
import { CsvParseStream } from 'https://deno.land/std@0.184.0/csv/mod.ts';
|
||||||
|
|
||||||
const fileStream = (await Deno.open('/home/brian/Downloads/options-data/2013-01-02options.cvs', {read: true})).readable;
|
const db = open({
|
||||||
const csvParseStream = new CsvParseStream({skipFirstRow: true});
|
path: 'options.lmdb',
|
||||||
|
compression: false,
|
||||||
|
encoding: 'msgpack',
|
||||||
|
sharedStructuresKey: Symbol.for('structures')
|
||||||
|
});
|
||||||
|
interface Row {
|
||||||
|
contract: string,
|
||||||
|
underlying: string,
|
||||||
|
expiration: string,
|
||||||
|
type: string,
|
||||||
|
strike: string,
|
||||||
|
style: string,
|
||||||
|
bid: string,
|
||||||
|
bid_size: string,
|
||||||
|
ask: string,
|
||||||
|
ask_size: string,
|
||||||
|
volume: string,
|
||||||
|
open_interest: string,
|
||||||
|
quote_date: string,
|
||||||
|
delta: string,
|
||||||
|
gamma: string,
|
||||||
|
theta: string,
|
||||||
|
vega: string,
|
||||||
|
implied_volatility: string,
|
||||||
|
};
|
||||||
|
|
||||||
const rowStream = fileStream
|
async function getCsvRowStream(){
|
||||||
.pipeThrough(new TextDecoderStream())
|
const fileStream = (await Deno.open('/home/brian/Downloads/options-data/2013-01-02options.cvs', {read: true})).readable;
|
||||||
.pipeThrough(csvParseStream)
|
const csvParseStream = new CsvParseStream({skipFirstRow: true});
|
||||||
;
|
|
||||||
const rowReader = rowStream.getReader();
|
|
||||||
|
|
||||||
|
const rowStream = fileStream
|
||||||
|
.pipeThrough(new TextDecoderStream())
|
||||||
|
.pipeThrough(csvParseStream)
|
||||||
|
;
|
||||||
|
return rowStream;
|
||||||
|
}
|
||||||
|
|
||||||
for(let i = 0; i<20; i++){
|
async function ingestCsvToLmdb(){
|
||||||
console.log(await rowReader.read());
|
const rowStream = await getCsvRowStream();
|
||||||
}
|
const rowReader = rowStream.getReader();
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
const row = (await rowReader.read()).value as unknown as Row;
|
||||||
|
if(typeof row !== 'undefined'){
|
||||||
|
db.put([row.underlying, row.quote_date, row.expiration, row.strike, row.type], row);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function countRowsInCsv(){
|
||||||
|
const rowStream = await getCsvRowStream();
|
||||||
|
const rowReader = rowStream.getReader();
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
while(true){
|
||||||
|
const row = await rowReader.read();
|
||||||
|
if(typeof row !== 'undefined' && typeof row.value !== 'undefined'){
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countRowsInLmdb(){
|
||||||
|
return db.getKeysCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log('rows-in-csv:', await countRowsInCsv());
|
||||||
|
//console.log('rows-in-lmdb:', countRowsInLmdb());
|
||||||
|
await ingestCsvToLmdb();
|
Loading…
Reference in New Issue