Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumping dependencies #225

Merged
merged 18 commits into from
Jun 13, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
jaesivsm committed Jun 12, 2023
commit 2e34bb03e931293060775ac32b85fa0ade746f7d
68 changes: 41 additions & 27 deletions jarr/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Article(Base): # type: ignore
"Represent an article from a feed."
__tablename__ = 'article'
__tablename__ = "article"

id = Column(Integer, primary_key=True)
entry_id = Column(String)
Expand All @@ -28,14 +28,15 @@ class Article(Base): # type: ignore
order_in_cluster = Column(Integer)

# integration control
article_type = Column(Enum(ArticleType),
default=None, nullable=True)
article_type = Column(
Enum(ArticleType), default=None, nullable=True
) # type: ignore

# parsing
tags = Column(PickleType, default=[])
vector = Column(TSVECTOR)
# reasons
cluster_reason = Column(Enum(ClusterReason), default=None)
cluster_reason = Column(Enum(ClusterReason), default=None) # type: ignore
cluster_score = Column(Integer, default=None)
cluster_tfidf_neighbor_size = Column(Integer, default=None)
cluster_tfidf_with = Column(Integer, default=None)
Expand All @@ -47,30 +48,36 @@ class Article(Base): # type: ignore
cluster_id = Column(Integer)

# relationships
user = relationship(
"User", back_populates='articles')
user = relationship("User", back_populates="articles")
cluster = relationship(
"Cluster", back_populates="articles", foreign_keys=[cluster_id],
overlaps="clusters")
"Cluster",
back_populates="articles",
foreign_keys=[cluster_id],
overlaps="clusters",
)
category = relationship(
"Category", back_populates="articles", foreign_keys=[category_id])
"Category", back_populates="articles", foreign_keys=[category_id]
)
feed = relationship(
"Feed", back_populates="articles", foreign_keys=[feed_id],
overlaps="clusters")
"Feed",
back_populates="articles",
foreign_keys=[feed_id],
overlaps="clusters",
)

__table_args__ = (
ForeignKeyConstraint([user_id], ['user.id'], ondelete='CASCADE'),
ForeignKeyConstraint([feed_id], ['feed.id'], ondelete='CASCADE'),
ForeignKeyConstraint([category_id], ['category.id'],
ondelete='CASCADE'),
ForeignKeyConstraint([cluster_id], ['cluster.id']),
Index('ix_article_uid_cluid', user_id, cluster_id),
Index('ix_article_uid_fid_cluid', user_id, feed_id, cluster_id),
Index('ix_article_uid_cid_cluid',
user_id, category_id, cluster_id),
Index('ix_article_uid_fid_eid', user_id, feed_id, entry_id),
Index('ix_article_uid_cid_linkh', user_id, category_id, link_hash),
Index('ix_article_retrdate', retrieved_date),
ForeignKeyConstraint([user_id], ["user.id"], ondelete="CASCADE"),
ForeignKeyConstraint([feed_id], ["feed.id"], ondelete="CASCADE"),
ForeignKeyConstraint(
[category_id], ["category.id"], ondelete="CASCADE"
),
ForeignKeyConstraint([cluster_id], ["cluster.id"]),
Index("ix_article_uid_cluid", user_id, cluster_id),
Index("ix_article_uid_fid_cluid", user_id, feed_id, cluster_id),
Index("ix_article_uid_cid_cluid", user_id, category_id, cluster_id),
Index("ix_article_uid_fid_eid", user_id, feed_id, entry_id),
Index("ix_article_uid_cid_linkh", user_id, category_id, link_hash),
Index("ix_article_retrdate", retrieved_date),
)

def __repr__(self):
Expand All @@ -86,13 +93,20 @@ def simple_vector(self):
def simple_vector_magnitude(self):
return get_simple_vector(self.vector)[1]

def get_tfidf_vector(self, frequencies, corpus_size,
will_be_left_member=False):
def get_tfidf_vector(
self, frequencies, corpus_size, will_be_left_member=False
):
vector, size = get_simple_vector(self.vector)
return TFIDFVector(vector, size, frequencies, corpus_size,
will_be_left_member=will_be_left_member)
return TFIDFVector(
vector,
size,
frequencies,
corpus_size,
will_be_left_member=will_be_left_member,
)

