diff options
author | Danijel Anđelković <adanijel99@gmail.com> | 2022-06-06 05:24:26 +0200 |
---|---|---|
committer | Danijel Anđelković <adanijel99@gmail.com> | 2022-06-06 05:24:26 +0200 |
commit | 5dc30c02319ba9fa8e8ddb33e9574272f05598fe (patch) | |
tree | e514ed32fe74b2b47dd04cd78e796daa4e28d6a1 /backend/api | |
parent | d1763481d6c08c955885ed490a284e634a56296b (diff) | |
parent | ec46487761e888935411cf4daa9e740913f2ee9b (diff) |
Merge branch 'redesign' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar
Diffstat (limited to 'backend/api')
-rw-r--r-- | backend/api/api/.config/dotnet-tools.json | 12 | ||||
-rw-r--r-- | backend/api/api/Controllers/DatasetController.cs | 32 | ||||
-rw-r--r-- | backend/api/api/Controllers/ModelController.cs | 32 | ||||
-rw-r--r-- | backend/api/api/Controllers/PredictorController.cs | 22 | ||||
-rw-r--r-- | backend/api/api/Interfaces/IDatasetService.cs | 3 | ||||
-rw-r--r-- | backend/api/api/Interfaces/IModelService.cs | 3 | ||||
-rw-r--r-- | backend/api/api/Models/Model.cs | 4 | ||||
-rw-r--r-- | backend/api/api/Services/DatasetService.cs | 20 | ||||
-rw-r--r-- | backend/api/api/Services/FileService.cs | 2 | ||||
-rw-r--r-- | backend/api/api/Services/FillAnEmptyDb.cs | 36 | ||||
-rw-r--r-- | backend/api/api/Services/ModelService.cs | 18 |
11 files changed, 151 insertions, 33 deletions
diff --git a/backend/api/api/.config/dotnet-tools.json b/backend/api/api/.config/dotnet-tools.json new file mode 100644 index 00000000..e80b80ff --- /dev/null +++ b/backend/api/api/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "6.0.5", + "commands": [ + "dotnet-ef" + ] + } + } +}
\ No newline at end of file diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs index c93ac9db..9a3c3d86 100644 --- a/backend/api/api/Controllers/DatasetController.cs +++ b/backend/api/api/Controllers/DatasetController.cs @@ -282,5 +282,37 @@ namespace api.Controllers return Ok($"Dataset with ID = {id} deleted"); } + + [HttpPut("UpdateAccessibleByLink/{datasetId}")] + [Authorize(Roles = "User")] + public ActionResult UpdateAccessibleByLink(string datasetId, [FromBody] bool accessibleByLink) + { + string uploaderId = getUserId(); + + Dataset dataset = _datasetService.GetOneDataset(datasetId); + + if (uploaderId != dataset.uploaderId) + return Unauthorized(); + + _datasetService.UpdateAccessibleByLink(datasetId, accessibleByLink); + + return Ok(dataset.accessibleByLink); + } + + [HttpPut("UpdateIsPublic/{datasetId}")] + [Authorize(Roles = "User")] + public ActionResult UpdateIsPublic(string datasetId, [FromBody] bool isPublic) + { + string uploaderId = getUserId(); + + Dataset dataset = _datasetService.GetOneDataset(datasetId); + + if (uploaderId != dataset.uploaderId) + return Unauthorized(); + + _datasetService.UpdateIsPublic(datasetId, isPublic); + + return Ok(dataset.isPublic); + } } }
\ No newline at end of file diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index c574de28..c7dfe89c 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -312,6 +312,38 @@ namespace api.Controllers } + [HttpPut("UpdateAccessibleByLink/{modelId}")] + [Authorize(Roles = "User")] + public ActionResult UpdateAccessibleByLink(string modelId, [FromBody] bool accessibleByLink) + { + string uploaderId = getUserId(); + + Model model = _modelService.GetOneModel(modelId); + + if (uploaderId != model.uploaderId) + return Unauthorized(); + + _modelService.UpdateAccessibleByLink(modelId, accessibleByLink); + + return Ok(model.accessibleByLink); + } + + [HttpPut("UpdateIsPublic/{modelId}")] + [Authorize(Roles = "User")] + public ActionResult UpdateIsPublic(string modelId, [FromBody] bool isPublic) + { + string uploaderId = getUserId(); + + Model model = _modelService.GetOneModel(modelId); + + if (uploaderId != model.uploaderId) + return Unauthorized(); + + _modelService.UpdateIsPublic(modelId, isPublic); + + return Ok(model.isPublic); + } + } public class TrainModelObject diff --git a/backend/api/api/Controllers/PredictorController.cs b/backend/api/api/Controllers/PredictorController.cs index 6ff7746a..56095553 100644 --- a/backend/api/api/Controllers/PredictorController.cs +++ b/backend/api/api/Controllers/PredictorController.cs @@ -21,7 +21,7 @@ namespace api.Controllers private readonly IHubContext<ChatHub> _ichat; private readonly IModelService _modelService; - public PredictorController(IPredictorService predictorService, IConfiguration configuration, IJwtToken Token, IMlConnectionService mlConnectionService, IExperimentService experimentService,IUserService userService, IHubContext<ChatHub> ichat,IModelService modelService) + public PredictorController(IPredictorService predictorService, IConfiguration configuration, IJwtToken Token, IMlConnectionService mlConnectionService, IExperimentService experimentService, IUserService userService, IHubContext<ChatHub> ichat, IModelService modelService) { _predictorService = predictorService; jwtToken = Token; @@ -78,7 +78,7 @@ namespace api.Controllers //public ActionResult<List<Predictor>> Search(string name) //{ // string username = getUsername(); - + // if (username == null) // return BadRequest(); @@ -138,7 +138,7 @@ namespace api.Controllers List<Predictor> lista = _predictorService.SortPredictors(userId, ascdsc, latest); - if(latest == 0) + if (latest == 0) return lista; else { @@ -155,19 +155,23 @@ namespace api.Controllers [HttpPost("add")] public async Task<ActionResult<Predictor>> Post([FromBody] Predictor predictor) { - var user=_userService.GetUserById(predictor.uploaderId); + var user = _userService.GetUserById(predictor.uploaderId); predictor.dateCreated = DateTime.Now.ToUniversalTime(); var model = _modelService.GetOneModel(predictor.modelId); - if (model == null || user==null) + if (model == null || user == null) return BadRequest("Model not found or user doesnt exist"); - Predictor p=_predictorService.Exists(predictor.modelId, predictor.experimentId); - if (p == null) + Predictor p = _predictorService.Exists(predictor.modelId, predictor.experimentId); + + if (p == null) { _predictorService.Create(predictor); - else + } + else { + predictor._id = p._id; _predictorService.Update(p._id, predictor); + } if (ChatHub.CheckUser(user._id)) foreach(var connection in ChatHub.getAllConnectionsOfUser(user._id)) - await _ichat.Clients.Client(connection).SendAsync("NotifyPredictor", predictor._id,model.name); + await _ichat.Clients.Client(connection).SendAsync("NotifyPredictor", predictor._id, model._id); return CreatedAtAction(nameof(Get), new { id = predictor._id }, predictor); } diff --git a/backend/api/api/Interfaces/IDatasetService.cs b/backend/api/api/Interfaces/IDatasetService.cs index 2f7d0010..5a91c82b 100644 --- a/backend/api/api/Interfaces/IDatasetService.cs +++ b/backend/api/api/Interfaces/IDatasetService.cs @@ -19,5 +19,8 @@ namespace api.Services public void Update(Dataset dataset); string GetDatasetId(string fileId); //bool CheckDb(); + + public void UpdateAccessibleByLink(string datasetId, bool accessibleByLink); + public void UpdateIsPublic(string datasetId, bool isPublic); } } diff --git a/backend/api/api/Interfaces/IModelService.cs b/backend/api/api/Interfaces/IModelService.cs index 41cd279c..949c7278 100644 --- a/backend/api/api/Interfaces/IModelService.cs +++ b/backend/api/api/Interfaces/IModelService.cs @@ -19,6 +19,9 @@ namespace api.Services void Delete(string userId, string name); bool CheckHyperparameters(int inputNeurons, int hiddenLayerNeurons, int hiddenLayers, int outputNeurons); bool CheckDb(); + + public void UpdateAccessibleByLink(string modelId, bool accessibleByLink); + public void UpdateIsPublic(string modelId, bool isPublic); } } diff --git a/backend/api/api/Models/Model.cs b/backend/api/api/Models/Model.cs index bbbf201e..6278cf8a 100644 --- a/backend/api/api/Models/Model.cs +++ b/backend/api/api/Models/Model.cs @@ -44,7 +44,7 @@ namespace api.Models { - public Layer(int layerNumber, string activationFunction, int neurons, string regularisation, float regularisationRate) + public Layer(int layerNumber, string activationFunction, int neurons, string regularisation, string regularisationRate) { this.layerNumber = layerNumber; this.activationFunction = activationFunction; @@ -57,7 +57,7 @@ namespace api.Models public string activationFunction { get; set; } public int neurons { get; set; } public string regularisation { get; set; } - public float regularisationRate { get; set; } + public string regularisationRate { get; set; } } } diff --git a/backend/api/api/Services/DatasetService.cs b/backend/api/api/Services/DatasetService.cs index 0b84721e..cd27f275 100644 --- a/backend/api/api/Services/DatasetService.cs +++ b/backend/api/api/Services/DatasetService.cs @@ -75,7 +75,7 @@ namespace api.Services public Dataset GetOneDataset(string userId, string id) { - return _dataset.Find(dataset => dataset.uploaderId == userId && dataset._id == id && dataset.isPreProcess).FirstOrDefault(); + return _dataset.Find(dataset => (dataset.uploaderId == userId || dataset.isPublic || dataset.accessibleByLink) && dataset._id == id && dataset.isPreProcess).FirstOrDefault(); } public Dataset GetOneDatasetN(string userId, string name) { @@ -104,6 +104,22 @@ namespace api.Services return dataset._id; } - + + public void UpdateAccessibleByLink(string datasetId, bool accessibleByLink) + { + Dataset dataset = _dataset.Find(dataset => dataset._id == datasetId).FirstOrDefault(); + dataset.accessibleByLink = accessibleByLink; + + _dataset.ReplaceOne(dataset => dataset._id == datasetId, dataset); + } + + public void UpdateIsPublic(string datasetId, bool isPublic) + { + Dataset dataset = _dataset.Find(dataset => dataset._id == datasetId).FirstOrDefault(); + dataset.isPublic = isPublic; + + _dataset.ReplaceOne(dataset => dataset._id == datasetId, dataset); + } + } } diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs index 6ef74ca1..e5b7945f 100644 --- a/backend/api/api/Services/FileService.cs +++ b/backend/api/api/Services/FileService.cs @@ -28,7 +28,7 @@ namespace api.Services public string GetFilePath(string id, string uploaderId) { FileModel file; - if (_dataset.Find(x=>x.fileId==id && x.isPublic==true).FirstOrDefault()!=null) + if (_dataset.Find(x=>x.fileId==id && (x.isPublic==true ||x.accessibleByLink==true)).FirstOrDefault()!=null) file = _file.Find(x => x._id == id).FirstOrDefault(); else file = _file.Find(x => x._id == id && x.uploaderId == uploaderId).FirstOrDefault(); diff --git a/backend/api/api/Services/FillAnEmptyDb.cs b/backend/api/api/Services/FillAnEmptyDb.cs index cd35dc78..c74de67d 100644 --- a/backend/api/api/Services/FillAnEmptyDb.cs +++ b/backend/api/api/Services/FillAnEmptyDb.cs @@ -117,10 +117,10 @@ namespace api.Services model.outputNeurons = 0; model.layers = new[] { - new Layer ( 0,"sigmoid", 3,"l1", 1f ), - new Layer ( 1,"sigmoid", 3,"l1", 1f ), - new Layer ( 2,"sigmoid", 3,"l1", 1f ), - new Layer ( 3,"sigmoid", 3,"l1", 1f ), + new Layer ( 0,"sigmoid", 3,"l1", "0" ), + new Layer ( 1,"sigmoid", 3,"l1", "0" ), + new Layer ( 2,"sigmoid", 3,"l1", "0" ), + new Layer ( 3,"sigmoid", 3,"l1", "0" ), }; model.outputLayerActivationFunction = "sigmoid"; model.metrics = new string[] { }; @@ -281,11 +281,11 @@ namespace api.Services model.outputNeurons = 0; model.layers = new[] { - new Layer ( 0,"softmax", 3,"l1", 3f ), - new Layer ( 1,"softmax", 3,"l1", 3f ), - new Layer ( 2,"softmax", 3,"l1", 3f ), - new Layer ( 3,"softmax", 3,"l1", 3f ), - new Layer ( 4,"softmax", 3,"l1", 3f ) + new Layer ( 0,"softmax", 3,"l1", "0" ), + new Layer ( 1,"softmax", 3,"l1", "0" ), + new Layer ( 2,"softmax", 3,"l1", "0" ), + new Layer ( 3,"softmax", 3,"l1", "0" ), + new Layer ( 4,"softmax", 3,"l1", "0" ) }; model.outputLayerActivationFunction = "softmax"; model.metrics = new string[] { }; @@ -435,9 +435,9 @@ namespace api.Services model.outputNeurons = 0; model.layers = new[] { - new Layer ( 0,"relu", 3,"l1", 1f ), - new Layer ( 1,"relu", 3,"l1", 1f ), - new Layer ( 2,"relu", 3,"l1", 1f ) + new Layer ( 0,"relu", 3,"l1", "0" ), + new Layer ( 1,"relu", 3,"l1", "0" ), + new Layer ( 2,"relu", 3,"l1", "0" ) }; model.outputLayerActivationFunction = "relu"; model.metrics = new string[] { }; @@ -593,10 +593,10 @@ namespace api.Services model.outputNeurons = 0; model.layers = new[] { - new Layer ( 0,"sigmoid", 3,"l1", 1f ), - new Layer ( 1,"sigmoid", 3,"l1", 1f ), - new Layer ( 2,"sigmoid", 3,"l1", 1f ), - new Layer ( 3,"sigmoid", 3,"l1", 1f ) + new Layer ( 0,"sigmoid", 3,"l1", "0" ), + new Layer ( 1,"sigmoid", 3,"l1", "0" ), + new Layer ( 2,"sigmoid", 3,"l1", "0" ), + new Layer ( 3,"sigmoid", 3,"l1", "0" ) }; model.outputLayerActivationFunction = "sigmoid"; model.metrics = new string[] { }; @@ -748,8 +748,8 @@ namespace api.Services model.outputNeurons = 0; model.layers = new[] { - new Layer ( 0,"relu", 3,"l1", 1f ), - new Layer ( 1,"relu", 3,"l1", 1f ) + new Layer ( 0,"relu", 3,"l1", "0" ), + new Layer ( 1,"relu", 3,"l1", "0" ) }; model.outputLayerActivationFunction = "relu"; model.metrics = new string[] { }; diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs index 71db6340..07581fc9 100644 --- a/backend/api/api/Services/ModelService.cs +++ b/backend/api/api/Services/ModelService.cs @@ -67,7 +67,7 @@ namespace api.Services public Model GetOneModelById(string userId, string id) { - return _model.Find(model => model.uploaderId == userId && model._id == id).FirstOrDefault(); + return _model.Find(model => (model.uploaderId == userId || model.isPublic || model.accessibleByLink) && model._id == id).FirstOrDefault(); } public Model GetOneModel(string id) @@ -106,5 +106,21 @@ namespace api.Services return true; } + + public void UpdateAccessibleByLink(string modelId, bool accessibleByLink) + { + Model model = _model.Find(model => model._id == modelId).FirstOrDefault(); + model.accessibleByLink = accessibleByLink; + + _model.ReplaceOne(model => model._id == modelId, model); + } + + public void UpdateIsPublic(string modelId, bool isPublic) + { + Model model = _model.Find(model => model._id == modelId).FirstOrDefault(); + model.isPublic = isPublic; + + _model.ReplaceOne(model => model._id == modelId, model); + } } } |