Skip to content

Commit

Permalink
fix(tportal): fix several issues from migration
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Jun 14, 2024
1 parent 7e5640b commit 8028f41
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ export class ProceedingsComponent implements OnInit, OnDestroy {
}
this.popover.task = undefined;
operation.onMouseEnter();
console.log(this.popover.pointer);
}

onOperationMouseLeave($event: MouseEvent, operation: Operation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export class DownloadModalComponent implements OnInit {
if (!(this.selectedTasks === null || this.selectedTasks === undefined)) {
// prepare package
const dateStr = DateTime.now().toFormat('yyyy-MM-dd_HH-mm-ss');
console.log(dateStr);
const requestPackage: {
entries: {
path: string,
Expand Down
30 changes: 13 additions & 17 deletions apps/transcription-portal/src/app/obj/operations/asr-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {UploadOperation} from './upload-operation';
import {AppSettings} from '../../shared/app.settings';
import {HttpClient} from '@angular/common/http';
import {FileInfo} from '@octra/web-media';
import {extractFileNameFromURL} from '@octra/utilities';
import {input} from '@angular/core';

export class ASROperation extends Operation {
public webService = '';
Expand All @@ -20,7 +22,7 @@ export class ASROperation extends Operation {

setTimeout(() => {
this.callASR(languageObject, httpclient, inputs[0], accessCode).then((file: FileInfo) => {
if (!(file === null || file === undefined)) {
if (file) {
this.callG2PChunker(languageObject, httpclient, file).then((finalResult) => {
this.time.duration = Date.now() - this.time.start;

Expand Down Expand Up @@ -124,7 +126,7 @@ export class ASROperation extends Operation {
'NOTE: audio files may be processed by commercial providers who may store and keep the data you send them!';
}

private callASR(languageObject: OHLanguageObject, httpClient: HttpClient, input: any, accessCode: string): Promise<FileInfo> {
private callASR(languageObject: OHLanguageObject, httpClient: HttpClient, input: FileInfo, accessCode: string): Promise<FileInfo> {
return new Promise<FileInfo>((resolve, reject) => {
this.webService = languageObject.asr;

Expand All @@ -137,23 +139,21 @@ export class ASROperation extends Operation {
url += `&ACCESSCODE=${accessCode}`;
}

console.log(`Call ${languageObject.asr}ASR:`);
console.log(url);
httpClient.post(url, {}, {
headers: {
'Content-Type': 'multipart/form-data'
},
responseType: 'text'
}).subscribe((result: string) => {
console.log(`XML Result:`);
console.log(result);
}).subscribe({
next: (result: string) => {
// convert result to json
const x2js = new X2JS();
let json: any = x2js.xml2js(result);
json = json.WebServiceResponseLink;

if (json.success === 'true') {
const file = FileInfo.fromURL(json.downloadLink, input.name, 'text/plain', Date.now());
const {extension} = extractFileNameFromURL(json.downloadLink)
const file = FileInfo.fromURL(json.downloadLink, 'text/plain', input.name + extension, Date.now());
file.updateContentFromURL(httpClient).then(() => {
// add messages to protocol
if (json.warnings !== '') {
Expand All @@ -169,9 +169,10 @@ export class ASROperation extends Operation {
reject(json.output);
}
},
(error) => {
error: (error) => {
reject(error.message);
});
}
});
});
}

Expand Down Expand Up @@ -204,7 +205,6 @@ export class ASROperation extends Operation {
}
);
}).then((asrURL) => {
console.log(`CALL G2P ${asrURL}`);
this.webService = languageObject.asr;

const url = this._commands[1].replace('{{host}}', languageObject.host)
Expand All @@ -213,10 +213,6 @@ export class ASROperation extends Operation {
.replace('{{asrType}}', `${languageObject.asr}`)
.replace('{{language}}', this.task?.language);


console.log(`Call G2P_CHUNKER:`);
console.log(url);

httpClient.post(url, {}, {
headers: {
'Content-Type': 'multipart/form-data'
Expand All @@ -229,8 +225,8 @@ export class ASROperation extends Operation {
json = json.WebServiceResponseLink;

if (json.success === 'true') {
const file = FileInfo.fromURL(json.downloadLink, 'text/plain', asrResult.name, Date.now());

const {extension} = extractFileNameFromURL(json.downloadLink)
const file = FileInfo.fromURL(json.downloadLink, 'text/plain', input.name + extension, Date.now());
setTimeout(() => {
file.updateContentFromURL(httpClient).then(() => {
// add messages to protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Operation} from './operation';
import {OHLanguageObject} from '../oh-config';
import {AppSettings} from '../../shared/app.settings';
import {FileInfo} from '@octra/web-media';
import {extractFileNameFromURL} from '@octra/utilities';

export class G2pMausOperation extends Operation {
// TODO change for the next version
Expand Down Expand Up @@ -50,7 +51,13 @@ export class G2pMausOperation extends Operation {
}

if (json.success === 'true') {
const {extension} = extractFileNameFromURL(json.downloadLink)
console.log("g2p");
console.log(inputs);
console.log(inputs[0].name + extension)
const file = FileInfo.fromURL(json.downloadLink, 'text/plain', undefined, Date.now());
console.log("file1");
console.log(file);
file.updateContentFromURL(httpclient).then(() => {
const name = (inputs[0].attributes?.originalFileName ?? inputs[0].fullname).replace(/\.[^.]+$/g, '');

Expand All @@ -60,6 +67,9 @@ export class G2pMausOperation extends Operation {

this.results.push(file);
this.changeState(TaskState.FINISHED);

console.log("file2");
console.log(file);
}).catch((error: any) => {
this.updateProtocol(error);
this.changeState(TaskState.ERROR);
Expand Down
4 changes: 1 addition & 3 deletions apps/transcription-portal/src/app/obj/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ export class Preprocessor {
const fileBlob = (file as FileInfo).file;

if (fileBlob) {
calcSHA256FromFile(fileBlob).then((hash) => {
console.log('TEST HASH: ' + hash);
}).catch((e) => {
calcSHA256FromFile(fileBlob).catch((e) => {
console.error(e);
})
}
Expand Down
1 change: 0 additions & 1 deletion apps/transcription-portal/src/app/obj/shortcut-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export class ShortcutManager {
}

const command = this.getCommand(shortcut, BrowserInfo.platform);
console.log(command);
if (!(command === null || command === undefined)) {
event.preventDefault();
resolve({
Expand Down
8 changes: 3 additions & 5 deletions apps/transcription-portal/src/app/obj/tasks/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export class TaskService implements OnDestroy {
let foundTask: Task | undefined;
if (result instanceof Task) {
for (const file of result.files) {
const escapedName = escapeRegex(result.files[0].attributes.originalFileName.replace(/.[^.]+$/g, ''));
foundTask = this.getTaskWithOriginalFileName(new RegExp(`${escapedName}(.[^.]+)$`));
const escapedName = escapeRegex(result.files[0].attributes.originalFileName.replace(/(_annot)?\.[^.]+$/g, ''));
foundTask = this.getTaskWithOriginalFileName(new RegExp(`^${escapedName}((_annot)?.[^.]+)$`));

if (foundTask) {
// found a task
Expand Down Expand Up @@ -326,7 +326,6 @@ export class TaskService implements OnDestroy {

if (!(firstLangObj === null || firstLangObj === undefined)) {
taskObj.asr = firstLangObj.asr;
console.log(`ASR NULL found: ${taskObj.asr}`);
}
}
const task = Task.fromAny(taskObj, AppSettings.configuration.api.commands, this.operations);
Expand Down Expand Up @@ -884,7 +883,6 @@ export class TaskService implements OnDestroy {
format.init(file.fullname, arrayBuffer);
if (format.channels > 1) {
const directory = new DirectoryInfo(path + file.attributes.originalFileName.replace(/\..+$/g, '') + '_dir/');
console.log(`split channels`);
const files = await format.splitChannelsToFiles(file.attributes.originalFileName.replace(/\..+$/g, ''), 'audio/wav', arrayBuffer);

if (this._splitPrompt === 'PENDING') {
Expand Down Expand Up @@ -1037,7 +1035,7 @@ export class TaskService implements OnDestroy {
const tasks: Task[] = this.taskList.getAllTasks();

for (const task of tasks) {
if (!(task.files[0].attributes.originalFileName === null || task.files[0].attributes.originalFileName === undefined)) {
if (task.files[0].attributes.originalFileName) {
for (const file of task.files) {
// console.log(`${cmpHash} === ${hash}`);
if ((task.operations[0].state === TaskState.PENDING || task.operations[0].state === TaskState.QUEUED
Expand Down
10 changes: 5 additions & 5 deletions apps/transcription-portal/src/app/shared/download.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export class DownloadService {
if (!(from === null || from === undefined)) {
const importConverter = from.obj;

console.log(`AudioFileName: ${audiofile.name ? audiofile.name + opResult.extension : opResult.fullname}`);
if (importConverter.name !== 'AnnotJSON') {
const importResult = importConverter.import({
name: audiofile.name ?? opResult.fullname,
name: audiofile.name ? audiofile.name.replace(/\.[^.]+$/g, "") + opResult.extension : opResult.fullname,
content,
encoding: 'utf-8',
type: 'text/plain'
Expand All @@ -90,17 +91,16 @@ export class DownloadService {
console.error(`importResult for import ${importConverter.name} is undefined!`);
}
} else {
annotJSON = JSON.parse(content);
annotJSON = OAnnotJSON.deserialize(JSON.parse(content));
}

if (!(annotJSON === null || annotJSON === undefined)) {
if (annotJSON) {
const levelnum = this.getLevelNumforConverter(exportConverter, annotJSON);

const conversion = exportConverter.obj.export(annotJSON, audiofile, levelnum);

if (conversion?.file) {
const file: File = FileInfo.getFileFromContent(conversion.file.content,
audiofile.name.replace(/\..+$/g, '') + exportConverter.obj.extension, conversion.file.type);
audiofile.name.replace(/\.[^.]+$/g, "") + exportConverter.obj.extension, conversion.file.type);

const fileInfo = new FileInfo(file.name, file.type, file.size, file);
resolve(fileInfo);
Expand Down
Loading

0 comments on commit 8028f41

Please sign in to comment.