<commit_before>import { Component, OnInit, Inject, Input, ViewEncapsulation, Output, EventEmitter } from '@angular/core';
import { TaskSubmissionService } from 'src/app/common/services/task-submission.service';
import { map } from 'rxjs/operators';
import { alertService } from 'src/app/ajs-upgraded-providers';
import { Subject } from 'rxjs';

export interface ISubmissionTab {
  id?: number;
  label?: string;
  timestamp: Date;
  timestampString?: string;
  content?: [{ label: string; result: string }];
  task?: any;
}

export class SubmissionTab implements ISubmissionTab {
  timestamp = new Date();
  id?: number;
  label?: string;
  timestampString?: string;
  content?: [{ label: string; result: string }];
  task?: any;
  constructor() {}
}

@Component({
  selector: 'task-submission-history',
  templateUrl: './task-submission-history.component.html',
  styleUrls: ['./task-submission-history.component.scss'],
})
export class TaskSubmissionHistoryComponent implements OnInit {
  @Input() task: any;
  @Output() hasNoData = new EventEmitter<boolean>();
  tabs: SubmissionTab[];
  timestamps: string[];
  selectedTab: SubmissionTab = new SubmissionTab();
  noDataFlag: boolean = false;
  @Input() refreshTrigger: Subject<boolean>;

  constructor(
    @Inject(alertService) private alerts: any,
    @Inject(TaskSubmissionService) private submissions: TaskSubmissionService,
  ) { }

  ngOnInit() {
    this.fillTabs();

    this.refreshTrigger.subscribe( () => {
      this.fillTabs();
   });
  }

  private handleError(error: any) {
    this.alerts.add('danger', 'Error: ' + error, 6000);
  }

  fillTabs(): void {
    this.submissions.getLatestSubmissionsTimestamps(this.task);
    let transformedData = this.submissions.getLatestSubmissionsTimestamps(this.task).pipe(
      map(data => {
        return data.result.map((ts: number) => {
          return { timestamp: new Date(ts * 1000), content: '', timestampString: ts };
        });
      })
    );

    transformedData.subscribe(
      tabs => {
          if (tabs) {
            this.tabs = tabs;
            this.noDataFlag = false;
            this.hasNoData.emit(this.noDataFlag);
          }
        this.openSubmission(tabs[0]);
      },
      error => {
        if (error) {
          this.tabs = [{timestamp: new Date()}];
          this.selectedTab.content = [{label: 'No Data', result: 'There are no submissions for this task at the moment.' }];
          this.noDataFlag = true;
          this.hasNoData.emit(this.noDataFlag);
        }
      }
    );
  }

  openSubmission(tab: SubmissionTab) {
    this.selectedTab.timestamp = tab.timestamp;
    this.selectedTab.timestampString = tab.timestampString;
    this.submissions.getSubmissionByTimestamp(this.task, tab.timestampString)
      .subscribe(
        sub => {
          this.selectedTab.content = sub;
        },
        error => {
          this.selectedTab.content = [{label: 'Error', result: error }];
        }
      );
  }
}
<commit_msg>ENHANCE: change timestamp array to an array of objects with additonal data.<commit_after>import { Component, OnInit, Inject, Input, ViewEncapsulation, Output, EventEmitter } from '@angular/core';
import { TaskSubmissionService } from 'src/app/common/services/task-submission.service';
import { map } from 'rxjs/operators';
import { alertService } from 'src/app/ajs-upgraded-providers';
import { Subject } from 'rxjs';

export interface ISubmissionTab {
  id?: number;
  label?: string;
  timestamp: Date;
  timestampString?: string;
  content?: [{ label: string; result: string }];
  task?: any;
  taskStatus?: any;
  submissionStatus?: any;
  createdAt?: any;
  updatedAt?: any;
  taskId?: any;
}

export class SubmissionTab implements ISubmissionTab {
  timestamp = new Date();
  id?: number;
  label?: string;
  timestampString?: string;
  content?: [{ label: string; result: string }];
  task?: any;
  taskStatus?: any;
  submissionStatus?: any;
  createdAt?: any;
  updatedAt?: any;
  taskId?: any;
  constructor() {}
}

@Component({
  selector: 'task-submission-history',
  templateUrl: './task-submission-history.component.html',
  styleUrls: ['./task-submission-history.component.scss'],
})
export class TaskSubmissionHistoryComponent implements OnInit {
  @Input() task: any;
  @Output() hasNoData = new EventEmitter<boolean>();
  tabs: SubmissionTab[];
  timestamps: string[];
  selectedTab: SubmissionTab = new SubmissionTab();
  noDataFlag: boolean = false;
  @Input() refreshTrigger: Subject<boolean>;

  constructor(
    @Inject(alertService) private alerts: any,
    @Inject(TaskSubmissionService) private submissions: TaskSubmissionService,
  ) { }

  ngOnInit() {
    this.fillTabs();

    this.refreshTrigger.subscribe( () => {
      this.fillTabs();
   });
  }

  private handleError(error: any) {
    this.alerts.add('danger', 'Error: ' + error, 6000);
  }

  fillTabs(): void {
    this.submissions.getLatestSubmissionsTimestamps(this.task);
    let transformedData = this.submissions.getLatestSubmissionsTimestamps(this.task).pipe(
      map(data => {
        return data.result.map((ts: any) => {
          return {
            timestamp: new Date(ts.submission_timestamp * 1000),
            content: '',
            timestampString: ts.submission_timestamp,
            taskStatus: ts.result_task_status,
            submissionStatus: ts.status,
            createdAt: ts.created_at,
            updatedAt: ts.updated_at,
            taskId: ts.task_id};
        });
      })
    );

    transformedData.subscribe(
      tabs => {
        if (tabs.length === 0) {
          this.tabs = [{timestamp: new Date()}];
          this.selectedTab.content = [{label: 'No Data', result: 'There are no submissions for this task at the moment.' }];
          this.noDataFlag = true;
          this.hasNoData.emit(this.noDataFlag);
        } else {
          this.tabs = tabs;
          this.noDataFlag = false;
          this.hasNoData.emit(this.noDataFlag);
        }
        this.openSubmission(tabs[0]);
      },
      error => {
        this.handleError(error);
      }
    );
  }

  openSubmission(tab: SubmissionTab) {
    this.selectedTab.timestamp = tab.timestamp;
    this.selectedTab.timestampString = tab.timestampString;
    this.selectedTab.taskStatus = tab.taskStatus;
    this.selectedTab.submissionStatus = tab.submissionStatus;

    this.submissions.getSubmissionByTimestamp(this.task, tab.timestampString)
      .subscribe(
        sub => {
          this.selectedTab.content = sub;
        },
        error => {
          this.selectedTab.content = [{label: 'Error', result: error }];
        }
      );
  }
}

{'fraction_non_alphanumeric': 0.13370599788487686, 'fraction_numerical': 0.0028705242483758877, 'mean_word_length': 3.0464547677261615, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '831794', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1982, 'n_words': 426}