Exemplo n.º 1
0
def radar_chart(request, user_facebook_id):
    user = get_current_user(request)  # the user presently logged in
    user_facebook_id = user.facebook_id
    user_name = user.full_name
    user_current = Overall_Rating.objects.filter(user=user)
    user_dept = []
    for i in range(len(user_current)):
        user_dept.append(user_current[i].course.department)
    #--------------------------------------------------------------------------
    # 1. convert dept list to value&name lists
    [course_taken_fullname,
     course_taken_value] = course_value_convert(user_dept)
    # 2. max courses have taken in one dept
    course_value_max = round(max(course_taken_value))
    if course_value_max % 2 != 0: course_value_max = course_value_max + 1
    if course_value_max < 6: course_value_max = 6
    # 3. make labels
    course_value_label = []
    for i in range(course_value_max):
        if i % 2 == 0:
            course_value_label.insert(i, str(i))
        else:
            course_value_label.insert(i, '')
        course_value_label[0] = ''

    #--------------------------------------------------------------------------
    chart = pyofc2.open_flash_chart()
    #chart.title = pyofc2.title(text=user.full_name+"'s  course-map")
    #chart.title.style =("{font-size:20px; color : #B0BFBA;}")   # title colour
    area = pyofc2.area_hollow()
    area.width = 1
    area.dot_size = 1
    area.halo_size = 1
    area.colour = '#36647F'  # area edge color B0BFBA
    area.fill_colour = '#36647F'  # area color FFFFFF
    area.fill_alpha = 0.5
    area.loop = True

    area.values = course_taken_value
    chart.add_element(area)

    r = pyofc2.radar_axis(max=course_value_max, steps=2)
    r.colour = '#DAD5E0'  # main axis color 36647F
    r.grid_colour = '#DAD5E0'  # grid color 36647F
    ra = pyofc2.radar_axis_labels(labels=course_value_label, size=12)
    ra.colour = '#3B3B40'  # label(on axis) color B0BFBA
    r.labels = ra

    sa = pyofc2.radar_spoke_labels(labels=course_taken_fullname, size=40)

    sa.colour = '#3B3B40'  # label color B0BFBA
    chart.radar_axis = r
    r.spoke_labels = sa
    tip = pyofc2.tooltip()
    tip.proximity = 1
    chart.tooltip = tip
    chart.bg_colour = '#FFFFFF'  # background color 3B3B40
    return HttpResponse(chart.render())
Exemplo n.º 2
0
def bars_data(request):
    url = 'https://api.bitbucket.org/1.0/repositories/lukaszb/django-richtemplates/changesets/'
    response = urllib2.urlopen(url)
    jdata = loads(response.read())
    changesets = jdata['changesets']

    added = pyofc2.bar()
    modified = pyofc2.bar()
    removed = pyofc2.bar()
    added.values, modified.values, removed.values = [], [], []
    added.colour = '#00c700'
    added.text = 'Added'
    modified.colour = '#ffaa00'
    modified.text = 'Modified'
    removed.colour = '#f27474'
    removed.text = 'Removed'

    x = pyofc2.x_axis()
    y = pyofc2.y_axis(steps=5)
    y_max = 0
    labels = []

    for changeset in changesets:
        labels.append(pyofc2.x_axis_label(text='%s:%s' %
            (changeset['revision'], changeset['node'])))
        files = changeset['files']
        tip = '#val#<br>Date: %s<br>Revision: %s:%s<br>Author: %s<br>Message: %s'
        tip = tip % tuple([changeset[key] for key in (
            'timestamp', 'revision', 'node', 'author', 'message')])
        tip = '%s: ' + tip
        # Added files
        added_count = len([f for f in files if f['type'] == 'added'])
        added.values.append(pyofc2.barvalue(top=added_count, tip=tip % 'Added'))
        # Modified files
        modified_count = len([f for f in files if f['type'] == 'modified'])
        modified.values.append(pyofc2.barvalue(top=modified_count,
            tip=tip % 'Modified'))
        # Removed files
        removed_count = len([f for f in files if f['type'] == 'removed'])
        removed.values.append(pyofc2.barvalue(top=removed_count,
            tip=tip % 'Removed'))
        y_max = max([y_max, added_count, modified_count, removed_count])

    y.min = 0
    y.max = y_max

    title = pyofc2.title(text='django-richtemplates changesets')
    chart = pyofc2.open_flash_chart()
    chart.title = title
    chart.add_element(added)
    chart.add_element(modified)
    chart.add_element(removed)
    chart.bg_colour = '#ffffff'
    x.labels = pyofc2.x_axis_labels(steps=1, rotate=25.0)
    x.labels.labels = labels
    chart.x_axis = x
    chart.y_axis = y
    return HttpResponse(chart.render(), mimetype='application/json')
