Beispiel #1
0
    def SearchSolutions(self, message):
        """Get potential pipelines and load into DB."""
        # Validate request is in required format, extract if it is
        dataset_uri, _ = self.validator.validate_search_solutions_request(
            message)
        # Generate search ID
        search_id = self._generate_id()

        # serialize the problem buf to json to save it in the db
        prob = json_format.MessageToDict(message.problem)
        prob = json.dumps(prob)

        # serialize the pipeline to a string for storage in db if one is provided
        search_template: str = None
        if message.HasField('template'):
            search_template_obj = api_utils.decode_pipeline_description(
                message.template, pipeline.Resolver())
            search_template = search_template_obj.to_json()

        # Create search row in DB
        search = models.Searches(id=search_id)
        self.session.add(search)
        self.session.commit()

        task = models.Tasks(problem=prob,
                            pipeline=search_template,
                            type="EXLINE",
                            dataset_uri=dataset_uri,
                            id=self._generate_id(),
                            search_id=search_id)
        self.session.add(task)

        # Add all to DB
        self.session.commit()
        return search_id
Beispiel #2
0
def create_dataset():
    import datetime as dt
    from sqlalchemy import func, asc
    form = fm.Create_Dataset(fl.request.form)
    if fl.request.method == 'GET':
        return fl.render_template('leadanalyst/dataset/create.html', form=form)
    else:
        # process
        if form.validate_on_submit():
            # submit to db
            user = fl.session['logged_in']
            ds = ml.Dataset(name=form.name.data, \
            search_type=int(form.search_type.data), user_created=int(user), \
            year_start=form.year_start.data, year_end=form.year_end.data, \
            owner=user, freq=int(form.freq.data))
            ds_auth_owner = ml.Dataset_Authd(access=user)
            ds_auth = ml.Dataset_Authd(access=form.access.data)
            time_created = datetime.datetime.now()
            ds.time_created = time_created
            ds.access.append(ds_auth)
            ds.access.append(ds_auth_owner)
            db.db_session.add(ds)
            fl.flash("Added the dataset!", "success")
            # now break up this into the correct amount of tasks
            freq_list, start, end = get_time_list(form.year_start.data, \
            form.year_end.data, form.freq.data)
            ds_id = ml.Dataset.query.order_by(asc(ml.Dataset.id)).first()
            if ds_id == None:
                ds_id = 1
            else:
                ds_id = ds_id.id
            for i in range(0, len(freq_list), 1):
                # create a task for every frequency object

                t_cur = ml.Tasks()
                t_cur.nickname = freq_list[i]
                t_cur.date_created = dt.datetime.now()
                t_cur.dataset_owner = int(ds_id)
                t_cur.date_start = start[i]
                t_cur.date_end = end[i]
                t_cur.who_assigned = int(user)
                t_cur.stage = 1
                t_cur.num_inv_found = 0
                t_cur.num_inv_progressing = 0
                t_cur.state = State.Working
                db.db_session.add(t_cur)

            db.db_session.commit()
            return fl.render_template('leadanalyst/dataset/create.html',
                                      form=form)
        else:
            # return str(form.freq.data)
            fl.flash("Dataset not created", "error")
            fl.flash(str(form.errors), 'error')
            return fl.render_template('leadanalyst/dataset/create.html',
                                      form=form)
Beispiel #3
0
 def test_on_data(self):
     session = UnifiedAlchemyMagicMock()
     session.add(models.Users("Jake", "email@email", "password", "role", "img"))
     session.add(models.Participants("email@email", "gc"))
     session.add(models.Projects("gc", "testName", "testDescription"))
     session.add(
         models.Tasks("testTitle", "testDescription", "date", "gc", "owner", "done")
     )
     with mock.patch("app.db.session", session):
         with mock.patch("app.request", RequestObj()):
             app.on_data({"email": "email@email"})
Beispiel #4
0
 def test_on_complete(self):
     session = UnifiedAlchemyMagicMock()
     session.add(
         models.Tasks(
             "mockTitle", "test", "11-04-2020", "abc", "aarati", "completed"
         )
     )
     data = {
         "email": "jake",
         "t": "true",
     }
     with mock.patch("app.db.session", session):
         app.on_complete_task(data)
