Skip to content

Commit

Permalink
Merge branch 'detection-features' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mayalb committed Oct 5, 2023
2 parents 0758add + 40a9b9b commit a809fff
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react';
import ButtonProgress from 'components/ButtonProgress';
import { ProjectGraphRecord, AnnotationRecord } from '@celluloid/types';
import AnnotationService from 'services/AnnotationService';

import {getConcept} from '../../../scenes/Video/api/Annotation'
import { getConcept } from '../../../scenes/Video/api/Annotation';

interface Props {
annotations: AnnotationRecord[];
project: ProjectGraphRecord;
buttonName: string;

}
interface Props {
annotations: AnnotationRecord[];
project: ProjectGraphRecord;
buttonName: string;
}

// import React from 'react'

Expand All @@ -21,104 +21,152 @@ interface Props {

// export default CSVAnnotationExport;

interface State {
loading: boolean;
dat: any;
}

export default (
(
class extends React.Component<Props> {
constructor(props:any){
super(props)
this.state={
dat : 'projectName, startTime, stopTime, user, sequecing, text, ontology,subConcept1,subConcept2,subConcept3' + '\n'
}
this.getData= this.getData.bind(this)

}
getData(d:any){
this.setState({dat:d})
return this.state
}
render() {

const {annotations, project } = this.props;

return (
<ButtonProgress
variant="contained"
color="primary"
size="small"
onClick={async() => {
// const p = Promise.resolve('Hello World');
let data = 'projectName, startTime, stopTime, user, text, ontology,subConcept1,subConcept2,subConcept3, relationConcept' + '\n';
// console.log('annotations: ', annotations.)
let subConcept1= ''
let subConcept2= ''
let subConcept3= ''
let relationConcept=''
await Promise.all(annotations.map(async (item) => {
console.log('item ', item.user.username)
let res= await getConcept(item.id)
// console.log('list des concept',res)
let ontology=res[0]
// console.log('print ontology ',ontology, item.text)
if(ontology=== undefined|| ontology===''){
ontology=''
// console.log('dkhlna khawti')
}else{
let superClasses=res[1]

for(let i=0;i< superClasses.length; i++){
subConcept1= superClasses[0]
if(subConcept1=== undefined){
subConcept1=''
}
subConcept2= superClasses[1]
if(subConcept2=== undefined){
subConcept2=''
}
subConcept3= superClasses[2]
if(subConcept3=== undefined){
subConcept3=''
}
}
relationConcept=res[2]

if(relationConcept=== undefined|| relationConcept===''){
relationConcept=''
}
}
let ontologyData = ontology;
let textData = item.text !== '' ? item.text : 'none';
data += project.shareName + ' , ' + item.startTime + ' , ' + item.stopTime
+ ' , ' + item.user.username + ' , ' + textData
+ ' , ' + ontologyData + ' , ' + subConcept1
+ ' , '+ subConcept2 +' , ' + subConcept3+' , ' + relationConcept+'\n';
// this.setState({dat:data})

this.setState({dat:data})
return this.state
} ))
let dublinCore='-------------------------------------------------------------Metadata-----------------------------------------------------------\n';

let resultat=dublinCore+Object.values(this.state)

var blob = new Blob([resultat.toString()], {type: 'text/csv'});
if ((window.navigator as any).msSaveOrOpenBlob) {
(window.navigator as any).msSaveBlob(blob, 'annotations_CSV_' + project.shareName);
} else {
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = 'annotations_' + project.shareName + '.csv';
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
export default (class extends React.Component<Props, State> {
constructor(props: any) {
super(props);
this.state = {
loading: false,
dat:
'projectName, startTime, stopTime, user, sequecing, text, ontology,subConcept1,subConcept2,subConcept3' +
'\n',
};
}

render() {
const { project } = this.props;

return (
<ButtonProgress
variant="contained"
color="primary"
size="small"
loading={this.state.loading}
onClick={async () => {
// const p = Promise.resolve('Hello World');
this.setState((prevState) => {
console.log('updated when clicked to ', {
...prevState,
loading: true,
});
return { ...prevState, loading: true };
});
let data =
'projectName, startTime, stopTime, user, text, emotion, autoDetect, semiAutoDetect, ontology,subConcept1,subConcept2,subConcept3, relationConcept' +
'\n';
// console.log('annotations: ', annotations.)
let subConcept1 = '';
let subConcept2 = '';
let subConcept3 = '';
let relationConcept = '';
let annotations: AnnotationRecord[] = await AnnotationService.list(
project.id,
{ autoDetect: true }
);

await Promise.all(
annotations.map(async (item: AnnotationRecord) => {
// console.log('item ', item.user.username);
let res = await getConcept(item.id);
// console.log('list des concept',res)
let ontology = res[0];
// console.log('print ontology ',ontology, item.text)
if (ontology === undefined || ontology === '') {
ontology = '';
// console.log('dkhlna khawti')
} else {
let superClasses = res[1];

for (let i = 0; i < superClasses.length; i++) {
subConcept1 = superClasses[0];
if (subConcept1 === undefined) {
subConcept1 = '';
}
subConcept2 = superClasses[1];
if (subConcept2 === undefined) {
subConcept2 = '';
}
subConcept3 = superClasses[2];
if (subConcept3 === undefined) {
subConcept3 = '';
}
}
>
{this.props.buttonName} CSV
</ButtonProgress>
);
relationConcept = res[2];

if (relationConcept === undefined || relationConcept === '') {
relationConcept = '';
}
}
let ontologyData = ontology;
let textData = item.text !== '' ? item.text : 'none';
data +=
project.shareName +
' , ' +
item.startTime +
' , ' +
item.stopTime +
' , ' +
item.user.username +
' , ' +
textData +
' , ' +
item.emotion +
' , ' +
item.autoDetect +
' , ' +
item.semiAutoDetect +
' , ' +
ontologyData +
' , ' +
subConcept1 +
' , ' +
subConcept2 +
' , ' +
subConcept3 +
' , ' +
relationConcept +
'\n';

this.setState((prevState) => ({ ...prevState, dat: data }));

return this.state;
})
);
let dublinCore =
'-------------------------------------------------------------Metadata-----------------------------------------------------------\n';

let resultat = dublinCore + Object.values({ dat: this.state.dat });

var blob = new Blob([resultat.toString()], { type: 'text/csv' });
if ((window.navigator as any).msSaveOrOpenBlob) {
(window.navigator as any).msSaveBlob(
blob,
'annotations_CSV_' + project.shareName
);
} else {
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = 'annotations_' + project.shareName + '.csv';
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}

}));


this.setState((prevState) => {
console.log('updated when finished to ', {
...prevState,
loading: false,
});
return { ...prevState, loading: false };
});
}}
>
{this.props.buttonName} CSV
</ButtonProgress>
);
}
});
2 changes: 1 addition & 1 deletion packages/client/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit a809fff

Please sign in to comment.