Public
Edited
Jan 16, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
// viewof file = Inputs.file()
Insert cell
// all = file.tsv()
Insert cell
// bMovies.map( d => {
// d.dw = all.filter( f=> f.tconst == d.imdb_id)
// return d
// })
Insert cell
// bMovies = FileAttachment("b-movies.json").json()
Insert cell
import {BMovies as bMovies} from "@hellonearthis/b-movies"
Insert cell
Insert cell
bmovies_with_writers = FileAttachment("untitled (7).json").json()
Insert cell
viewof file2 = Inputs.file()
Insert cell
url = file2.url()
Insert cell
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#processing_a_text_file_line_by_line

async function* makeTextFileLineIterator(fileURL) {
const utf8Decoder = new TextDecoder('utf-8');
const response = await fetch(fileURL);
const reader = response.body.getReader();
let { value: chunk, done: readerDone } = await reader.read();
chunk = chunk ? utf8Decoder.decode(chunk) : '';

const re = /\r\n|\n|\r/gm; // this regex was cr or lf or crlf, but that cause blank lines so I changed the order to crlf or cr or lf
let startIndex = 0;
let result;

while (true) {
let result = re.exec(chunk);
if (!result) {
if (readerDone) break;
let remainder = chunk.substr(startIndex);
({ value: chunk, done: readerDone } = await reader.read());
chunk = remainder + (chunk ? utf8Decoder.decode(chunk) : '');
startIndex = re.lastIndex = 0;
continue;
}
yield chunk.substring(startIndex, result.index);
startIndex = re.lastIndex;
}

if (startIndex < chunk.length) {
// console.log(`// Last line didn't end in a newline char`)
yield chunk.substr(startIndex);
}
}
Insert cell
{
let c = 0
for await (const line of makeTextFileLineIterator(url)) {
c++
// console.log ('line ', d3.tsvParse(line)) // process line
}
return c
}
Insert cell
Insert cell
WD = FileAttachment("writers_directors.csv").csv()
Insert cell
the_writers_directors = _.uniq(
_.flattenDeep(
WD.map( d => {
let dr = d.directors.split(',')
let wr = d.writers.split(',')
return [dr,wr]
})
)
)
Insert cell
Insert cell
who = FileAttachment("name_of_people.csv").csv()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more