aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/training/training.component.ts
blob: f60734cc9b13790cad3003ce2514f1b13837e578 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import Shared from '../Shared';
import Experiment from '../_data/Experiment';
import Model from '../_data/Model';
import { ExperimentsService } from '../_services/experiments.service';
import { ModelsService } from '../_services/models.service';

@Component({
  selector: 'app-training',
  templateUrl: './training.component.html',
  styleUrls: ['./training.component.css']
})
export class TrainingComponent implements OnInit{

  myExperiments?: Experiment[];
  selectedExperiment?: Experiment;
  selectedModel?: Model;

  trainingResult: any;

  term: string = "";

  constructor(private modelsService: ModelsService, private route: ActivatedRoute, private experimentsService: ExperimentsService) { 
  }

  ngOnInit(): void { 
    this.route.queryParams.subscribe(params => {
      let expId =this.route.snapshot.paramMap.get("id");

      this.experimentsService.getMyExperiments().subscribe((experiments) => {
        this.myExperiments = experiments;
        this.selectedExperiment = this.myExperiments.filter(x => x._id == expId)[0];
      });
    });
  }

  selectThisExperiment(experiment: Experiment) {
    this.selectedExperiment = experiment;
  }

  selectModel(model: Model) {
    this.selectedModel = model;
  }

  trainModel() {
    this.trainingResult = undefined;

    if (this.selectedExperiment == undefined) {
      Shared.openDialog("Greška", "Molimo Vas da izaberete eksperiment iz kolekcije.");
      return;
    }
    if (this.selectedModel == undefined) {
      Shared.openDialog("Greška", "Molimo Vas da izaberete model.");
      return;
    }
    this.modelsService.trainModel(this.selectedModel._id, this.selectedExperiment._id).subscribe((response: any) => {
      //console.log('Train model complete!', response);
      Shared.openDialog("Obaveštenje", "Treniranje modela je uspešno završeno!");
      this.trainingResult = response;
    });
  }
}