Skip to content

Commit

Permalink
Improve cohesion for statistics components
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjelonek committed Nov 9, 2023
1 parent 5f5b6ab commit bd57169
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 47 deletions.
30 changes: 15 additions & 15 deletions src/BakrepApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { GtdbtkResultSchema, type GtdbtkResult } from "./model/GtdbtkResult";
import { MlstResultSchema, type MlstResult } from "./model/MlstResults";
import type { SearchInfo, SearchRequest } from "./model/Search";
import {
RepositoryStatisticsDataSchema,
type RepositoryStatisticsData,
} from "./model/RepositoryStatisticsData";
RepositoryStatisticsSchema,
type RepositoryStatistics,
} from "./model/statistics/RepositoryStatistics";
import {
KeywordCountDataSchema,
type KeywordCountData,
} from "./model/KeywordCountData";
KeywordCountsSchema,
type KeywordCounts,
} from "./model/statistics/KeywordCounts";

import {
tsvSearchResultFromText,
Expand All @@ -36,9 +36,9 @@ interface BakrepApi {
fetchCheckmResult(dataset: Dataset): Promise<CheckmResult | undefined>;
fetchMlstResult(dataset: Dataset): Promise<MlstResult | undefined>;
fetchMetadata(dataset: Dataset): Promise<Metadata | undefined>;
fetchGenusStatistics(): Promise<KeywordCountData>;
fetchSpeciesStatistics(): Promise<KeywordCountData>;
fetchSummary(): Promise<RepositoryStatisticsData>;
fetchGenusStatistics(): Promise<KeywordCounts>;
fetchSpeciesStatistics(): Promise<KeywordCounts>;
fetchSummary(): Promise<RepositoryStatistics>;
search(request: SearchRequest): Promise<BakrepSearchResult>;
searchTsv(
request: SearchRequest,
Expand Down Expand Up @@ -136,20 +136,20 @@ class BakrepApiImpl implements BakrepApi {
}
return fetch(metadata[0].url).then(this.toJson).then(MetadataSchema.parse);
}
fetchSummary(): Promise<RepositoryStatisticsData> {
fetchSummary(): Promise<RepositoryStatistics> {
return fetch(baseurl + "/stats/summary")
.then(this.toJson)
.then(RepositoryStatisticsDataSchema.parse);
.then(RepositoryStatisticsSchema.parse);
}
fetchGenusStatistics(): Promise<KeywordCountData> {
fetchGenusStatistics(): Promise<KeywordCounts> {
return fetch(baseurl + "/stats/genus")
.then(this.toJson)
.then(KeywordCountDataSchema.parse);
.then(KeywordCountsSchema.parse);
}
fetchSpeciesStatistics(): Promise<KeywordCountData> {
fetchSpeciesStatistics(): Promise<KeywordCounts> {
return fetch(baseurl + "/stats/species")
.then(this.toJson)
.then(KeywordCountDataSchema.parse);
.then(KeywordCountsSchema.parse);
}
searchinfo(): Promise<SearchInfo> {
return fetch(baseurl + "/search/_info")
Expand Down
13 changes: 0 additions & 13 deletions src/model/KeywordCountData.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/model/RepositoryStatisticsData.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/model/statistics/KeywordCounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from "zod";

const KeywordCountSchema = z.object({
count: z.number(),
key: z.string(),
});

const KeywordCountsSchema = z.array(KeywordCountSchema);

export type KeywordCountEntry = z.infer<typeof KeywordCountSchema>;
export type KeywordCounts = z.infer<typeof KeywordCountsSchema>;

export { KeywordCountSchema, KeywordCountsSchema };
11 changes: 11 additions & 0 deletions src/model/statistics/RepositoryStatistics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

const RepositoryStatisticsSchema = z.object({
genera: z.number(),
datasets: z.number(),
species: z.number(),
});

export type RepositoryStatistics = z.infer<typeof RepositoryStatisticsSchema>;

export { RepositoryStatisticsSchema };
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const router = createRouter({
{
path: "/statistics",
name: "statistics",
component: () => import("../views/StatisticsView.vue"),
component: () => import("../views/statistics/StatisticsView.vue"),
},
],
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { type KeywordCountData } from "@/model/KeywordCountData";
import { type KeywordCounts } from "@/model/statistics/KeywordCounts";
import Plotly from "plotly.js-dist-min";
import type { Data, Layout } from "plotly.js-dist-min";
import {
Expand All @@ -12,12 +12,12 @@ import {
import type { PropType } from "vue";
const props = defineProps({
inputData: { type: Object as PropType<KeywordCountData>, required: true },
inputData: { type: Array as PropType<KeywordCounts>, required: true },
});
let data: Data[] = [];
const reversedData: ComputedRef<KeywordCountData> = computed(() =>
const reversedData: ComputedRef<KeywordCounts> = computed(() =>
[...props.inputData].reverse(),
);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useApi } from "@/BakrepApi";
import PhylogenyCountsBarChart from "@/components/PhylogenyCountsBarchart.vue";
import RepositoryStatistics from "@/components/RepositoryStatistics.vue";
import PhylogenyCountsBarChart from "./PhylogenyCountsBarchart.vue";
import RepositoryStatistics from "./RepositoryStatistics.vue";
import usePageState, { State } from "@/PageState";
import Loading from "@/components/Loading.vue";
const api = useApi();
Expand Down

0 comments on commit bd57169

Please sign in to comment.