Ejemplo n.º 1
0
def main():
    # prepare to read data and apply basic filtering
    rows = common.rawData()
    rows = (row for row in rows if row['SamplingRate'] == 1)
    rows = (row for row in rows if row['Effort'] == 5)

    percents = []
    time_aggressive = []
    time_only_metrics = []
    for row in rows:
        if row['conj_total'] == None:
            continue
        pruned = row['compl_cr_pruned_conj'] + row['compl_cr_pruned_disj']
        total = row['conj_total'] + row['disj_total']
        percents.append(float(pruned) / total)

        time_aggressive.append(row['time_compl_cr'])
        time_only_metrics.append(row['time'])

    print 'Aggressive pruning efficiency: %lf of total' % common.average(
        percents)

    print '\nTimes:'
    print 'When everything is computed (no pruning, no metrics): %d seconds' % average_time(
        'data/times-compute-all.txt')
    print 'Only metrics are applied: %d seconds' % common.average(
        time_only_metrics)
    print 'Moderate pruning is applied: %d seconds' % average_time(
        'data/times-moderate-pruning.txt')
    print 'Aggressive pruning is applied: %d seconds' % common.average(
        time_aggressive)
Ejemplo n.º 2
0
def main():
    [outfile, kind] = sys.argv[1:]

    # prepare to read data and apply basic filtering
    rows = common.rawData()
    rows = (row for row in rows if row['SamplingRate'] == 1)

    # collect and index individual data points of interest
    data = {}
    for row in rows:
        coord = (row['Application'], row['Effort'])
        value = row[kind + '_interesting']
        if value == None: value = 0
        data.setdefault(coord, []).append(value)

    # summarize by averaging values at each (app, effort) coordinate
    for coord, counts in data.iteritems():
        data[coord] = common.average(counts)

    # extract effort levels to serve as X axis category labels
    efforts = (coord[1] for coord in data.iterkeys())
    efforts = set(efforts)
    efforts = sorted(efforts)
    categories = [(effort, ) for effort in efforts]

    # tick marks, in same order as common.apps
    # line styles rotate automatically
    ticks = [
        tick_mark.blackcircle3, tick_mark.blacksquare3, tick_mark.blacktri3,
        tick_mark.blackdtri3, tick_mark.plus3, tick_mark.x3
    ]

    # create plot area
    theme.output_file = outfile
    common.setTheme()
    x_coord = category_coord.T(categories, 0)
    x_axis = axis.X(label='/ieffort', format='%d%%')
    y_coord = log_coord.T()
    y_axis = axis.Y(label='Number of interesting predicates',
                    format=common.format_count)

    loc = {'conj': (100, 20), 'disj': (130, 7)}[kind]
    leg = legend.T(loc=loc)

    ar = area.T(x_axis=x_axis,
                x_coord=x_coord,
                y_axis=y_axis,
                y_coord=y_coord,
                legend=leg)

    # add one line plot for each application
    for (app, tick) in izip(common.apps, ticks):
        slice = [(effort, data[app, effort]) for effort in efforts]
        line = line_plot.T(label='/C/6' + app, data=slice, tick_mark=tick)
        ar.add_plot(line)

    # save the rendered result
    ar.draw()
Ejemplo n.º 3
0
 def plots():
     prior = None
     for fate in fates:
         series = [(app, data[app, fate]) for app in common.apps]
         overall = common.average([point[1] for point in series])
         series.append(('Overall', overall))
         bars = bar_plot.T(data=series, stack_on=prior, label=fate)
         prior = bars
         yield bars
Ejemplo n.º 4
0
def basic_suite(datapoints):
  basic_list = []

  basic_list.append(('Average', float_str_format(average(datapoints))))
  basic_list.append(('Median', median(datapoints)))
  basic_list.append(('Mode', mode(datapoints)))
  basic_list.append(('Range', data_range(datapoints)))
  basic_list.append(('Variance', float_str_format(variance(datapoints))))
  basic_list.append(('Standard Deviation', float_str_format(standard_deviation(datapoints))))

  return basic_list
