Skip to content

Commit

Permalink
[MOD] Refactoring and Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
KennBro committed Nov 2, 2020
1 parent 8bbeb29 commit 0e985cf
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 361 deletions.
110 changes: 55 additions & 55 deletions frontend/src/app/@core/data/fecalface-image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,119 +15,119 @@ import { catchError, map } from 'rxjs/operators';
import { NbGlobalLogicalPosition, NbGlobalPhysicalPosition, NbGlobalPosition, NbComponentStatus } from '@nebular/theme';

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class FecalfaceImageService {
private data = {};
private globalResult: any = {};
export class FecalfaceImageService {

private data = {};
private globalResult: any = {};

private email: string;
private username: string;
public response: any;
private visualTasks: any;

constructor(private http: HttpClient,
private dialogService: NbDialogService) {}

/* Global Data */
public initialize() {
public initialize() {
this.globalResult = {};
console.log('dataService Initialize globalResult :', this.globalResult)
console.log('dataService Initialize globalResult :', this.globalResult);
return this.globalResult;
}
public pushResult(key, value) {
}

public pushResult(key, value) {
this.globalResult[key] = value;
console.log('dataService Push globalResult :', this.globalResult)
}
public pullResult() {
console.log('dataService Pull globalResult :', this.globalResult)
console.log('dataService Push globalResult :', this.globalResult);
}

public pullResult() {
console.log('dataService Pull globalResult :', this.globalResult);
return this.globalResult;
}
public removeResult(key) {
}

public removeResult(key) {
delete this.globalResult[key];
console.log('dataService Remove globalResult :', this.globalResult)
}
console.log('dataService Remove globalResult :', this.globalResult);
}

/* Http Service */
// TODO : Use environment to set processUrl
// private readonly processUrl: string = 'http://127.0.0.1:5000/';
private readonly processUrl: string = environment.apiURL;

// Get test
public postTest$(): Observable<any> {
return this.http.post<any>(this.processUrl + 'testing', 1);
}

// Generic GET request
public getRequest$(url: string): Observable<any> {
return this.http.get<any>(this.processUrl + url);
}

// Generic POST request
public postRequest$(module: string, param: any): Observable<any> {
console.log("POST ", this.processUrl + module, param);
console.log('POST ', this.processUrl + module, param);
return this.http.post<any>(this.processUrl + module, param);
}

/* Get Avatar from instagram */
public getInstagramAvatar(username: string, lang: string) {
console.log('Get Instagram Avatar', this.processUrl);
this.postRequest$('instagram', {username: username, lang: lang})
.subscribe(this.responseAvatar,
err => console.error('Ops: ', err.message),
() => console.log('Completed Source')
() => console.log('Completed Source'),
);
}

public detectFaceAvatar(image: string, lang: string) {
console.log('Detect Face in Avatar');
this.postRequest$('fecaldetect', {image_name: image, lang: lang})
.subscribe(this.responseAvatar,
err => console.error('Ops: ', err.message),
() => console.log('Completed Detect')
() => console.log('Completed Detect'),
);
}

public makeupFaceAvatar(image: string) {
console.log('Makeup Face in Avatar');
this.postRequest$('fecalmakeup', {image_name: image})
.subscribe(this.responseAvatar,
err => console.error('Ops: ', err.message),
() => console.log('Completed Makeup')
() => console.log('Completed Makeup'),
);
}

public recogFaceAvatar(image: string) {
console.log('Recognition Face in Avatar');
this.postRequest$('fecalrecog', {image_name: image})
.subscribe(this.responseAvatar,
err => console.error('Ops: ', err.message),
() => console.log('Completed Recognition')
() => console.log('Completed Recognition'),
);
}

// Callbacks
private responseAvatar = (data: any): any => {
// this.globalResult['source'] = data;
this.globalResult[data['module']] = data;
console.log('************************************************************************');
console.log('JSON :', this.globalResult);

if (data['module'] == 'source' && data['status'] == 'Profile Ok') {
if (data['module'] === 'source' && data['status'] === 'Profile Ok') {
console.log('Image', data['username'] + '.jpg');
console.log('Launch face detect');
this.detectFaceAvatar(data['username'] + '.jpg', this.globalResult['lang'])
this.detectFaceAvatar(data['username'] + '.jpg', this.globalResult['lang']);
}
if (data['module'] == 'detect' && data['status'] == "Face detected") {
if (data['module'] === 'detect' && data['status'] === 'Face detected') {
console.log('Launch face makeup');
console.log('Image', this.globalResult['source']['username']);
this.makeupFaceAvatar(this.globalResult['source']['username'] + '.jpg');
}
if (data['module'] == 'makeup') {
if (data['module'] === 'makeup') {
console.log('Launch face recognition');
console.log('Image', this.globalResult['source']['username']);
this.recogFaceAvatar(this.globalResult['source']['username'] + '.jpg');
Expand All @@ -138,38 +138,38 @@ export class FecalfaceImageService {
// Generic Callback
private processResponse = (data: any): any => {
this.response = data;
let module_name = this.response.result[0].module;
let param = this.response.result[1].param;
const module_name = this.response.result[0].module;
const param = this.response.result[1].param;
console.log('************************************************************************');
console.log('Module :', module_name);
console.log('Param :', param);
console.log('************************************************************************');


this.globalResult['taskresume'][0].PS++;
this.globalResult[module_name] = data;

for (let indexTaskexec in this.globalResult['taskexec']) {
if (this.globalResult['taskexec'][indexTaskexec].module == module_name &&
this.globalResult['taskexec'][indexTaskexec].param == param) {
for (const indexTaskexec in this.globalResult['taskexec']) {
if (this.globalResult['taskexec'][indexTaskexec].module === module_name &&
this.globalResult['taskexec'][indexTaskexec].param === param) {

this.globalResult['taskexec'][indexTaskexec].state = "SUCCESS";
console.log("State change..................SUCCESS");
this.globalResult['taskexec'][indexTaskexec].state = 'SUCCESS';
console.log('State change..................SUCCESS');
console.log(this.globalResult[module_name].result[2].validation);

// Reprocess validation
if (this.globalResult['taskexec'][indexTaskexec].score > 99) {
this.globalResult[module_name].result[2].validation = "hard";
this.globalResult[module_name].result[2].validation = 'hard';
} else if (this.globalResult['taskexec'][indexTaskexec].score > 9) {
this.globalResult[module_name].result[2].validation = "soft";
this.globalResult[module_name].result[2].validation = 'soft';
} else {
this.globalResult[module_name].result[2].validation = "no";
this.globalResult[module_name].result[2].validation = 'no';
}

}
}
}

console.log('Gathered :', this.globalResult);
};
}
}

}
18 changes: 0 additions & 18 deletions frontend/src/app/@theme/layouts/fecalface/fecalface.layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,9 @@ import { Component } from '@angular/core';
styleUrls: ['./fecalface.layout.scss'],
template: `
<nb-layout windowMode>
<!--
<nb-layout-header fixed>
<ngx-header></ngx-header>
</nb-layout-header>
-->
<!--
<nb-sidebar class="menu-sidebar" tag="menu-sidebar" responsive>
<ng-content select="nb-menu"></ng-content>
</nb-sidebar>
-->
<nb-layout-column>
<ng-content select="router-outlet"></ng-content>
</nb-layout-column>
<!--
<nb-layout-footer fixed>
<ngx-footer></ngx-footer>
</nb-layout-footer>
-->
</nb-layout>
`,
})
Expand Down
34 changes: 14 additions & 20 deletions frontend/src/app/pages/fecalface/avatar/avatar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,56 @@ import { environment } from '../../../../environments/environment';
templateUrl: 'avatar.component.html',
styleUrls: ['avatar.component.scss'],
})
export class AvatarComponent {
export class AvatarComponent implements OnInit {
@Input() private data: any;
public avatarDesc : string = "";
public avatarName : string = "";
public avatarSummary : string = "";
public apiURL : string = "";
public avatarURL : string = "";
public avatarDesc: string = '';
public avatarName: string = '';
public avatarSummary: string = '';
public apiURL: string = '';
public avatarURL: string = '';

ngOnInit() {
console.log("Avatar Component");
console.log('Avatar Component');
this.apiURL = environment.apiURL;
console.log("Environment : ", this.apiURL);


if (this.data['module'] == 'source') {
if (this.data['module'] === 'source') {
this.avatarName = this.data['d1'];
this.avatarDesc = this.data['d2'];
this.avatarSummary = this.data['d3'];
if (this.data['url_img'] == undefined) {
if (this.data['url_img'] === undefined) {
this.avatarURL = this.apiURL + 'static/default/notfound.png';
} else {
this.avatarURL = this.apiURL + this.data['url_img'];
}
console.log("Avatar URL", this.avatarURL);
}

if (this.data['module'] == 'detect') {
if (this.data['module'] === 'detect') {
this.avatarName = this.data['d1'];
this.avatarDesc = this.data['d2'];
this.avatarSummary = this.data['d3'];
if (this.data['url_img'] == undefined) {
if (this.data['url_img'] === undefined) {
this.avatarURL = this.apiURL + 'static/default/undetected.png';
} else {
this.avatarURL = this.apiURL + this.data['url_img'];
}
console.log("Avatar URL", this.avatarURL);
}

if (this.data['module'] == 'makeup') {
if (this.data['module'] === 'makeup') {
this.avatarName = this.data['d1'];
this.avatarDesc = this.data['d2'];
this.avatarSummary = this.data['d3'];
this.avatarURL = this.apiURL + this.data['url_img'];
console.log("Avatar URL", this.avatarURL);
}

if (this.data['module'] == 'recog') {
if (this.data['module'] === 'recog') {
this.avatarName = this.data['d1'];
this.avatarDesc = this.data['d2'];
this.avatarSummary = this.data['d3'];
if (this.data['url_img'] == undefined) {
if (this.data['url_img'] === undefined) {
this.avatarURL = this.apiURL + 'static/default/notrecon.png';
} else {
this.avatarURL = this.apiURL + this.data['url_img'];
}
console.log("Avatar URL", this.avatarURL);
}
}
}
27 changes: 12 additions & 15 deletions frontend/src/app/pages/fecalface/fecalface.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class FecalfaceComponent implements OnInit, OnDestroy {

private alive = true;
public flipped: Boolean = false;
public selectedLang: string = "spanish";
public selectedItem: string = "instagram";
public selectedStep: string = "Detect";
public selectedLang: string = 'spanish';
public selectedItem: string = 'instagram';
public selectedStep: string = 'Detect';
public result: any;

constructor(private fecalfaceImageService: FecalfaceImageService) { }
Expand All @@ -29,26 +29,23 @@ export class FecalfaceComponent implements OnInit, OnDestroy {
}

toggleFlipViewAndProcess(lang, rrss, username) {
console.log("lang", this.selectedLang);
console.log("rrss", this.selectedItem);
console.log("username", username);

this.flipped = !this.flipped;

this.result = this.fecalfaceImageService.initialize();
console.log("Global data initialize", this.result);
console.log('Global data initialize', this.result);

this.result = this.fecalfaceImageService.pushResult("lang", lang);
this.result = this.fecalfaceImageService.getInstagramAvatar(username, this.selectedLang);
this.result = this.fecalfaceImageService.pushResult('lang', lang);
this.result = this.fecalfaceImageService.getInstagramAvatar(username, this.selectedLang);
this.result = this.fecalfaceImageService.pullResult();

console.log("Global result", this.result);
console.log('Global result', this.result);
}

toggleFlipView() {
this.flipped = !this.flipped;
}

ngOnDestroy() {
this.alive = false;
}
Expand All @@ -64,10 +61,10 @@ export class FecalfaceComponent implements OnInit, OnDestroy {
}

async downloadImg(url: string) {
console.log("Image : ", url)
const a = document.createElement("a");
console.log('Image : ', url);
const a = document.createElement('a');
a.href = await this.toDataURL(environment.apiURL + url);
a.download = "avatar-fecalface.jpg";
a.download = 'avatar-fecalface.jpg';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
Expand Down
Loading

0 comments on commit 0e985cf

Please sign in to comment.