Skip to content

Commit 79e1376

Browse files
authored
Merge pull request #31 from xeptagondev/iverfiy-rdc-be
Iverfiy rdc be
2 parents b0c622c + cbc6fde commit 79e1376

File tree

4 files changed

+81
-17
lines changed

4 files changed

+81
-17
lines changed

apps/triage/src/app/app.service.ts

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import { PerspectiveClientService } from '@iverify/perspective-client/src/lib/pe
88
import { MlServiceType } from '@iverify/iverify-common';
99
import { TranslateService } from './TranslateService/TranslateService';
1010

11+
const RadioFilterConvert = {
12+
"Désinfo - Politique": "POLITIQUE",
13+
"Désinfo - Sécurité": "SÉCURITÉ",
14+
"Désinfo - Genre et Société":"GENRE ET SOCIÉTÉ",
15+
"Désinfo - Environment et Santé":"ENVIRONNEMENT ET SANTÉ",
16+
}
17+
1118
@Injectable()
1219
export class AppService {
1320
private readonly logger = new Logger('TriageAppService');
@@ -23,7 +30,7 @@ export class AppService {
2330
private translate: TranslateService
2431
){}
2532

26-
async pullRadioMessages(): Promise<number> {
33+
async pullRadioMessages(): Promise<any> {
2734
if (this.config.enableRadioMessages != 'true') {
2835
this.logger.log('Radio messages feature disabled')
2936
return
@@ -51,23 +58,47 @@ export class AppService {
5158
const pageIndex = pageCount - 1;
5259
let createdItems = [];
5360
let createdPosts = [];
54-
for(let page = pageIndex ; page >=0 ; page --) {
55-
const list = await this.unitedwaveClient.getPosts(page,startTime).toPromise();
56-
for (let i = list.length - 1; i >= 0; i--) {
57-
const post = list[i];
58-
const title = ['radio', post?.keywords, post?.date_reported]
59-
.filter(Boolean)
60-
.join(' - ');
61+
for (let page = pageIndex; page >= 0; page--) {
62+
const list = await this.unitedwaveClient
63+
.getPosts(page, startTime)
64+
.toPromise();
65+
for (let i = list.length - 1; i >= 0; i--) {
66+
const post = list[i];
67+
const title = ['radio', post?.keywords, post?.date_reported]
68+
.filter(Boolean)
69+
.join(' - ');
70+
const arr = post.filters.split(',');
71+
72+
const realValue = arr.find((item) => RadioFilterConvert[item]) || '';
73+
const category:string = RadioFilterConvert[realValue] || '';
74+
75+
console.log('posts-category', category, title);
6176
// check duplication
62-
const isDuplicate = this.isDuplicatePost(post, createdPosts);
63-
if (!isDuplicate) {
64-
const item = await this.checkClient.createItemFromRadio(post?.clip_url, title, post?.source_text, post?.date_reported).toPromise();
65-
if(!item.error) {
77+
const isDuplicate = this.isDuplicatePost(post, createdPosts);
78+
if (!isDuplicate) {
79+
try {
80+
const item = await this.checkClient.createItemFromRadio(
81+
post?.clip_url,
82+
title,
83+
post?.source_text,
84+
post?.date_reported
85+
).toPromise();
86+
87+
if (item && !item.error) {
6688
createdItems = [...createdItems, item];
6789
createdPosts = [...createdPosts, post];
90+
91+
if (category) {
92+
const annotationList = item.data.createProjectMedia.project_media.tasks.edges;
93+
94+
await this.checkClient.UpdateRadioCategory(category, annotationList).toPromise();
95+
}
6896
}
97+
} catch (error) {
98+
console.error('Error while creating item:', error);
6999
}
70100
}
101+
}
71102
}
72103
this.logger.log(`Created ${createdItems.length} items.`)
73104
return createdItems.length;

libs/common/src/lib/tasks-labels.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export const TasksLabels = {
4141
upload_file: 'Upload Files',
4242
audio_url:'audio_url',
4343
message:'message',
44-
original_reported_date: 'original_reported_date'
44+
original_reported_date: 'original_reported_date',
45+
meedan_category:'category'
4546
},
4647
es: {
4748
claim: 'Declaración',
@@ -85,7 +86,8 @@ export const TasksLabels = {
8586
upload_file: 'Upload Files',
8687
audio_url:'audio_url',
8788
message:'message',
88-
original_reported_date: 'original_reported_date'
89+
original_reported_date: 'original_reported_date',
90+
meedan_category:'categoria'
8991
},
9092
fr: {
9193
claim: 'Affirmation',
@@ -129,7 +131,8 @@ export const TasksLabels = {
129131
upload_file: 'Téléchargements de fichiers',
130132
audio_url:'url_audio',
131133
message:'message',
132-
original_reported_date: 'date_de_rapport_originale'
134+
original_reported_date: 'date_de_rapport_originale',
135+
meedan_category:'Catégorie'
133136
},
134137
mkd: {
135138
claim: 'Тврдење',
@@ -173,6 +176,7 @@ export const TasksLabels = {
173176
upload_file: 'Upload Files',
174177
audio_url:'audio_url',
175178
message:'message',
176-
original_reported_date: 'original_reported_date'
179+
original_reported_date: 'original_reported_date',
180+
meedan_category:'category'
177181
},
178182
}

libs/meedan-check-client/src/lib/helper.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ export class CheckClientHelperService {
101101
project_media {
102102
dbid
103103
id
104+
tasks {
105+
edges {
106+
node {
107+
id
108+
fieldset
109+
label
110+
}
111+
}
112+
}
104113
}
105114
}
106115
}

libs/meedan-check-client/src/lib/meedan-check-client.service.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class MeedanCheckClientService {
189189
}
190190

191191
private getAnnotationId(annotationList: any[], label: string): string {
192-
console.log('getAnnotationId', annotationList)
192+
// console.log('getAnnotationId', annotationList)
193193
return annotationList
194194
.filter((edge) => edge.node.label === label)
195195
.map((edge) => edge.node.id)
@@ -246,6 +246,26 @@ export class MeedanCheckClientService {
246246
return this.postData(combinedQuery, headers);
247247
}
248248

249+
UpdateRadioCategory(
250+
category: string,
251+
annotationList?: any[],
252+
): Observable<any> {
253+
const headers = this.config.headers;
254+
const categoryId = this.getAnnotationId(
255+
annotationList,
256+
TasksLabels[this.lang].meedan_category
257+
);
258+
console.log('UpdateRadioCategory',categoryId,category)
259+
const combinedQuery = this.helper.buildAnnotationItemsCombinedFromWpMutation(
260+
categoryId,
261+
'task_response_single_choice',
262+
'response_single_choice',
263+
category
264+
);
265+
266+
return this.postData(combinedQuery, headers);
267+
}
268+
249269
private async handleFiles(
250270
files: string[],
251271
headers: any,

0 commit comments

Comments
 (0)