Skip to content

Commit

Permalink
Minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
TLCFEM committed Nov 28, 2024
1 parent 363872b commit 0d14fd4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
8 changes: 4 additions & 4 deletions gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
},
"devDependencies": {
"@types/leaflet": "^1.9.14",
"@types/node": "^22.9.3",
"@types/node": "^22.10.0",
"@types/plotly.js-dist-min": "^2.3.4",
"prettier": "^3.3.3",
"prettier": "^3.4.1",
"solid-devtools": "^0.30.1",
"typescript": "^5.7.2",
"vite": "^5.4.11",
"vite-plugin-solid": "^2.10.2"
"vite-plugin-solid": "^2.11.0"
},
"dependencies": {
"@suid/icons-material": "^0.8.1",
"@suid/material": "^0.18.0",
"@suid/vite-plugin": "^0.3.1",
"@tanstack/solid-table": "^8.20.5",
"axios": "^1.7.7",
"axios": "^1.7.8",
"leaflet": "^1.9.4",
"plotly.js-dist-min": "^2.35.2",
"solid-js": "^1.9.3",
Expand Down
22 changes: 20 additions & 2 deletions gui/src/API.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ function stringify(obj: any) {
return JSON.stringify(obj, (_, value) => (value === null || value === undefined ? undefined : value));
}

export async function query_api(config: QueryConfig, mongo: boolean) {
export async function query_api(config: QueryConfig) {
const response = (
await axios.post<QueryResponse>(mongo ? "/query" : "/search", stringify(config), {
await axios.post<QueryResponse>("/search", stringify(config), {
headers: { "Content-Type": "application/json" }
})
).data;
Expand All @@ -138,6 +138,24 @@ export async function get_total_api() {
return (await axios.get<TotalResponse>("/total")).data.total[0];
}

interface StatsResponse {
magnitude: AggregationBucket;
pga: AggregationBucket;
}

class AggregationBucket {
public buckets: AggregationItem[];
}

class AggregationItem {
public key: number;
public doc_count: number;
}

export async function get_stats() {
return (await axios.get<StatsResponse>("/stats")).data;
}

export async function post_total_api(configs: QueryConfig[]) {
return (
await axios.post<TotalResponse>("/total", stringify(configs), {
Expand Down
4 changes: 3 additions & 1 deletion gui/src/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import mb_logo from "./assets/logo.svg";
import mongoengine_logo from "./assets/mongoengine.png";
import celery_logo from "./assets/celery.png";
import scipy_logo from "./assets/scipy.svg";
import { post_total_api, QueryConfig } from "./API";
import { get_stats, post_total_api, QueryConfig } from "./API";

export default function AboutModal() {
const [open, setOpen] = createSignal(false);
Expand All @@ -47,6 +47,8 @@ export default function AboutModal() {
configs.push(config);

setStats(await post_total_api(configs));

console.log(await get_stats());
});

const commit_link = <Link href="https://github.com/TLCFEM/motion-base/tree/git-commit-long">git-commit-short</Link>;
Expand Down
12 changes: 1 addition & 11 deletions gui/src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const [error, setError] = createSignal("");

const Settings: Component<sxProps> = (props) => {
const [loading, setLoading] = createSignal(false);
const [mongo, setMongo] = createSignal(false);

async function fetch() {
setLoading(true);
Expand All @@ -100,7 +99,7 @@ const Settings: Component<sxProps> = (props) => {
if (stationCode()) config.station_code = stationCode();

try {
setRecords(await query_api(config, mongo()));
setRecords(await query_api(config));
} catch (e) {
// clear();
setError((e as Error).message);
Expand Down Expand Up @@ -313,15 +312,6 @@ const Settings: Component<sxProps> = (props) => {
disabled={loading()}
/>
</Stack>
<Stack sx={stackProps}>
<FormControlLabel
id="chk-mongo"
name="chk-mongo"
label="mongoDB"
disabled={true}
control={<Checkbox checked={mongo()} onChange={(_, checked) => setMongo(checked)} />}
/>
</Stack>
<ButtonGroup variant="contained" orientation="vertical">
<Button size="small" onClick={fetch} id="btn-search" disabled={loading()}>
Search
Expand Down

0 comments on commit 0d14fd4

Please sign in to comment.