Beispiel #5
0
    def ScoreSolution(self, request):
        """
        Create a 'task' for each bit of the score objective
        """
        # validate and unpack message if valid
        # TODO: HAVE SENSIBLE DEFAULTS HERE
        # SO THEY CAN BE STORED IN DB
        (solution_id, dataset_uri, metrics, method, folds, train_test_ratio,
         shuffle, random_seed,
         stratified) = self.validator.validate_score_solution_request(request)

        # TODO: if it has been scored already in the same manner,
        # return the request_id from that first time
        score_request_id = self._generate_id()
        solution_id = request.solution_id
        # Create mapping between score_request and solution_id
        _request = models.Requests(id=score_request_id,
                                   solution_id=solution_id,
                                   type="SCORE")
        self.session.add(_request)
        self.session.commit()

        # Attempt to create a scoring_config
        # Add a SCORE task per metric in the request
        for metric in metrics:
            conf_id = self._generate_id()
            conf = models.ScoreConfig(
                id=conf_id,
                metric=metric,
                method=method,
                num_folds=folds,
                # TODO: train_test_ratio is currently unused by SolutionScorer
                # remove it or fix it
                train_test_ratio=train_test_ratio,
                shuffle=shuffle,
                random_seed=random_seed,
                stratified=stratified)
            self.session.add(conf)
            task_id = self._generate_id()
            task = models.Tasks(id=task_id,
                                type="SCORE",
                                solution_id=solution_id,
                                dataset_uri=dataset_uri,
                                score_config_id=conf_id)
            self.session.add(task)
            # Add configs and tasks to pool
            self.session.commit()

        return score_request_id
Beispiel #6
0
def on_create_task(data):
    print("Received new task data: ", data)
    email = data["email"]
    title = data["title"]
    description = data["description"]
    deadline = data["deadline"]
    proj_name = data["project"]
    complete_status = "F"

    gc = ""
    user_gc = [
        db_par.group_code
        for db_par in db.session.query(models.Participants).filter(
            models.Participants.email == email)
    ]

    for code in user_gc:
        exists = (db.session.query(
            models.Projects).filter(models.Projects.group_code == code).filter(
                models.Projects.proj_name == proj_name).scalar())
        print(exists)
        if exists:
            for db_proj in db.session.query(models.Projects):
                print()
            gc = [
                db_proj.group_code
                for db_proj in db.session.query(models.Projects).filter(
                    models.Projects.group_code == code).filter(
                        models.Projects.proj_name == proj_name)
            ]

            break

    owner = ""

    db.session.add(
        models.Tasks(title, description, deadline, gc[0], owner,
                     complete_status))
    db.session.commit()
    message = """
    Hello {},
    
    You have created a task on the Project Manager app!
    """
    create_and_send_email(email, message)
Beispiel #7
0
    def ProduceSolution(self, message):
        # Generate request ID
        request_id = self._generate_id()

        # Validate request is in required format, extract if it is
        extracted_fields = self.validator.validate_produce_solution_request(
            message)
        fitted_solution_id, dataset_uri, output_key = extracted_fields

        # Get existing fit_solution.id
        fit_solution = self.session.query(models.FitSolution) \
                          .filter(models.FitSolution.id==fitted_solution_id) \
                          .first()

        if fit_solution is None:
            raise ValueError("Fitted solution id {} doesn't exist".format(
                fitted_solution_id))

        # add a produce task to the tasks table
        task_id = self._generate_id()
        task = models.Tasks(id=task_id,
                            type="PRODUCE",
                            request_id=request_id,
                            fit_solution_id=fitted_solution_id,
                            solution_id=fit_solution.solution_id,
                            dataset_uri=dataset_uri,
                            output_key=output_key)
        self.session.add(task)
        self.session.commit()

        # make a record for the request and commit to the database
        request_record = models.Requests(id=request_id,
                                         task_id=task.id,
                                         type="PRODUCE",
                                         fit_solution_id=fitted_solution_id)
        self.session.add(request_record)
        self.session.commit()

        return request_id
 def setUp(self):
     self.tasks = t.Tasks()