-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
290 lines (256 loc) · 11.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!doctype html>
<html class="no-js" lang="">
<head>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<style>
table {
border-collapse: collapse;
overflow-y:scroll;
height:500px;
display:block;
}
th {
background-color: #0b5ed7;
Color: white;
}
th,
td {
width: 150px;
text-align: center;
border: 1px solid gray;
padding: 5px
}
</style>
<script src="sorttable.js"></script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
<meta name="description" content="" />
<meta property="og:title" content="cesium database" />
<meta property="og:type" content="" />
<meta property="og:url" content="" />
<meta property="og:image" content="" />
<meta property="og:image:alt" content="" />
<link rel="icon" href="/favicon.ico" sizes="any" />
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="icon.png" />
<link rel="manifest" href="site.webmanifest" />
<meta name="theme-color" content="#fafafa" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.0/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<script>
let paths = [];
let data;
let minR = 100;
let maxR = 0;
let minS = 100;
let maxS = 0;
let types = [];
let combos = {};
document.addEventListener("DOMContentLoaded", function () {
const form = document.querySelector("#form");
const numReactionsInput =
document.querySelector("#numReactions");
const numSpeciesInput = document.querySelector("#numSpecies");
const modelTypeInput = document.querySelector("#mtype");
const modelsFound = document.querySelector("#found");
form.addEventListener("submit", (event) => {
event.preventDefault();
lookupModels();
});
numReactionsInput.addEventListener("input", lookupModels);
numSpeciesInput.addEventListener("input", lookupModels);
modelTypeInput.addEventListener("input", lookupModels);
load_metadata()
.then((mtd) => {
data = mtd; // Store the JSON data from the fetched URL
console.log(data[0]);
for (let i = 0; i < data.length; i++) {
if (!types.includes(data[i].modelType)) {
types.push(data[i].modelType);
}
if (data[i].numSpecies > maxS) {
maxS = data[i].numSpecies;
}
if (data[i].numSpecies < minS) {
minS = data[i].numSpecies;
}
if (data[i].numReactions > maxR) {
maxR = data[i].numReactions;
}
if (data[i].numReactions < minR) {
minR = data[i].numReactions;
}
}
document.querySelector("#nspl").textContent =
`Number of Species (${minS.toString()}-${maxS.toString()}):`;
document.querySelector("#nrpl").textContent =
`Number of Reactions (${minR.toString()}-${maxR.toString()}):`;
let typesStr = "<option selected=\"\">Please select</option>";
types.forEach((typesStrKey) => {
typesStr += `<option value=\"${typesStrKey}\">${typesStrKey}</option>`;
});
document.getElementById("mtype").innerHTML = typesStr
})
.catch((error) => {
console.error("Error:", error); // Logs any error that occurred during the fetch
});
function setInputs(ns, nr, mt) {
numSpeciesInput.value = ns;
numReactionsInput.value = nr;
modelTypeInput.value = mt;
}
function updateTable(){
combos = {}
for (let i = 0; i < data.length; i++){
if(data[i].modelType === modelTypeInput.value) {
let key = `<tr
><td>${data[i].numSpecies}</td><td>${data[i].numReactions}</td> <td>${data[i].modelType}</td>`
if (combos[key] == null) {
combos[key] = 1;
} else {
combos[key] += 1;
}
}
}
let tableBody = "";
for (let i = 0; i < Object.keys(combos).length; i++) {
tableBody += Object.keys(combos)[i] + `<td>${combos[Object.keys(combos)[i]]}</td></tr>`
}
document.getElementById("table").innerHTML = "" +
"<table id=\"sortable\">\n" +
" <thead>\n" +
" <tr><th>Number of Species</th><th>Number of Reactions</th> <th>Model Type</th> <th>Number of Models Found</th></tr>\n" +
" </thead>\n" +
" <tbody>\n" + tableBody +
" </tbody>\n" +
" </table>"
sorttable.makeSortable(document.getElementById("sortable"));
}
function lookupModels() {
const species_num = numSpeciesInput.value
? parseInt(numSpeciesInput.value)
: null;
const reaction_num = numReactionsInput.value
? parseInt(numReactionsInput.value)
: null;
const model_type =
modelTypeInput.value !== "Please select"
? modelTypeInput.value
: null;
document.getElementById("spectext").innerHTML = "";
updateTable()
paths = data
.filter(
(item) =>
(species_num === null ||
item.numSpecies === species_num) &&
(reaction_num === null ||
item.numReactions === reaction_num) &&
(model_type === null ||
item.modelType === model_type),
)
.map(
(item) =>
"https://raw.githubusercontent.com/sys-bio/cesium/master/" +
item.path,
);
modelsFound.textContent = `Number of models found: ${paths.length}`;
}
});
async function fetchFile(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(
"Network response was not ok " + response.statusText,
);
}
return response.blob();
}
async function downloadFiles() {
if (paths.length === 0) {
document.getElementById("spectext").innerHTML =
"No models selected, no models downloaded.";
return;
}
document.getElementById("spectext").innerHTML =
"Downloading models...";
const zip = new JSZip();
const fetchPromises = paths.map(async (path) => {
const filename = path.split("/").pop();
const fileBlob = await fetchFile(path);
zip.file(filename, fileBlob);
});
await Promise.all(fetchPromises);
const content = await zip.generateAsync({ type: "blob" });
saveAs(content, "models.zip");
document.getElementById("spectext").innerHTML =
"Downloaded models.";
}
function load_metadata() {
return fetch(
"https://raw.githubusercontent.com/sys-bio/cesium/master/model_db/cesium_metadata.json",
).then((response) => {
if (!response.ok) {
throw new Error(
"Network response was not ok " +
response.statusText,
);
}
return response.json();
});
}
</script>
</head>
<body>
<!-- Add your site or application content here -->
<div class="text-center">
<h1>Cesium Database Lookup</h1>
<form id="form">
<label id="nspl" for="numSpecies">Number of Species:</label
><br />
<input type="number" id="numSpecies" name="nspecies" /><br />
<label id="nrpl" for="numReactions">Number of Reactions:</label
><br />
<input
type="number"
id="numReactions"
name="nreactions"
/><br />
<div class="row mb-4 justify-content-center">
<div class="col-auto">
<label for="mtype" class="col-sm-10 col-form-label"
>Model Type</label
>
<select
class="form-select"
id="mtype"
name="mtype"
aria-label="Default select example"
autocomplete="off"
placeholder="Please select"
required=""
>
</select>
</div>
</div>
</form>
<br />
<p id="found">Amount of models found: 0</p>
<button class="btn btn-primary" onclick="downloadFiles()">
Download found models
</button>
<br />
<br />
<p id="spectext" class="text-primary"></p>
<div id = "table" class="full-width" style="justify-content: center; display: flex">
</div>
<br>
</div>
</body>
</html>