def __init__(self, in_bps, out_bps, link_speed): self.in_bps = in_bps self.out_bps = out_bps self.link_speed = link_speed self.load_in_percent = get_traffic_load_in_percent(in_bps, link_speed) self.rgb = get_traffic_rgb(self.load_in_percent) if self.load_in_percent is not None: self.formatted_load_in_percent = "{0:.2f}".format( self.load_in_percent) else: self.formatted_load_in_percent = None
def traffic_load_gradient(request): """Json with 100 items where each row represent the RGB color load indexed by percentage.""" keys = ('r', 'g', 'b') # again thar be dragons. response = HttpResponse( simplejson.dumps(( [dict(zip(keys, get_traffic_rgb(percent))) for percent in range(0, 101)]))) response['Content-Type'] = 'application/json; charset=utf-8' return response