예제 #1
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'
예제 #2
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))
예제 #3
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}')"
예제 #4
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
예제 #5
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')