예제 #1
0
class StreamParameter(db.Model):
    __tablename__ = 'stream_parameter'
    stream_id = db.Column(db.Integer,
                          db.ForeignKey('stream.id'),
                          primary_key=True)
    parameter_id = db.Column(db.Integer,
                             db.ForeignKey('parameter.id'),
                             primary_key=True)
예제 #2
0
class Response(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String)
    summary = db.Column(db.String)
    relevance = db.Column(db.Integer)

    def __repr__(self):
        return '<Response {}>'.format(self.id)
예제 #3
0
class UnlabelledExample(db.Model):
    index = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.String)
    author = db.Column(db.String)
    subreddit = db.Column(db.String)
    post = db.Column(db.String)

    def __repr__(self):
        return '<UnlabelledExample {}>'.format(self.index)
예제 #4
0
class ServiceImage(db.Model, Image):
    """Service Service Image model"""
    service_id = db.Column(db.Integer,
                           db.ForeignKey('service.id'),
                           primary_key=True)
    service = db.relationship('Service')
    __tablename__ = 'service_image'
예제 #5
0
class CustomerProfile(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    region = db.Column(db.PickleType, nullable=False)
    serviceType = db.Column(db.PickleType, nullable=False)
    attackType = db.Column(db.PickleType, nullable=False)
    deploymentTime = db.Column(db.Text,
                               nullable=False,
                               default=datetime.utcnow)
    deploymentTimeWeight = db.Column(db.Integer, nullable=False)
    leasingPeriod = db.Column(db.PickleType, nullable=False)
    leasingPeriodWeight = db.Column(db.PickleType, nullable=False)
    budget = db.Column(db.Integer, nullable=False)
    budgetWeight = db.Column(db.Integer, nullable=False)

    @property
    def serialize(self):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'region': self.region,
            'serviceType': self.serviceType,
            'attackType': self.attackType,
            'deploymentTime': self.deploymentTime,
            'deploymentTimeWeight': self.deploymentTimeWeight,
            'leasingPeriod': self.leasingPeriod,
            'leasingPeriodWeight': self.leasingPeriodWeight,
            'budget': self.budget,
            'budgetWeight': self.budgetWeight,
        }

    def __repr__(self):
        return f"CustomerProfile('{self.region}', '{self.serviceType}', '{self.deploymentTime}', '{self.leasingPeriod}', '{self.budget}', '{self.attackType}')"

    def json_to_obj(self, json):
        self.region = json["region"]
        self.serviceType = json["serviceType"]
        self.attackType = json["attackType"]
        self.deploymentTime = json["deploymentTime"]
        self.deploymentTimeWeight = json["deploymentTimeWeight"]
        self.leasingPeriod = json["leasingPeriod"]
        self.leasingPeriodWeight = json["leasingPeriodWeight"]
        self.budget = json["budget"]
        self.budgetWeight = json["budgetWeight"]
        return self
예제 #6
0
class ParameterFunction(db.Model):
    __tablename__ = 'parameter_function'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250))
    function_type_id = db.Column(db.Integer, db.ForeignKey('function_type.id'))
    function_type = db.relationship(FunctionType)
    function = db.Column(db.String(250))
    owner = db.Column(db.String(250))
    description = db.Column(db.String(4096))
예제 #7
0
class Review(db.Model):
    """Service Review model"""
    id = db.Column(db.Integer, primary_key=True)
    service_id = db.Column(db.Integer, db.ForeignKey('service.id'))
    fileName = db.Column(db.Text, nullable=False)
    fileData = db.Column(db.LargeBinary)
    rating = db.Column(db.Integer, nullable=False)
    comment = db.Column(db.Text, nullable=False)

    @property
    def serialize(self):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'fileName': self.fileName,
            'rating': self.rating,
            'comment': self.comment,
        }
예제 #8
0
class Service(db.Model):
    """Service model"""

    id = db.Column(db.Integer, primary_key=True)
    providerName = db.Column(db.String(100), nullable=False)
    serviceHash = db.Column(db.String(100), unique=True)
    txHash = db.Column(db.String(100))
    serviceName = db.Column(db.String(100), nullable=False)
    image = image_attachment('ServiceImage')
    imageName = db.Column(db.String(30), default='default.png')
    description = db.Column(db.Text, nullable=False)
    type = db.Column(db.PickleType, nullable=False)
    features = db.Column(db.PickleType, nullable=False)
    region = db.Column(db.PickleType, nullable=False)
    deployment = db.Column(db.Text, nullable=False)
    leasingPeriod = db.Column(db.Text, nullable=False)
    price = db.Column(db.Integer, nullable=False)
    currency = db.Column(db.Text, nullable=False, default='USD')
    reviews = db.relationship('Review', backref="service", lazy='dynamic')
    __tablename__ = 'service'

    def serialize(self,
                  cosine_similarity='',
                  jaccard_similarity='',
                  euclidean_distance='',
                  manhattan_distance='',
                  pearson_correlation='',
                  minkowski_distance='',
                  weighted_similarity=[]):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'providerName': self.providerName,
            'serviceName': self.serviceName,
            'serviceHash': self.serviceHash,
            'txHash': self.txHash,
            'image': base64.b64encode(self.image.make_blob()).decode("utf-8"),
            'description': self.description,
            'type': self.type,
            'features': self.features,
            'region': self.region,
            'deployment': self.deployment,
            'leasingPeriod': self.leasingPeriod,
            'price': self.price,
            'currency': self.currency,
            'reviews': [r.serialize for r in self.reviews],
            'cosineSimilarity': cosine_similarity,
            'jaccardSimilarity': jaccard_similarity,
            'euclideanDistance': euclidean_distance,
            'manhattanDistance': manhattan_distance,
            'pearsonCorrelation': pearson_correlation,
            'minkowskiDistance': minkowski_distance,
            'weightedSimilarity': weighted_similarity
        }

    def json_to_obj(self, json):
        self.providerName = json["provider"]
        self.serviceName = json["productName"]
        self.description = json["description"]
        self.image = json["logo"]
        self.imageName = json["fileName"]
        self.region = json["region"]
        self.type = json["serviceType"]
        self.features = json["attackType"]
        self.deployment = json["deploymentTime"]
        self.leasingPeriod = json["leasingPeriod"]
        self.price = json["price"]
        self.txHash = json["txHash"]
        self.serviceHash = json["serviceHash"]
        return self

    def form_to_obj(self, form, file):
        self.providerName = form["provider"]
        self.serviceName = form["productName"]
        self.description = form["description"]
        self.imageName = file.filename
        self.region = form["region"].split()
        self.type = form["serviceType"].split()
        self.features = form["attackType"].split()
        self.deployment = form["deploymentTime"]
        self.leasingPeriod = form["leasingPeriod"]
        self.price = form["price"]
        self.txHash = form["txHash"]
        self.serviceHash = form["serviceHash"]
        return self

    def __repr__(self):
        return f"Service('{self.serviceName}', '{self.type}', '{self.region}', '{self.price}', '{self.currency}', '{self.txHash}', '{self.serviceHash}')"
