Skip to content

Commit

Permalink
remove Metric
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenkims committed Jul 28, 2021
1 parent 67cd7ae commit 39e2750
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 159 deletions.
33 changes: 0 additions & 33 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2246,39 +2246,6 @@ def __repr__(self):
return f"<AuthorizedAddress {self.id} {self.email} {self.mailbox_id}>"


class Metric(db.Model, ModelMixin):
"""For storing different metrics like number of users, etc"""

date = db.Column(ArrowType, default=arrow.utcnow, nullable=False)
name = db.Column(db.String(256), nullable=False)
value = db.Column(db.Float, nullable=False)

NB_USER = "nb_user"
NB_ACTIVATED_USER = "nb_activated_user"

NB_PREMIUM = "nb_premium"
NB_APPLE_PREMIUM = "nb_apple_premium"
NB_CANCELLED_PREMIUM = "nb_cancelled_premium"
NB_MANUAL_PREMIUM = "nb_manual_premium"
NB_COINBASE_PREMIUM = "nb_coinbase_premium"

# nb users who have been referred
NB_REFERRED_USER = "nb_referred_user"
NB_REFERRED_USER_PAID = "nb_referred_user_paid"

NB_ALIAS = "nb_alias"

NB_FORWARD = "nb_forward"
NB_BLOCK = "nb_block"
NB_REPLY = "nb_reply"
NB_BOUNCED = "nb_bounced"
NB_SPAM = "nb_spam"

NB_VERIFIED_CUSTOM_DOMAIN = "nb_verified_custom_domain"

NB_APP = "nb_app"


class Metric2(db.Model, ModelMixin):
"""
For storing different metrics like number of users, etc
Expand Down
126 changes: 0 additions & 126 deletions cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
Monitoring,
Contact,
CoinbaseSubscription,
Metric,
TransactionalEmail,
Bounce,
Metric2,
Expand Down Expand Up @@ -214,128 +213,6 @@ def poll_apple_subscription():
LOG.d("Finish poll_apple_subscription")


def compute_metrics():
now = arrow.now()

Metric.create(date=now, name=Metric.NB_USER, value=User.query.count(), commit=True)
Metric.create(
date=now,
name=Metric.NB_ACTIVATED_USER,
value=User.query.filter_by(activated=True).count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_REFERRED_USER,
value=User.query.filter(User.referral_id.isnot(None)).count(),
commit=True,
)

nb_referred_user_paid = 0
for user in User.query.filter(User.referral_id.isnot(None)):
if user.is_paid():
nb_referred_user_paid += 1

Metric.create(
date=now,
name=Metric.NB_REFERRED_USER_PAID,
value=nb_referred_user_paid,
commit=True,
)

Metric.create(
date=now, name=Metric.NB_ALIAS, value=Alias.query.count(), commit=True
)

Metric.create(
date=now,
name=Metric.NB_BOUNCED,
value=EmailLog.query.filter_by(bounced=True).count(),
commit=True,
)
Metric.create(
date=now,
name=Metric.NB_SPAM,
value=EmailLog.query.filter_by(is_spam=True).count(),
commit=True,
)
Metric.create(
date=now,
name=Metric.NB_REPLY,
value=EmailLog.query.filter_by(is_reply=True).count(),
commit=True,
)
Metric.create(
date=now,
name=Metric.NB_BLOCK,
value=EmailLog.query.filter_by(blocked=True).count(),
commit=True,
)
Metric.create(
date=now,
name=Metric.NB_FORWARD,
value=EmailLog.query.filter_by(
bounced=False, is_spam=False, is_reply=False, blocked=False
).count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_PREMIUM,
value=Subscription.query.filter(Subscription.cancelled.is_(False)).count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_CANCELLED_PREMIUM,
value=Subscription.query.filter(Subscription.cancelled.is_(True)).count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_APPLE_PREMIUM,
value=AppleSubscription.query.count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_MANUAL_PREMIUM,
value=ManualSubscription.query.filter(
ManualSubscription.end_at > now,
ManualSubscription.is_giveaway.is_(False),
).count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_COINBASE_PREMIUM,
value=CoinbaseSubscription.query.filter(
CoinbaseSubscription.end_at > now
).count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_VERIFIED_CUSTOM_DOMAIN,
value=CustomDomain.query.filter_by(verified=True).count(),
commit=True,
)

Metric.create(
date=now,
name=Metric.NB_APP,
value=Client.query.count(),
commit=True,
)


def compute_metric2() -> Metric2:
now = arrow.now()
nb_referred_user_paid = 0
Expand Down Expand Up @@ -485,9 +362,6 @@ def stats():
# nothing to do
return

# todo: remove metrics1
compute_metrics()

stats_today = compute_metric2()
stats_yesterday = (
Metric2.query.filter(Metric2.date < stats_today.date)
Expand Down
Empty file added docs/investigation.md
Empty file.
37 changes: 37 additions & 0 deletions migrations/versions/2021_072818_20c738810b1b_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""empty message
Revision ID: 20c738810b1b
Revises: 5662122eac21
Create Date: 2021-07-28 18:19:59.477042
"""
import sqlalchemy_utils
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '20c738810b1b'
down_revision = '5662122eac21'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('metric')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('metric',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('name', sa.VARCHAR(length=256), autoincrement=False, nullable=False),
sa.Column('value', postgresql.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='metric_pkey')
)
# ### end Alembic commands ###
Empty file added newrelic.ini
Empty file.

0 comments on commit 39e2750

Please sign in to comment.