aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_elements/model-load/model-load.component.ts
blob: 1d38de68417632804190b8f48fa5688d19192f0a (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Component, OnInit } from '@angular/core';
import Shared from 'src/app/Shared';
import Model, { ActivationFunction, Encoding, LossFunction, LossFunctionBinaryClassification, LossFunctionMultiClassification, LossFunctionRegression, Metrics, MetricsBinaryClassification, MetricsMultiClassification, MetricsRegression, NullValueOptions, Optimizer, ProblemType } from 'src/app/_data/Model';
import { ModelsService } from 'src/app/_services/models.service';

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

  newModel: Model = new Model();

  ProblemType = ProblemType;
  Encoding = Encoding;
  ActivationFunction = ActivationFunction;
  metrics: any = Metrics;
  LossFunction = LossFunction;
  Optimizer = Optimizer;
  Object = Object;
  document = document;
  shared = Shared;

  term: string = "";
  selectedProblemType: string = '';
  selectedMetrics = [];
  tempTestSetDistribution = 90;
  lossFunction: any = LossFunction;

  constructor(private models: ModelsService) { }

  ngOnInit(): void {
  }

  getMetrics() {
    this.newModel.metrics = [];
    let cb = document.getElementsByName("cbmetrics");

    for (let i = 0; i < cb.length; i++) {
      let chb = <HTMLInputElement>cb[i];
      if (chb.checked == true)
        this.newModel.metrics.push(chb.value);
    }
  }

  addModel() {
    this.getMetrics();

    this.newModel.randomTestSetDistribution = 1 - Math.round(this.tempTestSetDistribution / 100 * 10) / 10;
    this.newModel.username = Shared.username;

    this.models.addModel(this.newModel).subscribe((response) => {
      Shared.openDialog('Model dodat', 'Model je uspešno dodat u bazu.');
      // treba da se selektuje nov model u listi modela
    }, (error) => {
      Shared.openDialog('Greška', 'Model sa unetim nazivom već postoji u Vašoj kolekciji.\nPromenite naziv modela i nastavite sa kreiranim datasetom.');
    });
  }

  filterOptions() {
    switch (this.newModel.type) {
      case 'regresioni':
        this.lossFunction = LossFunctionRegression;
        this.metrics = MetricsRegression;
        break;
      case 'binarni-klasifikacioni':
        this.lossFunction = LossFunctionBinaryClassification;
        this.metrics = MetricsBinaryClassification;
        break;
      case 'multi-klasifikacioni':
        this.lossFunction = LossFunctionMultiClassification;
        this.metrics = MetricsMultiClassification;
        break;
      default:
        break;
    }
  }
}