Changeset 35433


Ignore:
Timestamp:
2021-09-20T16:50:02+12:00 (3 years ago)
Author:
cstephen
Message:

Check for duplicates before transcribing them

Location:
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/AudioUpload.vue

    r35432 r35433  
    158158         */
    159159        async getTranscriptions(files) {
    160             await Util.delay(1000); // TODO: Remove - UI testing purposes only
     160            await Util.delay(200); // TODO: Remove - UI testing purposes only
     161
     162            const validFiles = [];
     163
     164            // Skip any files that have already been transcribed
     165            for (const file of files) {
     166                if (this.$store.getters.hasTranscriptionOfFile(file)) {
     167                    this.createFailure(file.file_name, this.translations.get("AudioUpload_AlreadyTranscribed"));
     168                }
     169                else {
     170                    validFiles.push(file);
     171                }
     172            }
     173
     174            if (validFiles.length === 0) {
     175                return;
     176            }
    161177
    162178            try {
    163                 for await (const batch of transcribeService.batchTranscribeFiles(files)) {
     179                for await (const batch of transcribeService.batchTranscribeFiles(validFiles)) {
    164180                    for (const t of batch) {
    165181                        if (!t.success) {
    166                             createFailure(this, t);
    167                         }
    168                         else {
    169                             const f = files.find(f => f.name === t.file_name);
    170                             if (f === undefined) {
    171                                 createFailure(this, t, this.translations.get("ErrorTryAgain"));
    172                             }
    173 
    174                             const tvm = new TranscriptionViewModel(t, f);
    175 
    176                             try {
    177                                 this.$store.commit("transcriptionAdd", tvm);
    178                             }
    179                             catch (TranscriptionExistsError) {
    180                                 createFailure(this, t, this.translations.get("AudioUpload_AlreadyTranscribed"));
    181                             }
     182                            this.createFailure(t.file_name, t.log);
     183                            continue;
     184                        }
     185
     186                        const f = files.find(f => f.name === t.file_name);
     187                        if (f === undefined) {
     188                            this.createFailure(t.file_name, this.translations.get("ErrorTryAgain"));
     189                            continue;
     190                        }
     191
     192                        const tvm = new TranscriptionViewModel(t, f);
     193
     194                        try {
     195                            this.$store.commit("transcriptionAdd", tvm);
     196                        }
     197                        catch (TranscriptionExistsError) {
     198                            this.createFailure(t.file_name, this.translations.get("AudioUpload_AlreadyTranscribed"));
    182199                        }
    183200                    }
     
    188205                console.error(e);
    189206
    190                 const failure = new TranscriptionViewFailure(e.fileName, e.message);
    191                 this.failures.set(failure.id, failure);
    192             }
    193 
    194             function createFailure(that, t, reason = null) {
    195                 const failure = new TranscriptionViewFailure(t.file_name, reason ?? t.log);
    196                 that.failures.set(failure.id, failure);
    197             }
     207                this.createFailure(e.fileName, e.message)
     208            }
     209        },
     210        createFailure(fileName, reason) {
     211            const failure = new TranscriptionViewFailure(fileName, reason);
     212            this.failures.set(failure.id, failure);
    198213        }
    199214    }
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/main.js

    r35432 r35433  
    1313    constructor(transcription, file) {
    1414        /** @type {String} The UUID of this transcription. */
    15         this.id = file.name + file.size + file.type; // Should be a fairly reliable indicator of uniqueness.
     15        this.id = TranscriptionViewModel.getId(file); // Should be a fairly reliable indicator of uniqueness.
    1616
    1717        /** @type {String} The transcription. */
     
    2626        /** @type {File} The file from which the transcription was generated. */
    2727        this.file = file;
     28    }
     29
     30    static getId(file) {
     31        return file.name + file.size + file.type;
    2832    }
    2933}
     
    110114            state.translations = translations;
    111115        }
     116    },
     117    getters: {
     118        hasTranscriptionOfFile: (state) => (file) => {
     119            const id = TranscriptionViewModel.getId(file);
     120            return state.rawTranscriptions.has(id);
     121        }
    112122    }
    113123});
Note: See TracChangeset for help on using the changeset viewer.