def get_average_by_manufacturer(table, manufacturer):
    """Answer the question: What is the average amount of games in stock of
    a given manufacturer?? Args: table with all games. Returns: number of games"""

    stock_amount = [int(game[4]) for game in table if game[2] == manufacturer]
    while not stock_amount:
        ui.print_error_message("There is no such manufacturer.")
        return

    stock = common.average(stock_amount)
    ui.print_result([stock], 'Amount of games by {}'.format(manufacturer))
    return stock
Ejemplo n.º 6
0
def variance(datapoints):
  if len(datapoints) == 0:
    return None

  mu = average(datapoints)
  squaresum = 0
 
  for dp in datapoints:
    squaresum += (dp.as_float()-mu)*(dp.as_float()-mu)

  sigma = squaresum/len(datapoints)

  return sigma
Ejemplo n.º 7
0
def main():
    subdir = dirname(__file__)

    # prepare to read data and apply basic filtering
    rows = common.rawData()
    rows = (row for row in rows if row['Effort'] == 5)

    # prepare master data table
    densities = [1, 1.01, 2, 5, 10, 100, 1000]
    kinds = ['Conjunctions', 'Simple', 'Disjunctions']
    data = dict(((app, density, kind), []) for app in common.apps
                for density in densities for kind in kinds)

    # collect and index individual data points of interest
    for row in rows:
        app = row['Application']
        density = row['SamplingRate']

        def record(kind, column):
            count = row[column]
            if count != None:
                data[app, density, kind].append(count)

        record('Conjunctions', 'conj_interesting')
        record('Disjunctions', 'disj_interesting')
        record('Simple', 'simple_preds')

    # summarize by averaging values at each (app, density, kind) coordinate
    for coord, counts in data.iteritems():
        data[coord] = common.average(counts)
        if data[coord] == 0:
            data[coord] = None

    # create common plot area elements
    common.setTheme(size=(120, 93))
    densities = [1, 1.01, 2, 5, 10, 100, 1000]
    categories = [(label, ) for label in densities]
    x_coord = category_coord.T(categories, 0)
    x_axis = axis.X(label='Sampling Rate', format=format_x)
    y_coord = log_coord.T()
    y_axis = axis.Y(label='Number of Predicates', format=common.format_count)

    # create single-application plot
    theme.reinitialize()
    leg = legend.T(loc=(115, 10))
    ar = area.T(x_axis=x_axis,
                x_coord=x_coord,
                y_axis=y_axis,
                y_coord=y_coord,
                legend=leg)

    # one data series (line) per category of counted predicates
    app = 'print_tokens2'
    for series in kinds:
        counts = [(density, data[app, density, series])
                  for density in densities]
        ar.add_plot(line_plot.T(label=series, data=counts))

    # render plots to disk
    ar.draw(canvas.init('%s/sampling-%s.pdf' % (subdir, app)))
    ar.draw(canvas.init('%s/sampling-%s.eps' % (subdir, app)))

    # LaTeX fragment with table rows
    latex = file(subdir + '/sampling.tex', 'w')
    for app in common.apps:
        protected = app.replace('_', '\\_')
        print >> latex, '\\prog{%s}' % protected,
        for series in ['Simple', 'Conjunctions', 'Disjunctions']:
            for density in [1, 100, 1000]:
                count = data[app, density, series]
                if count == None:
                    cell = '-'
                else:
                    cell = locale.format('%.0f', count, grouping=True)
                print >> latex, '&', cell,
        print >> latex, '\\\\'
Ejemplo n.º 8
0
def returnOnShe(netIncome, dividends, currentShe, prevShe):
    return (netIncome - dividends) / common.average(currentShe, prevShe)
Ejemplo n.º 9
0
def returnOnAssets(netIncome, currentAssets, prevAssets):
    return netIncome / common.average(currentAssets, prevAssets)
