Skip to content

Commit

Permalink
select category and users
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenasandoval88 committed Aug 16, 2024
1 parent eca4993 commit 6247857
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
14 changes: 7 additions & 7 deletions sdk/get23.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ get23.getAllUsers = async function () {
return dt
}

get23.getTxts = async function (table,usersData) {
get23.getTxts = async function (usersData) {
console.log("getTxts function")
// clearTableUsingKeyLength(table,maxKeys)
let arr = []
Expand All @@ -48,10 +48,10 @@ get23.getTxts = async function (table,usersData) {
// let storageList = await table.keys()
// console.log("storageList.filter(x => urls.includes(x)",storageList.filter(x => urls.includes(x)))

storage.clearTableButKeepKeyList(table, urls)
storage.clearTableButKeepKeyList(userTxts, urls)

for (let i = 0; i < urls.length; i++) {
let parsedUser2 = await table.getItem(urls[i]);
let parsedUser2 = await userTxts.getItem(urls[i]);
console.log("processing user #", i)

if (parsedUser2 == null) {
Expand All @@ -64,7 +64,7 @@ get23.getTxts = async function (table,usersData) {

// console.log("parsedUser",parsedUser)
arr.push(parsedUser)
table.setItem(urls[i], parsedUser);
userTxts.setItem(urls[i], parsedUser);
} else {
// console.log(i,"parsedUser2 NOT null");
arr.push(parsedUser2)
Expand Down Expand Up @@ -126,7 +126,7 @@ get23.getUsersByType = async function (type, users) {


// get users with a specific phenotype, filter users with 23andme data
get23.getUsersByPhenotypeId = async function (phenoId,table,keysLen) {
get23.getUsersByPhenotypeId = async function (phenoId,keysLen) {
console.log("---------------------------")
console.log("running... get23.getUsersByPhenotypeId function")
console.log("phenotype id:", phenoId)
Expand All @@ -148,7 +148,7 @@ get23.getUsersByPhenotypeId = async function (phenoId,table,keysLen) {
console.log("Warning: user txts for phenotypeID", phenoId, "> 6. First 6 files used.")
}
// get 23 and me texts from urls using getTxts function
let snpTxts = await get23.getTxts(table,cleanUsers,keysLen,maxKeys)
let snpTxts = await get23.getTxts(cleanUsers,keysLen,maxKeys)

console.log("User txts for phenotypeID", phenoId, ": ", snpTxts)
return snpTxts
Expand Down Expand Up @@ -181,7 +181,7 @@ const id = 3
const keysLen = 9
const maxKeys = 14
// const storageSize = 1.3
const td2Users = await get23.getUsersByPhenotypeId(id,userTxts,keysLen)
const td2Users = await get23.getUsersByPhenotypeId(id,keysLen)
const name = await get23.getPhenotypeNameFromId(id)
const phenotypes = (await get23.getUserPhenotypes()).sort((a, b) => a.id - b.id)
console.log("phenotypes",phenotypes)
Expand Down
22 changes: 19 additions & 3 deletions sdk/ui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import {getPgs} from "./getPgs.js"
import {get23} from "./get23.js"

let userTxts = localforage.createInstance({
name: "userTxts",
storeName: "userTxts"
})


import localforage from 'https://cdn.skypack.dev/localforage';

localforage.config({
driver: [
localforage.INDEXEDDB,
localforage.LOCALSTORAGE,
localforage.WEBSQL
],
name: 'localforage'
});

const ui = async function(targetDiv = document.body) {
console.log("ui-----------------------------")
Expand Down Expand Up @@ -51,7 +67,7 @@ const ui = async function(targetDiv = document.body) {
const keysLen = 9
const maxKeys = 14
// const storageSize = 1.3
const userTxts = await get23.getUsersByPhenotypeId(id,userTxts,keysLen)
const userTxts = await get23.getUsersByPhenotypeId(id,keysLen)
const name = await get23.getPhenotypeNameFromId(id)
const phenotypes = (await get23.getUserPhenotypes()).sort((a, b) => a.id - b.id)
console.log("phenotypes",phenotypes)
Expand All @@ -73,8 +89,8 @@ const ui = async function(targetDiv = document.body) {
// Create options and add them to the dropdown
dt.user.phenotypes.map(x=> {
const op = new Option();
op.value = x;
op.text = x;
op.value = x.characteristic;
op.text = x.characteristic;
dropdown2.options.add(op)
})
// Add the dropdown to the div
Expand Down

0 comments on commit 6247857

Please sign in to comment.