Beispiel #1
0
    def create_operation(self, operation: Operation) -> GetOperation:
        """
        create_operation - adds operation to db
        :param operation: received data
        :return: dataclass with operation data
        """
        if operation.category_id is not None:
            category = (self.session.query(CategoryModel).filter(
                and_(CategoryModel.id == operation.category_id,
                     CategoryModel.user_id == self.user_id)).first())

            if category is None:
                raise EntityDoesNotExistError()

        new_operation = OperationModel(amount=(int(operation.amount * 100)),
                                       description=operation.description,
                                       datetime=operation.datetime,
                                       type_operation=operation.type_operation,
                                       user_id=self.user_id,
                                       category_id=operation.category_id)

        self.session.add(new_operation)
        self.session.commit()
        self.operation_id = new_operation.as_dict().get('id')
        return self.get_operation()
Beispiel #2
0
async def div(params: ParamsModel):
    try:
        res = ResultModel(result=(params.a / params.b))
    except ZeroDivisionError:
        raise HTTPException(404, "error division by zero")
    await db.add(OperationModel(operation=div.__name__, params=params, result=res))
    return res
Beispiel #3
0
    def mutate(self, info, id, content, nameOp):

        resultOp = nlp_Operation(content, nameOp)
        operation = OperationModel(nameOp=nameOp,
                                   dateOp=date.today(),
                                   resultOp=resultOp)
        newText = TextModel(content=content,
                            dateCr=date.today(),
                            emotion=-1,
                            fakeNews=-1)

        user = UserModel.objects.get(pk=ObjectId(id))
        user.text.append(newText)
        for x in user.text:
            if (x['content'] == content):
                x.operation.append(operation)
        print(resultOp)
        user.save()
        return AddText(user=user)
Beispiel #4
0
    def mutate(self, info, id, content):
        rs: number
        resultOp = TrainingModels.getResult("data/DTC.pkl", content)
        if (resultOp[0] == 'Positive'):
            rs = 1
        else:
            rs = 0

        operation = OperationModel(nameOp="emt",
                                   dateOp=date.today(),
                                   resultOp=resultOp)
        newText = TextModel(content=content,
                            dateCr=date.today(),
                            emotion=rs,
                            fakeNews=-1)

        user = UserModel.objects.get(pk=ObjectId(id))
        user.text.append(newText)
        for x in user.text:
            if (x['content'] == content):
                x.operation.append(operation)
        print(resultOp)
        user.save()
        return AddEmotion(user=user)
Beispiel #5
0
    def mutate(self, info, id, content):
        rs = []
        resultOp = TrainingModel.getResult("data/Fake/knn.pkl", content)
        if (resultOp[0] == 1):
            rs = rs.append("1")
        else:
            rs = rs.append("0")

        operation = OperationModel(nameOp="emt",
                                   dateOp=date.today(),
                                   resultOp=rs)
        newText = TextModel(content=content,
                            dateCr=date.today(),
                            emotion=-1,
                            fakeNews=resultOp[0])

        user = UserModel.objects.get(pk=ObjectId(id))
        user.text.append(newText)
        for x in user.text:
            if (x['content'] == content):
                x.operation.append(operation)
        # print(resultOp)
        user.save()
        return AddFake(user=user)
Beispiel #6
0
async def mul(params: ParamsModel):
    res = ResultModel(result=(params.a * params.b))
    await db.add(OperationModel(operation=mul.__name__, params=params, result=res))
    return res