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

Stats: save amount of data since start #1430

Merged
merged 8 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,4 @@ _Nothing merged in CLI during this sprint_
- Save number of inactive projects ([#1426](https://github.com/ScilifelabDataCentre/dds_web/pull/1426))
- Save number of unique Project Owners ([#1421](https://github.com/ScilifelabDataCentre/dds_web/pull/1421))
- Save amount of TB's currently stored in system ([#1424](https://github.com/ScilifelabDataCentre/dds_web/pull/1424))
- Save amount of TB's uploaded since start ([#1430](https://github.com/ScilifelabDataCentre/dds_web/pull/1430))
7 changes: 7 additions & 0 deletions dds_web/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ def collect_stats():
# Imports
# Installed
import flask_mail
from sqlalchemy.sql import func

# Own
import dds_web.utils
Expand All @@ -690,6 +691,7 @@ def collect_stats():
Reporting,
Project,
ProjectUsers,
Version,
)

# Get current time
Expand Down Expand Up @@ -730,6 +732,10 @@ def collect_stats():
# Amount of data
bytes_stored_now: int = sum(proj.size for proj in Project.query.filter_by(is_active=True))
tb_stored_now: float = round(bytes_stored_now / 1e12, 2)
bytes_uploaded_since_start = db.session.query(
func.sum(Version.size_stored).label("sum_bytes")
).first()
tb_uploaded_since_start: float = round(int(bytes_uploaded_since_start.sum_bytes) / 1e12, 2)

# Add to database
new_reporting_row = Reporting(
Expand All @@ -744,6 +750,7 @@ def collect_stats():
active_project_count=active_project_count,
inactive_project_count=inactive_project_count,
tb_stored_now=tb_stored_now,
tb_uploaded_since_start=tb_uploaded_since_start,
)
db.session.add(new_reporting_row)
db.session.commit()
Expand Down
1 change: 1 addition & 0 deletions dds_web/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,3 +1089,4 @@ class Reporting(db.Model):
active_project_count = db.Column(db.Integer, unique=False, nullable=True)
inactive_project_count = db.Column(db.Integer, unique=False, nullable=True)
tb_stored_now = db.Column(db.Float, unique=False, nullable=True)
tb_uploaded_since_start = db.Column(db.Float, unique=False, nullable=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""tb_uploaded_since_start_added

Revision ID: aec752f1e0a5
Revises: d48ecb4db259
Create Date: 2023-05-31 14:09:07.327919

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "aec752f1e0a5"
down_revision = "d48ecb4db259"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("reporting", sa.Column("tb_uploaded_since_start", sa.Float(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("reporting", "tb_uploaded_since_start")
# ### end Alembic commands ###
7 changes: 7 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ def test_collect_stats(client, cli_runner, fs: FakeFilesystem):
Reporting,
Project,
ProjectUsers,
Version,
)
import dds_web.utils

def verify_reporting_row(row, time_date):
"""Verify correct values in reporting row."""
Expand Down Expand Up @@ -478,6 +480,11 @@ def verify_reporting_row(row, time_date):
assert row.tb_stored_now == round(
sum(proj.size for proj in Project.query) / 1000000000000, 2
)
assert row.tb_uploaded_since_start == round(
sum(version.size_stored for version in dds_web.utils.page_query(Version.query))
/ 1000000000000,
2,
)

# Verify that there are no reporting rows
assert Reporting.query.count() == 0
Expand Down