Ejemplo n.º 10
0
def assetTurnover(sales, currentAssets, prevAssets):
    return sales / common.average(currentAssets, prevAssets)
Ejemplo n.º 11
0
def main():
    [outfile, kind] = sys.argv[1:]

    # prepare to read data and apply basic filtering
    rows = common.rawData()
    rows = (row for row in rows if row['SamplingRate'] == 1)
    rows = (row for row in rows if row['Effort'] == 5)

    # prepare master data table
    data = dict(((app, fate), []) for app in common.apps for fate in fates)

    # collect and index individual data points of interest
    for row in rows:
        app = row['Application']

        total = row[kind + '_total']
        if total != None:
            compute = row[kind + '_computed']
            retain = row[kind + '_interesting']
            waste = compute - retain
            bound = row[kind + '_ub_est_pruned']
            effort = row[kind + '_pdg_metric_pruned']
            assert retain + waste + bound + effort == total

            total = float(total)
            data[app, computeRetain].append(retain / total)
            data[app, computeDiscard].append(waste / total)
            data[app, pruneBound].append(bound / total)
            data[app, pruneEffort].append(effort / total)

    # summarize by averaging at each data point
    for coord, values in data.iteritems():
        data[coord] = common.average(values)

    # create plot area
    theme.output_file = outfile
    common.setTheme()
    x_coord = common.appsCoord(overall=True)
    x_axis = common.appsAxisX()
    y_axis = axis.Y(label='Fraction of complex predicates',
                    format=common.format_percent)
    leg = legend.T(loc=(23, 100), shadow=(1, -1, fill_style.gray50))
    ar = area.T(x_axis=x_axis,
                x_coord=x_coord,
                y_axis=y_axis,
                y_range=(0, 1),
                y_grid_interval=0.1,
                legend=leg)

    # add stacked bars in reverse order so legend looks right

    def plots():
        prior = None
        for fate in fates:
            series = [(app, data[app, fate]) for app in common.apps]
            overall = common.average([point[1] for point in series])
            series.append(('Overall', overall))
            bars = bar_plot.T(data=series, stack_on=prior, label=fate)
            prior = bars
            yield bars

    bars = reversed(list(plots()))
    ar.add_plot(*bars)

    # save rendered plot
    ar.draw()
Ejemplo n.º 12
0
def integer_overview(query):
  datapoints = DataPoint.get_by_query(query)
  return 'Average: ' + float_str_format(average(datapoints))
Ejemplo n.º 13
0
def average_time(fname):
    data = file(fname).readlines()[1:]
    data = [line.split(' ')[-1] for line in data]
    data = [int(line) for line in data]
    return common.average(data)
Ejemplo n.º 14
0
def inventoryTurnover(Cogs, inventory1, inventory2):
    return Cogs / common.average(inventory1, inventory2)
Ejemplo n.º 15
0
def receivablesTurnover(creditSales, grossAcctReceivable1,
                        grossAcctReceivable2):
    return creditSales / common.average(grossAcctReceivable1,
                                        grossAcctReceivable2)
recommenderFile = '../play/test-data/codechanges.txt.inferred_ast_operations.recommender'

RANKING_INDEX = 1
TIME_INDEX = 3

header,results = common.readCSV(recommenderFile)
nom_rows = len(results)
num_col = len(results[0])

maxRankings = 0
rankings = []
maxTime = 0;
time = []
for line in results:
	if (line[RANKING_INDEX] > maxRankings):
		maxRankings = line[RANKING_INDEX]
	if (line[TIME_INDEX] > maxTime):
		maxTime = line[TIME_INDEX]
	rankings.append(line[RANKING_INDEX])
	time.append(line[TIME_INDEX])

rankings = [float(x) for x in rankings]
time = [float(x) for x in time]

print 'maximum ranking = ' + str(maxRankings)
print 'Average ranking = ' + str(common.average(rankings))

print 'maximum time = ' + str(maxTime)
print 'Average time = '+ str(common.average(time))