Skip to content

Commit

Permalink
feat: track more events to Matomo: export download, install
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Aug 21, 2024
1 parent 8668103 commit 11eb3cc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ As this project is a user-facing application, the places in the semantic version

### Added

- Track some events to Matomo (run/abort annotation) [#166](https://github.com/spraakbanken/mink-frontend/issues/166)
- Track some events to Matomo [#166](https://github.com/spraakbanken/mink-frontend/issues/166)

### Fixed

Expand Down
3 changes: 0 additions & 3 deletions src/corpus/analysis/AnalysisPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import useExports from "../exports/exports.composable";
import useJob from "../job/job.composable";
import ActionButton from "@/components/ActionButton.vue";
import PendingContent from "@/spin/PendingContent.vue";
import { useMatomo } from "@/matomo";
const corpusId = useCorpusIdParam();
const { runJob, jobState, isJobRunning } = useJob(corpusId);
const { canBeReady } = useCorpusState(corpusId);
const { exports, loadExports, downloadResult, getDownloadFilename } =
useExports(corpusId);
const { isDone } = useCorpusState(corpusId);
const matomo = useMatomo();
const isPending = ref(false);
const canRun = computed(
Expand All @@ -25,7 +23,6 @@ loadExports();
async function doRunJob() {
isPending.value = true;
matomo?.trackEvent("Corpus", "Run annotation", corpusId);
await runJob();
isPending.value = false;
}
Expand Down
11 changes: 8 additions & 3 deletions src/corpus/exports/exports.composable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { computed } from "vue";
import { downloadFile } from "@/util";
import { useMatomo } from "@/matomo";
import useMinkBackend from "@/api/backend.composable";
import { useResourceStore } from "@/store/resource.store";
import useMessenger from "@/message/messenger.composable";

export default function useExports(corpusId: string) {
const resourceStore = useResourceStore();
const mink = useMinkBackend();
const { alertError } = useMessenger();
const matomo = useMatomo();

const corpus = computed(() => resourceStore.corpora[corpusId]);
/** Exports sorted alphabetically by path, but "stats_*" first. */
const exports = computed(() =>
Expand All @@ -14,15 +19,14 @@ export default function useExports(corpusId: string) {
?.sort((a, b) => a.path.localeCompare(b.path))
.sort((a, b) => b.path.indexOf("stats_") - a.path.indexOf("stats_")),
);
const mink = useMinkBackend();
const { alertError } = useMessenger();

async function loadExports() {
const exports = await mink.loadExports(corpusId).catch(alertError);
corpus.value.exports = exports;
}

async function downloadResult() {
matomo?.trackEvent("Corpus result", "Download export archive", corpusId);
const data = await mink.downloadExports(corpusId).catch(alertError);
if (!data) return;
downloadFile(data, getDownloadFilename());
Expand All @@ -33,11 +37,12 @@ export default function useExports(corpusId: string) {
}

async function downloadResultFile(path: string) {
const filename = path.split("/").pop()!;
matomo?.trackEvent("Corpus result", "Download export file", filename);
const data = await mink
.downloadExportFiles(corpusId, path)
.catch(alertError);
if (!data) return;
const filename = path.split("/").pop()!;
downloadFile(data, filename);
}

Expand Down
9 changes: 1 addition & 8 deletions src/corpus/job/JobStatus.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { computed } from "vue";
import { useMatomo } from "@/matomo";
import useJob from "@/corpus/job/job.composable";
import JobStatusMessage from "@/corpus/job/JobStatusMessage.vue";
import { formatDate } from "@/util";
Expand All @@ -14,19 +13,13 @@ import TextData from "@/components/TextData.vue";
const corpusId = useCorpusIdParam();
const { abortJob, jobStatus, isJobRunning } = useJob(corpusId);
const { isFailed } = useCorpusState(corpusId);
const matomo = useMatomo();
const hasStarted = computed(
() =>
Object.values(jobStatus.value?.status || {}).some(
(status) => status != "none",
) || jobStatus.value?.priority,
);
async function doAbortJob() {
matomo?.trackEvent("Corpus", "Abort annotation", corpusId);
await abortJob();
}
</script>

<template>
Expand All @@ -45,7 +38,7 @@ async function doAbortJob() {
<ActionButton
v-if="isJobRunning"
class="button-danger ml-2"
@click="doAbortJob"
@click="abortJob"
>
{{ $t("job.abort") }}
</ActionButton>
Expand Down
6 changes: 6 additions & 0 deletions src/corpus/job/job.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import useMinkBackend from "@/api/backend.composable";
import { useResourceStore } from "@/store/resource.store";
import useMessenger from "@/message/messenger.composable";
import type { JobType } from "@/api/api.types";
import { useMatomo } from "@/matomo";

// Module-scope ticker, can be watched to perform task intermittently
const pollTick = useInterval(2000);
Expand All @@ -16,6 +17,7 @@ export default function useJob(corpusId: string) {
const corpus = computed(() => resourceStore.corpora[corpusId]);
const mink = useMinkBackend();
const { alertError } = useMessenger();
const matomo = useMatomo();

async function loadJob() {
const info = await mink.resourceInfoOne(corpusId).catch(alertError);
Expand All @@ -24,23 +26,27 @@ export default function useJob(corpusId: string) {
}

async function runJob() {
matomo?.trackEvent("Corpus", "Run annotation", corpusId);
const info = await mink.runJob(corpusId).catch(alertError);
corpus.value.status = info.job;
}

async function installKorp() {
matomo?.trackEvent("Tool", "Install corpus in Korp", corpusId);
const info = await mink.installKorp(corpusId).catch(alertError);
if (!info) return;
corpus.value.status = info.job;
}

async function installStrix() {
matomo?.trackEvent("Tool", "Install corpus in Strix", corpusId);
const info = await mink.installStrix(corpusId).catch(alertError);
if (!info) return;
corpus.value.status = info.job;
}

async function abortJob() {
matomo?.trackEvent("Corpus", "Abort annotation", corpusId);
await mink.abortJob(corpusId).catch(alertError);
await loadJob();
}
Expand Down

0 comments on commit 11eb3cc

Please sign in to comment.