aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/api/.gitignore1
-rw-r--r--backend/api/api/Controllers/AuthController.cs8
-rw-r--r--backend/api/api/Controllers/DatasetController.cs237
-rw-r--r--backend/api/api/Controllers/FileController.cs121
-rw-r--r--backend/api/api/Controllers/FileUploadController.cs47
-rw-r--r--backend/api/api/Controllers/ModelController.cs202
-rw-r--r--backend/api/api/Controllers/PredictorController.cs231
-rw-r--r--backend/api/api/Controllers/UserController.cs142
-rw-r--r--backend/api/api/Controllers/WebSocketController.cs63
-rw-r--r--backend/api/api/Data/UserStoreDatabaseSettings.cs3
-rw-r--r--backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs3
-rw-r--r--backend/api/api/Models/Dataset.cs46
-rw-r--r--backend/api/api/Models/FileModel.cs16
-rw-r--r--backend/api/api/Models/JwtToken.cs42
-rw-r--r--backend/api/api/Models/Model.cs47
-rw-r--r--backend/api/api/Models/Predictor.cs22
-rw-r--r--backend/api/api/Models/User.cs2
-rw-r--r--backend/api/api/Program.cs17
-rw-r--r--backend/api/api/Services/AuthService.cs6
-rw-r--r--backend/api/api/Services/DatasetService.cs45
-rw-r--r--backend/api/api/Services/FileService.cs35
-rw-r--r--backend/api/api/Services/IAuthService.cs1
-rw-r--r--backend/api/api/Services/IDatasetService.cs11
-rw-r--r--backend/api/api/Services/IFileService.cs10
-rw-r--r--backend/api/api/Services/IMLWebSocketService.cs7
-rw-r--r--backend/api/api/Services/IMlConnectionService.cs8
-rw-r--r--backend/api/api/Services/IModelService.cs18
-rw-r--r--backend/api/api/Services/IPredictorService.cs18
-rw-r--r--backend/api/api/Services/IUserService.cs6
-rw-r--r--backend/api/api/Services/MLWebSocketService.cs68
-rw-r--r--backend/api/api/Services/MlConnectionService.cs18
-rw-r--r--backend/api/api/Services/ModelService.cs72
-rw-r--r--backend/api/api/Services/PredictorService.cs68
-rw-r--r--backend/api/api/Services/TempFileService.cs33
-rw-r--r--backend/api/api/Services/TempRemovalService.cs73
-rw-r--r--backend/api/api/Services/UserService.cs37
-rw-r--r--backend/api/api/api.csproj3
-rw-r--r--backend/api/api/appsettings.json16
-rw-r--r--backend/microservice/PythonServer/project/api/socket2/client.py16
-rw-r--r--backend/microservice/PythonServer/project/api/socket2/server.py39
-rw-r--r--backend/microservice/__pycache__/mlservice.cpython-310.pycbin0 -> 5009 bytes
-rw-r--r--backend/microservice/api.py (renamed from backend/microservice/PythonServer/project/api/api.py)0
-rw-r--r--backend/microservice/data.html (renamed from backend/microservice/PythonServer/project/api/templates/data.html)0
-rw-r--r--backend/microservice/fcnn.ipynb322
-rw-r--r--backend/microservice/index.html (renamed from backend/microservice/PythonServer/project/api/templates/index.html)0
-rw-r--r--backend/microservice/ml_socket.py25
-rw-r--r--backend/microservice/mlservice.py5
-rw-r--r--backend/microservice/network1.gv.pdfbin0 -> 19913 bytes
-rw-r--r--backend/microservice/titanic.csv (renamed from backend/microservice/PythonServer/project/api/titanic.csv)0
49 files changed, 1838 insertions, 372 deletions
diff --git a/backend/api/api/.gitignore b/backend/api/api/.gitignore
index 242abea5..9a89b63c 100644
--- a/backend/api/api/.gitignore
+++ b/backend/api/api/.gitignore
@@ -5,6 +5,7 @@
##Ignore contents for UploadedFiles Folder
UploadedFiles/*
+TempFiles/*
# User-specific files
*.rsuser
diff --git a/backend/api/api/Controllers/AuthController.cs b/backend/api/api/Controllers/AuthController.cs
index 6dfe483a..901454e1 100644
--- a/backend/api/api/Controllers/AuthController.cs
+++ b/backend/api/api/Controllers/AuthController.cs
@@ -30,6 +30,12 @@ namespace api.Controllers
return Ok(_auth.Login(user));
}
+ [HttpPost("guestToken")]
+ public async Task<ActionResult<string>> guestToken()
+ {
+
+ return Ok(_auth.GuestToken());
+ }
[HttpGet("Auth")]
[Authorize(Roles ="User")]
@@ -49,8 +55,6 @@ namespace api.Controllers
return Ok(newToken);
-
-
}
diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs
index d022d6d2..bae05ba9 100644
--- a/backend/api/api/Controllers/DatasetController.cs
+++ b/backend/api/api/Controllers/DatasetController.cs
@@ -1,6 +1,9 @@
using api.Models;
using api.Services;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Net.Http.Headers;
+using System.Net.Http.Headers;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -11,39 +14,156 @@ namespace api.Controllers
public class DatasetController : ControllerBase
{
private readonly IDatasetService _datasetService;
+ private JwtToken jwtToken;
- public DatasetController(IDatasetService datasetService)
+ public DatasetController(IDatasetService datasetService, IConfiguration configuration)
{
_datasetService = datasetService;
+ jwtToken = new JwtToken(configuration);
}
+ // GET: api/<DatasetController>/mydatasets
+ [HttpGet("mydatasets")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Dataset>> Get()
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ //ako bude trebao ID, samo iz baze uzeti
+
+ return _datasetService.GetMyDatasets(username);
+ }
+
+ // GET: api/<DatasetController>/datesort/{ascdsc}/{latest}
+ //asc - rastuce 1
+ //desc - opadajuce 0
+ //ako se posalje 0 kao latest onda ce da izlista sve u nekom poretku
+ [HttpGet("datesort/{ascdsc}/{latest}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Dataset>> SortDatasets(bool ascdsc, int latest)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ List<Dataset> lista = _datasetService.SortDatasets(username, ascdsc, latest);
- // GET: api/<DatasetController>/{id}/datasets
- [HttpGet("{id}/datasets")]
- public ActionResult<List<Dataset>> Get(string id)
+
+ if (latest == 0)
+ return lista;
+ else
+ {
+ List<Dataset> novaLista = new List<Dataset>();
+ for (int i = 0; i < latest; i++)
+ novaLista.Add(lista[i]);
+ return novaLista;
+ }
+ }
+
+ // GET: api/<DatasetController>/publicdatasets
+ [HttpGet("publicdatasets")]
+ public ActionResult<List<Dataset>> GetPublicDS()
{
- return _datasetService.GetAllDatesets(id);
+ return _datasetService.GetPublicDatasets();
}
- // GET api/<DatasetController>/{id}/{name}
- [HttpGet("{id}/{name}")]
- public ActionResult<Dataset> Get(string id, string name)
+ //SEARCH za datasets (public ili private sa ovim imenom )
+ // GET api/<DatasetController>/search/{name}
+ [HttpGet("search/{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Dataset>> Search(string name)
{
- var dataset = _datasetService.GetOneDataset(id, name);
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ //ako bude trebao ID, samo iz baze uzeti
+
+ return _datasetService.SearchDatasets(name, username);
+ }
+
+
+ // GET api/<DatasetController>/{name}
+ //get odredjeni dataset
+ [HttpGet("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<Dataset> Get(string name)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var dataset = _datasetService.GetOneDataset(username, name);
if (dataset == null)
- return NotFound($"Dataset with name = {name} not found");
+ return NotFound($"Dataset with name = {name} not found or dataset is not public");
return dataset;
}
- // POST api/<DatasetController>
- [HttpPost("post")]
+ /*za pretragu vratiti dataset koji je public
+ public ActionResult<Dataset> Get(string name)
+ {
+
+
+ var dataset = _datasetService.GetOneDataset(username, name);
+
+ if (dataset == null)
+ return NotFound($"Dataset with name = {name} or user with username = {username} not found");
+
+ return dataset;
+ }
+ */
+
+ // POST api/<DatasetController>/add
+ [HttpPost("add")]
+ [Authorize(Roles = "User,Guest")]
public ActionResult<Dataset> Post([FromBody] Dataset dataset)
{
- var existingUser = _datasetService.GetOneDataset(dataset.uploaderId,dataset.name);
+ //da li ce preko tokena da se ubaci username ili front salje
+ //dataset.username = usernameToken;
+ //username = "" ako je GUEST DODAO
+ var existingDataset = _datasetService.GetOneDataset(dataset.username, dataset.name);
- if (existingUser != null)
+ if (existingDataset != null)
return NotFound($"Dateset with name = {dataset.name} exisits");
else
{
@@ -53,30 +173,61 @@ namespace api.Controllers
}
}
- // PUT api/<DatasetController>/5
- [HttpPut("{id}/{name}")]
- public ActionResult Put(string id, string name, [FromBody] Dataset dataset)
+ // PUT api/<DatasetController>/{name}
+ [HttpPut("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult Put(string name, [FromBody] Dataset dataset)
{
- var existingDataset = _datasetService.GetOneDataset(id, name);
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var existingDataset = _datasetService.GetOneDataset(username, name);
//ne mora da se proverava
if (existingDataset == null)
- return NotFound($"Dataset with name = {name} not found");
+ return NotFound($"Dataset with name = {name} or user with username = {username} not found");
+
+ dataset.lastUpdated = DateTime.UtcNow;
- _datasetService.Update(id, name, dataset);
- return NoContent();
+ _datasetService.Update(username, name, dataset);
+
+ return Ok($"Dataset with name = {name} updated");
}
- // DELETE api/<DatasetController>/5
- [HttpDelete("{id}")]
- public ActionResult Delete(string id, string name)
+ // DELETE api/<DatasetController>/name
+ [HttpDelete("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult Delete(string name)
{
- var dataset = _datasetService.GetOneDataset(id, name);
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var dataset = _datasetService.GetOneDataset(username, name);
if (dataset == null)
- return NotFound($"Dataset with name = {name} not found");
+ return NotFound($"Dataset with name = {name} or user with username = {username} not found");
- _datasetService.Delete(dataset.uploaderId,dataset.name);
+ _datasetService.Delete(dataset.username, dataset.name);
return Ok($"Dataset with name = {name} deleted");
@@ -86,27 +237,15 @@ namespace api.Controllers
/*
{
- "_id": "",
- "uploaderId" : "uploaderId",
- "name" : "name",
- "description" : "description",
- "dateCreated" : "dateCreated",
- "inputColumns" : [2,3,4],
- "columnToPredict" : 1,
- "randomTestSet" : true,
- "randomTestSetDistribution" : 1,
- "type" : "type",
- "encoding" : "encoding",
- "optimizer" : "optimizer",
- "lossFunction" : "lossFunction",
- "inputNeurons" : 2,
- "hiddenLayerNeurons" : 3,
- "hiddenLayers" : 8,
- "batchSize" : 6,
- "inputLayerActivationFunction" : "inputLayerActivationFunction",
- "hiddenLayerActivationFunction" : "hiddenLayerActivationFunction",
- "outputLayerActivationFunction" : "outputLayerActivationFunction",
- "extension" : "extension"
-
+ "_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
diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs
new file mode 100644
index 00000000..a6bab373
--- /dev/null
+++ b/backend/api/api/Controllers/FileController.cs
@@ -0,0 +1,121 @@
+using System.Net.Http.Headers;
+using api.Models;
+using api.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Net.Http.Headers;
+namespace api.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class FileController : ControllerBase
+ {
+ private string[] permittedExtensions = { ".csv" };
+ private readonly IConfiguration _configuration;
+ private JwtToken _token;
+ private IFileService _fileservice;
+ public FileController(IConfiguration configuration,IFileService fileService)
+ {
+ _configuration = configuration;
+ _token = new JwtToken(configuration);
+ _fileservice = fileService;
+
+ }
+
+
+ [HttpPost("Csv")]
+ [Authorize(Roles = "User,Guest")]
+ public async Task<ActionResult<string>> CsvUpload([FromForm]IFormFile file)
+ {
+
+ //get username from jwtToken
+ string username;
+ string folderName;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = _token.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }else
+ return BadRequest();
+ if (username == "")
+ {
+ folderName = "TempFiles";
+ }
+ else
+ {
+ folderName = "UploadedFiles";
+ }
+
+
+ //Check filetype
+ var filename=file.FileName;
+ var ext=Path.GetExtension(filename).ToLowerInvariant();
+ var name = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant();
+ if (string.IsNullOrEmpty(ext) || ! permittedExtensions.Contains(ext)) {
+ return BadRequest("Wrong file type");
+ }
+ var folderPath=Path.Combine(Directory.GetCurrentDirectory(),folderName, username);
+ //Check Directory
+ if (!Directory.Exists(folderPath))
+ {
+ Directory.CreateDirectory(folderPath);
+ }
+ //Index file if same filename
+ var fullPath = Path.Combine(folderPath, filename);
+ int i=0;
+
+ while (System.IO.File.Exists(fullPath)) {
+ i++;
+ fullPath = Path.Combine(folderPath,name+i.ToString()+ext);
+ }
+
+
+ //Write file
+ using (var stream=new FileStream(fullPath, FileMode.Create))
+ {
+ await file.CopyToAsync(stream);
+ }
+ FileModel fileModel= new FileModel();
+ fileModel.path=fullPath;
+ fileModel.username=username;
+ fileModel.date = DateTime.Now.ToUniversalTime();
+ fileModel =_fileservice.Create(fileModel);
+
+
+ return Ok(fileModel);
+ }
+
+ [HttpGet("Download")]
+ [Authorize(Roles = "User,Guest")]
+ public async Task<ActionResult> DownloadFile(string id)
+ {
+ //Get Username
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = _token.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ string filePath = _fileservice.GetFilePath(id, username);
+ if (filePath == null)
+ return BadRequest();
+
+ return File(System.IO.File.ReadAllBytes(filePath),"application/octet-stream", Path.GetFileName(filePath));
+
+ }
+
+ }
+}
diff --git a/backend/api/api/Controllers/FileUploadController.cs b/backend/api/api/Controllers/FileUploadController.cs
deleted file mode 100644
index 46e7f4f9..00000000
--- a/backend/api/api/Controllers/FileUploadController.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-namespace api.Controllers
-{
- [Route("api/[controller]")]
- [ApiController]
- public class FileUploadController : ControllerBase
- {
- private string[] permittedExtensions = { ".csv" };
-
-
- [HttpPost("Csv")]
- [Authorize(Roles = "User")]
- public async Task<ActionResult<string>> CsvUpload([FromForm]IFormFile file,[FromForm]string username)//???Umesto username poslati jwt odakle se moze preuzeti username radi sigurnosti
- {
- var filename=file.FileName;
- var ext=Path.GetExtension(filename).ToLowerInvariant();
- var name = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant();
- if (string.IsNullOrEmpty(ext) || ! permittedExtensions.Contains(ext)) {
- return BadRequest("Wrong file type");
- }
- var folderPath=Path.Combine(Directory.GetCurrentDirectory(),"UploadedFiles",username);
- if (!Directory.Exists(folderPath))
- {
- Directory.CreateDirectory(folderPath);
- }
-
- var fullPath = Path.Combine(folderPath, filename);
- int i=0;
-
- while (System.IO.File.Exists(fullPath)) {
- i++;
- fullPath = Path.Combine(folderPath,name+i.ToString()+ext);
- }
-
-
-
- using (var stream=new FileStream(fullPath, FileMode.Create))
- {
- await file.CopyToAsync(stream);
- }
-
- return Ok();
- }
- }
-}
diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs
new file mode 100644
index 00000000..b4a4b4f2
--- /dev/null
+++ b/backend/api/api/Controllers/ModelController.cs
@@ -0,0 +1,202 @@
+using api.Models;
+using api.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Net.Http.Headers;
+using System.Net.Http.Headers;
+
+namespace api.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class ModelController : ControllerBase
+ {
+
+ private IMlConnectionService _mlService;
+ private readonly IModelService _modelService;
+ private JwtToken jwtToken;
+
+
+ public ModelController(IMlConnectionService mlService, IModelService modelService, IConfiguration configuration)
+ {
+ _mlService = mlService;
+ _modelService = modelService;
+ jwtToken = new JwtToken(configuration);
+ }
+
+ [HttpPost("sendModel")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<string>> Test([FromBody] object model)
+ {
+ var result = await _mlService.SendModelAsync(model);
+ return Ok(result);
+ }
+
+ // GET: api/<ModelController>/mymodels
+ [HttpGet("mymodels")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Model>> Get()
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ return _modelService.GetMyModels(username);
+ }
+
+ // vraca svoj model prema nekom imenu
+ // GET api/<ModelController>/{name}
+ [HttpGet("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<Model> Get(string name)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var model = _modelService.GetOneModel(username, name);
+
+ if (model == null)
+ return NotFound($"Model with name = {name} not found");
+
+ return model;
+ }
+
+ //odraditi da vraca modele prema nekom imenu
+
+
+
+ // moze da vraca sve modele pa da se ovde odradi orderByDesc
+ //odraditi to i u Datasetove i Predictore
+ // GET: api/<ModelController>/getlatestmodels/{number}
+ [HttpGet("getlatestmodels/{latest}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Model>> GetLatestModels(int latest)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ //ako bude trebao ID, samo iz baze uzeti
+
+ List<Model> lista = _modelService.GetLatestModels(username);
+
+ List<Model> novaLista = new List<Model>();
+
+ for (int i = 0; i < latest; i++)
+ novaLista.Add(lista[i]);
+
+ return novaLista;
+ }
+
+
+
+
+ // POST api/<ModelController>/add
+ [HttpPost("add")]
+ [Authorize(Roles = "User,Guest")]
+ public ActionResult<Model> Post([FromBody] Model model)
+ {
+ //username="" ako je GUEST
+ if (_modelService.CheckHyperparameters(model.inputNeurons, model.hiddenLayerNeurons, model.hiddenLayers, model.outputNeurons) == false)
+ return BadRequest("Bad parameters!");
+
+ var existingModel = _modelService.GetOneModel(model.username, model.name);
+
+ if (existingModel != null)
+ return NotFound($"Model with name = {model.name} exisits");
+ else
+ {
+ _modelService.Create(model);
+
+ return CreatedAtAction(nameof(Get), new { id = model._id }, model);
+ }
+ }
+
+ // PUT api/<ModelController>/{name}
+ [HttpPut("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult Put(string name, [FromBody] Model model)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+
+ var existingModel = _modelService.GetOneModel(username, name);
+
+ if (existingModel == null)
+ return NotFound($"Model with name = {name} or user with username = {username} not found");
+
+ _modelService.Update(username, name, model);
+ return NoContent();
+ }
+
+ // DELETE api/<ModelController>/name
+ [HttpDelete("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult Delete(string name)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var model = _modelService.GetOneModel(username, name);
+
+ if (model == null)
+ return NotFound($"Model with name = {name} or user with username = {username} not found");
+
+ _modelService.Delete(model.username, model.name);
+
+ return Ok($"Model with name = {name} deleted");
+
+ }
+
+ }
+}
diff --git a/backend/api/api/Controllers/PredictorController.cs b/backend/api/api/Controllers/PredictorController.cs
new file mode 100644
index 00000000..7f8f1692
--- /dev/null
+++ b/backend/api/api/Controllers/PredictorController.cs
@@ -0,0 +1,231 @@
+using api.Models;
+using api.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Net.Http.Headers;
+using System.Net.Http.Headers;
+
+namespace api.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class PredictorController : Controller
+ {
+ private readonly IPredictorService _predictorService;
+ private JwtToken jwtToken;
+
+ public PredictorController(IPredictorService predictorService, IConfiguration configuration)
+ {
+ _predictorService = predictorService;
+ jwtToken = new JwtToken(configuration);
+ }
+
+ // GET: api/<PredictorController>/mypredictors
+ [HttpGet("mypredictors")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Predictor>> Get()
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ return _predictorService.GetMyPredictors(username);
+ }
+ // GET: api/<PredictorController>/publicpredictors
+ [HttpGet("publicpredictors")]
+ public ActionResult<List<Predictor>> GetPublicPredictors()
+ {
+ return _predictorService.GetPublicPredictors();
+ }
+
+
+
+ //SEARCH za predictore (public ili private sa ovim imenom )
+ // GET api/<PredictorController>/search/{name}
+ [HttpGet("search/{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Predictor>> Search(string name)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ //ako bude trebao ID, samo iz baze uzeti
+
+ return _predictorService.SearchPredictors(name, username);
+ }
+
+ //da li da se odvoji search za public i posebno za private?
+ // GET api/<PredictorController>/{name}
+ [HttpGet("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<Predictor> Get(string name)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var predictor = _predictorService.GetOnePredictor(username, name);
+
+ if (predictor == null)
+ return NotFound($"Predictor with name = {name} not found or predictor is not public");
+
+ return predictor;
+ }
+ // moze da vraca sve modele pa da se ovde odradi orderByDesc
+ //odraditi to i u Datasetove i Predictore
+ // GET: api/<PredictorController>/datesort/{ascdsc}/{latest}
+ //asc - rastuce 1
+ //desc - opadajuce 0
+ //ako se posalje 0 kao latest onda ce da izlista sve u nekom poretku
+ [HttpGet("datesort/{ascdsc}/{latest}")]
+ [Authorize(Roles = "User")]
+ public ActionResult<List<Predictor>> SortPredictors(bool ascdsc, int latest)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ //ako bude trebao ID, samo iz baze uzeti
+
+ List<Predictor> lista = _predictorService.SortPredictors(username, ascdsc, latest);
+
+ if(latest == 0)
+ return lista;
+ else
+ {
+ List<Predictor> novaLista = new List<Predictor>();
+
+ for (int i = 0; i < latest; i++)
+ novaLista.Add(lista[i]);
+
+ return novaLista;
+ }
+ }
+ // POST api/<PredictorController>/add
+ [HttpPost("add")]
+ [Authorize(Roles = "User")]
+ public ActionResult<Predictor> Post([FromBody] Predictor predictor)
+ {
+ var existingPredictor = _predictorService.GetOnePredictor(predictor.username, predictor.name);
+
+ if (existingPredictor != null)
+ return NotFound($"Predictor with name = {predictor.name} exisits");
+ else
+ {
+ _predictorService.Create(predictor);
+
+ return CreatedAtAction(nameof(Get), new { id = predictor._id }, predictor);
+ }
+ }
+
+
+
+ // PUT api/<PredictorController>/{name}
+ [HttpPut("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult Put(string name, [FromBody] Predictor predictor)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var existingPredictor = _predictorService.GetOnePredictor(username, name);
+
+ //ne mora da se proverava
+ if (existingPredictor == null)
+ return NotFound($"Predictor with name = {name} or user with username = {username} not found");
+
+ _predictorService.Update(username, name, predictor);
+
+ return Ok($"Predictor with name = {name} updated");
+ }
+
+ // odraditi pretragu predictora
+ //potrebna public i private pretraga
+ //prvo da napakuje svoje pa onda ostale
+ //
+ //isto odraditi i za datasetove
+ //
+
+
+ // DELETE api/<PredictorController>/name
+ [HttpDelete("{name}")]
+ [Authorize(Roles = "User")]
+ public ActionResult Delete(string name)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ var predictor = _predictorService.GetOnePredictor(username, name);
+
+ if (predictor == null)
+ return NotFound($"Predictor with name = {name} or user with username = {username} not found");
+
+ _predictorService.Delete(predictor.username, predictor.name);
+
+ return Ok($"Predictor with name = {name} deleted");
+
+ }
+
+
+
+
+ }
+}
diff --git a/backend/api/api/Controllers/UserController.cs b/backend/api/api/Controllers/UserController.cs
index d41a42e3..0287f3cb 100644
--- a/backend/api/api/Controllers/UserController.cs
+++ b/backend/api/api/Controllers/UserController.cs
@@ -1,7 +1,10 @@
using api.Models;
using api.Services;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Net.Http.Headers;
using System.Diagnostics;
+using System.Net.Http.Headers;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
//dovrsi kontroler
@@ -12,10 +15,12 @@ namespace api.Controllers
public class UserController : ControllerBase
{
private readonly IUserService userService;
+ private JwtToken jwtToken;
- public UserController(IUserService userService)
+ public UserController(IUserService userService, IConfiguration configuration)
{
this.userService = userService;
+ jwtToken = new JwtToken(configuration);
}
// GET: api/<UserController>
@@ -24,25 +29,26 @@ namespace api.Controllers
{
return userService.Get();
}
-
+
// GET api/<UserController>/5
//potrebno za profile page
- [HttpGet("{id}")]
- public ActionResult<User> Get(string id)
- {
- var user = userService.Get(id);
-
- if (user == null)
- return NotFound($"User with Id = {id} not found");
-
- return user;
- }
- /*
- // GET api/<UserController>/5
- //potrebno za profile page
- [HttpGet("{id}")]
- public ActionResult<User> GetUserUsername(string username)
+ [HttpGet("myprofile")]
+ [Authorize(Roles = "User")]
+ public ActionResult<User> MyProfilePage()
{
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
var user = userService.GetUserUsername(username);
if (user == null)
@@ -50,7 +56,7 @@ namespace api.Controllers
return user;
}
- */
+
// POST api/<UserController>
[HttpPost]
public ActionResult<User> Post([FromBody] User user)
@@ -70,41 +76,91 @@ namespace api.Controllers
}
}
- // PUT api/<UserController>/5
- [HttpPut("{id}")]
- public ActionResult Put(string id, [FromBody] User user)
+ // PUT api/<UserController>/changepass
+ [HttpPut("changepass")]
+ [Authorize(Roles = "User")]
+ public ActionResult PutPass([FromBody] string[] Password)
{
- var existingUser = userService.Get(id);
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+
- //ne mora da se proverava
- if(existingUser == null)
- return NotFound($"User with Id = {id} not found");
+ User user = new User();
- userService.Update(id, user);
+ user = userService.GetUserUsername(username);
+
+ if(PasswordCrypt.checkPassword(Password[0], user.Password))
+ {
+ if(PasswordCrypt.checkPassword(Password[1], user.Password))
+ {
+ return BadRequest($"Identical password!");
+ }
+
+ user.Password = PasswordCrypt.hashPassword(Password[1]);
+ userService.Update(username, user);
+ return Ok($"Succeful password change!");
+ }
+ else
+ return BadRequest($"Wrong old password!");
+
+
+ return NoContent();
+ }
+
+ // PUT api/<UserController>/5
+ [HttpPut("changeinfo")]
+ public ActionResult Put([FromBody] User user)
+ {
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ userService.Update(username, user);
return NoContent();
}
// DELETE api/<UserController>/5
- [HttpDelete("{id}")]
- public ActionResult Delete(string id)
+ [HttpDelete("deleteprofile")]
+ [Authorize(Roles = "User")]
+ public ActionResult Delete()
{
- var user = userService.Get(id);
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
- if (user == null)
- return NotFound($"User with Id = {id} not found");
+ var user = userService.GetUserUsername(username);
userService.Delete(user._id);
- return Ok($"Student with Id = {id} deleted");
+ return Ok($"Profile with username = {username} deleted!");
}
}
-}
-/*
-{
- "_id": "",
- "username" : "ivan996sk",
- "email" : "ivan996sk@gmail.com",
- "password" : "proba",
- "firstName" : "Ivan",
- "lastName" : "Ljubisavljevic"
-}
-*/ \ No newline at end of file
+} \ No newline at end of file
diff --git a/backend/api/api/Controllers/WebSocketController.cs b/backend/api/api/Controllers/WebSocketController.cs
new file mode 100644
index 00000000..184b47e7
--- /dev/null
+++ b/backend/api/api/Controllers/WebSocketController.cs
@@ -0,0 +1,63 @@
+using api.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System.Net.WebSockets;
+
+namespace api.Controllers
+{
+ [Route("api")]
+ [ApiController]
+ public class WebSocketController : ControllerBase
+ {
+ private IMLWebSocketService mlWS;
+ public WebSocketController(IMLWebSocketService mlWS)
+ {
+ this.mlWS = mlWS;
+ }
+
+ [HttpGet("wstest")]
+ public string Test()
+ {
+ this.mlWS.Send("ABC123");
+ return "MESSAGE SENT!";
+ }
+
+ [HttpGet("ws")]
+ public async Task Get()
+ {
+ if (HttpContext.WebSockets.IsWebSocketRequest)
+ {
+ using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
+ await Echo(webSocket);
+ }
+ else
+ {
+ HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
+ }
+ }
+
+ private static async Task Echo(WebSocket webSocket)
+ {
+ var buffer = new byte[1024 * 4];
+ var receiveResult = await webSocket.ReceiveAsync(
+ new ArraySegment<byte>(buffer), CancellationToken.None);
+
+ while (!receiveResult.CloseStatus.HasValue)
+ {
+ await webSocket.SendAsync(
+ new ArraySegment<byte>(buffer, 0, receiveResult.Count),
+ receiveResult.MessageType,
+ receiveResult.EndOfMessage,
+ CancellationToken.None);
+
+ receiveResult = await webSocket.ReceiveAsync(
+ new ArraySegment<byte>(buffer), CancellationToken.None);
+ }
+
+ await webSocket.CloseAsync(
+ receiveResult.CloseStatus.Value,
+ receiveResult.CloseStatusDescription,
+ CancellationToken.None);
+ }
+ }
+}
diff --git a/backend/api/api/Data/UserStoreDatabaseSettings.cs b/backend/api/api/Data/UserStoreDatabaseSettings.cs
index 0d923fc7..e83d2b54 100644
--- a/backend/api/api/Data/UserStoreDatabaseSettings.cs
+++ b/backend/api/api/Data/UserStoreDatabaseSettings.cs
@@ -10,5 +10,8 @@ namespace api.Data
public string DatabaseName { get; set; } = String.Empty;
public string CollectionName { get; set; } = String.Empty;
public string DatasetCollectionName { get; set; } = String.Empty;
+ public string PredictorCollectionName { get; set; } = String.Empty;
+ public string ModelCollectionName { get; set; } = String.Empty;
+ public string FilesCollectionName { get; set; } = String.Empty;
}
}
diff --git a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
index 8d2a175f..a5b5f5eb 100644
--- a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
+++ b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
@@ -6,5 +6,8 @@
string DatabaseName { get; set; }
string CollectionName { get; set; }
string DatasetCollectionName { get; set; }
+ string PredictorCollectionName { get; set; }
+ string ModelCollectionName { get; set; }
+ string FilesCollectionName { get; set; }
}
}
diff --git a/backend/api/api/Models/Dataset.cs b/backend/api/api/Models/Dataset.cs
index 0dc87f40..67ef8cfe 100644
--- a/backend/api/api/Models/Dataset.cs
+++ b/backend/api/api/Models/Dataset.cs
@@ -1,46 +1,26 @@
-using MongoDB.Bson;
+using System;
+using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace api.Models
{
- public class Dataset
- {
- internal string uploaderId;
+ public class Dataset
+ {
+ public string username { get; set; }
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net
public string _id { get; set; }
- [BsonElement("uploaderId")]
- public string UploaderId { get; set; }
- [BsonElement("name")]
public string name { get; set; }
-
public string description { get; set; }
- //datetime
- public string dateCreated { get; set; }
-
- public int[] inputColumns { get; set; }
- public int columnToPredict { get; set; }
- public bool randomTestSet { get; set; }
- public int randomTestSetDistribution { get; set; }
-
-
- public string type { get; set; }
- public string encoding { get; set; }
- public string optimizer { get; set; }
- public string lossFunction { get; set; }
- public int inputNeurons { get; set; }
- public int hiddenLayerNeurons { get; set; }
- public int hiddenLayers { get; set; }
- public int batchSize { get; set; }
- public string inputLayerActivationFunction { get; set; }
- public string hiddenLayerActivationFunction { get; set; }
- public string outputLayerActivationFunction { get; set; }
-
-
- [BsonElement("extension")]
+ public string[] header { get; set; }
+ public string fileId { get; set; }
public string extension { get; set; }
-
-
+ public bool isPublic { get; set; }
+ public bool accessibleByLink { get; set; }
+ public DateTime dateCreated { get; set; }
+ public DateTime lastUpdated { get; set; }
+ public string delimiter { get; set; }
}
}
+
diff --git a/backend/api/api/Models/FileModel.cs b/backend/api/api/Models/FileModel.cs
new file mode 100644
index 00000000..30211372
--- /dev/null
+++ b/backend/api/api/Models/FileModel.cs
@@ -0,0 +1,16 @@
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace api.Models
+{
+ public class FileModel
+ {
+ [BsonId]
+ [BsonRepresentation(BsonType.ObjectId)]
+ public string _id { get; set; }
+ public string username { get; set; }
+ public string path { get; set; }
+ [BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
+ public DateTime date { get; set; }
+ }
+}
diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs
index 3ecbf92d..f262fd23 100644
--- a/backend/api/api/Models/JwtToken.cs
+++ b/backend/api/api/Models/JwtToken.cs
@@ -23,7 +23,7 @@ namespace api.Models
{
Subject = new ClaimsIdentity(new[] { new Claim("name", user.UserName),
new Claim("role", "User")}),
- Expires = DateTime.UtcNow.AddDays(1),
+ Expires = DateTime.UtcNow.AddMinutes(20),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
@@ -33,13 +33,25 @@ namespace api.Models
public string RenewToken(string existingToken)
{
- if (existingToken == null)
+ var userName = TokenToUsername(existingToken);
+ if (userName == null)
+ return null;
+ var authUser = new AuthRequest();
+ authUser.UserName = userName;
+
+ return GenToken(authUser);
+
+ }
+
+ public string TokenToUsername(string token)
+ {
+ if (token == null)
return null;
var tokenHandler = new JwtSecurityTokenHandler();
- var key= Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value);
+ var key = Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value);
try
{
- tokenHandler.ValidateToken(existingToken, new TokenValidationParameters
+ tokenHandler.ValidateToken(token, new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
@@ -48,11 +60,7 @@ namespace api.Models
}, out SecurityToken validatedToken);
var jwtToken = (JwtSecurityToken)validatedToken;
- var userName =jwtToken.Claims.First(x => x.Type == "name").Value;
- var authUser = new AuthRequest();
- authUser.UserName = userName;
-
- return GenToken(authUser);
+ return jwtToken.Claims.First(x => x.Type == "name").Value;
}
catch
{
@@ -61,6 +69,22 @@ namespace api.Models
}
+ public string GenGuestToken()
+ {
+ var tokenHandler = new JwtSecurityTokenHandler();
+ var key = Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value);
+ var tokenDescriptor = new SecurityTokenDescriptor
+ {
+ Subject = new ClaimsIdentity(new[] { new Claim("name",""),
+ new Claim("role", "Guest")}),
+ Expires = DateTime.UtcNow.AddMinutes(20),
+ SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
+ };
+ var token = tokenHandler.CreateToken(tokenDescriptor);
+ return tokenHandler.WriteToken(token);
+
+ }
+
}
diff --git a/backend/api/api/Models/Model.cs b/backend/api/api/Models/Model.cs
new file mode 100644
index 00000000..5678daaf
--- /dev/null
+++ b/backend/api/api/Models/Model.cs
@@ -0,0 +1,47 @@
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace api.Models
+{
+ public class Model
+ {
+
+ [BsonId]
+ [BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net
+ public string _id { get; set; }
+ public string username { get; set; }
+
+
+ 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 datasetId { get; set; }
+
+ //Test set settings
+ public string[] inputColumns { get; set; }
+ public string columnToPredict { get; set; }
+ public bool randomOrder {get;set;}
+ public bool randomTestSet { get; set; }
+ public float randomTestSetDistribution { get; set; }
+
+ //Neural net training
+ public string type { get; set; }
+ public string encoding { get; set; }
+ public string optimizer { get; set; }
+ public string lossFunction { get; set; }
+ public int inputNeurons { get; set; }
+ public int hiddenLayerNeurons { get; set; }
+ public int hiddenLayers { get; set; }
+ public int batchSize { get; set; }
+ // na izlazu je moguce da bude vise neurona (klasifikacioni problem sa vise od 2 klase)
+ public int outputNeurons { get; set; }
+ public string inputLayerActivationFunction { get; set; }
+ public string hiddenLayerActivationFunction { get; set; }
+ public string outputLayerActivationFunction { get; set; }
+
+
+ }
+}
diff --git a/backend/api/api/Models/Predictor.cs b/backend/api/api/Models/Predictor.cs
new file mode 100644
index 00000000..568719fc
--- /dev/null
+++ b/backend/api/api/Models/Predictor.cs
@@ -0,0 +1,22 @@
+using System;
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace api.Models
+{
+ public class Predictor
+ {
+ [BsonId]
+ [BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net
+ public string _id { get; set; }
+ public string username { get; set; }
+ public string name { get; set; }
+ public string description { get; set; }
+ public string[] inputs { get; set; }
+ public string output { get; set; }
+ public bool isPublic { get; set; }
+ public bool accessibleByLink { get; set; }
+ public DateTime dateCreated { get; set; }
+ }
+}
+
diff --git a/backend/api/api/Models/User.cs b/backend/api/api/Models/User.cs
index 46db50ab..1ae8e437 100644
--- a/backend/api/api/Models/User.cs
+++ b/backend/api/api/Models/User.cs
@@ -24,5 +24,7 @@ namespace api.Models
[BsonElement("lastName")]
public string LastName { get; set; }
+ public string photoId { get; set; }
+
}
}
diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs
index 2c569daf..5913c2d3 100644
--- a/backend/api/api/Program.cs
+++ b/backend/api/api/Program.cs
@@ -28,6 +28,17 @@ builder.Services.AddSingleton<IMongoClient>(s =>
builder.Services.AddScoped<IDatasetService, DatasetService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IAuthService, AuthService>();
+builder.Services.AddScoped<IMlConnectionService, MlConnectionService>();
+builder.Services.AddScoped<IModelService, ModelService>();
+builder.Services.AddScoped<IPredictorService, PredictorService>();
+builder.Services.AddScoped<IFileService, FileService>();
+
+var mlwss = new MLWebSocketService();
+
+builder.Services.AddSingleton<IMLWebSocketService>(mlwss);
+builder.Services.AddHostedService(_ => mlwss);
+
+builder.Services.AddHostedService<TempFileService>();
//Add Authentication
builder.Services.AddAuthentication(
@@ -47,6 +58,12 @@ builder.Services.AddControllers();
var app = builder.Build();
+var webSocketOptions = new WebSocketOptions
+{
+ KeepAliveInterval = TimeSpan.FromMinutes(2)
+};
+
+app.UseWebSockets(webSocketOptions);
//Add Cors
app.UseCors(
diff --git a/backend/api/api/Services/AuthService.cs b/backend/api/api/Services/AuthService.cs
index 4f838463..a646cc9d 100644
--- a/backend/api/api/Services/AuthService.cs
+++ b/backend/api/api/Services/AuthService.cs
@@ -36,6 +36,7 @@ namespace api.Services
u.Password = PasswordCrypt.hashPassword(user.password);
u.FirstName = user.firstName;
u.LastName = user.lastName;
+ u.photoId = "1";
if (_users.Find(user => user.Username == u.Username).FirstOrDefault() != null)
return "Username Already Exists";
if (_users.Find(user => user.Email == u.Email).FirstOrDefault() != null)
@@ -57,6 +58,11 @@ namespace api.Services
return null;
}
+ public string GuestToken()
+ {
+ return _jwt.GenGuestToken();
+ }
+
}
}
diff --git a/backend/api/api/Services/DatasetService.cs b/backend/api/api/Services/DatasetService.cs
index 1b6d22be..5e708d11 100644
--- a/backend/api/api/Services/DatasetService.cs
+++ b/backend/api/api/Services/DatasetService.cs
@@ -13,6 +13,12 @@ namespace api.Services
var database = mongoClient.GetDatabase(settings.DatabaseName);
_dataset = database.GetCollection<Dataset>(settings.DatasetCollectionName);
}
+
+ public List<Dataset> SearchDatasets(string name, string username)
+ {
+ return _dataset.Find(dataset => dataset.name == name && dataset.isPublic == true).ToList();
+ }
+
//kreiranje dataseta
public Dataset Create(Dataset dataset)
{
@@ -21,23 +27,46 @@ namespace api.Services
}
//brisanje odredjenog name-a
- public void Delete(string uploaderId, string name)
+ public void Delete(string username, string name)
{
- _dataset.DeleteOne(dataset => (dataset.UploaderId == uploaderId && dataset.name == name));
+ _dataset.DeleteOne(dataset => (dataset.username == username && dataset.name == name));
}
- public List<Dataset> GetAllDatesets(string uploaderId)
+
+ public List<Dataset> GetMyDatasets(string username)
{
- return _dataset.Find(dataset => dataset.uploaderId == uploaderId).ToList();
+ return _dataset.Find(dataset => dataset.username == username).ToList();
}
- public Dataset GetOneDataset(string uploaderId, string name)
+
+ //poslednji datasetovi
+ public List<Dataset> SortDatasets(string username, bool ascdsc, int latest)
{
- return _dataset.Find(dataset => dataset.UploaderId == uploaderId && dataset.name == name).FirstOrDefault();
+ List<Dataset> list = _dataset.Find(dataset => dataset.username == username).ToList();
+
+ if(ascdsc)
+ list = list.OrderBy(dataset => dataset.lastUpdated).ToList();
+ else
+ list = list.OrderByDescending(dataset => dataset.lastUpdated).ToList();
+
+ return list;
}
+ public List<Dataset> GetPublicDatasets()
+ {
+ return _dataset.Find(dataset => dataset.isPublic == true).ToList();
+ }
+
+ public Dataset GetOneDataset(string username, string name)
+ {
+ return _dataset.Find(dataset => dataset.username == username && dataset.name == name).FirstOrDefault();
+ }
+ //odraditi za pretragu getOne
+
//ako je potrebno da se zameni name ili ekstenzija
- public void Update(string uploaderId, string name, Dataset dataset)
+ public void Update(string username, string name, Dataset dataset)
{
- _dataset.ReplaceOne(dataset => dataset.UploaderId == uploaderId && dataset.name == name, dataset);
+ _dataset.ReplaceOne(dataset => dataset.username == username && dataset.name == name, dataset);
}
+
+
}
}
diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs
new file mode 100644
index 00000000..b02d0da4
--- /dev/null
+++ b/backend/api/api/Services/FileService.cs
@@ -0,0 +1,35 @@
+using api.Interfaces;
+using api.Models;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class FileService : IFileService
+ {
+
+ private readonly IMongoCollection<FileModel> _file;
+
+ public FileService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _file = database.GetCollection<FileModel>(settings.FilesCollectionName);
+ }
+
+ public FileModel Create(FileModel file)
+ {
+ if (file == null)
+ return null;
+ _file.InsertOne(file);
+ return file;
+
+ }
+ public string GetFilePath(string id, string username)
+ {
+ FileModel file = _file.Find(x => x._id == id && x.username == username).FirstOrDefault();
+ if (file == null)
+ return null;
+ return file.path;
+ }
+
+ }
+}
diff --git a/backend/api/api/Services/IAuthService.cs b/backend/api/api/Services/IAuthService.cs
index 591d122d..9a109208 100644
--- a/backend/api/api/Services/IAuthService.cs
+++ b/backend/api/api/Services/IAuthService.cs
@@ -7,5 +7,6 @@ namespace api.Services
string Login(AuthRequest user);
string Register(RegisterRequest user);
string RenewToken(string token);
+ public string GuestToken();
}
} \ No newline at end of file
diff --git a/backend/api/api/Services/IDatasetService.cs b/backend/api/api/Services/IDatasetService.cs
index 9cf8c3cb..be56f5cb 100644
--- a/backend/api/api/Services/IDatasetService.cs
+++ b/backend/api/api/Services/IDatasetService.cs
@@ -5,10 +5,13 @@ namespace api.Services
{
public interface IDatasetService
{
- Dataset GetOneDataset(string uploaderId, string name);
- List<Dataset> GetAllDatesets(string uploaderId);
+ Dataset GetOneDataset(string username, string name);
+ List<Dataset> SearchDatasets(string name, string username);
+ List<Dataset> GetMyDatasets(string username);
+ List<Dataset> SortDatasets(string username, bool ascdsc, int latest);
+ List<Dataset> GetPublicDatasets();
Dataset Create(Dataset dataset);
- void Update(string uploaderId, string name, Dataset dataset);
- void Delete(string uploaderId, string name);
+ void Update(string username, string name, Dataset dataset);
+ void Delete(string username, string name);
}
}
diff --git a/backend/api/api/Services/IFileService.cs b/backend/api/api/Services/IFileService.cs
new file mode 100644
index 00000000..7446e283
--- /dev/null
+++ b/backend/api/api/Services/IFileService.cs
@@ -0,0 +1,10 @@
+using api.Models;
+
+namespace api.Services
+{
+ public interface IFileService
+ {
+ FileModel Create(FileModel file);
+ string GetFilePath(string id, string username);
+ }
+} \ No newline at end of file
diff --git a/backend/api/api/Services/IMLWebSocketService.cs b/backend/api/api/Services/IMLWebSocketService.cs
new file mode 100644
index 00000000..52efb7fc
--- /dev/null
+++ b/backend/api/api/Services/IMLWebSocketService.cs
@@ -0,0 +1,7 @@
+namespace api.Services
+{
+ public interface IMLWebSocketService
+ {
+ void Send(string message);
+ }
+}
diff --git a/backend/api/api/Services/IMlConnectionService.cs b/backend/api/api/Services/IMlConnectionService.cs
new file mode 100644
index 00000000..f38fb50a
--- /dev/null
+++ b/backend/api/api/Services/IMlConnectionService.cs
@@ -0,0 +1,8 @@
+
+namespace api.Services
+{
+ public interface IMlConnectionService
+ {
+ Task<string> SendModelAsync(object model);
+ }
+} \ No newline at end of file
diff --git a/backend/api/api/Services/IModelService.cs b/backend/api/api/Services/IModelService.cs
new file mode 100644
index 00000000..ee5c279f
--- /dev/null
+++ b/backend/api/api/Services/IModelService.cs
@@ -0,0 +1,18 @@
+using System;
+using api.Models;
+
+namespace api.Services
+{
+ public interface IModelService
+ {
+ Model GetOneModel(string username, string name);
+ List<Model> GetMyModels(string username);
+ List<Model> GetLatestModels(string username);
+ //List<Model> GetPublicModels();
+ Model Create(Model model);
+ void Update(string username, string name, Model model);
+ void Delete(string username, string name);
+ bool CheckHyperparameters(int inputNeurons, int hiddenLayerNeurons, int hiddenLayers, int outputNeurons);
+ }
+}
+
diff --git a/backend/api/api/Services/IPredictorService.cs b/backend/api/api/Services/IPredictorService.cs
new file mode 100644
index 00000000..2017add2
--- /dev/null
+++ b/backend/api/api/Services/IPredictorService.cs
@@ -0,0 +1,18 @@
+using System;
+using api.Models;
+
+namespace api.Services
+{
+ public interface IPredictorService
+ {
+ Predictor GetOnePredictor(string username, string name);
+ List<Predictor> SearchPredictors(string name, string username);
+ List<Predictor> GetMyPredictors(string username);
+ List<Predictor> SortPredictors(string username, bool ascdsc, int latest);
+ List<Predictor> GetPublicPredictors();
+ Predictor Create(Predictor predictor);
+ void Update(string username, string name, Predictor predictor);
+ void Delete(string username, string name);
+ }
+}
+
diff --git a/backend/api/api/Services/IUserService.cs b/backend/api/api/Services/IUserService.cs
index b6725694..1cb6a609 100644
--- a/backend/api/api/Services/IUserService.cs
+++ b/backend/api/api/Services/IUserService.cs
@@ -1,14 +1,14 @@
using api.Models;
+using Microsoft.AspNetCore.Mvc;
namespace api.Services
{
public interface IUserService
{
List<User> Get();// daje sve korisnike
- User Get(string id); //daje korisnika po id-u
User GetUserUsername(string username); //daje korisnika po korisnickom imenu
User Create(User user); // kreira korisnika
- void Update(string id, User user); //apdejruje korisnika po idu
- void Delete(string id);//brise korisnika
+ void Update(string username, User user); //apdejtuje korisnika po idu
+ void Delete(string username);//brise korisnika
}
}
diff --git a/backend/api/api/Services/MLWebSocketService.cs b/backend/api/api/Services/MLWebSocketService.cs
new file mode 100644
index 00000000..ca6919bf
--- /dev/null
+++ b/backend/api/api/Services/MLWebSocketService.cs
@@ -0,0 +1,68 @@
+using System.Net.WebSockets;
+using System.Text;
+
+namespace api.Services
+{
+ public class MLWebSocketService: BackgroundService, IMLWebSocketService
+ {
+ private static readonly string Connection = "ws://localhost:5027";
+
+ private Queue<string> dataQueue = new Queue<string>();
+
+ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
+ {
+ while (!stoppingToken.IsCancellationRequested)
+ using (var socket = new ClientWebSocket())
+ try
+ {
+ await socket.ConnectAsync(new Uri(Connection), stoppingToken);
+
+
+ while(dataQueue.Count > 0)
+ {
+ await Send(socket, dataQueue.Dequeue(), stoppingToken);
+ }
+
+ Receive(socket, stoppingToken);
+
+ await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", stoppingToken);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"ERROR - {ex.Message}");
+ }
+ }
+
+ private async Task Send(ClientWebSocket socket, string data, CancellationToken stoppingToken) =>
+ await socket.SendAsync(Encoding.UTF8.GetBytes(data), WebSocketMessageType.Text, true, stoppingToken);
+
+ private async Task Receive(ClientWebSocket socket, CancellationToken stoppingToken)
+ {
+ var buffer = new ArraySegment<byte>(new byte[2048]);
+ while (!stoppingToken.IsCancellationRequested)
+ {
+ WebSocketReceiveResult result;
+ using (var ms = new MemoryStream())
+ {
+ do
+ {
+ result = await socket.ReceiveAsync(buffer, stoppingToken);
+ ms.Write(buffer.Array, buffer.Offset, result.Count);
+ } while (!result.EndOfMessage);
+
+ if (result.MessageType == WebSocketMessageType.Close)
+ break;
+
+ ms.Seek(0, SeekOrigin.Begin);
+ using (var reader = new StreamReader(ms, Encoding.UTF8))
+ Console.WriteLine(await reader.ReadToEndAsync());
+ }
+ };
+ }
+
+ public void Send(string data)
+ {
+ dataQueue.Enqueue(data);
+ }
+ }
+}
diff --git a/backend/api/api/Services/MlConnectionService.cs b/backend/api/api/Services/MlConnectionService.cs
new file mode 100644
index 00000000..9b167537
--- /dev/null
+++ b/backend/api/api/Services/MlConnectionService.cs
@@ -0,0 +1,18 @@
+using RestSharp;
+using System.Net.WebSockets;
+using System.Text;
+
+namespace api.Services
+{
+ public class MlConnectionService : IMlConnectionService
+ {
+ public async Task<string> SendModelAsync(object model)
+ {
+ RestClient client = new RestClient("http://localhost:5000");
+ var request = new RestRequest("data", Method.Post);
+ request.AddJsonBody(model);
+ var result = await client.ExecuteAsync(request);
+ return result.Content;//Response od ML microservisa
+ }
+ }
+}
diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs
new file mode 100644
index 00000000..f42219f5
--- /dev/null
+++ b/backend/api/api/Services/ModelService.cs
@@ -0,0 +1,72 @@
+using System;
+using api.Interfaces;
+using api.Models;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class ModelService : IModelService
+ {
+ private readonly IMongoCollection<Model> _model;
+
+ public ModelService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _model = database.GetCollection<Model>(settings.ModelCollectionName);
+ }
+
+ public Model Create(Model model)
+ {
+ _model.InsertOne(model);
+ return model;
+ }
+
+ public void Delete(string username, string name)
+ {
+ _model.DeleteOne(model => (model.username == username && model.name == name));
+ }
+
+ public List<Model> GetMyModels(string username)
+ {
+ return _model.Find(model => model.username == username).ToList();
+ }
+ public List<Model> GetLatestModels(string username)
+ {
+ List<Model> list = _model.Find(model => model.username == username).ToList();
+
+ list = list.OrderByDescending(model => model.lastUpdated).ToList();
+
+ return list;
+ }
+
+ /*
+ public List<Model> GetPublicModels()
+ {
+ return _model.Find(model => model.isPublic == true).ToList();
+ }
+ */
+ public Model GetOneModel(string username, string name)
+ {
+ return _model.Find(model => model.username == username && model.name == name).FirstOrDefault();
+ }
+
+ public void Update(string username, string name, Model model)
+ {
+ _model.ReplaceOne(model => model.username == username && model.name == name, model);
+ }
+ //
+ public bool CheckHyperparameters(int inputNeurons, int hiddenLayerNeurons, int hiddenLayers, int outputNeurons)
+ {
+ if (hiddenLayers <= 0 || hiddenLayerNeurons <= 0)
+ return false;
+ if (hiddenLayers > inputNeurons)
+ return false;
+ if (hiddenLayerNeurons <= 2 * inputNeurons || hiddenLayerNeurons <= (2 / 3) * inputNeurons + outputNeurons || (hiddenLayerNeurons <= Math.Max(inputNeurons, outputNeurons) && hiddenLayerNeurons >= Math.Min(inputNeurons, outputNeurons)))
+ return true;
+ return false;
+ }
+
+
+ }
+}
+
diff --git a/backend/api/api/Services/PredictorService.cs b/backend/api/api/Services/PredictorService.cs
new file mode 100644
index 00000000..05860126
--- /dev/null
+++ b/backend/api/api/Services/PredictorService.cs
@@ -0,0 +1,68 @@
+using api.Interfaces;
+using api.Models;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class PredictorService : IPredictorService
+ {
+ private readonly IMongoCollection<Predictor> _predictor;
+
+ public PredictorService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _predictor = database.GetCollection<Predictor>(settings.PredictorCollectionName);
+ }
+
+ public List<Predictor> SearchPredictors(string name, string username)
+ {
+ return _predictor.Find(predictor => predictor.name == name && predictor.isPublic == true).ToList();
+ }
+
+ public Predictor Create(Predictor predictor)
+ {
+ _predictor.InsertOne(predictor);
+ return predictor;
+ }
+
+ public void Delete(string username, string name)
+ {
+ _predictor.DeleteOne(predictor => (predictor.username == username && predictor.name == name));
+ }
+
+ public List<Predictor> GetMyPredictors(string username)
+ {
+ return _predictor.Find(predictor => predictor.username == username).ToList();
+ }
+
+ public Predictor GetOnePredictor(string username, string name)
+ {
+ return _predictor.Find(predictor => predictor.username == username && predictor.name == name).FirstOrDefault();
+
+ }
+ //last private models
+ public List<Predictor> SortPredictors(string username, bool ascdsc, int latest)
+ {
+ List<Predictor> list = _predictor.Find(predictor => predictor.username == username).ToList();
+
+
+ if (ascdsc)
+ list = list.OrderBy(predictor => predictor.dateCreated).ToList();
+ else
+ list = list.OrderByDescending(predictor => predictor.dateCreated).ToList();
+ return list;
+ }
+
+ public List<Predictor> GetPublicPredictors()
+ {
+ return _predictor.Find(predictor => predictor.isPublic == true).ToList();
+ }
+
+ public void Update(string username, string name, Predictor predictor)
+ {
+ _predictor.ReplaceOne(predictor => predictor.username == username && predictor.name == name, predictor);
+
+ }
+
+ }
+}
diff --git a/backend/api/api/Services/TempFileService.cs b/backend/api/api/Services/TempFileService.cs
new file mode 100644
index 00000000..adfe8c75
--- /dev/null
+++ b/backend/api/api/Services/TempFileService.cs
@@ -0,0 +1,33 @@
+using api.Interfaces;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class TempFileService : IHostedService
+ {
+ private readonly TempRemovalService _removalService;
+ private Timer _timer;
+
+ public TempFileService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ _removalService = new TempRemovalService(settings, mongoClient);
+ }
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ _timer = new Timer(RemoveTempFiles,null,TimeSpan.Zero,TimeSpan.FromHours(6));
+
+
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ _timer?.Change(Timeout.Infinite, 0);
+ return Task.CompletedTask;
+ }
+ private void RemoveTempFiles(object state)
+ {
+ _removalService.DeleteTemps();
+ }
+ }
+}
diff --git a/backend/api/api/Services/TempRemovalService.cs b/backend/api/api/Services/TempRemovalService.cs
new file mode 100644
index 00000000..342304f0
--- /dev/null
+++ b/backend/api/api/Services/TempRemovalService.cs
@@ -0,0 +1,73 @@
+using api.Interfaces;
+using api.Models;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class TempRemovalService
+ {
+ private readonly IMongoCollection<FileModel> _file;
+ private readonly IMongoCollection<Model> _model;
+ private readonly IMongoCollection<Dataset> _dataset;
+
+ public TempRemovalService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _file = database.GetCollection<FileModel>(settings.FilesCollectionName);
+ _model= database.GetCollection<Model>(settings.ModelCollectionName);
+ _dataset = database.GetCollection<Dataset>(settings.DatasetCollectionName);
+ }
+ public void DeleteTemps()
+ {
+ List<FileModel> files = _file.Find(file => file.username == "").ToList();
+ foreach (var file in files)
+ {
+ if ((DateTime.Now.ToUniversalTime() - file.date).TotalDays >= 1)
+ {
+ DeleteFile(file._id);
+ List<Dataset> datasets = _dataset.Find(dataset => dataset.fileId == file._id && dataset.username=="").ToList();
+ foreach(var dataset in datasets)
+ {
+ DeleteDataset(dataset._id);
+ List<Model> models = _model.Find(model => model.datasetId == dataset._id && model.username=="").ToList();
+ foreach(var model in models)
+ {
+ DeleteModel(model._id);
+ }
+ }
+ if (File.Exists(file.path))
+ File.Delete(file.path);
+ }
+ }
+ //Brisanje modela ukoliko gost koristi vec postojeci dataset
+ List<Model> models1= _model.Find(model =>model.username == "").ToList();
+ foreach(var model in models1)
+ {
+ if ((DateTime.Now.ToUniversalTime() - model.dateCreated.ToUniversalTime()).TotalDays >= 1)
+ {
+ DeleteModel(model._id);
+ }
+ }
+
+
+ }
+
+
+
+
+ public void DeleteFile(string id)
+ {
+ _file.DeleteOne(file => file._id == id);
+ }
+ public void DeleteModel(string id)
+ {
+ _model.DeleteOne(model=>model._id==id);
+ }
+ public void DeleteDataset(string id)
+ {
+ _dataset.DeleteOne(dataset => dataset._id == id);
+ }
+
+
+ }
+}
diff --git a/backend/api/api/Services/UserService.cs b/backend/api/api/Services/UserService.cs
index c626889d..f613f923 100644
--- a/backend/api/api/Services/UserService.cs
+++ b/backend/api/api/Services/UserService.cs
@@ -18,50 +18,23 @@ namespace api.Services
_users.InsertOne(user);
return user;
}
-
public List<User> Get()
{
return _users.Find(user => true).ToList();
}
-
public User GetUserUsername(string username)
{
return _users.Find(user => user.Username == username).FirstOrDefault();
}
-
- public User Get(string id)
+ public void Update(string username, User user)
{
- return _users.Find(user => user._id == id).FirstOrDefault();
+ //username koji postoji u bazi
+ _users.ReplaceOne(user => user.Username == username, user);
}
-
- public void Delete(string id)
+ public void Delete(string username)
{
- _users.DeleteOne(user => user._id == id);
+ _users.DeleteOne(user => user.Username == username);
}
- public void Update(string id, User user)
- {
- _users.ReplaceOne(user => user._id == id, user);
- }
}
}
-/*
- {
- "_id": "",
- "username" : "ivan996sk",
- "email" : "ivan996sk@gmail.com",
- "password" : "proba",
- "firstName" : "Ivan",
- "lastName" : "Ljubisavljevic"
-}
-
-{
- "_id": {
- "$oid": "62291140d88e6bcf95c96a58"
- },
- "uploaderId":"",
- "extension" : "",
- "name" : ""
-}
-
-*/
diff --git a/backend/api/api/api.csproj b/backend/api/api/api.csproj
index 46842c3e..658f7c05 100644
--- a/backend/api/api/api.csproj
+++ b/backend/api/api/api.csproj
@@ -10,6 +10,8 @@
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.16.0" />
+ <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
+ <PackageReference Include="RestSharp" Version="107.3.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.16.0" />
</ItemGroup>
@@ -19,6 +21,7 @@
</ItemGroup>
<ItemGroup>
+ <Folder Include="TempFiles\" />
<Folder Include="UploadedFiles\" />
</ItemGroup>
diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json
index 3661f171..fdccfb07 100644
--- a/backend/api/api/appsettings.json
+++ b/backend/api/api/appsettings.json
@@ -11,13 +11,21 @@
"AllowedHosts": "*",
"UserStoreDatabaseSettings": {
/* LocalHost
+ */
"ConnectionString": "mongodb://127.0.0.1:27017/",
"DatabaseName": "si_project",
- "CollectionName": "User"
- */
+ "CollectionName": "users",
+ "DatasetCollectionName": "Dataset",
+ "ModelCollectionName": "Model",
+ "PredictorCollectionName": "Predictor",
+ "FilesCollectionName": "Files"
+ /*
"ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
"DatabaseName": "si_db",
"CollectionName": "users",
- "DatasetCollectionName" : "Dataset"
+ "DatasetCollectionName": "Dataset",
+ "ModelCollectionName": "Model",
+ "PredictorCollectionName": "Predictor",
+ "FilesCollectionName": "Files"*/
}
-}
+} \ No newline at end of file
diff --git a/backend/microservice/PythonServer/project/api/socket2/client.py b/backend/microservice/PythonServer/project/api/socket2/client.py
new file mode 100644
index 00000000..65e76b55
--- /dev/null
+++ b/backend/microservice/PythonServer/project/api/socket2/client.py
@@ -0,0 +1,16 @@
+# Import socket module
+import socket
+
+# Create a socket object
+s = socket.socket()
+
+# Define the port on which you want to connect
+port = 12345
+
+# connect to the server on local computer
+s.connect(('127.0.0.1', port))
+
+# receive data from the server and decoding to get the string.
+print (s.recv(1024).decode())
+# close the connection
+s.close() \ No newline at end of file
diff --git a/backend/microservice/PythonServer/project/api/socket2/server.py b/backend/microservice/PythonServer/project/api/socket2/server.py
new file mode 100644
index 00000000..c65dae78
--- /dev/null
+++ b/backend/microservice/PythonServer/project/api/socket2/server.py
@@ -0,0 +1,39 @@
+# first of all import the socket library
+import socket
+
+# next create a socket object
+s = socket.socket()
+print ("Socket successfully created")
+
+# reserve a port on your computer in our
+# case it is 12345 but it can be anything
+port = 12345
+
+# Next bind to the port
+# we have not typed any ip in the ip field
+# instead we have inputted an empty string
+# this makes the server listen to requests
+# coming from other computers on the network
+s.bind(('', port))
+print ("socket binded to %s" %(port))
+
+# put the socket into listening mode
+s.listen(5)
+print ("socket is listening")
+
+# a forever loop until we interrupt it or
+# an error occurs
+while True:
+
+# Establish connection with client.
+ c, addr = s.accept()
+ print ('Got connection from', addr )
+
+ # send a thank you message to the client. encoding to send byte type.
+ c.send('Thank you for connecting'.encode())
+
+ # Close the connection with the client
+ c.close()
+
+ # Breaking once connection closed
+ break \ No newline at end of file
diff --git a/backend/microservice/__pycache__/mlservice.cpython-310.pyc b/backend/microservice/__pycache__/mlservice.cpython-310.pyc
new file mode 100644
index 00000000..c079459a
--- /dev/null
+++ b/backend/microservice/__pycache__/mlservice.cpython-310.pyc
Binary files differ
diff --git a/backend/microservice/PythonServer/project/api/api.py b/backend/microservice/api.py
index 4768f34c..4768f34c 100644
--- a/backend/microservice/PythonServer/project/api/api.py
+++ b/backend/microservice/api.py
diff --git a/backend/microservice/PythonServer/project/api/templates/data.html b/backend/microservice/data.html
index d2fb44ab..d2fb44ab 100644
--- a/backend/microservice/PythonServer/project/api/templates/data.html
+++ b/backend/microservice/data.html
diff --git a/backend/microservice/fcnn.ipynb b/backend/microservice/fcnn.ipynb
index 52bcf790..494ca1d9 100644
--- a/backend/microservice/fcnn.ipynb
+++ b/backend/microservice/fcnn.ipynb
@@ -13,7 +13,8 @@
},
"language_info": {
"name": "python"
- }
+ },
+ "accelerator": "GPU"
},
"cells": [
{
@@ -27,7 +28,7 @@
},
{
"cell_type": "code",
- "execution_count": 209,
+ "execution_count": 1,
"metadata": {
"id": "V-j3D7ZDhxOl"
},
@@ -44,7 +45,7 @@
"metadata": {
"id": "1JWeUSyJrxLz"
},
- "execution_count": 210,
+ "execution_count": 2,
"outputs": []
},
{
@@ -66,9 +67,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "Wjvd-3oBtdpW",
- "outputId": "97277f04-34be-4eaf-e906-49fabbfb69ce"
+ "outputId": "f14d5464-c985-4360-ec0b-c09412eeb835"
},
- "execution_count": 211,
+ "execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
@@ -90,7 +91,7 @@
]
},
"metadata": {},
- "execution_count": 211
+ "execution_count": 3
}
]
},
@@ -113,9 +114,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "eIOQ2r3WsNjc",
- "outputId": "11b9e11c-94ea-475b-a2ba-144922b5f112"
+ "outputId": "f9f7d9a0-5ae2-4a30-9127-610ee1254b18"
},
- "execution_count": 212,
+ "execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
@@ -134,7 +135,7 @@
]
},
"metadata": {},
- "execution_count": 212
+ "execution_count": 4
}
]
},
@@ -157,9 +158,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "GuGUR4MjsVAt",
- "outputId": "89240693-611e-4f7b-9f2f-5cfad26e6634"
+ "outputId": "9e94a049-a738-4ea2-e3a6-c72f0fd42949"
},
- "execution_count": 213,
+ "execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
@@ -169,7 +170,7 @@
]
},
"metadata": {},
- "execution_count": 213
+ "execution_count": 5
}
]
},
@@ -192,9 +193,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "JNaqQhAzsdM4",
- "outputId": "76c91cdd-e659-4685-f857-cce3e73338db"
+ "outputId": "126cea03-aa32-423a-c433-96aa1b84dcee"
},
- "execution_count": 214,
+ "execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
@@ -204,7 +205,7 @@
]
},
"metadata": {},
- "execution_count": 214
+ "execution_count": 6
}
]
},
@@ -218,9 +219,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "DuOj9XjKtNET",
- "outputId": "58f90430-84f3-4e68-e6fe-ded889bbf6b4"
+ "outputId": "0e28d6b0-109e-43b7-bdca-1b9ab0983f7a"
},
- "execution_count": 215,
+ "execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
@@ -255,7 +256,7 @@
]
},
"metadata": {},
- "execution_count": 215
+ "execution_count": 7
}
]
},
@@ -269,9 +270,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "mcX29JkpuI71",
- "outputId": "b079071c-a689-46a9-de6a-e345f0531b98"
+ "outputId": "0eb7c5eb-156b-4445-bd2e-56f2cc7d76d4"
},
- "execution_count": 216,
+ "execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
@@ -281,7 +282,7 @@
]
},
"metadata": {},
- "execution_count": 216
+ "execution_count": 8
}
]
},
@@ -293,7 +294,7 @@
"metadata": {
"id": "rhnFUqKRr6f1"
},
- "execution_count": 217,
+ "execution_count": 9,
"outputs": []
},
{
@@ -313,7 +314,7 @@
"metadata": {
"id": "DYt9-pEGr_AG"
},
- "execution_count": 218,
+ "execution_count": 10,
"outputs": []
},
{
@@ -324,7 +325,7 @@
"metadata": {
"id": "-drBC0Wvtil3"
},
- "execution_count": 219,
+ "execution_count": 11,
"outputs": []
},
{
@@ -344,7 +345,7 @@
"metadata": {
"id": "GwbnpRsbtmha"
},
- "execution_count": 220,
+ "execution_count": 12,
"outputs": []
},
{
@@ -357,9 +358,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "vTElNnAJtvGL",
- "outputId": "78aae55d-78e7-45b9-edca-182b9516fbe6"
+ "outputId": "15eea781-ab94-4a7f-87f6-3a8b8bffba93"
},
- "execution_count": 221,
+ "execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
@@ -369,7 +370,7 @@
]
},
"metadata": {},
- "execution_count": 221
+ "execution_count": 13
}
]
},
@@ -383,9 +384,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "VMnIE4ARuAnv",
- "outputId": "1c9533aa-55ec-4263-d59b-9e38d24b0e82"
+ "outputId": "05bfffb3-1d50-4dd9-e185-e0e570967014"
},
- "execution_count": 222,
+ "execution_count": 14,
"outputs": [
{
"output_type": "execute_result",
@@ -395,7 +396,7 @@
]
},
"metadata": {},
- "execution_count": 222
+ "execution_count": 14
}
]
},
@@ -418,9 +419,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "9aCST5jHvAkE",
- "outputId": "36b91b77-1531-4399-8282-c0c4a78927d9"
+ "outputId": "a539e40e-6918-418c-daed-a2901e593457"
},
- "execution_count": 223,
+ "execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
@@ -434,7 +435,7 @@
]
},
"metadata": {},
- "execution_count": 223
+ "execution_count": 15
}
]
},
@@ -455,7 +456,7 @@
"metadata": {
"id": "1jaGEMe9vdL6"
},
- "execution_count": 224,
+ "execution_count": 16,
"outputs": []
},
{
@@ -479,7 +480,7 @@
"metadata": {
"id": "HtsqX74Gve7i"
},
- "execution_count": 225,
+ "execution_count": 17,
"outputs": []
},
{
@@ -492,9 +493,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "0zGchJnWzWhh",
- "outputId": "3f2778cb-dd2a-4967-b75d-a7f877c70472"
+ "outputId": "68ba5b26-9222-4dba-9073-c6abb42afa4a"
},
- "execution_count": 226,
+ "execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
@@ -509,7 +510,7 @@
]
},
"metadata": {},
- "execution_count": 226
+ "execution_count": 18
}
]
},
@@ -533,7 +534,7 @@
"metadata": {
"id": "PHZDe92Dn12k"
},
- "execution_count": 227,
+ "execution_count": 19,
"outputs": []
},
{
@@ -563,23 +564,23 @@
"base_uri": "https://localhost:8080/"
},
"id": "qKso0x4Pn5th",
- "outputId": "87f1ab66-965d-4d41-8003-08db5935403b"
+ "outputId": "614cc227-974b-456d-b0f5-7d95c0a14128"
},
- "execution_count": 228,
+ "execution_count": 20,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
- "Model: \"sequential_6\"\n",
+ "Model: \"sequential\"\n",
"_________________________________________________________________\n",
" Layer (type) Output Shape Param # \n",
"=================================================================\n",
- " dense_15 (Dense) (None, 100) 3100 \n",
+ " dense (Dense) (None, 100) 3100 \n",
" \n",
- " dense_16 (Dense) (None, 40) 4040 \n",
+ " dense_1 (Dense) (None, 40) 4040 \n",
" \n",
- " dense_17 (Dense) (None, 1) 41 \n",
+ " dense_2 (Dense) (None, 1) 41 \n",
" \n",
"=================================================================\n",
"Total params: 7,181\n",
@@ -626,7 +627,7 @@
"metadata": {
"id": "iAY-da-In_pT"
},
- "execution_count": 229,
+ "execution_count": 21,
"outputs": []
},
{
@@ -657,54 +658,77 @@
"base_uri": "https://localhost:8080/"
},
"id": "gF31rSh6oDCd",
- "outputId": "e036c5eb-2846-4a6f-9a81-06040771627f"
+ "outputId": "ce87f1ce-7948-44e9-9440-4d3652b3a188"
},
- "execution_count": 230,
+ "execution_count": 22,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Epoch 1/20\n",
- "5/5 [==============================] - 1s 46ms/step - loss: 0.7196 - accuracy: 0.4843 - val_loss: 0.5961 - val_accuracy: 0.7250\n",
+ "5/5 [==============================] - 3s 55ms/step - loss: 0.5302 - accuracy: 0.8365 - val_loss: 0.4567 - val_accuracy: 0.8625\n",
"Epoch 2/20\n",
- "5/5 [==============================] - 0s 9ms/step - loss: 0.4791 - accuracy: 0.9277 - val_loss: 0.4321 - val_accuracy: 0.9125\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.3698 - accuracy: 0.9214 - val_loss: 0.3395 - val_accuracy: 0.9000\n",
"Epoch 3/20\n",
- "5/5 [==============================] - 0s 11ms/step - loss: 0.3433 - accuracy: 0.9465 - val_loss: 0.3273 - val_accuracy: 0.9375\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.2711 - accuracy: 0.9403 - val_loss: 0.2566 - val_accuracy: 0.9375\n",
"Epoch 4/20\n",
- "5/5 [==============================] - 0s 11ms/step - loss: 0.2586 - accuracy: 0.9434 - val_loss: 0.2569 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 9ms/step - loss: 0.2082 - accuracy: 0.9465 - val_loss: 0.1980 - val_accuracy: 0.9375\n",
"Epoch 5/20\n",
- "5/5 [==============================] - 0s 13ms/step - loss: 0.2032 - accuracy: 0.9528 - val_loss: 0.2095 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.1673 - accuracy: 0.9591 - val_loss: 0.1589 - val_accuracy: 0.9375\n",
"Epoch 6/20\n",
- "5/5 [==============================] - 0s 10ms/step - loss: 0.1657 - accuracy: 0.9560 - val_loss: 0.1775 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.1417 - accuracy: 0.9654 - val_loss: 0.1308 - val_accuracy: 0.9750\n",
"Epoch 7/20\n",
- "5/5 [==============================] - 0s 10ms/step - loss: 0.1420 - accuracy: 0.9623 - val_loss: 0.1549 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.1251 - accuracy: 0.9654 - val_loss: 0.1103 - val_accuracy: 0.9875\n",
"Epoch 8/20\n",
- "5/5 [==============================] - 0s 10ms/step - loss: 0.1232 - accuracy: 0.9717 - val_loss: 0.1399 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.1115 - accuracy: 0.9717 - val_loss: 0.0972 - val_accuracy: 0.9875\n",
"Epoch 9/20\n",
- "5/5 [==============================] - 0s 10ms/step - loss: 0.1094 - accuracy: 0.9717 - val_loss: 0.1303 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 11ms/step - loss: 0.1019 - accuracy: 0.9748 - val_loss: 0.0864 - val_accuracy: 1.0000\n",
"Epoch 10/20\n",
- "5/5 [==============================] - 0s 11ms/step - loss: 0.0999 - accuracy: 0.9717 - val_loss: 0.1231 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0946 - accuracy: 0.9748 - val_loss: 0.0783 - val_accuracy: 1.0000\n",
"Epoch 11/20\n",
- "5/5 [==============================] - 0s 9ms/step - loss: 0.0920 - accuracy: 0.9717 - val_loss: 0.1177 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0891 - accuracy: 0.9811 - val_loss: 0.0715 - val_accuracy: 1.0000\n",
"Epoch 12/20\n",
- "5/5 [==============================] - 0s 12ms/step - loss: 0.0865 - accuracy: 0.9717 - val_loss: 0.1131 - val_accuracy: 0.9750\n",
+ "5/5 [==============================] - 0s 11ms/step - loss: 0.0846 - accuracy: 0.9811 - val_loss: 0.0664 - val_accuracy: 1.0000\n",
"Epoch 13/20\n",
- "5/5 [==============================] - 0s 10ms/step - loss: 0.0812 - accuracy: 0.9717 - val_loss: 0.1096 - val_accuracy: 0.9750\n",
+ "5/5 [==============================] - 0s 11ms/step - loss: 0.0810 - accuracy: 0.9811 - val_loss: 0.0620 - val_accuracy: 1.0000\n",
"Epoch 14/20\n",
- "5/5 [==============================] - 0s 11ms/step - loss: 0.0779 - accuracy: 0.9717 - val_loss: 0.1086 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0771 - accuracy: 0.9811 - val_loss: 0.0579 - val_accuracy: 1.0000\n",
"Epoch 15/20\n",
- "5/5 [==============================] - 0s 10ms/step - loss: 0.0738 - accuracy: 0.9780 - val_loss: 0.1051 - val_accuracy: 0.9625\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0742 - accuracy: 0.9811 - val_loss: 0.0554 - val_accuracy: 1.0000\n",
"Epoch 16/20\n",
- "5/5 [==============================] - 0s 11ms/step - loss: 0.0707 - accuracy: 0.9780 - val_loss: 0.1028 - val_accuracy: 0.9750\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0713 - accuracy: 0.9811 - val_loss: 0.0513 - val_accuracy: 1.0000\n",
"Epoch 17/20\n",
- "5/5 [==============================] - 0s 10ms/step - loss: 0.0681 - accuracy: 0.9780 - val_loss: 0.1016 - val_accuracy: 0.9750\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0687 - accuracy: 0.9811 - val_loss: 0.0485 - val_accuracy: 1.0000\n",
"Epoch 18/20\n",
- "5/5 [==============================] - 0s 11ms/step - loss: 0.0652 - accuracy: 0.9811 - val_loss: 0.0993 - val_accuracy: 0.9750\n",
+ "5/5 [==============================] - 0s 11ms/step - loss: 0.0659 - accuracy: 0.9811 - val_loss: 0.0461 - val_accuracy: 1.0000\n",
"Epoch 19/20\n",
- "5/5 [==============================] - 0s 9ms/step - loss: 0.0627 - accuracy: 0.9843 - val_loss: 0.0980 - val_accuracy: 0.9750\n",
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0639 - accuracy: 0.9811 - val_loss: 0.0446 - val_accuracy: 1.0000\n",
"Epoch 20/20\n",
- "5/5 [==============================] - 0s 11ms/step - loss: 0.0605 - accuracy: 0.9843 - val_loss: 0.0977 - val_accuracy: 0.9750\n"
+ "5/5 [==============================] - 0s 10ms/step - loss: 0.0616 - accuracy: 0.9811 - val_loss: 0.0421 - val_accuracy: 1.0000\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "pip install ann_visualizer"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "2reQpFLKF8bt",
+ "outputId": "b9ee84df-6ff8-4748-a3d4-0b62879ed6ad"
+ },
+ "execution_count": 26,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Requirement already satisfied: ann_visualizer in /usr/local/lib/python3.7/dist-packages (2.5)\n"
]
}
]
@@ -712,6 +736,28 @@
{
"cell_type": "code",
"source": [
+ "from ann_visualizer.visualize import ann_viz;"
+ ],
+ "metadata": {
+ "id": "_kcAIbmgGMu7"
+ },
+ "execution_count": 27,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "ann_viz(model, view=True, title=\"test\", filename=\"visualized\")"
+ ],
+ "metadata": {
+ "id": "qO_6X1buGl8k"
+ },
+ "execution_count": 29,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
"history.epoch"
],
"metadata": {
@@ -721,7 +767,7 @@
"id": "EUbVgdutD3-L",
"outputId": "e5bd59e4-44c0-463f-f3db-ac7ac915f163"
},
- "execution_count": 231,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -743,7 +789,7 @@
"metadata": {
"id": "CmTvhOiFoJsb"
},
- "execution_count": 232,
+ "execution_count": null,
"outputs": []
},
{
@@ -770,7 +816,7 @@
"id": "dPoCecWwoKzk",
"outputId": "bfdaac91-e0a8-4b63-b581-277b4284b382"
},
- "execution_count": 233,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -810,7 +856,7 @@
"id": "MJpq_PEBoQTT",
"outputId": "3a13860c-7f1a-491a-9127-7564c5c9a83c"
},
- "execution_count": 234,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -859,7 +905,7 @@
"id": "j9qI4bbZoRHH",
"outputId": "ce60c889-af9f-400e-ea00-1a9abce7d6e6"
},
- "execution_count": 235,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -906,7 +952,7 @@
"metadata": {
"id": "o2u2R2peoUdQ"
},
- "execution_count": 236,
+ "execution_count": null,
"outputs": []
},
{
@@ -928,7 +974,7 @@
"id": "67OXuSK4od4-",
"outputId": "f1c6d7ba-9ad3-43be-fdfa-d5bde9d43e6c"
},
- "execution_count": 237,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -947,7 +993,7 @@
"metadata": {
"id": "WVVUQDVZojDB"
},
- "execution_count": 238,
+ "execution_count": null,
"outputs": []
},
{
@@ -958,7 +1004,7 @@
"metadata": {
"id": "CtO0VIVDos5F"
},
- "execution_count": 239,
+ "execution_count": null,
"outputs": []
},
{
@@ -973,7 +1019,7 @@
"id": "Mx-qvrayotTl",
"outputId": "856603a8-bfa7-447b-8047-907aa3344764"
},
- "execution_count": 240,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -999,7 +1045,7 @@
"id": "J18nkwLsotnW",
"outputId": "1b2f2c44-9fc4-4c16-a828-a720998deb06"
},
- "execution_count": 241,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1025,7 +1071,7 @@
"id": "TDuqhqW2ozix",
"outputId": "7e21ac31-f96c-4301-9c2b-f03eb744315e"
},
- "execution_count": 242,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1053,7 +1099,7 @@
"id": "DQJ5ImLcOR4Q",
"outputId": "a4d65d3b-2f1a-41c7-a64d-cb64029cb6e4"
},
- "execution_count": 243,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1084,7 +1130,7 @@
"metadata": {
"id": "418_Fqi2o1Vd"
},
- "execution_count": 244,
+ "execution_count": null,
"outputs": []
},
{
@@ -1098,7 +1144,7 @@
"metadata": {
"id": "nUEFLoC1o3oQ"
},
- "execution_count": 245,
+ "execution_count": null,
"outputs": []
},
{
@@ -1113,7 +1159,7 @@
"id": "wYFb_UtuOjDL",
"outputId": "7e78d7b3-0d39-4455-e386-faaa24345051"
},
- "execution_count": 246,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1141,7 +1187,7 @@
"id": "rCtetAZIOvhl",
"outputId": "84fb81e0-ce85-4ece-8a86-acb43ab85d66"
},
- "execution_count": 247,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1195,7 +1241,7 @@
"id": "Q2mrvuqTo6XK",
"outputId": "ac11cbdf-24fd-486b-8705-1f390a4b1645"
},
- "execution_count": 248,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -1226,7 +1272,7 @@
"metadata": {
"id": "YtafEf6Ho6rU"
},
- "execution_count": 249,
+ "execution_count": null,
"outputs": []
},
{
@@ -1250,7 +1296,7 @@
"id": "CGtGSzlOo659",
"outputId": "6b332ab3-7737-458d-d65b-0d471f5799b7"
},
- "execution_count": 250,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -1314,7 +1360,7 @@
"id": "wS-Ktb5Co7LA",
"outputId": "4c0a02fa-3188-4632-ab87-fc821220d722"
},
- "execution_count": 251,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1354,7 +1400,7 @@
"id": "JwJfrlo8pDJ5",
"outputId": "af949097-15e9-4609-9362-6be4d3f139a2"
},
- "execution_count": 252,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1392,7 +1438,7 @@
"id": "s0B7C3S_pDGp",
"outputId": "cb6766e1-4621-45d4-d264-403556138512"
},
- "execution_count": 253,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -1422,7 +1468,7 @@
"metadata": {
"id": "3XTt8tjEpDDa"
},
- "execution_count": 254,
+ "execution_count": null,
"outputs": []
},
{
@@ -1433,7 +1479,7 @@
"metadata": {
"id": "I4hWvlyepC_w"
},
- "execution_count": 255,
+ "execution_count": null,
"outputs": []
},
{
@@ -1444,7 +1490,7 @@
"metadata": {
"id": "LCO4fGnCpC8c"
},
- "execution_count": 256,
+ "execution_count": null,
"outputs": []
},
{
@@ -1463,7 +1509,7 @@
"id": "dUu5UdsbpCy1",
"outputId": "47d822fc-9616-477a-9d58-f52ab47982b7"
},
- "execution_count": 257,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -1502,7 +1548,7 @@
"metadata": {
"id": "P7FAagykpCmG"
},
- "execution_count": 300,
+ "execution_count": null,
"outputs": []
},
{
@@ -1513,7 +1559,7 @@
"metadata": {
"id": "Y74hvjABpXYa"
},
- "execution_count": 301,
+ "execution_count": null,
"outputs": []
},
{
@@ -1539,7 +1585,7 @@
"id": "c34Ie_JSpXVt",
"outputId": "b1657516-8848-4b8b-bdf3-1b118979f4c7"
},
- "execution_count": 302,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1565,7 +1611,7 @@
"id": "YfrApCbfpXTS",
"outputId": "53ce422c-fbae-412f-a849-5c6665f94347"
},
- "execution_count": 303,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1593,7 +1639,7 @@
"id": "cva5m83-pXQi",
"outputId": "bb860358-2911-4ab9-d769-b4f3e5b01276"
},
- "execution_count": 304,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1642,7 +1688,7 @@
"id": "nctQM_cUpXN6",
"outputId": "3a479125-23fc-42ce-cb94-c7cbb9bc5f0f"
},
- "execution_count": 305,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1669,7 +1715,7 @@
"id": "zHqaqabFpXK-",
"outputId": "a5f67a83-05a0-4c9a-a3aa-1b72305a212f"
},
- "execution_count": 306,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1695,7 +1741,7 @@
"id": "Rm6eaTpIpXH0",
"outputId": "f16b81d1-0ccf-4124-dd66-2a59c45345e7"
},
- "execution_count": 307,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1718,7 +1764,7 @@
"metadata": {
"id": "3nEc4nJTpXE_"
},
- "execution_count": 266,
+ "execution_count": null,
"outputs": []
},
{
@@ -1729,7 +1775,7 @@
"metadata": {
"id": "W-vWpFEPptY5"
},
- "execution_count": 308,
+ "execution_count": null,
"outputs": []
},
{
@@ -1749,7 +1795,7 @@
"metadata": {
"id": "_mDvqQ5AptVn"
},
- "execution_count": 309,
+ "execution_count": null,
"outputs": []
},
{
@@ -1764,7 +1810,7 @@
"id": "ITk_zSDDptSv",
"outputId": "0d8320dc-6ec6-4877-a204-170a1a888b54"
},
- "execution_count": 310,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1790,7 +1836,7 @@
"id": "kLdsXkVHptPm",
"outputId": "46a39c8d-dfa6-4675-f971-2a4cea4cb34b"
},
- "execution_count": 311,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1812,7 +1858,7 @@
"metadata": {
"id": "vPM0dY0jX_yj"
},
- "execution_count": 312,
+ "execution_count": null,
"outputs": []
},
{
@@ -1827,7 +1873,7 @@
"id": "3DXntlPIYEDg",
"outputId": "1347661a-01a2-43f2-cca9-81e6ad699265"
},
- "execution_count": 313,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1853,7 +1899,7 @@
"id": "FM_UUBtPptM9",
"outputId": "638e2905-2e3a-46a5-cbef-9df410c9ce79"
},
- "execution_count": 314,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -1937,7 +1983,7 @@
"metadata": {
"id": "Fe5hjC_9ptKT"
},
- "execution_count": 315,
+ "execution_count": null,
"outputs": []
},
{
@@ -1952,7 +1998,7 @@
"id": "Q0zmpxfrptHS",
"outputId": "3a1eeec0-c68d-4483-d02f-5c1f67fa58b0"
},
- "execution_count": 316,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2134,7 +2180,7 @@
"id": "EP8E0gfvptEl",
"outputId": "aec779b0-e150-48ef-a240-27ed4d68fe44"
},
- "execution_count": 317,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2160,7 +2206,7 @@
"id": "1ITXT_PAptBh",
"outputId": "d63590d0-0c56-406d-c4bb-80bef8fd8aa5"
},
- "execution_count": 318,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2183,7 +2229,7 @@
"metadata": {
"id": "z2Himo4-ps92"
},
- "execution_count": 319,
+ "execution_count": null,
"outputs": []
},
{
@@ -2202,7 +2248,7 @@
"id": "2teoM5sjps7A",
"outputId": "93b4b151-97d8-4068-8469-f304f8067fd9"
},
- "execution_count": 320,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -2236,7 +2282,7 @@
"metadata": {
"id": "UP7T50GKps0c"
},
- "execution_count": 321,
+ "execution_count": null,
"outputs": []
},
{
@@ -2247,7 +2293,7 @@
"metadata": {
"id": "Boyap8pipse1"
},
- "execution_count": 322,
+ "execution_count": null,
"outputs": []
},
{
@@ -2262,7 +2308,7 @@
"id": "FSKPF94NqDMu",
"outputId": "8e5d751c-0759-422d-bf46-cb9a7b25d54e"
},
- "execution_count": 323,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -2305,7 +2351,7 @@
"id": "Gh1HOc0nqDAI",
"outputId": "5590807f-bd11-4eeb-904e-369b1970cf92"
},
- "execution_count": 324,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2339,7 +2385,7 @@
"metadata": {
"id": "hs2pqyifrWwf"
},
- "execution_count": 296,
+ "execution_count": null,
"outputs": []
},
{
@@ -2350,7 +2396,7 @@
"metadata": {
"id": "AHP4hJ-3rYC0"
},
- "execution_count": 297,
+ "execution_count": null,
"outputs": []
},
{
@@ -2365,7 +2411,7 @@
"id": "ZlVuLx1qd8m7",
"outputId": "4bfad379-aefc-4e73-aae2-148cf507bcbf"
},
- "execution_count": 325,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2397,7 +2443,7 @@
"id": "aIMGNDbpeBAp",
"outputId": "bea2b826-041c-4dc2-aac3-75140a027899"
},
- "execution_count": 326,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2429,7 +2475,7 @@
"id": "Am2WtlHyrZy0",
"outputId": "7b73649a-9b38-4a4d-a16b-97cb8293874e"
},
- "execution_count": 327,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -2462,7 +2508,7 @@
"id": "syg7Ftq8rcTk",
"outputId": "44f3bc9b-7981-45fd-bc8c-22646321b453"
},
- "execution_count": 328,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
@@ -2485,7 +2531,7 @@
"id": "81Eo4m0Zreov",
"outputId": "13fcb2f5-296f-4e00-bf65-3b37dbac7b57"
},
- "execution_count": 329,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2511,7 +2557,7 @@
"id": "qRqRU23Vrf0W",
"outputId": "9ee72ce9-47de-40c7-8ebd-f656864ebd3e"
},
- "execution_count": 330,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2537,7 +2583,7 @@
"id": "qsI8pRM5rhl5",
"outputId": "568825f3-c1ec-40b7-d48b-14046530e15f"
},
- "execution_count": 331,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2573,7 +2619,7 @@
"id": "U3VVHL-UrkCa",
"outputId": "f12c40ba-7b88-4e01-84de-fc6aa1d2a141"
},
- "execution_count": 332,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2599,7 +2645,7 @@
"id": "eUFCCciArlLu",
"outputId": "97da500a-d7c1-4822-e10a-42f2bb5882e4"
},
- "execution_count": 333,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2626,7 +2672,7 @@
"id": "2LnkkaOlrmhp",
"outputId": "46e65722-9a6d-4929-99e8-88898a29f012"
},
- "execution_count": 339,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2662,7 +2708,7 @@
"metadata": {
"id": "QHbV6P1Krogm"
},
- "execution_count": 335,
+ "execution_count": null,
"outputs": []
},
{
@@ -2677,7 +2723,7 @@
"id": "T8-EEGvGrpeN",
"outputId": "59bf3c52-12ef-4d0e-dc25-94340b2f49f3"
},
- "execution_count": 340,
+ "execution_count": null,
"outputs": [
{
"output_type": "execute_result",
@@ -2699,7 +2745,7 @@
"metadata": {
"id": "hcIYHksfrrIS"
},
- "execution_count": 341,
+ "execution_count": null,
"outputs": []
},
{
@@ -2719,7 +2765,7 @@
"id": "G3-q4lPvruG7",
"outputId": "62500d33-ea1b-4cde-fe3e-07927d65708a"
},
- "execution_count": 343,
+ "execution_count": null,
"outputs": [
{
"output_type": "stream",
diff --git a/backend/microservice/PythonServer/project/api/templates/index.html b/backend/microservice/index.html
index 98b35d52..98b35d52 100644
--- a/backend/microservice/PythonServer/project/api/templates/index.html
+++ b/backend/microservice/index.html
diff --git a/backend/microservice/ml_socket.py b/backend/microservice/ml_socket.py
new file mode 100644
index 00000000..5489b787
--- /dev/null
+++ b/backend/microservice/ml_socket.py
@@ -0,0 +1,25 @@
+import asyncio
+import websockets
+import json
+
+def get_or_create_eventloop():
+ try:
+ return asyncio.get_event_loop()
+ except RuntimeError as ex:
+ if "There is no current event loop in thread" in str(ex):
+ loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(loop)
+ return asyncio.get_event_loop()
+
+# create handler for each connection
+async def handler(websocket, path):
+ #data = json.loads(await websocket.recv())
+ #reply = f"Data recieved as: {data}!"
+ #print(data['test'])
+ msg = await websocket.recv()
+ await websocket.send("[" + msg + "]")
+
+start_server = websockets.serve(handler, "localhost", 5027)
+
+get_or_create_eventloop().run_until_complete(start_server)
+get_or_create_eventloop().run_forever() \ No newline at end of file
diff --git a/backend/microservice/mlservice.py b/backend/microservice/mlservice.py
index 3385a18e..b2eafe9a 100644
--- a/backend/microservice/mlservice.py
+++ b/backend/microservice/mlservice.py
@@ -406,6 +406,11 @@ def obuka(dataunos,params,modelunos,dataunosdrugog):
### 27)ROC
fpr, tpr, _ = sm.roc_curve(y_test,y_pred)
+ # https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
+ # tn, fp, fn, tp = confusion_matrix(y_test, y_pred).ravel()
+ # Korelaciona matrica
+ # https://datatofish.com/correlation-matrix-pandas/
+
'''
plt.plot(fpr, tpr, color='blue')
plt.title('ROC')
diff --git a/backend/microservice/network1.gv.pdf b/backend/microservice/network1.gv.pdf
new file mode 100644
index 00000000..797b23db
--- /dev/null
+++ b/backend/microservice/network1.gv.pdf
Binary files differ
diff --git a/backend/microservice/PythonServer/project/api/titanic.csv b/backend/microservice/titanic.csv
index 5cc466e9..5cc466e9 100644
--- a/backend/microservice/PythonServer/project/api/titanic.csv
+++ b/backend/microservice/titanic.csv