Skip to content

Commit

Permalink
vers 1 and 2 of serohub.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasalmeida committed Aug 11, 2024
1 parent 0f96047 commit 9d927ba
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions serohub1.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Plotly = (await import("https://esm.sh/[email protected]")).default
//const Plotly = (await import("https://episphere.github.io/plotly/esm.mjs")).esm
const localForage = (await import('https://esm.run/[email protected]/src/localforage.js')).default
const url = 'https://episphere.github.io/serohub/seroprevalence.json.zip'
let seroHub={
loadedAt:Date(),
loadedFrom:url
}
let dt = await localForage.getItem('seroHub_Prevalence')
//if(true){
if(!dt){
const loadZip = (await import('https://episphere.github.io/serohub/loadZip.mjs'))
dt = await loadZip.loadZippedFiles(url)
localForage.setItem('seroHub_Prevalence',dt)
}
seroHub.seroprevalence=dt['seroprevalence.json']
// transpose
seroHub.variables = Object.keys(seroHub.seroprevalence.seroprevalences[0])
seroHub.values=function(variable='age'){
if(typeof(variable)=='number'){
variable = seroHub.variables[variable]
}
console.log(`reading variable "${variable}"`)
return seroHub.seroprevalence.seroprevalences.map(row=>row[variable])
}
seroHub.uniqueValues=function(variable='age'){
if(typeof(variable)=='number'){
variable = seroHub.variables[variable]
}
console.log(`unique values for "${variable}"`)
return [... new Set(seroHub.seroprevalence.seroprevalences.map(row=>row[variable]))]
}
// Plots



export{
seroHub
}
39 changes: 39 additions & 0 deletions serohub2.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//const Plotly = (await import("https://esm.sh/[email protected]")).default
const Plotly = (await import("https://episphere.github.io/plotly/esm.mjs")).esm
const localForage = (await import('https://esm.run/[email protected]/src/localforage.js')).default
const url = 'https://episphere.github.io/serohub/seroprevalence.json.zip'
let seroHub={
loadedAt:Date(),
loadedFrom:url
}
let dt = await localForage.getItem('seroHub_Prevalence')
//if(true){
if(!dt){
const loadZip = (await import('https://episphere.github.io/serohub/loadZip.mjs'))
dt = await loadZip.loadZippedFiles(url)
localForage.setItem('seroHub_Prevalence',dt)
}
seroHub.seroprevalence=dt['seroprevalence.json']
// transpose
seroHub.variables = Object.keys(seroHub.seroprevalence.seroprevalences[0])
seroHub.values=function(variable='age'){
if(typeof(variable)=='number'){
variable = seroHub.variables[variable]
}
console.log(`reading variable "${variable}"`)
return seroHub.seroprevalence.seroprevalences.map(row=>row[variable])
}
seroHub.uniqueValues=function(variable='age'){
if(typeof(variable)=='number'){
variable = seroHub.variables[variable]
}
console.log(`unique values for "${variable}"`)
return [... new Set(seroHub.seroprevalence.seroprevalences.map(row=>row[variable]))]
}
// Plots



export{
seroHub
}

0 comments on commit 9d927ba

Please sign in to comment.