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)
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')
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()}
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')
class Port(StructuredNode): # Properties number = IntegerProperty(unique_index=True) details = JSONProperty() # Relationships device = RelationshipFrom('Device', 'USES_PORT')
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])
class SupportedByRel(StructuredRel): # ---- attributi info_id = StringProperty(UniqueIndex=True, Required=True) sample = StringProperty(UniqueIndex=True, Required=True) phased = BooleanProperty() state = StringProperty() attributes = JSONProperty()
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')
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)
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.")
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()
class File(StructuredNode): # ---- attributi name = StringProperty(UniqueIndex=True, Required=True) extension = StringProperty() statistics = JSONProperty() # ---- relazioni composedBy = RelationshipFrom('Experiment', 'Composed_By') contains = RelationshipTo('Info', 'Contains')
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')
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')
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
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')
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()
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
class OrbitEphemerisMessage(BaseAccess): """A `neomodel` model representing an orbit ephemeris message. """ ephemeris_lines = JSONProperty() ccsds_oem_vers = StringProperty() creation_date = StringProperty() originator = StringProperty() object_name = StringProperty() object_id = StringProperty() center_name = StringProperty() ref_frame = StringProperty() time_system = StringProperty() start_time = StringProperty() stop_time = StringProperty() in_cos_object = RelationshipTo('COSObject', 'stored_in')
class Hospital(StructuredNode): hid = UniqueIdProperty() name = StringProperty() nickName = StringProperty() fullName = StringProperty() hType = StringProperty() description = StringProperty() managementMode = StringProperty() sourceUrl = StringProperty() sourceType = StringProperty(choices=SOURCETYPE) province = RelationshipTo(Province, "HosptialProvinceRel") city = RelationshipTo(City, "HospitalCityRel") district = RelationshipTo(District, "HospitalDistrictRel") street = StringProperty() place = StringProperty() email = StringProperty() direction = StringProperty() website = StringProperty() level = StringProperty() adcode = StringProperty() streetNumber = StringProperty() medicalInsurance = StringProperty() telephone = StringProperty() longitude = FloatProperty() latitude = FloatProperty() baiduCoordinate = JSONProperty() gaodeCoordinate = JSONProperty() aimilarity = Relationship('Hospital', "HospitalAimilarity", model=HospitalSimilarity) departments = Relationship('Department', "HospitalDepartmentRel") def getCity(self): query = "MATCH (a) WHERE id(a)={self}MATCH (a)-[:HospitalCityRel]->(b) RETURN b" results, columns = self.cypher(query) return City().inflate(results[0][0]) if results else None
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
def convert_resources(self, resource_types): for resource_name, resource in resource_types.items(): fields = { 'uid': StringProperty(unique_index=True), 'name': StringProperty(required=True), 'kind': StringProperty(required=True), 'metadata': JSONProperty(required=True), } for field_name, field in resource.get('model', {}).items(): cls_name = field.pop("type") target_cls = field.pop('target') model_name = field.pop('model') field['model'] = registry.get_type(model_name) fields[field_name] = globals().get(to_camel_case(cls_name))( target_cls, model_name, **field) registry.add(type(resource_name, (StructuredNode, ), fields))
class Block(StructuredNode): height = IntegerProperty(unique_index=True, required=True) # Block height proposer = StringProperty( default="unknown") # Proposer address for easy single node querying json_blob = JSONProperty() # raw data from the Stargazer API validator_misses = IntegerProperty( ) # How many precommits are missing from the block uid = UniqueIdProperty() # traverse outgoing TX relations, inflate to Block objects tx = RelationshipFrom('Validator', 'TX', model=Transaction, cardinality=ZeroOrMore) proposal = RelationshipFrom('Validator', 'PROPOSAL', model=Propose, cardinality=ZeroOrMore)
class User(StructuredNode): uid = UniqueIdProperty() address = StringProperty() currency = StringProperty() date_joined = DateTimeProperty(default=datetime.now()) favourites = JSONProperty() first_name = StringProperty() latitude = StringProperty() longitude = StringProperty() last_name = StringProperty() username = StringProperty(unique_index=True) email = EmailProperty(unique_index=True) is_active = BooleanProperty() last_login = DateTimeProperty() password = StringProperty() city = RelationshipTo(City, 'LIVES_IN') @property def serialize(self): return { 'node_properties': { "id": self.uid, "address": self.address, "currency": self.currency, "date_joined": self.date_joined, "first_name": self.first_name, "latitude": str(self.latitude), "longitude": str(self.longitude), "last_name": self.last_name, "username": self.username, "email": self.email, "favourites": self.favourites, }, } @property def serialize_connections(self): return [ { 'nodes_type': 'City', 'nodes_related': self.serialize_relationships(self.city.all()), }, ]
class Phenotype(TimestampedNode): name = StringProperty(required=True, is_restricted=True) age = IntegerProperty() sex = StringProperty(required=True) identified_genes = JSONProperty(is_restricted=True) defined_in = RelationshipTo("Study", "DEFINED_IN", cardinality=ZeroOrMore) describe = RelationshipFrom("Dataset", "IS_DESCRIBED_BY", cardinality=ZeroOrOne) birth_place = RelationshipTo("GeoData", "BIRTH_PLACE", cardinality=ZeroOrOne) confirmed_variant = RelationshipFrom("Variant", "CONFIRMED_IN") son = RelationshipTo("Phenotype", "SON", cardinality=ZeroOrMore) father = RelationshipTo("Phenotype", "FATHER", cardinality=ZeroOrMore) mother = RelationshipTo("Phenotype", "MOTHER", cardinality=ZeroOrMore) hpo = RelationshipTo("HPO", "DESCRIBED_BY", cardinality=ZeroOrMore)
class File(IdentifiedNode): name = StringProperty(required=True) type = StringProperty() size = IntegerProperty() status = StringProperty() task_id = StringProperty() metadata = JSONProperty() dataset = RelationshipFrom("Dataset", "CONTAINS", cardinality=ZeroOrMore) has_variant = RelationshipFrom("Variant", "OBSERVED_IN", cardinality=ZeroOrMore, model=VariantRelation) has_not_variant = RelationshipFrom("Variant", "NOT_OBSERVED_IN", cardinality=ZeroOrMore, model=VariantRelation)
class User(SpotifyNode): ''' Represents a user on Spotify as per Spotify API ''' playlists = RelationshipFrom('model.graph.spotify.playlist.Playlist', 'OWNED BY') display_name = StringProperty() external_urls = JSONProperty() href = StringProperty() spotify_id = StringProperty(unique_index=True) type = StringProperty() uri = StringProperty() @classmethod def clean(cls, **kwargs): if 'id' in kwargs: kwargs['spotify_id'] = kwargs.pop('id') return cls(**kwargs), {}
class Artist(StructuredNode): ''' Represents an artist on Spotify as per Spotify API ''' tracks = RelationshipFrom('model.spotify.track.Track', 'BY') albums = RelationshipFrom('model.spotify.album.Album', 'BY') external_urls = JSONProperty() href = StringProperty() spotify_id = StringProperty(unique_index=True) name = StringProperty() type = StringProperty() uri = StringProperty() @classmethod def inst(cls, **kwargs): e = exists(cls, kwargs.get('id')) if e: return e kwargs['spotify_id'] = kwargs.pop('id') return cls(**kwargs).save()
class User(StructuredNode): ''' Represents a user on Spotify as per Spotify API ''' playlists = RelationshipFrom('model.spotify.playlist.Playlist', 'OWNED BY') display_name = StringProperty() external_urls = JSONProperty() href = StringProperty() spotify_id = StringProperty(unique_index=True) type = StringProperty() uri = StringProperty() @classmethod def inst(cls, **kwargs): e = exists(cls, kwargs.get('id')) if e: return e kwargs['spotify_id'] = kwargs.pop('id') return cls(**kwargs).save()
class Trip(StructuredNode): uid = UniqueIdProperty() destination = StringProperty() start_date = DateProperty() end_date = DateProperty() adults = IntegerProperty() infants = IntegerProperty() estimated_budget_start = IntegerProperty() estimated_budget_end = IntegerProperty() events = JSONProperty() creation_date = DateTimeProperty(default=datetime.now()) last_updated = DateTimeProperty(default=datetime.now()) user = RelationshipTo(User, 'PLANNED_BY') @property def serialize(self): return { 'node_properties': { "id": self.uid, "destination": self.destination, "start_date": self.start_date, "end_date": self.end_date, "adults": self.adults, "infants": self.infants, "estimated_budget_start": self.estimated_budget_start, "estimated_budget_end": self.estimated_budget_end, "events": self.events, }, } @property def serialize_connections(self): return [ { 'nodes_type': 'User', 'nodes_related': self.serialize_relationships(self.user.all()), }, ]