Skip to content
This repository was archived by the owner on Sep 26, 2018. It is now read-only.
Open
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 cloud/endagaweb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ class Subscriber(models.Model):
# When toggled, this will protect a subsriber from getting "vacuumed." You
# can still delete subs with the usual "deactivate" button.
prevent_automatic_deactivation = models.BooleanField(default=False)
role = models.TextField(default='retailer')

@classmethod
def update_balance(cls, imsi, other_bal):
Expand Down
29 changes: 29 additions & 0 deletions cloud/endagaweb/stats_app/stats_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,32 @@ def timeseries(self, key=None, **kwargs):
if 'aggregation' not in kwargs:
kwargs['aggregation'] = 'average_value'
return self.aggregate_timeseries(key, **kwargs)


class TransferStatsClient(StatsClientBase):
""" Gather retailer transfer and recharge report """

def __init__(self, *args, **kwargs):
super(TransferStatsClient, self).__init__(*args, **kwargs)

def timeseries(self, kind=None, **kwargs):
# Set queryset from subscriber role as retailer
kwargs['query'] = Q(subscriber__role='retailer')
return self.aggregate_timeseries(kind, **kwargs)


class TopUpStatsClient(StatsClientBase):
def __init__(self, *args, **kwargs):
super(TopUpStatsClient, self).__init__(*args, **kwargs)

def timeseries(self, kind=None, **kwargs):
# Change is negative convert to compare
try:
raw_amount = [(float(denom) * -1 / 100000) for denom in
kwargs['extras'].split('-')]
kwargs['query'] = Q(change__gte=raw_amount[1]) & Q(
change__lte=raw_amount[0]) & Q(subscriber__role='retailer')
return self.aggregate_timeseries(kind, **kwargs)
except ValueError:
# If no denominations available in this network
raise ValueError('no denominations available in current network')
Loading