diff options
author | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-05-19 00:52:45 +0200 |
---|---|---|
committer | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-05-19 00:52:45 +0200 |
commit | 3041334bd4686a8e0a9d434c2c99c13f39fa1ada (patch) | |
tree | f9abc0dff14d3d49d03a81134190cec14b053633 /backend/api | |
parent | bd2f7b29e92e3cda13b0a77590c4c3c1e09870d1 (diff) | |
parent | 684b924b88e5aea92c74e58f3656b4518e3950ce (diff) |
Merge branch 'redesign' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into redesign
Diffstat (limited to 'backend/api')
-rw-r--r-- | backend/api/api/Controllers/DatasetController.cs | 21 | ||||
-rw-r--r-- | backend/api/api/Controllers/ModelController.cs | 60 | ||||
-rw-r--r-- | backend/api/api/Interfaces/IModelService.cs | 1 | ||||
-rw-r--r-- | backend/api/api/Models/Model.cs | 6 | ||||
-rw-r--r-- | backend/api/api/Models/Predictor.cs | 25 | ||||
-rw-r--r-- | backend/api/api/Services/DatasetService.cs | 12 | ||||
-rw-r--r-- | backend/api/api/Services/FillAnEmptyDb.cs | 13 | ||||
-rw-r--r-- | backend/api/api/Services/ModelService.cs | 5 | ||||
-rw-r--r-- | backend/api/api/appsettings.json | 8 |
9 files changed, 81 insertions, 70 deletions
diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs index 80c9f2a9..6fb139bd 100644 --- a/backend/api/api/Controllers/DatasetController.cs +++ b/backend/api/api/Controllers/DatasetController.cs @@ -196,7 +196,7 @@ namespace api.Controllers string ext = ".csv"; - //nesto + //Check Directory if (!Directory.Exists(folderPath)) @@ -227,8 +227,6 @@ namespace api.Controllers dataset.fileId = fileModel1._id; - //nesto - dataset.isPreProcess = true; _datasetService.Create(dataset); @@ -281,19 +279,4 @@ namespace api.Controllers } } -} - -/* -{ - "_id": "", - "name": "name", - "description": "description", - "header" : ["ag","rt"], - "fileId" : "652", - "extension": "csb", - "isPublic" : true, - "accessibleByLink": true, - "dateCreated": "dateCreated", - "lastUpdated" : "proba12" -} -*/
\ No newline at end of file +}
\ No newline at end of file diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index c9e36ca4..be30ae6f 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -149,6 +149,26 @@ namespace api.Controllers return model; } + + // GET api/<ModelController>/byid/{id} + [HttpGet("byid/{id}")] + [Authorize(Roles = "User,Guest")] + public ActionResult<Model> GetModelById(string id) + { + string userId = getUserId(); + + if (userId == null) + return BadRequest(); + + var model = _modelService.GetOneModelById(userId, id); + + if (model == null) + return NotFound($"Model with id = {id} not found"); + + return model; + } + + //odraditi da vraca modele prema nekom imenu @@ -191,6 +211,8 @@ namespace api.Controllers return BadRequest("Bad parameters!");*/ model.uploaderId = getUserId(); + model.dateCreated = DateTime.Now; + model.lastUpdated = DateTime.Now; var existingModel = _modelService.GetOneModel(model.uploaderId, model.name); @@ -212,6 +234,44 @@ namespace api.Controllers } } + // POST api/<ModelController>/stealModel + [HttpPost("stealModel")] + [Authorize(Roles = "User,Guest")] + public ActionResult<Model> StealModel([FromBody] Model model)//, bool overwrite) + { + bool overwrite = false; + //username="" ako je GUEST + //Experiment e = _experimentService.Get(model.experimentId); umesto 1 ide e.inputColumns.Length TODO!!!!!!!!!!!!!!!!! + //model.inputNeurons = e.inputColumns.Length; + /*if (_modelService.CheckHyperparameters(1, model.hiddenLayerNeurons, model.hiddenLayers, model.outputNeurons) == false) + return BadRequest("Bad parameters!");*/ + + model.uploaderId = getUserId(); + model._id = ""; + model.dateCreated = DateTime.Now; + model.lastUpdated = DateTime.Now; + model.isPublic = false; + + var existingModel = _modelService.GetOneModel(model.uploaderId, model.name); + + + if (existingModel != null && !overwrite && model.validationSize < 1 && model.validationSize > 0) + return NotFound($"Model already exisits or validation size is not between 0-1"); + else + { + //_modelService.Create(model); + //return Ok(); + if (existingModel == null) + _modelService.Create(model); + else + { + _modelService.Replace(model); + } + + return CreatedAtAction(nameof(Get), new { id = model._id }, model); + } + } + // PUT api/<ModelController>/{name} [HttpPut("{name}")] [Authorize(Roles = "User,Guest")] diff --git a/backend/api/api/Interfaces/IModelService.cs b/backend/api/api/Interfaces/IModelService.cs index 8c4543de..41cd279c 100644 --- a/backend/api/api/Interfaces/IModelService.cs +++ b/backend/api/api/Interfaces/IModelService.cs @@ -6,6 +6,7 @@ namespace api.Services public interface IModelService { Model GetOneModel(string userId, string name); + Model GetOneModelById(string userId, string name); Model GetOneModel(string id); List<Model> GetMyModels(string userId); List<Model> GetMyModelsByType(string userId, string problemType); diff --git a/backend/api/api/Models/Model.cs b/backend/api/api/Models/Model.cs index a807316f..bbbf201e 100644 --- a/backend/api/api/Models/Model.cs +++ b/backend/api/api/Models/Model.cs @@ -14,18 +14,14 @@ namespace api.Models public string name { get; set; } public string description { get; set; } - //datetime public DateTime dateCreated { get; set; } public DateTime lastUpdated { get; set; } - //proveriti id - //public string experimentId { get; set; } //Neural net training public string type { get; set; } public string optimizer { get; set; } public string lossFunction { get; set; } - //public int inputNeurons { get; set; } public int hiddenLayers { get; set; } public string batchSize { get; set; } public string learningRate { get; set; } @@ -36,8 +32,6 @@ namespace api.Models public string[] metrics { get; set; } public int epochs { get; set; } - //public bool isTrained { get; set; } - //public NullValues[] nullValues { get; set; } public bool randomOrder { get; set; } public bool randomTestSet { get; set; } public float randomTestSetDistribution { get; set; } diff --git a/backend/api/api/Models/Predictor.cs b/backend/api/api/Models/Predictor.cs index 530257b2..bfe95a0f 100644 --- a/backend/api/api/Models/Predictor.cs +++ b/backend/api/api/Models/Predictor.cs @@ -29,27 +29,4 @@ namespace api.Models } -} - -/** -* Paste one or more documents here - -{ - "_id": { - "$oid": "625dc348b7856ace8a6f8702" - - }, - "uploaderId" : "6242ea59486c664208d4255c", - "inputs": ["proba", - "proba2", - "proba3" - ], - "output" : "izlaz", - "isPublic" : true, - "accessibleByLink" : true, - "dateCreated" : "2022-04-11T20:33:26.937+00:00", - "experimentId" : "Neki id eksperimenta", - "modelId" : "Neki id eksperimenta", - "h5FileId" : "Neki id eksperimenta", - "metrics" : [{ }] -}*/
\ No newline at end of file +}
\ No newline at end of file diff --git a/backend/api/api/Services/DatasetService.cs b/backend/api/api/Services/DatasetService.cs index f38a363b..0b84721e 100644 --- a/backend/api/api/Services/DatasetService.cs +++ b/backend/api/api/Services/DatasetService.cs @@ -104,16 +104,6 @@ namespace api.Services return dataset._id; } - /* -public bool CheckDb() -{ - Dataset? dataset = null; - dataset = _dataset.Find(dataset => dataset.username == "igrannonica").FirstOrDefault(); - - if (dataset != null) - return false; - else - return true; -}*/ + } } diff --git a/backend/api/api/Services/FillAnEmptyDb.cs b/backend/api/api/Services/FillAnEmptyDb.cs index 811e723a..cd35dc78 100644 --- a/backend/api/api/Services/FillAnEmptyDb.cs +++ b/backend/api/api/Services/FillAnEmptyDb.cs @@ -54,7 +54,7 @@ namespace api.Services dataset._id = ""; dataset.uploaderId = "000000000000000000000000"; - dataset.name = "Titanik dataset(public)"; + dataset.name = "Titanik dataset (public)"; dataset.description = "Titanik dataset"; dataset.fileId = _fileService.GetFileId(fullPath); dataset.extension = ".csv"; @@ -277,6 +277,7 @@ namespace api.Services model.lossFunction = "sparse_categorical_crossentropy"; model.hiddenLayers = 5; model.batchSize = "64"; + model.learningRate = "1"; model.outputNeurons = 0; model.layers = new[] { @@ -368,7 +369,7 @@ namespace api.Services dataset._id = ""; dataset.uploaderId = "000000000000000000000000"; dataset.name = "IMDB-Movie-Data Dataset (public)"; - dataset.description = "IMDB-Movie-Data Dataset(public)"; + dataset.description = "IMDB-Movie-Data Dataset (public)"; dataset.fileId = _fileService.GetFileId(fullPath); dataset.extension = ".csv"; dataset.isPublic = true; @@ -421,8 +422,8 @@ namespace api.Services model._id = ""; model.uploaderId = "000000000000000000000000"; - model.name = "IMDB model"; - model.description = "IMDB model"; + model.name = "IMDB model (public)"; + model.description = "IMDB model (public)"; model.dateCreated = DateTime.Now; model.lastUpdated = DateTime.Now; model.type = "regresioni"; @@ -579,8 +580,8 @@ namespace api.Services model._id = ""; model.uploaderId = "000000000000000000000000"; - model.name = "Churn model"; - model.description = "Churn model"; + model.name = "Churn model (public)"; + model.description = "Churn model (public)"; model.dateCreated = DateTime.Now; model.lastUpdated = DateTime.Now; model.type = "binarni-klasifikacioni"; diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs index e852d71f..71db6340 100644 --- a/backend/api/api/Services/ModelService.cs +++ b/backend/api/api/Services/ModelService.cs @@ -65,6 +65,11 @@ namespace api.Services return _model.Find(model => model.uploaderId == userId && model.name == name).FirstOrDefault(); } + public Model GetOneModelById(string userId, string id) + { + return _model.Find(model => model.uploaderId == userId && model._id == id).FirstOrDefault(); + } + public Model GetOneModel(string id) { return _model.Find(model => model._id == id).FirstOrDefault(); diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json index ec8f7dd8..44d63ac3 100644 --- a/backend/api/api/appsettings.json +++ b/backend/api/api/appsettings.json @@ -16,22 +16,22 @@ "UserStoreDatabaseSettings": { /* LocalHost*/ - "ConnectionString": "mongodb://127.0.0.1:27017/", + /*"ConnectionString": "mongodb://127.0.0.1:27017/", "DatabaseName": "si_project", "CollectionName": "users", "DatasetCollectionName": "Dataset", "ModelCollectionName": "Model", "PredictorCollectionName": "Predictor", "FilesCollectionName": "Files", - "ExperimentCollectionName": "Experiment" + "ExperimentCollectionName": "Experiment"*/ - /*"ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority", + "ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority", "DatabaseName": "si_db", "CollectionName": "users", "DatasetCollectionName": "Dataset", "ModelCollectionName": "Model", "PredictorCollectionName": "Predictor", "FilesCollectionName": "Files", - "ExperimentCollectionName": "Experiment" */ + "ExperimentCollectionName": "Experiment" } }
\ No newline at end of file |