Skip to content

Commit

Permalink
Add traffic history to Pycroft datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeto committed Aug 18, 2018
1 parent 8c022c8 commit 37e233c
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions sipa/model/pycroft/user.py
Expand Up @@ -65,6 +65,7 @@ def cache_user_data(self, user_data):
self._mail = user_data['mail']
self._use_cache = user_data['cache']
self._credit = user_data['traffic_balance']
self._traffic_history = user_data['traffic_history']
self._interfaces = user_data['interfaces']
self._finance_information = FinanceInformation(
balance=user_data['finance_balance'],
Expand All @@ -83,27 +84,19 @@ def change_password(self, old, new):

@property
def traffic_history(self):
# TODO: Implement
from random import random

def rand():
return random() * 7 * 1024 ** 2

return [{
'day': day,
**(lambda i, o: {
'input': i,
'output': o,
'throughput': i + o,
})(rand(), rand() * 0.04),
'credit': random() * 1024 ** 2 * 210,
} for day in range(7)]
'input': to_kib(entry['ingress']),
'output': to_kib(entry['egress']),
'throughput': to_kib(entry['ingress']) + to_kib(entry['egress']),
'credit': to_kib(entry['balance']),
} for day, entry in enumerate(self._traffic_history)]

@property
def credit(self):
return self._credit
return to_kib(self._credit)

max_credit = 105 * 1024 * 1024
max_credit = 210 * 1024 * 1024
daily_credit = 5 * 1024 * 1024

@active_prop
Expand Down Expand Up @@ -213,6 +206,8 @@ def payment_details(self) -> PaymentDetails:
),
)

def to_kib(v):
return (v // 1024) if v is not None else 0

def evaluate_status(status):
message = None
Expand Down

0 comments on commit 37e233c

Please sign in to comment.