Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do 15 #19

Merged
merged 4 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions data_owner/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

class TrainingStatus(Enum):
WAITING = 0
INITIATED = 1
IN_PROGRESS = 2
FINISHED = 3
READY = 1
INITIATED = 2
IN_PROGRESS = 3
FINISHED = 4


class ModelColumn(types.UserDefinedType):
Expand Down
5 changes: 3 additions & 2 deletions data_owner/resources/models_resource.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_restplus import Resource, Namespace, fields, reqparse
from data_owner.models.model import TrainingStatus
from data_owner.services.entities.model_response import ModelResponse
from data_owner.services.model_service import ModelService

api = Namespace('models', description='Model related operations')
Expand Down Expand Up @@ -41,6 +41,7 @@
'creation_date': fields.String(description='The model creation date'),
'updated_date': fields.String(description='The model updated date'),
'user_id': fields.String(required=True, description='The model user_id'),
'requirements': fields.String(required=True, description='The requirements on the data for training the model'),
'name': fields.String(required=True, description='The model name')
})

Expand Down Expand Up @@ -74,4 +75,4 @@ class ModelResources(Resource):
@api.doc('Get trained model')
@api.marshal_with(model_data)
def get(self, model_id):
return ModelService.get(model_id)
return ModelResponse(ModelService.get(model_id))
1 change: 1 addition & 0 deletions data_owner/services/entities/model_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, model):
"creation_date": model.creation_date,
"updated_date": model.updated_date,
"user_id": model.user_id,
"requirements": model.requirements,
"name": model.name}

self.metrics = {"mse": model.mse,
Expand Down
10 changes: 9 additions & 1 deletion data_owner/services/model_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from data_owner.models.model import Model
from data_owner.services.datasets_service import DatasetsService
from data_owner.models.model import TrainingStatus


class ModelService:

Expand All @@ -9,4 +12,9 @@ def get_all(cls, args):

@classmethod
def get(cls, model_id):
return Model.get(model_id)
model = Model.get(model_id)
dataset = DatasetsService().get_dataset_for_training(model.requirements)
if dataset and model.status == TrainingStatus.WAITING.name:
model.status = TrainingStatus.READY.name
model.update()
return model
19 changes: 16 additions & 3 deletions node-server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ var routes = {
DATASETS: "/datasets",
MODELS: "/models",
MODEL: "/models/:id",
ACCEPT: "/trainings/:id/accept"
};

var httpMethods = {
POST: "POST",
GET: "GET"
GET: "GET",
PUT: "PUT"
};


Expand Down Expand Up @@ -84,6 +86,16 @@ app.post(routes.LOGIN, async (req, res) => {
}
});

app.put(routes.ACCEPT, async (req, res) => {
try {
const {id} = req.params;
res.json(executeFetchJson(httpMethods.PUT, "/trainings/"+id+"/accept", JSON.stringify(req.body)));
} catch (e) {
//this will eventually be handled by your error handling middleware
console.log(e)
}
});

app.post(routes.DATASETS, async (req, res) => {
try {
upload(req, res, function (err) {
Expand Down Expand Up @@ -131,13 +143,14 @@ app.get(routes.MODELS, async (req, res) => {

app.get(routes.MODEL, async (req, res) => {
try {
const {id} = req.params;
console.log(req.param("tagId"))
res.json(await executeFetchJson(httpMethods.GET, routes.MODEL));
res.json(await executeFetchJson(httpMethods.GET, "/models/"+id));
} catch (e) {
//this will eventually be handled by your error handling middleware
console.log(e)
}
});


app.listen(port, () => console.log(`Example app listening on port ${port}!`))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))