200 lines
5.7 KiB
JavaScript
200 lines
5.7 KiB
JavaScript
import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm';
|
|
|
|
|
|
//import * as arrow from 'https://cdn.skypack.dev/apache-arrow@9'
|
|
|
|
|
|
var rif_commentatori = [];
|
|
var rif_autori = [];
|
|
var rif_areetematiche = [];
|
|
var rif_fonti = [];
|
|
var listaidversi = []
|
|
const cantobadgeclassBis = 'badge badge-outline-warning badge-pill'
|
|
|
|
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
|
|
|
|
// Select a bundle based on browser checks
|
|
const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);
|
|
|
|
const worker_url = URL.createObjectURL(
|
|
new Blob([`importScripts("${bundle.mainWorker}");`], { type: 'text/javascript' })
|
|
);
|
|
|
|
// Instantiate the asynchronus version of DuckDB-wasm
|
|
const worker = new Worker(worker_url);
|
|
const logger = new duckdb.ConsoleLogger();
|
|
const db = new duckdb.AsyncDuckDB(logger, worker);
|
|
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
|
|
URL.revokeObjectURL(worker_url);
|
|
|
|
console.log('datamgr init done')
|
|
|
|
|
|
//await db.registerFileURL('remote.parquet', 'http://localhost:8000/js/data/riferimenti_3.parquet', DuckDBDataProtocol.HTTP, false);
|
|
|
|
/*const res = await fetch('http://localhost:8000/js/data/riferimenti_3.parquet');
|
|
|
|
await db.registerFileBuffer('buffer.parquet', new Uint8Array(await res.arrayBuffer()));*/
|
|
|
|
const conn = await db.connect();
|
|
|
|
await conn.query(`
|
|
CREATE TABLE riferimenti AS
|
|
SELECT * FROM "https://lida.dantenetwork.it/js/data/riferimenti_3.parquet";
|
|
`);
|
|
|
|
var table = await conn.query(`
|
|
select distinct Aut from riferimenti order by Aut COLLATE NOCASE;
|
|
`);
|
|
const result = table.toArray().map((row) => row.toJSON());
|
|
rif_autori = result.map((x) => x['Aut']);
|
|
//console.log(rif_autori)
|
|
|
|
|
|
var table = await conn.query(`
|
|
select distinct Com from riferimenti;
|
|
`);
|
|
const result2 = table.toArray().map((row) => row.toJSON());
|
|
rif_commentatori = result2.map((x) => x['Com']);
|
|
|
|
|
|
|
|
/*rif_commentatori.sort((a, b) => {
|
|
var sre= (a.replace(/^\D+/g, '')-b.replace(/^\D+/g, ''))
|
|
console.log(sre)
|
|
return sre
|
|
})*/
|
|
//console.log(rif_commentatori)
|
|
|
|
|
|
var table = await conn.query(`
|
|
select distinct CA from riferimenti order by CA;
|
|
`);
|
|
const result3 = table.toArray().map((row) => row.toJSON());
|
|
|
|
rif_areetematiche = result3.map((x) => x['CA']);
|
|
|
|
|
|
var table1 = await conn.query(`
|
|
select distinct TiFo from riferimenti;
|
|
`);
|
|
const result4 = table1.toArray().map((row) => row.toJSON());
|
|
rif_fonti = result4.map((x) => x['TiFo']);
|
|
|
|
//console.log(rif_fonti)
|
|
await conn.close();
|
|
|
|
console.log('done')
|
|
export function getListaRis(){
|
|
return listaidversi;
|
|
}
|
|
export function getFontiS() {
|
|
|
|
return rif_fonti
|
|
}
|
|
|
|
export function getAreeTematicheS() {
|
|
|
|
return rif_areetematiche
|
|
}
|
|
|
|
export function getAutoriFontiCitazioniS() {
|
|
|
|
return rif_autori
|
|
}
|
|
|
|
export function getCommentatoriS() {
|
|
|
|
return rif_commentatori
|
|
}
|
|
|
|
export async function getVersiConCitazioni(canticapar = '', cantopar = '') {
|
|
|
|
//let citcantiche = ['Inferno', 'Purgatorio', 'Paradiso']
|
|
if (canticapar == '') {
|
|
return
|
|
}
|
|
const tconn = await db.connect();
|
|
var table = await tconn.query(`
|
|
select Ann as Annotazione, Com as Commentario, FrN as frammentoNota, AC as AutoreCitazione,
|
|
F as FonteCitazione, LF as LuogoFonteCitazione, NF as NotaFonteCitazione,
|
|
TF as TestoFonteCitazione, UF as URLFonteCitazione, NaRi as NaturaRiferimento,
|
|
RCC as RapportoCommentoCommentatoreText, RSO as RapportoSoggettoOggetto,
|
|
Aut as NomeAutoreCitazione, TiFo as TitoloFonteCitazione, Verso as VersoCitazione, CA as AreaTematica,
|
|
TiCi as TipoCitazione, CEP as CitEpisodi, CIM as CitImmagini, CTE as CitTeorie,
|
|
CMO as CitMotivi, CST as CitStilemi, CTO as CitTopografie
|
|
from riferimenti
|
|
where Cantica='${canticapar}' and Canto='${cantopar}' order by verso;
|
|
`);
|
|
|
|
var result4 = table.toArray().map((row) => row.toJSON());
|
|
|
|
|
|
await tconn.close();
|
|
return result4
|
|
|
|
}
|
|
export async function queryRiferimenti(filtro, cid) {
|
|
if (filtro == null) {
|
|
return
|
|
}
|
|
console.log(filtro)
|
|
const tconn = await db.connect();
|
|
var querytl = 'select Cantica, Canto, Verso from riferimenti'
|
|
var queryfi = ' where '
|
|
if (filtro.Commentatore != null && filtro.Commentatore.trim() != 'all')
|
|
queryfi += "Com='" + filtro.Commentatore.trim() + "'"
|
|
else
|
|
queryfi += "Com like '%'"
|
|
if (filtro.Autore_Fonte != null && filtro.Autore_Fonte.trim() != 'all')
|
|
queryfi += " and Aut='" + filtro.Autore_Fonte.trim() + "'"
|
|
|
|
var rs = await tconn.query(querytl + queryfi)
|
|
var result4 = rs.toArray().map((row) => row.toJSON());
|
|
|
|
await tconn.close();
|
|
var resxcantica = Object.groupBy(result4, ({ Cantica }) => Cantica);
|
|
|
|
|
|
var numcid = cid.split('_')[1]
|
|
for (var cantica in resxcantica) {
|
|
var $nctags = $(' .navig-canto')
|
|
console.log(resxcantica[cantica].length)
|
|
var i = 1;
|
|
if (cantica == 'Purgatorio')
|
|
i = 2
|
|
if (cantica == 'Paradiso')
|
|
i = 3
|
|
var spanbadgecantica = $('<span />');
|
|
spanbadgecantica.attr('class', 'badge badge-warning badge-pill mx-2');
|
|
spanbadgecantica.append(resxcantica[cantica].length)
|
|
spanbadgecantica.appendTo($('#cantica' + i + '-badge'))
|
|
console.log(spanbadgecantica)
|
|
var tmp = resxcantica[cantica]
|
|
var resxcanto = Object.groupBy(tmp, ({ Canto }) => Canto);
|
|
for (var canto in resxcanto) {
|
|
var tmpv = resxcanto[canto]
|
|
var spanbadge = $('<span />');
|
|
spanbadge.attr('class', cantobadgeclassBis);
|
|
spanbadge.append(resxcanto[canto].length)
|
|
if (canto.startsWith('0')) {
|
|
canto = canto.replace('0', '')
|
|
}
|
|
spanbadge.appendTo($nctags.filter('[name="' + cantica + 'Canto ' + canto + '"]'))
|
|
for (const tmpvi of tmpv) {
|
|
let myveid = '#' + cantica + '_Canto_' + canto + '_' + tmpvi.Verso.split('-')[0]
|
|
console.log(myveid)
|
|
listaidversi.push(myveid)
|
|
if (cid.includes(cantica) && numcid == canto)
|
|
$(myveid).addClass("font-weight-bold mark ")
|
|
}
|
|
|
|
}
|
|
drawMinimap(cid, true)
|
|
|
|
}
|
|
/*console.log(resxcantica)*/
|
|
return listaidversi
|
|
|
|
}
|