mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 00:03:03 +08:00
Compute Proton metrics (#1135)
* compute nb_proton_premium * compute nb_proton_user
This commit is contained in:
parent
02b39f98b7
commit
66a2152ea3
4 changed files with 89 additions and 0 deletions
|
@ -2775,12 +2775,14 @@ class Metric2(Base, ModelMixin):
|
||||||
|
|
||||||
nb_user = sa.Column(sa.Float, nullable=True)
|
nb_user = sa.Column(sa.Float, nullable=True)
|
||||||
nb_activated_user = sa.Column(sa.Float, nullable=True)
|
nb_activated_user = sa.Column(sa.Float, nullable=True)
|
||||||
|
nb_proton_user = sa.Column(sa.Float, nullable=True)
|
||||||
|
|
||||||
nb_premium = sa.Column(sa.Float, nullable=True)
|
nb_premium = sa.Column(sa.Float, nullable=True)
|
||||||
nb_apple_premium = sa.Column(sa.Float, nullable=True)
|
nb_apple_premium = sa.Column(sa.Float, nullable=True)
|
||||||
nb_cancelled_premium = sa.Column(sa.Float, nullable=True)
|
nb_cancelled_premium = sa.Column(sa.Float, nullable=True)
|
||||||
nb_manual_premium = sa.Column(sa.Float, nullable=True)
|
nb_manual_premium = sa.Column(sa.Float, nullable=True)
|
||||||
nb_coinbase_premium = sa.Column(sa.Float, nullable=True)
|
nb_coinbase_premium = sa.Column(sa.Float, nullable=True)
|
||||||
|
nb_proton_premium = sa.Column(sa.Float, nullable=True)
|
||||||
|
|
||||||
# nb users who have been referred
|
# nb users who have been referred
|
||||||
nb_referred_user = sa.Column(sa.Float, nullable=True)
|
nb_referred_user = sa.Column(sa.Float, nullable=True)
|
||||||
|
|
29
cron.py
29
cron.py
|
@ -37,6 +37,7 @@ from app.email_utils import (
|
||||||
is_valid_email,
|
is_valid_email,
|
||||||
get_email_domain_part,
|
get_email_domain_part,
|
||||||
)
|
)
|
||||||
|
from app.errors import ProtonPartnerNotSetUp
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import (
|
from app.models import (
|
||||||
Subscription,
|
Subscription,
|
||||||
|
@ -63,7 +64,10 @@ from app.models import (
|
||||||
Directory,
|
Directory,
|
||||||
DeletedDirectory,
|
DeletedDirectory,
|
||||||
DeletedSubdomain,
|
DeletedSubdomain,
|
||||||
|
PartnerSubscription,
|
||||||
|
PartnerUser,
|
||||||
)
|
)
|
||||||
|
from app.proton.utils import get_proton_partner
|
||||||
from app.utils import sanitize_email
|
from app.utils import sanitize_email
|
||||||
from server import create_light_app
|
from server import create_light_app
|
||||||
|
|
||||||
|
@ -270,11 +274,35 @@ def compute_metric2() -> Metric2:
|
||||||
if user.is_paid():
|
if user.is_paid():
|
||||||
nb_referred_user_paid += 1
|
nb_referred_user_paid += 1
|
||||||
|
|
||||||
|
# compute nb_proton_premium, nb_proton_user
|
||||||
|
nb_proton_premium = nb_proton_user = 0
|
||||||
|
try:
|
||||||
|
proton_partner = get_proton_partner()
|
||||||
|
nb_proton_premium = (
|
||||||
|
Session.query(PartnerSubscription, PartnerUser)
|
||||||
|
.filter(
|
||||||
|
PartnerSubscription.partner_user_id == PartnerUser.id,
|
||||||
|
PartnerUser.partner_id == proton_partner.id,
|
||||||
|
PartnerSubscription.end_at > now,
|
||||||
|
)
|
||||||
|
.count()
|
||||||
|
)
|
||||||
|
nb_proton_user = (
|
||||||
|
Session.query(PartnerUser)
|
||||||
|
.filter(
|
||||||
|
PartnerUser.partner_id == proton_partner.id,
|
||||||
|
)
|
||||||
|
.count()
|
||||||
|
)
|
||||||
|
except ProtonPartnerNotSetUp:
|
||||||
|
LOG.d("Proton partner not set up")
|
||||||
|
|
||||||
return Metric2.create(
|
return Metric2.create(
|
||||||
date=now,
|
date=now,
|
||||||
# user stats
|
# user stats
|
||||||
nb_user=User.count(),
|
nb_user=User.count(),
|
||||||
nb_activated_user=User.filter_by(activated=True).count(),
|
nb_activated_user=User.filter_by(activated=True).count(),
|
||||||
|
nb_proton_user=nb_proton_user,
|
||||||
# subscription stats
|
# subscription stats
|
||||||
nb_premium=Subscription.filter(Subscription.cancelled.is_(False)).count(),
|
nb_premium=Subscription.filter(Subscription.cancelled.is_(False)).count(),
|
||||||
nb_cancelled_premium=Subscription.filter(
|
nb_cancelled_premium=Subscription.filter(
|
||||||
|
@ -289,6 +317,7 @@ def compute_metric2() -> Metric2:
|
||||||
nb_coinbase_premium=CoinbaseSubscription.filter(
|
nb_coinbase_premium=CoinbaseSubscription.filter(
|
||||||
CoinbaseSubscription.end_at > now
|
CoinbaseSubscription.end_at > now
|
||||||
).count(),
|
).count(),
|
||||||
|
nb_proton_premium=nb_proton_premium,
|
||||||
# referral stats
|
# referral stats
|
||||||
nb_referred_user=User.filter(User.referral_id.isnot(None)).count(),
|
nb_referred_user=User.filter(User.referral_id.isnot(None)).count(),
|
||||||
nb_referred_user_paid=nb_referred_user_paid,
|
nb_referred_user_paid=nb_referred_user_paid,
|
||||||
|
|
29
migrations/versions/2022_070218_516c21ea7d87_.py
Normal file
29
migrations/versions/2022_070218_516c21ea7d87_.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 516c21ea7d87
|
||||||
|
Revises: bfebc2d5c719
|
||||||
|
Create Date: 2022-07-02 18:10:05.689033
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sqlalchemy_utils
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '516c21ea7d87'
|
||||||
|
down_revision = 'bfebc2d5c719'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('metric2', sa.Column('nb_proton_premium', sa.Float(), nullable=True))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('metric2', 'nb_proton_premium')
|
||||||
|
# ### end Alembic commands ###
|
29
migrations/versions/2022_070218_bd7d032087b2_.py
Normal file
29
migrations/versions/2022_070218_bd7d032087b2_.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: bd7d032087b2
|
||||||
|
Revises: 516c21ea7d87
|
||||||
|
Create Date: 2022-07-02 18:28:41.643769
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sqlalchemy_utils
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'bd7d032087b2'
|
||||||
|
down_revision = '516c21ea7d87'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('metric2', sa.Column('nb_proton_user', sa.Float(), nullable=True))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('metric2', 'nb_proton_user')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in a new issue