예제 #9
0
class Parameter(db.Model):
    __tablename__ = 'parameter'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False)
    parameter_type_id = db.Column(db.Integer,
                                  db.ForeignKey('parameter_type.id'))
    parameter_type = db.relationship(ParameterType)
    value_encoding_id = db.Column(db.Integer,
                                  db.ForeignKey('value_encoding.id'))
    value_encoding = db.relationship(ValueEncoding)
    code_set_id = db.Column(db.Integer, db.ForeignKey('code_set.id'))
    code_set = db.relationship(CodeSet)
    unit_id = db.Column(db.Integer, db.ForeignKey('unit.id'))
    unit = db.relationship(Unit)
    fill_value_id = db.Column(db.Integer, db.ForeignKey('fill_value.id'))
    fill_value = db.relationship(FillValue)
    display_name = db.Column(db.String(4096))
    precision = db.Column(db.Integer)
    parameter_function_id = db.Column(db.Integer,
                                      db.ForeignKey('parameter_function.id'))
    parameter_function = db.relationship(ParameterFunction)
    parameter_function_map = db.Column(db.PickleType(pickler=json))
    data_product_identifier = db.Column(db.String(250))
    description = db.Column(db.String(4096))
    streams = db.relationship('Stream', secondary='stream_parameter')

    def parse_pdid(self, pdid_string):
        return int(pdid_string.split()[0][2:])

    def needs(self, needed=None):
        if needed is None:
            needed = []

        if self in needed:
            return

        if self.parameter_type.value == 'function':
            for value in self.parameter_function_map.values():
                if isinstance(value, basestring) and value.startswith('PD'):
                    try:
                        pdid = self.parse_pdid(value)
                        sub_param = Parameter.query.get(pdid)
                        if sub_param in needed:
                            continue
                        sub_param.needs(needed)
                    except (ValueError, AttributeError):
                        pass

        if self not in needed:
            needed.append(self)
        return needed

    def needs_cc(self, needed=None):
        if needed is None:
            needed = []

        if self.parameter_type.value == 'function':
            for value in self.parameter_function_map.values():

                if isinstance(value, basestring) and value.startswith(
                        'CC') and value not in needed:
                    needed.append(value)

        return needed
예제 #10
0
class FunctionType(db.Model):
    __tablename__ = 'function_type'
    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.String(250), nullable=False, unique=True)
예제 #11
0
class FillValue(db.Model):
    __tablename__ = 'fill_value'
    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.String(20), nullable=False)
예제 #12
0
class Unit(db.Model):
    __tablename__ = 'unit'
    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.String(250), nullable=False, unique=True)
예제 #13
0
class CodeSet(db.Model):
    __tablename__ = 'code_set'
    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.String(250), nullable=False)
예제 #14
0
class Stream(db.Model):
    __tablename__ = 'stream'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False, unique=True)
    parameters = db.relationship('Parameter', secondary='stream_parameter')
예제 #15
0
class ValueEncoding(db.Model):
    __tablename__ = 'value_encoding'
    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.String(20), nullable=False, unique=True)
예제 #16
0
class ParameterType(db.Model):
    __tablename__ = 'parameter_type'
    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.String(20), nullable=False, unique=True)
예제 #17
0
class Query(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String)

    def __repr__(self):
        return '<Query {}>'.format(self.id)
예제 #18
0
class LabelledExample(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    original_index = db.Column(db.Integer)
    date = db.Column(db.String)
    author = db.Column(db.String)
    subreddit = db.Column(db.String)
    post = db.Column(db.String)
    gender = db.Column(db.String)
    employment = db.Column(db.String)
    student = db.Column(db.String)
    immigrant = db.Column(db.String)
    age = db.Column(db.String)
    relationship = db.Column(db.String)
    psychology = db.Column(db.String)

    def __repr__(self):
        return '<LabelledExample {}>'.format(self.index)