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

fix: better counting without under_review and dictionaries #725

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions backend/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def entities(self) -> list[dict]:
def contains_open_data(self):
"""Returns true if there are tables or columns with open coverages"""
open_data = False
tables = self.tables.all()
tables = self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").all()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incluir dictionarycomo slug

for table in tables:
table_coverages = table.coverages.filter(is_closed=False)
if table_coverages:
Expand All @@ -663,29 +663,29 @@ def contains_open_data(self):
@property
def contains_closed_data(self):
"""Returns true if there are tables or columns with closed coverages, or if the uncompressed file size is above 1 GB"""
for table in self.tables.all():
for table in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").all():
if table.contains_closed_data:
return True
return False

@property
def contains_tables(self):
"""Returns true if there are tables in the dataset"""
return len(self.tables.all()) > 0
return len(self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").all()) > 0

@property
def contains_raw_data_sources(self):
"""Returns true if there are raw data sources in the dataset"""
return len(self.raw_data_sources.all()) > 0
return len(self.raw_data_sources.exclude(status__slug="under_review").all()) > 0

@property
def contains_information_requests(self):
"""Returns true if there are information requests in the dataset"""
return len(self.information_requests.all()) > 0
return len(self.information_requests.exclude(status__slug="under_review").all()) > 0

@property
def n_tables(self):
return len(self.tables.exclude(status__slug="under_review").all())
return len(self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").all())

@property
def n_raw_data_sources(self):
Expand All @@ -697,18 +697,18 @@ def n_information_requests(self):

@property
def first_table_id(self):
if resource := self.tables.exclude(status__slug="under_review").order_by("order").first():
if resource := self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").order_by("order").first():
return resource.pk

@property
def first_open_table_id(self):
for resource in self.tables.exclude(status__slug="under_review").order_by("order").all():
for resource in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").order_by("order").all():
if resource.contains_open_data:
return resource.pk

@property
def first_closed_table_id(self):
for resource in self.tables.exclude(status__slug="under_review").order_by("order").all():
for resource in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").order_by("order").all():
if resource.contains_closed_data:
return resource.pk

Expand All @@ -735,23 +735,23 @@ def first_information_request_id(self):
@property
def table_last_updated_at(self):
updates = [
u.last_updated_at for u in self.tables.all()
u.last_updated_at for u in self.tables.exclude(status__slug="under_review").exclude(slug="dicionario").all()
if u.last_updated_at
] # fmt: skip
return max(updates) if updates else None

@property
def raw_data_source_last_polled_at(self):
polls = [
u.last_polled_at for u in self.raw_data_sources.all()
u.last_polled_at for u in self.raw_data_sources.exclude(status__slug="under_review").all()
if u.last_polled_at
] # fmt: skip
return max(polls) if polls else None

@property
def raw_data_source_last_updated_at(self):
updates = [
u.last_updated_at for u in self.raw_data_sources.all()
u.last_updated_at for u in self.raw_data_sources.exclude(status__slug="under_review").all()
if u.last_updated_at
] # fmt: skip
return max(updates) if updates else None
Expand Down
Loading