@cached_property
def content_generator(self):
from jarr.lib.content_generator import get_content_generator

return get_content_generator(self)
59 changes: 34 additions & 25 deletions jarr/models/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Cluster(Base): # type: ignore
"Represent a cluster of articles from one or several feeds"
__tablename__ = 'cluster'
__tablename__ = "cluster"

id = Column(Integer, primary_key=True)
cluster_type = Column(String)
Expand All @@ -27,42 +27,49 @@ class Cluster(Base): # type: ignore
main_link = Column(String, default=None)

# reasons
read_reason = Column(Enum(ReadReason), default=None)
read_reason = Column(Enum(ReadReason), default=None) # type: ignore

# foreign keys
user_id = Column(Integer, nullable=False)
main_article_id = Column(
Integer,
ForeignKey('article.id', name='fk_article_id', use_alter=True))
Integer, ForeignKey("article.id", name="fk_article_id", use_alter=True)
)

# relationships
user = relationship(
'User', back_populates='clusters')
user = relationship("User", back_populates="clusters")
main_article = relationship(
Article, uselist=False, foreign_keys=main_article_id)
Article, uselist=False, foreign_keys=main_article_id
)
articles = relationship(
Article, back_populates='cluster', foreign_keys=[Article.cluster_id],
order_by=Article.date.asc())
Article,
back_populates="cluster",
foreign_keys=[Article.cluster_id],
order_by=Article.date.asc(),
)
feeds = relationship(
'Feed', back_populates='clusters', secondary='article',
"Feed",
back_populates="clusters",
secondary="article",
foreign_keys=[Article.feed_id, Article.cluster_id],
overlaps="articles,clusters,cluster,feed")
overlaps="articles,clusters,cluster,feed",
)
categories = relationship(
'Category', back_populates='clusters', secondary='article',
"Category",
back_populates="clusters",
secondary="article",
foreign_keys=[Article.cluster_id, Article.category_id],
overlaps="articles,category,cluster,clusters,feeds")
overlaps="articles,category,cluster,clusters,feeds",
)

__table_args__ = (
ForeignKeyConstraint([user_id], ['user.id'], ondelete='CASCADE'),
Index('ix_cluster_uid_date',
user_id, main_date.desc().nullslast()),
Index('ix_cluster_liked_uid', liked, user_id),
Index('ix_cluster_read_uid', read, user_id),
# used by cluster deletion in FeedController.delete
Index('ix_cluster_uid_martid',
user_id, main_article_id.nullsfirst()),
# triggered by article.ondelete
Index('ix_cluster_martid', main_article_id.nullslast()),
ForeignKeyConstraint([user_id], ["user.id"], ondelete="CASCADE"),
Index("ix_cluster_uid_date", user_id, main_date.desc().nullslast()),
Index("ix_cluster_liked_uid", liked, user_id),
Index("ix_cluster_read_uid", read, user_id),
# used by cluster deletion in FeedController.delete
Index("ix_cluster_uid_martid", user_id, main_article_id.nullsfirst()),
# triggered by article.ondelete
Index("ix_cluster_martid", main_article_id.nullslast()),
)

@property
Expand All @@ -78,5 +85,7 @@ def icons_url(self):
return {feed.icon_url for feed in self.feeds}

def __repr__(self):
return (f"<Cluster(id={self.id}, title={self.main_title!r}, "
f" date={self.main_date!r})>")
return (
f"<Cluster(id={self.id}, title={self.main_title!r}, "
f" date={self.main_date!r})>"
)
8 changes: 4 additions & 4 deletions jarr/models/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ class Feed(Base): # type: ignore
description = Column(String, default="")
link = Column(String)
site_link = Column(String, default="")
status: FeedStatus = Column(
status = Column(
Enum(FeedStatus), default=FeedStatus.active, nullable=False
)
) # type: ignore
created_date = Column(UTCDateTime, default=utc_now)
filters = Column(PickleType, default=[])
unread_count = Column(Integer, default=0)

# integration control
feed_type: FeedType = Column(
feed_type = Column(
Enum(FeedType), default=FeedType.classic, nullable=False
)
) # type: ignore
truncated_content = Column(Boolean, default=False, nullable=False)

# clustering control
Expand Down