Exemplo n.º 3
0
def radar_chart(request,user_facebook_id):
    user=get_current_user(request) # the user presently logged in
    user_facebook_id = user.facebook_id
    user_name = user.full_name
    user_current = Overall_Rating.objects.filter(user=user)
    user_dept=[]
    for i in range(len(user_current)):
	    user_dept.append(user_current[i].course.department)
    #--------------------------------------------------------------------------
    # 1. convert dept list to value&name lists
    [course_taken_fullname,course_taken_value]=course_value_convert(user_dept)	
    # 2. max courses have taken in one dept
    course_value_max=round(max(course_taken_value))
    if course_value_max %2!=0: course_value_max = course_value_max +1
    if course_value_max <6: course_value_max = 6
    # 3. make labels
    course_value_label = []
    for i in range(course_value_max):
	    if i%2==0:
		    course_value_label.insert(i,str(i))
	    else:
		    course_value_label.insert(i,'')
	    course_value_label[0]=''

    #--------------------------------------------------------------------------
    chart = pyofc2.open_flash_chart() 
    #chart.title = pyofc2.title(text=user.full_name+"'s  course-map")
    #chart.title.style =("{font-size:20px; color : #B0BFBA;}")   # title colour
    area = pyofc2.area_hollow()
    area.width = 1
    area.dot_size = 1
    area.halo_size = 1
    area.colour = '#36647F'	 # area edge color B0BFBA
    area.fill_colour = '#36647F'    # area color FFFFFF
    area.fill_alpha = 0.5
    area.loop = True
    
    area.values = course_taken_value
    chart.add_element(area) 

    r = pyofc2.radar_axis(max=course_value_max,steps=2)
    r.colour ='#DAD5E0'     # main axis color 36647F
    r.grid_colour = '#DAD5E0'   # grid color 36647F
    ra = pyofc2.radar_axis_labels(labels=course_value_label,size=12)
    ra.colour = '#3B3B40'   # label(on axis) color B0BFBA
    r.labels = ra
    
    sa = pyofc2.radar_spoke_labels(labels=course_taken_fullname ,size=40)
    
    sa.colour = '#3B3B40'   # label color B0BFBA
    chart.radar_axis = r 
    r.spoke_labels = sa
    tip = pyofc2.tooltip()
    tip.proximity = 1
    chart.tooltip = tip
    chart.bg_colour = '#FFFFFF' # background color 3B3B40
    return HttpResponse(chart.render())
Exemplo n.º 4
0
 def response(self, request, username, project_slug):
     import random
     import pyofc2
     t = pyofc2.title(text=_("Tasks"))
     b1 = pyofc2.bar()
     b1.values = range(10)
     b2 = pyofc2.bar()
     b2.values = [random.randint(0, 9) for i in range(9)]
     b2.colour = '#56acde'
     chart = pyofc2.open_flash_chart()
     chart.title = t
     chart.add_element(b1)
     chart.add_element(b2)
     return HttpResponse(chart.render())
Exemplo n.º 5
0
 def response(self, request, username, project_slug):
     import random
     import pyofc2
     t = pyofc2.title(text=_("Tasks"))
     b1 = pyofc2.bar()
     b1.values = range(10)
     b2 = pyofc2.bar()
     b2.values = [random.randint(0,9) for i in range(9)]
     b2.colour = '#56acde'
     chart = pyofc2.open_flash_chart()
     chart.title = t
     chart.add_element(b1)
     chart.add_element(b2)
     return HttpResponse(chart.render())
