aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_elements/model-load/model-load.component.ts
blob: 73872694c5db34c9eb7a93cbe6c385e02f844144 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { Component, OnInit, ViewChild, Output, EventEmitter } from '@angular/core';
import Shared from 'src/app/Shared';
import Model, { ActivationFunction, LossFunction, LossFunctionBinaryClassification, LossFunctionMultiClassification, LossFunctionRegression, Metrics, MetricsBinaryClassification, MetricsMultiClassification, MetricsRegression, NullValueOptions, Optimizer, ProblemType } from 'src/app/_data/Model';
import { ModelsService } from 'src/app/_services/models.service';
import { GraphComponent } from '../graph/graph.component';


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

  @ViewChild(GraphComponent) graph!: GraphComponent;
  @Output() selectedModelChangeEvent = new EventEmitter<Model>();

  newModel: Model = new Model();
  myModels?: Model[];
  selectedModel?: Model;

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

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

  showMyModels: boolean = true;

  constructor(private modelsService: ModelsService) {
    this.modelsService.getMyModels().subscribe((models) => {
      this.myModels = models;
    });
  }

  ngOnInit(): void {
  }
  batchSizePower:number=1;
  updateBatchSize()
  {
    this.newModel.batchSize=2**this.batchSizePower;
  }

  updateGraph() {
    this.graph.update();
  }

  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);
    }
  }

  uploadModel() {
    this.getMetrics();

    this.newModel.uploaderId = Shared.userId;

    this.modelsService.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
      //this.selectedModel = 
    }, (error) => {
      Shared.openDialog('Greška', 'Model sa unetim nazivom već postoji u Vašoj kolekciji. Promenite 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;
    }
  }

  viewMyModelsForm() {
    this.showMyModels = true;
  }
  viewNewModelForm() {
    this.showMyModels = false;
  }

  selectThisModel(model: Model) {
    this.selectedModel = model;
    this.selectedModelChangeEvent.emit(this.selectedModel);
  }

}