Ejemplo n.º 1
0
class Bill(StructuredNode):
    STATES = {
        '-1': 'created',
        '0': 'mined',
        '1': 'pendingSubmission',
        '2': 'submitted',
        '3': 'pendingApproval',
        '4': 'approved',
        '5': 'pendingDisbursal',
        '6': 'disbursed',
        '7': 'requiresApproval',
        '8': 'requiresDisbursal'
    }
    uuid = StringProperty(unique_index=True)
    uuidhash = StringProperty(unique_index=True)
    metadata = JSONProperty(required=True)
    expenseMap = JSONProperty(required=True)
    createdBy = StringProperty(required=True)
    # -1 for created, 0 for mined, 1 for pending approval, 2 for all splits submitted fully
    state = StringProperty(required=True, choices=STATES)
    group = RelationshipTo(
        'Group', 'BILL_OF', model=BillOf,
        cardinality=cardinality.One)  # can belong to only one grp
    parentBill = RelationshipTo(
        'Bill', 'CHILD_OF',
        cardinality=cardinality.One)  # can have only one parent bill
    childBills = RelationshipFrom('Bill', 'CHILD_OF')
class UserAccount(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    roles = JSONProperty()
    rights = JSONProperty()
    accessToCluster = RelationshipTo('Cluster', 'CAN_ACCESS')
    ownsNamespace = RelationshipTo('Namespace', 'OWNS')
    ownNode = RelationshipTo('Nodes', 'OWNS')
class Component(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    componentType = StringProperty()
    version = StringProperty()
    metaData = JSONProperty()
    spec = JSONProperty()
    alarms = ArrayProperty()
    cloudType = StringProperty(default="Kubernetes")
class Namespace(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    version = StringProperty()
    metaData = JSONProperty()
    spec = JSONProperty()
    labels = StringProperty()
    cloudType = StringProperty(default="Kubernetes")
    workload = RelationshipFrom('WorkLoad', 'PART_OF')
Ejemplo n.º 5
0
class Playlist(SpotifyNode):
    '''
    Represents a Playlist on Spotify
    '''

    owner = RelationshipTo('model.graph.spotify.user.User', 'OWNED BY')

    tracks = RelationshipFrom('model.graph.spotify.track.Track', 'FEATURED IN')

    spotify_id = StringProperty(unique_index=True)
    name = StringProperty()
    collaborative = BooleanProperty()
    description = StringProperty()
    external_urls = JSONProperty()
    href = StringProperty()
    images = JSONProperty()
    primary_color = StringProperty()
    public = BooleanProperty()
    snapshot_id = StringProperty()
    type = StringProperty()
    uri = StringProperty()

    @staticmethod
    def post_clean(obj, to_connect: dict):
        from model.graph.spotify.user import User
        owner = to_connect['owner']
        owner = User.inst(**owner)
        obj.owner.connect(owner)
        return obj

    @classmethod
    def clean(cls, **kwargs):
        if 'tracks' in kwargs:
            del kwargs['tracks']
        if 'id' in kwargs:
            kwargs['spotify_id'] = kwargs.pop('id')

        to_connect = {'owner': kwargs.pop('owner')}
        obj = cls(**kwargs)
        return obj, to_connect

    @classmethod
    def get_tracks(cls, spotify_id):
        s = time()
        from model.graph.spotify.track import SmallTrack
        db.set_connection(connection_url())
        query = '''
        MATCH (p: Playlist {spotify_id: "%s"}) <-[r1: `FEATURED IN`]- (t: Track)
        RETURN t.uri, t.zVector, t.spotify_id, t.name
        ''' % spotify_id
        results, meta = db.cypher_query(query)
        print('Results fetched', time() - s)
        keys = ['uri', 'zVector', 'spotify_id', 'name']
        kwargs = [{keys[i]: val
                   for i, val in enumerate(result)} for result in results]

        return [SmallTrack(**result) for result in kwargs]
class WorkLoad(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    workLoadType = StringProperty()
    version = StringProperty()
    metaData = JSONProperty()
    spec = JSONProperty()
    alarms = ArrayProperty()
    labels = StringProperty()
    cloudType = StringProperty(default="Kubernetes")
    component = RelationshipFrom('Component', 'PART_OF')
Ejemplo n.º 7
0
class Element(StructuredNode):
    """Base element type."""

    __abstrac__abstract_node__ = True
    uid = StringProperty(unique_index=True)
    name = StringProperty()
    properties = JSONProperty()
    object_properties = Relationship('Property', 'OBJ_PROPERTY')
    tags = JSONProperty()
    object_tags = Relationship('Tag', 'OBJ_TAG')
Ejemplo n.º 8
0
class AssociationRel(BaseRelation):
    _id = StringProperty()
    relation_type = "Association"
    association_type = StringProperty()
    src_cardinality_lower_val = StringProperty()
    src_cardinality_upper_val = StringProperty()
    dest_cardinality_lower_val = StringProperty()
    dest_cardinality_upper_val = StringProperty()
    src_properties = JSONProperty()
    dest_properties = JSONProperty()
class Policy(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    version = StringProperty()
    viewType = StringProperty(default="crisp")
    metaData = JSONProperty()
    spec = JSONProperty()
    policyRules = JSONProperty()
    labels = StringProperty()
    cloudType = StringProperty(default="Kubernetes")
    appliesToNS = RelationshipTo('Namespace', 'APPLIES_TO')
    appliesToCluster = RelationshipTo('Cluster', 'APPLIES_TO')
    appliesToWorkLoad = RelationshipTo('WorkLoad', 'APPLIES_TO')
    instanceOf = RelationshipTo(CrispNode, "MAPS_TO_SECURITYCONFIGURATIONS")
Ejemplo n.º 10
0
class User(GeniusNode):
    '''
    Represents user data from Genius.com
    '''

    genius_id = IntegerProperty()

    # TODO: Build connections with annotations
    api_path = StringProperty(unique_index=True)
    avatar = JSONProperty()
    header_image_url = StringProperty()
    human_readable_role_for_display = StringProperty()
    iq = IntegerProperty()
    login = StringProperty(unique_index=True)
    name = StringProperty()
    role_for_display = StringProperty()
    url = StringProperty()

    @classmethod
    def inst(cls, **kwargs):
        kwargs['genius_id'] = kwargs.pop('id')
        kwargs.pop('current_user_metadata')

        # TODO: clean this shit

        raise NotImplementedError('Not fully implemented yet')
Ejemplo n.º 11
0
class AvailabilityZone(StructuredNode):
    """AV of a region where the elements are available."""

    name = StringProperty()
    properties = JSONProperty()
    elements = Relationship('Element', 'ELEMENT')
    resource_groups = Relationship('ResourceGroup', 'RESOURCE_GROUP')
Ejemplo n.º 12
0
class EquilibriumState(Mixin, StructuredNode, metaclass=ExtNodeMeta):
    xyz_json = JSONProperty()
    energy = FloatProperty()
    signature = StringProperty(unique_index=True,
                               required=True)  # signature of EQ
    complex = RelationshipTo('Complex', 'E2C', cardinality=One, model=Mapping)
    transition_states = RelationshipTo('TransitionState', 'E2T', model=Barrier)

    def __init__(self, structure: MoleculeContainer = None, **kwargs):
        if structure is not None:
            xyz = structure._conformers[0]
            energy = structure.meta['energy']
            signature = [None] * len(structure)
            for n, m in structure.atoms_order.items():
                signature[m - 1] = [round(x, 4) for x in xyz[n]]
            signature = str(signature)
            super().__init__(xyz_json=xyz, energy=energy, signature=signature)
            try:
                self.save()
            except UniqueProperty:
                self.id = self.nodes.get(signature=signature,
                                         lazy=True)  # get id of existing node
                self.refresh()
                if not -.0001 < self.energy - energy < .0001:
                    raise ValueError(
                        'same EquilibriumState with different energy exists')
        else:
            super().__init__(**kwargs)

    @property
    def xyz(self):
        return {int(k): tuple(v) for k, v in self.xyz_json.items()}
Ejemplo n.º 13
0
class Places(StructuredNode):
    uid = UniqueIdProperty()
    name = StringProperty(required=True)
    reference = StringProperty(required=True)
    types = ArrayProperty(default=None)
    formatted_address = StringProperty(required=True)
    opening_hours = JSONProperty(required=False)
    rating = IntegerProperty(required=False)
    photos = JSONProperty(required=False)
    place_id = StringProperty(required=True)
    created_at = DateTimeProperty(default_now=True)
    updated_at = DateTimeProperty(default_now=True)
    deleted_at = DateTimeProperty(default_now=False)
    locations = RelationshipTo('Locations',
                               'LOCATED_AT',
                               model=LocatedAtRelationship)
Ejemplo n.º 14
0
class Info(StructuredNode):

	# ---- attributi
	info_id = StringProperty(UniqueIndex=True, Required=True)
	END = IntegerProperty()
	ID = StringProperty()
	QUAL = FloatProperty()
	FILTER = StringProperty()
	FORMAT = StringProperty()
	HETEROZIGOSITY = FloatProperty()
	dbSNP = StringProperty()

	DP = FloatProperty()
	Gene_refGene = ArrayProperty()
	Func_refGene = ArrayProperty()
	QD = FloatProperty()
	SIFT_score = FloatProperty()
	otg_all = FloatProperty()
	NM = IntegerProperty()
	LM = ArrayProperty()
	FS = FloatProperty()
	MQ0 = FloatProperty()
	attributes = JSONProperty()

	# ---- relazioni
	contains = RelationshipFrom('File', 'Contains')
	supportedBy = RelationshipTo('Genotype', 'Supported_By', model=SupportedByRel)
	forVariant = RelationshipTo('Variant', 'For_Variant')
Ejemplo n.º 15
0
class GT_RCVotes(StructuredNode):
    category_one = StringProperty(default="")
    category_label = StringProperty(default="")
    chamber = StringProperty(default="")
    chamber_label = StringProperty(default="")
    congress = IntegerProperty()
    created = StringProperty(default="")
    vote_id = IntegerProperty(unique_index=True)
    link = StringProperty(default="")
    missing_data = BooleanProperty()
    number = IntegerProperty()
    question = StringProperty(default="")
    question_details = StringProperty(default="")
    related_amendment = IntegerProperty()
    related_bill = JSONProperty()
    required = StringProperty()
    result = StringProperty(default="")
    session = StringProperty(default="")
    source = StringProperty(default="")
    source_label = StringProperty(default="")
    total_minus = IntegerProperty()
    total_other = IntegerProperty()
    total_plus = IntegerProperty()
    vote_type = StringProperty(default="")

    # relationships
    option = RelationshipTo('GTVoteOption', 'HAS_A')
Ejemplo n.º 16
0
class Port(StructuredNode):
    # Properties
    number = IntegerProperty(unique_index=True)
    details = JSONProperty()

    # Relationships
    device = RelationshipFrom('Device', 'USES_PORT')
Ejemplo n.º 17
0
class TextNode(StructuredNode):
    order_id = IntegerProperty(required=True, unique_index=True)
    label = StringProperty(required=True)
    text = StringProperty(required=True)
    alg_results = JSONProperty()
    link = Relationship('TextNode', 'ALG', model=TextRelation)

    def short(self):
        res = ''.join([
            word.strip() + ' ' for word in re.split(r'[\n ]', self.text, 5)[:5]
        ])
        return res

    def describe(self):
        return f"""
            <h1>Фрагмент: {self.order_id} </h1>
            <table border="1" width=100%>
                <caption>
                    Информация о вершине
                </caption>
                <tr>
                    <th>Количество символов</th>
                    <td>{self.character_num()}</td>
                </tr>
                <tr>
                    <th>Количество слов</th>
                    <td>{self.words_num()}</td>
                </tr>
                <tr>
                    <th>Количество предложений</th>
                    <td>{self.sentences_num()}</td>
                </tr>
                <tr>
                    <th>Количество связей</th>
                    <td>{len(self.link)}</td>
                </tr>
            </table>
        """

    def preview(self, frag_num=0):
        leading = 3
        if frag_num > 0:
            leading = int(np.floor(np.log10(frag_num))) + 1
            if str(self.order_id) != str(self.label):
                return f"{str(self.order_id).zfill(leading)}: " \
                   + f"[{self.label}] {self.short()}..."
            else:
                return f"{str(self.order_id).zfill(leading)}: " \
                       + f"[{self.label}] {self.short()}..."
        return f"[{self.label}] {self.short()}..."

    def words_num(self):
        return len(self.text.split())

    def character_num(self):
        return len(self.text)

    def sentences_num(self):
        return len([s for s in self.text.split('.') if len(s) > 2])
Ejemplo n.º 18
0
class SupportedByRel(StructuredRel):

	# ---- attributi
	info_id = StringProperty(UniqueIndex=True, Required=True)
	sample = StringProperty(UniqueIndex=True, Required=True)
	phased = BooleanProperty()
	state = StringProperty()
	attributes = JSONProperty()
Ejemplo n.º 19
0
class ResourceGroup(StructuredNode):
    """RG that groups elements on an AV."""

    name = StringProperty()
    subscription_id = StringProperty(unique_index=True)
    properties = JSONProperty()
    elements = Relationship('Element', 'ELEMENT_RESOURCE_GROUP')
    object_tags = Relationship('Tag', 'OBJ_TAG')
    object_properties = Relationship('Property', 'OBJ_PROPERTY')
Ejemplo n.º 20
0
class Locations(StructuredNode):
    uid = UniqueIdProperty()
    country = StringProperty(required=True)
    latitude = FloatProperty(required=True)
    longitude = FloatProperty(required=True)
    viewport = JSONProperty(required=False)
    created_at = DateTimeProperty(default_now=True)
    updated_at = DateTimeProperty(default_now=True)
    deleted_at = DateTimeProperty(required=False, default=None)
Ejemplo n.º 21
0
class Places(StructuredNode):
    uid = UniqueIdProperty()
    name = StringProperty(required=True)
    reference = StringProperty(required=True)
    types = ArrayProperty(default=None)
    formatted_address = StringProperty(required=True)
    opening_hours = JSONProperty(required=False)
    rating = IntegerProperty(required=False)
    photos = JSONProperty(required=False)
    place_id = StringProperty(required=True)
    created_at = DateTimeProperty(default_now=True)
    updated_at = DateTimeProperty(default_now=True)
    deleted_at = DateTimeProperty(default_now=False)
    locations = RelationshipTo(Locations, "LOCATED_AT", model=EdgeRelationship)

    def find(self, page=0, per_page=15, **kwargs):
        skip = 0 if page <= 1 else page - 1
        limit = skip + per_page
        order_by = 'created_at'

        if "order_by" in kwargs and kwargs['order_by']:
            order_by = kwargs['order_by']
        if "uid" in kwargs and kwargs['uid']:
            return self.find_by_id(uid=kwargs['uid'])
        else:
            return self.nodes.has(locations=True).order_by(order_by).filter(
                deleted_at__isnull=True)[skip:limit]

    def find_by_id(self, uid):
        return self.nodes.has(locations=True).get(uid=uid,
                                                  deleted_at__isnull=True)

    def save(self, **kwargs):
        if "location_id" in kwargs:
            location = Locations().find_by_id(uid=kwargs['location_id'])
            if location:
                saved_location = super().save()
                """ save location relationship after saving the place node """
                self.locations.connect(location)
                return saved_location
            else:
                raise LookupError("Location ID not found.")
        else:
            raise LookupError("Location not found.")
Ejemplo n.º 22
0
class GoogleOAuth(StructuredNode, DefaultPropertyMixin, DefaultHelperMixin):
    user_id = StringProperty(required=True)
    credentials = JSONProperty()

    user_rel = RelationshipFrom("application.models.User",
                                "HAS_GOOGLE_OAUTH",
                                cardinality=cardinality.One)

    @classmethod
    def create_from_id_token(cls, token):
        google_id, _ = validate_google_id_token(token)
        existing_google_oauth = cls.find_by(user_id=google_id, force=False)
        if existing_google_oauth:
            raise GoogleOAuthConflict(
                f"User: {existing_google_oauth.user.username} "
                f"is already connected with that google account")
        return cls(user_id=google_id).save()

    @property
    def user(self):
        return self.user_rel.single()

    @property
    def has_offline_access(self):
        if not self.credentials:
            return False
        credentials = credentials_from_dict(self.credentials)
        request = google.auth.transport.requests.Request()
        try:
            credentials.refresh(request)
            return True
        except RefreshError:
            return False

    def set_credentials(self, auth_code):
        flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
            current_app.config["CLIENT_SECRET_PATH"],
            scopes=None,
            redirect_uri="postmessage")
        flow.fetch_token(code=auth_code)
        self.credentials = credentials_to_dict(flow.credentials)

    def revoke_access(self):
        if not self.credentials:
            raise EmptyCredentialsError
        revoke = requests.post(
            "https://accounts.google.com/o/oauth2/revoke",
            params={"token": self.credentials["token"]},
            headers={"content-type": "application/x-www-form-urlencoded"},
        )
        if not revoke.status_code == 200:
            raise RequestError
        self.credentials = None
        for drive in self.user.drives:
            drive.delete()
        self.save()
Ejemplo n.º 23
0
class File(StructuredNode):
	
	# ---- attributi
	name = StringProperty(UniqueIndex=True, Required=True)
	extension = StringProperty()
	statistics = JSONProperty()

	# ---- relazioni
	composedBy = RelationshipFrom('Experiment', 'Composed_By')
	contains = RelationshipTo('Info', 'Contains')
Ejemplo n.º 24
0
class Owner(StructuredNode):
    """Owner of an element."""

    uid = StringProperty(unique_index=True)
    name = StringProperty()
    regions = Relationship('Region', 'REGION')
    elements = Relationship('Element', 'OWNED_ELEMENT')
    properties = JSONProperty()
    object_tags = Relationship('Tag', 'OBJ_TAG')
    object_properties = Relationship('Property', 'OBJ_PROPERTY')
    resource_groups = Relationship('ResourceGroup', 'OWNED_RESOURCE_GROUP')
Ejemplo n.º 25
0
class MetaData(StructuredNode):
    """ Any metaData stored in any service level """

    # key = StringProperty(index=True)
    # metatype = StringProperty()         # Describe the level of metadata
    # value = StringProperty(index=True)

    content = JSONProperty()

    pid = RelationshipTo(PID, 'DESCRIBED_BY')
    data = RelationshipTo(DigitalEntity, 'DESCRIBED_BY')
    resource = RelationshipTo(Resource, 'DESCRIBED_BY')
Ejemplo n.º 26
0
class Playlist(StructuredNode):
    '''
    Represents a Playlist on Spotify
    '''

    owner = RelationshipTo('model.spotify.user.User', 'OWNED BY')

    tracks = RelationshipFrom('model.spotify.track.Track', 'FEATURED IN')

    spotify_id = StringProperty(unique_index=True)
    name = StringProperty()
    collaborative = BooleanProperty()
    description = StringProperty()
    external_urls = JSONProperty()
    href = StringProperty()
    images = JSONProperty()
    primary_color = StringProperty()
    public = BooleanProperty()
    snapshot_id = StringProperty()
    type = StringProperty()
    uri = StringProperty()

    @classmethod
    def inst(cls, **kwargs):
        e = exists(cls, kwargs.get('id'))
        if e:
            return e

        if 'tracks' in kwargs:
            del kwargs['tracks']

        owner = kwargs.pop('owner')
        kwargs['spotify_id'] = kwargs.pop('id')

        obj = cls(**kwargs).save()

        owner = User.inst(**owner)
        obj.owner.connect(owner)

        return obj
Ejemplo n.º 27
0
class Annotation(GeniusNode):
    '''
    Represents annotation data from Genius.com
    '''

    # TODO: Make objects for these properties
    authors = ArrayProperty()
    verified_by = JSONProperty()
    referent = JSONProperty()

    genius_id = IntegerProperty(unique_index=True)

    api_path = StringProperty()
    body = StringProperty()
    comment_count = IntegerProperty()
    community = BooleanProperty()
    custom_preview = StringProperty()
    has_voters = BooleanProperty()
    pinned = BooleanProperty()
    share_url = StringProperty(unique_index=True)
    source = StringProperty()
    state = StringProperty()
    url = StringProperty()
    verified = BooleanProperty()
    votes_total = IntegerProperty()
    cosigned_by = ArrayProperty()
    rejection_comment = StringProperty()

    @classmethod
    def inst(cls, **kwargs):
        del kwargs['current_user_metadata']
        kwargs['genius_id'] = kwargs.pop('id')
        kwargs['body'] = kwargs['body']['plain']
        kwargs.pop('current_user_metadata')

        # TODO: clean this shit

        raise NotImplementedError('Not fully implemented yet')
Ejemplo n.º 28
0
class model(StructuredNode, grest.models.Node):
    GREEK = (("A", "Alpha"), ("B", "Beta"), ("G", "Gamma"))

    uuid = UniqueIdProperty()
    string = StringProperty(required=True)
    choices = StringProperty(choices=GREEK)
    integer = IntegerProperty()
    json = JSONProperty()
    array_of_string = ArrayProperty(StringProperty())
    raw_data = ArrayProperty()
    date = DateProperty()
    datetime = DateTimeProperty()
    boolean = BooleanProperty()
    email = EmailProperty()
Ejemplo n.º 29
0
class Album(StructuredNode):
    artists = RelationshipTo('model.spotify.artist.Artist', 'BY')

    tracks = RelationshipFrom('model.spotify.track.Track', 'FROM')

    available_markets = ArrayProperty()
    images = JSONProperty()

    album_type = StringProperty()
    release_date = StringProperty()
    external_urls = JSONProperty()
    href = StringProperty()
    spotify_id = StringProperty(unique_index=True)
    name = StringProperty()
    release_date_precision = StringProperty()
    total_tracks = IntegerProperty()
    type = StringProperty()
    uri = StringProperty()

    @classmethod
    def inst(cls, **kwargs):
        e = exists(cls, kwargs.get('id'))
        if e:
            return e

        artists = kwargs.pop('artists')

        kwargs['spotify_id'] = kwargs.pop('id')

        obj = cls(**kwargs).save()

        from model.spotify.artist import Artist
        artists = [Artist.inst(**a) for a in artists]
        for artist in artists:
            obj.artists.connect(artist)

        return obj
Ejemplo n.º 30
0
class Album(SpotifyNode):
    artists = RelationshipTo('model.graph.spotify.artist.Artist', 'BY')

    tracks = RelationshipFrom('model.graph.spotify.track.Track', 'FROM')

    available_markets = ArrayProperty()
    images = JSONProperty()

    album_type = StringProperty()
    release_date = StringProperty()
    external_urls = JSONProperty()
    href = StringProperty()
    spotify_id = StringProperty(unique_index=True)
    name = StringProperty()
    release_date_precision = StringProperty()
    total_tracks = IntegerProperty()
    type = StringProperty()
    uri = StringProperty()

    @staticmethod
    def post_clean(obj, to_connect: dict):
        from model.graph.spotify.artist import Artist

        artists = [Artist.inst(**a) for a in to_connect['artists']]
        for artist in artists:
            obj.artists.connect(artist)

        return obj

    @classmethod
    def clean(cls, **kwargs):
        to_connect = {'artists': kwargs.pop('artists')}
        if 'id' in kwargs:
            kwargs['spotify_id'] = kwargs.pop('id')
        obj = cls(**kwargs)
        return obj, to_connect