Exemplo n.º 6
0
def generate_chart_data(request, address=None, fields=None, *args, **kwargs):
    '''Generates charting data for fields'''
    span = request.GET.get('span', None)
    colours = request.GET.get('colours', None)
    start = request.GET.get('start', None)
    end = request.GET.get('end', None)
    raw = request.GET.get('raw', "true").lower() == "true"
    smooth = request.GET.get('smooth', "false").lower() == "true"
    smooth_len = float(request.GET.get('smooth_factor', "0.2"))

    fields = fields.split(',')
    address = address.replace('_', ':')

    span = SPANS[span] * 60

    dev = models.SensorSDKRemoteDevice.objects.get(address=address)
    dev = models.get_subclass(dev)
    __check_field_is_valid(dev, fields)

    if end is None:
        end = datetime.now()

    if start is None:
        start = datetime.fromtimestamp(time.mktime(end.timetuple()) - span)

    qs = generate_data(dev=dev, fields=fields, start=start, end=end)
    data = qs.values('timestamp', *fields)
    if colours is not None:
        col = colours
        colours = {}
        for f in colours.split(','):
            field, colour = f.split('=', 1)
            colours[field] = colour
    else:
        colours = {}
        i = 0
        for field in fields:
            colours[field] = COLOURS[i]
            i += 1
            if i >= len(COLOURS):
                i = 0
        for field in fields:
            colours['%s_average' % field] = COLOURS[i]
            i += 1
            if i >= len(COLOURS):
                i = 0

    sets = {}

    for field in fields:
        sets[field] = clear_duplicates(data, field)

    if smooth:
        for f in fields:
            #sets[a] = [pyofc2.scatter_value(**vals) for vals in moving_average(sets(f), smooth_len)]
            s = [({'x': a['timestamp'], 'y': a[f]}) for a in data]
            sets["%s_average" % f] = low_pass_filter(s, smooth_len)

    x_axis = pyofc2.x_axis()

    x_axis.min = int(time.mktime(start.timetuple()))
    x_axis.max = int(time.mktime(end.timetuple()))
    x_axis.steps = (x_axis.max - x_axis.min) / 10

    if x_axis.max - x_axis.min <= 60 * 60 * 24:
        format = 'H:i'
    else:
        format = 'm-d-Y H:i'

    labels = [{
        'x': a,
        'text': '#date:%s#' % format,
    } for a in range(x_axis.min, x_axis.max + x_axis.steps, x_axis.steps)]
    x_axis.labels = pyofc2.x_axis_labels(labels=labels, rotate='45')

    y_axis = pyofc2.y_axis()
    y_axis.min = None
    y_axis.max = None
    for field in fields:
        b = qs.aggregate(min=Min(field), max=Max(field))
        if y_axis.min is None or y_axis.min > b['min']:
            y_axis.min = b['min']
        if y_axis.max is None or y_axis.max < b['max']:
            y_axis.max = b['max']
    if y_axis.min is None:
        y_axis.min = -1
    if y_axis.max is None:
        y_axis.max = 1
    y_axis.min = 0.9 * y_axis.min
    y_axis.max = 1.1 * y_axis.max

    y_axis.steps = (y_axis.max - y_axis.min) / 10

    chart = pyofc2.open_flash_chart()
    chart.title = pyofc2.title(text="%s [%s]: %s" %
                               (dev.friendly_name, address, fields))
    #chart.tooltip=pyofc2.tooltip(text="#date: Y-m-d H:i#<br>#y#\n")
    for c in sets:
        if not raw and not c.endswith('average'):
            continue
        if not smooth and c.endswith('average'):
            continue
        s = pyofc2.scatter_line()
        s.values = [pyofc2.scatter_value(x=x, y=y) for x, y in sets[c]]
        s.text = c
        s.dot_style = {
            'tip': "%s<br>#date:Y-m-d H:i#<br>%s: #val#" % (c, _("Value"))
        }
        if colours.get(c, None):
            s.colour = colours[c]
        chart.add_element(s)

    chart.x_axis = x_axis
    chart.y_axis = y_axis

    return HttpResponse(chart.render(), content_type='application/json')
Exemplo n.º 7
0
def bars_data(request):
    url = 'https://api.bitbucket.org/1.0/repositories/lukaszb/django-richtemplates/changesets/'
    response = urllib2.urlopen(url)
    jdata = loads(response.read())
    changesets = jdata['changesets']

    added = pyofc2.bar()
    modified = pyofc2.bar()
    removed = pyofc2.bar()
    added.values, modified.values, removed.values = [], [], []
    added.colour = '#00c700'
    added.text = 'Added'
    modified.colour = '#ffaa00'
    modified.text = 'Modified'
    removed.colour = '#f27474'
    removed.text = 'Removed'

    x = pyofc2.x_axis()
    y = pyofc2.y_axis(steps=5)
    y_max = 0
    labels = []

    for changeset in changesets:
        labels.append(
            pyofc2.x_axis_label(text='%s:%s' %
                                (changeset['revision'], changeset['node'])))
        files = changeset['files']
        tip = '#val#<br>Date: %s<br>Revision: %s:%s<br>Author: %s<br>Message: %s'
        tip = tip % tuple([
            changeset[key]
            for key in ('timestamp', 'revision', 'node', 'author', 'message')
        ])
        tip = '%s: ' + tip
        # Added files
        added_count = len([f for f in files if f['type'] == 'added'])
        added.values.append(pyofc2.barvalue(top=added_count,
                                            tip=tip % 'Added'))
        # Modified files
        modified_count = len([f for f in files if f['type'] == 'modified'])
        modified.values.append(
            pyofc2.barvalue(top=modified_count, tip=tip % 'Modified'))
        # Removed files
        removed_count = len([f for f in files if f['type'] == 'removed'])
        removed.values.append(
            pyofc2.barvalue(top=removed_count, tip=tip % 'Removed'))
        y_max = max([y_max, added_count, modified_count, removed_count])

    y.min = 0
    y.max = y_max

    title = pyofc2.title(text='django-richtemplates changesets')
    chart = pyofc2.open_flash_chart()
    chart.title = title
    chart.add_element(added)
    chart.add_element(modified)
    chart.add_element(removed)
    chart.bg_colour = '#ffffff'
    x.labels = pyofc2.x_axis_labels(steps=1, rotate=25.0)
    x.labels.labels = labels
    chart.x_axis = x
    chart.y_axis = y
    return HttpResponse(chart.render(), mimetype='application/json')