Browse Source

Merge branch 'devel' of https://github.com/nerosketch/djing into djing_mon_feauture

devel
bashmak 9 years ago
parent
commit
4ee5b2f826
  1. 7
      abonapp/views.py
  2. 4
      mydefs.py
  3. 2
      statistics/models.py

7
abonapp/views.py

@ -725,11 +725,10 @@ def charts(request, gid, uid):
if abon.ip_address is None: if abon.ip_address is None:
charts_data = None charts_data = None
else: else:
charts_data = StatElem.objects.filter(ip=abon.ip_address.ip)
oct_limit = StatElem.percentile([cd.octets for cd in charts_data], 0.01)
charts_data = StatElem.objects.filter(ip=abon.ip_address)
#oct_limit = StatElem.percentile([cd.octets for cd in charts_data], 0.05)
# ниже возвращаем пары значений трафика который переведён в mByte, и unix timestamp # ниже возвращаем пары значений трафика который переведён в mByte, и unix timestamp
charts_data = ["{x:%d,y:%.4f}" % (cd.cur_time.timestamp(), byte_to_mbit(cd.octets)) for cd in charts_data if
cd.octets < oct_limit]
charts_data = ["{x:%d,y:%.4f}" % (cd.cur_time.timestamp(), byte_to_mbit(cd.octets)) for cd in charts_data]
except models.Abon.DoesNotExist: except models.Abon.DoesNotExist:
messages.error(request, _('Abon does not exist')) messages.error(request, _('Abon does not exist'))

4
mydefs.py

@ -75,12 +75,12 @@ class MyGenericIPAddressField(models.GenericIPAddressField):
description = "Int32 notation ip address" description = "Int32 notation ip address"
def __init__(self, protocol='ipv4', *args, **kwargs): def __init__(self, protocol='ipv4', *args, **kwargs):
super().__init__(protocol=protocol, *args, **kwargs)
super(MyGenericIPAddressField, self).__init__(protocol=protocol, *args, **kwargs)
self.max_length = 8 self.max_length = 8
def get_prep_value(self, value): def get_prep_value(self, value):
# strIp to Int # strIp to Int
value = super().get_prep_value(value)
value = super(MyGenericIPAddressField, self).get_prep_value(value)
return ip2int(value) return ip2int(value)
def to_python(self, addr): def to_python(self, addr):

2
statistics/models.py

@ -10,7 +10,7 @@ class StatManager(models.Manager):
def traffic_by_ip(self, ip): def traffic_by_ip(self, ip):
try: try:
traf = self.filter(ip=ip, octets__gt=524288)[0]
traf = self.order_by('-cur_time').filter(ip=ip, octets__gt=524288)[0]
now = datetime.now() now = datetime.now()
if traf.cur_time < now - timedelta(minutes=55): if traf.cur_time < now - timedelta(minutes=55):
# значит трафа небыло больше 5 минут # значит трафа небыло больше 5 минут

Loading…
Cancel
Save