示例#1
0
def give_graphs(prod_dict):
    """ Produces graphs. 
    
    prod_dict -- dict {prod : count}
    """
    # get labels and sizes :
    labels = list(prod_count.keys())
    sizes = list(prod_count.values())
    N_diff_samples = sum(sizes)
    # calculates sizes as percentages (total 100%)
    if len(labels) == len(sizes):
        relative_sizes = [(sizes[i] / N_diff_samples * 100)
                          for i in range(len(labels))]

    # make list of tuples to sort while label and size comined :
    count_prod_tuple = list(zip(sizes, labels))
    sorted_high = sorted(count_prod_tuple, key=itemgetter(0, 1), reverse=True)
    # show bar plot in descending order :
    ylabel = "Product group"
    title = "Unique samples per product group"
    count_prod_list = [list(t) for t in zip(*sorted_high)]
    count_list = count_prod_list[0]
    prod_list = count_prod_list[1]

    bar_plot(prod_list, count_list, title, ylabel)
    # prints product and unique samples per line
    print("PRODUCT\tN_UNIQUE_SAMPLES")
    for i in range(len(sorted_high)):
        print("{}\t{}".format(sorted_high[i][0], sorted_high[i][1]))

    # create figures:
    pie_chart(labels, relative_sizes, 1, title)
示例#2
0
def index(request, report_name_url, posted=False):


    report_name = report_name_url.replace('_', ' ')
    if request.method == 'POST' and not posted:
        report_form = ReportForm(request.POST)
        if report_form.is_valid():
            report_form.save(commit=True)
            return index(request, report_name_url, posted=True)
        else:
            print report_form.errors
    else:
        report_form = ReportForm()
    locked_populate()
    try:
        report = Report.objects.get(name=report_name)
        jira_connector = Jira.objects.get(report=report)
        report_table = Report_Table(Bug.objects.filter(jira_connect=jira_connector))
        RequestConfig(request).configure(report_table)
        chart = pie_chart(report)
    except Report.DoesNotExist:
        pass



    context_dict = dict({'report_table': report_table, 'report_name': report_name,
                         'reports': Report.objects.all(), 'report_form': report_form}.items()
                          + chart.items())
    print(context_dict)
    return render(request, "report_view/index.html", context_dict)
                                                      # 'chart': chart})
示例#3
0
def index(request, report_name_url, posted=False):

    report_name = report_name_url.replace('_', ' ')
    if request.method == 'POST' and not posted:
        report_form = ReportForm(request.POST)
        if report_form.is_valid():
            report_form.save(commit=True)
            return index(request, report_name_url, posted=True)
        else:
            print report_form.errors
    else:
        report_form = ReportForm()
    locked_populate()
    try:
        report = Report.objects.get(name=report_name)
        jira_connector = Jira.objects.get(report=report)
        report_table = Report_Table(
            Bug.objects.filter(jira_connect=jira_connector))
        RequestConfig(request).configure(report_table)
        chart = pie_chart(report)
    except Report.DoesNotExist:
        pass

    context_dict = dict({
        'report_table': report_table,
        'report_name': report_name,
        'reports': Report.objects.all(),
        'report_form': report_form
    }.items() + chart.items())
    print(context_dict)
    return render(request, "report_view/index.html", context_dict)
def get_stats(rows, root, count=10, print_stats=True):
    cols = []  #to return for plot_daily
    print '\nViews\tEngage\tDonate\tValue\tTitle\n'
    for row in rows:
        if count == 0: break
        if not row[1]: break
        if row[0]:
            cols.append(row[0])
            title = capitalize(row[0])
        print row[1], '\t', int(row[2]), '\t', int(
            row[3]), '\t', '{0:.2f}'.format(row[3] /
                                            float(row[1])), '\t', title
        count -= 1

    date = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
    outputf = 'output/stats_{}.csv'.format(date)
    text = '{}\n'.format(query_header)

    #save results
    if print_stats:
        with open(os.path.join(root, outputf), 'w') as f:
            for row in rows:
                if not row[1]: break
                if row[0]:
                    title = capitalize(row[0])
                    title = '"' + title + '"'
                    title = title.encode('utf-8')
                else:
                    title = ''
                text += '{},{},{},{},{}\n'.format(
                    title, row[1], int(row[2]), int(row[3]),
                    '{0:.2f}'.format(row[3] / float(row[1])))
            f.write(text)

    #plot and/or return results
    inputf = os.path.join(root, outputf)
    outputf = os.path.join(root, outputf.replace('csv', 'png'))

    if print_stats:
        title = 'Top Referral Channels'
        include_others = True
        pie_chart(inputf, outputf, title, include_others)

    #return list of shows and new outputf
    outputf = os.path.join(root, outputf.replace('stats_', 'trending_stats_'))

    return cols, outputf
'''
other setup
'''

#where output files go
root_graphics = 'output_graphics'
root_tables = 'output_tables'

#create needed folders if they don't exist
if not os.path.isdir(root_graphics): os.mkdir(root_graphics)
if not os.path.isdir(root_tables): os.mkdir(root_tables)
'''
process
'''

#get passport data
df = get_channel_views(date_start, date_end)
output_head = title.replace(' ', '_')
df.to_csv(root_tables + '/' + output_head + '.csv',
          index=False,
          encoding='utf-8-sig')
print df.head(20)
print '\nTOTAL VIEWS', df['total_count'].sum()

#plot results
inputf = df
outputf = os.path.join(root_graphics, output_head + '.jpg')
include_others = True

pie_chart(inputf, outputf, title, include_others)
def basic_pie_chart(data_option):
	ips = get_ips()
	if data_option == '1':
		score = get_score()
		pie_chart(ips, score)
	elif data_option == '2':
		total_vuln = get_total_vulnerabilities()
		pie_chart(ips, total_vuln)
	elif data_option == '3':
		crits = get_crits()
		pie_chart(ips, crits)
	elif data_option == '4':
		high_vuln = get_high()
		pie_chart(ips, high_vuln)
	elif data_option == '5':
		medium_vuln = get_medium()
		pie_chart(ips, medium_vuln)
	elif data_option == '6':
		low_vuln = get_low()
		pie_chart(ips, low_vuln)
	elif data_option == '7':
		info_vuln == get_info_vulns()
		pie_chart(ips, info_vuln)
示例#7
0
文件: server.py 项目: diogo149/simbo
def importances_graph(uuid):
    k, v = load_importances(uuid)
    return graphs.pie_chart(k, v)
示例#8
0
文件: server.py 项目: diogo149/simbo
def sample_pie():
    return graphs.pie_chart(["Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawberry", "Pineapple"],
                            [3, 4, 0, 1, 5, 7, 3])