Example #1
0
def tab_printer(args):
    args = vars(args)
    keys = sorted(args.keys())
    t = Texttable() 
    t.set_precision(10)
    t.add_rows([["Parameter", "Value"]] +  [[k.replace("_"," ").capitalize(),args[k]] for k in keys])
    print(t.draw())
 def __str__(self):
     table = Texttable()
     table.set_precision(20)
     table.add_row(self._weights)
     auxRow = []
     outputRow = []
     if self._noOfInputs % 2 == 1:
         for i in range(floor(self._noOfInputs / 2)):
             auxRow.append('\\')
             outputRow.append(' ')
         auxRow.append('|')
         outputRow.append(self._output)
         for i in range(floor(self._noOfInputs / 2)):
             auxRow.append('/')
             outputRow.append(' ')
     else:
         for i in range(floor(self._noOfInputs / 2)):
             auxRow.append('\\')
             outputRow.append(' ')
         outputRow.append(self._output)
         for i in range(floor(self._noOfInputs / 2)):
             auxRow.append('/')
             outputRow.append(' ')
     auxRow2 = ['|' for i in range(self._noOfInputs)]
     table.add_row(auxRow2)
     table.add_row(auxRow)
     table.add_row(outputRow)
     return table.draw()
Example #3
0
def print_price_data(data):

    # Current BTC Price
    # --------------------
    print '\n%s' % colorize('CaVirtex Market\n---------------', colors.CYAN)
    

    status_color = colors.GREEN if data['net'] > 0 else colors.RED

    print '\n%s' % colorize('Price', colors.BLUE)
    
    print '\n%s' % colorize('$%.2f CAD/BTC' % data['current_price'], status_color)

    # Latest Trades
    # ----------------
    print '\n%s\n' % colorize('Latest Trades', colors.BLUE)
    
    trades_table = Texttable()
    trades_table.set_deco(Texttable.HEADER)
    trades_table.set_precision(2)
    trades_table.set_cols_dtype(['f', 'f', 'f', 't'])
    trades_table.add_rows(data['latest_trades'])

    print trades_table.draw()
    
    # Investment Returns
    # ---------------------
    print '\n%s' % colorize('Your Investment', colors.BLUE)

    print '\nNet: %s' % colorize('$%.2f CAD' % data['net'], status_color)
    print '\nVOI: %s' % colorize('$%.2f CAD' % data['voi'], status_color)
    print '\nROI: %s' % colorize('%.2f%%' % data['roi'], status_color)
Example #4
0
def print_table(final_results, sizes, scale):
    traffic_unit = scale["traffic_unit"]
    pkt_unit = scale["pkt_unit"]

    table = Texttable(max_width=0)
    table.set_chars(['', '|', '', ''])
    table.set_precision(2)
    table.set_deco(Texttable.VLINES)
    rows = [[
        "| Packet size", "Line Utilization (%)",
        "Total L1 {}".format(traffic_unit), "Total L2 {}".format(traffic_unit),
        "CPU Util (%)", "Total {}".format(pkt_unit),
        "BW per core {} <1>".format(traffic_unit),
        "{} per core <2>".format(pkt_unit), "Multiplier"
    ]]
    for size in sizes:
        pkt_result = final_results[size]
        pkt_str = "| " + str(pkt_result["Packet size"])
        row = [
            pkt_str, pkt_result["Line Utilization (%)"],
            pkt_result["Total L1 {}".format(traffic_unit)],
            pkt_result["Total L2 {}".format(traffic_unit)],
            pkt_result["CPU Util (%)"],
            pkt_result["Total {}".format(pkt_unit)],
            pkt_result["BW per core {}".format(traffic_unit)],
            pkt_result["{} per core".format(pkt_unit)],
            pkt_result["Multiplier"]
        ]
        rows.append(row)

    table.add_rows(rows)

    print(table.draw())
Example #5
0
def _dataframe_to_texttable(df, align=None):
    """Convert data frame to texttable. Sets column widths to the
    widest entry in each column."""
    ttab = Texttable()
    ttab.set_precision(1)
    h = [[x for x in df]]
    h.extend([x for x in df.to_records(index=False)])
    if align:
        colWidths = [max(len(x), len(".. class:: {}".format(y))) for x,y in izip(df.columns, align)]
    else:
        colWidths = [len(x) for x in df.columns]
    for row in h:
        for i in range(0, len(row)):
            if type(row[i]) == str:
                colWidths[i] = max([len(str(x)) for x in row[i].split("\n")] + [colWidths[i]])
            colWidths[i] = max(len(str(row[i])), colWidths[i])
    table_data = []
    if align:
        for row in h:
            table_row = []
            i = 0
            for col, aln in izip(row, align):
                table_row.append(".. class:: {}".format(aln) + " " * colWidths[i] + "{}".format(col))
                i = i + 1
            table_data.append(table_row)
    else:
        table_data = h
    ttab.add_rows(table_data)
    ttab.set_cols_width(colWidths)
    # Note: this does not affect the final pdf output
    ttab.set_cols_align(["r"] * len(colWidths))
    return ttab
Example #6
0
    def __init__(self):
        '''Shows a table Integrate Numerically the Student’s t-distribution
        'probability density 'function ( t-distribution pdf) using Simpson’s'
        'rule. The total' 'probability' is the area of the function (the integral)'
        'from -t to t. The total probability is p'

        '''
        calculate = Calculate('history.txt')
        values = calculate.get_total_probability_p()
        table = Texttable()
        table.set_cols_align(["l", "c", "c"])
        table.set_cols_valign(["m", "m", "m"])
        table.set_cols_dtype(['t', 'i', 'f'])
        table.set_precision(5)
        label = [
            color(bcolors.GREEN,"Test"),'',
            color(bcolors.GREEN,"Expected Values")]
        head = [
            color(bcolors.GREEN,"t"),
            color(bcolors.GREEN,"dof"),
            color(bcolors.GREEN,"p")]
        rows = []
        rows.append(label)
        rows.append(head)
        [rows.append(element) for element in values]
        table.add_rows(rows)
        print(table.draw() + "\n")
Example #7
0
def _write_output_table(writer, table, write_table_name=False):
    tt = Texttable()
    tt.set_deco(Texttable.HEADER)
    tt.set_precision(10)

    if table.columns_type:
        tt.set_cols_dtype(table.columns_type)
    tt.header(table.columns_name)
    ids = table.columns_id
    for raw_row in table.rows:
        row = [raw_row[i] for i in ids]
        tt.add_row(row)

    drawn_table = tt.draw()

    writer.write('\n')

    if write_table_name:
        line_length = len(drawn_table.split('\n')[0])
        spacing = (line_length - len(table.name)) // 2

        writer.write(' ' * spacing)
        writer.write(table.name)
        writer.write('\n')

    writer.write(tt.draw())
Example #8
0
def test_file(name) -> None:
    print(f">>>>>>>>>> {name} <<<<<<<<<<")
    print()

    t = Texttable(max_width=100)
    t.set_deco(Texttable.BORDER | Texttable.HEADER | Texttable.VLINES)
    t.set_precision(3)
    t.header(["Encoder", "Size", "Diff", "Diff%"])
    t.set_cols_align(["l", "r", "r", "r"])

    rows = []

    for encoder, encode in ENCODERS.items():
        nintendo_len = len(TEST_FILE_DATA[name])
        encoder_len = len(encode(TEST_FILE_DATA_UNCOMP[name]))
        diff = encoder_len - nintendo_len
        ratio = encoder_len / nintendo_len
        percentage = (ratio - 1) * 100.0
        rows.append([encoder, encoder_len, diff, percentage])

    # Sort by diff.
    rows.sort(key=lambda row: row[2])
    t.add_rows(rows, header=False)

    print(t.draw())
    print()
Example #9
0
    def __init__(self):
        '''Show results

        '''
        calculate = Requeriments()
        values = calculate.calculate_all_values()
        labels = ["r","r^2","Significance","B0","B1","P","Range","UPI(70%)","LIP(70%)"]
        table = Texttable()
        table.set_cols_align(["c", "c","c"])
        table.set_cols_valign(["m","m","m"])
        table.set_cols_dtype(['t','t','f'])
        table.set_cols_width([15 for i in range(3)])
        table.set_precision(9)
        label = [
            color(bcolors.GREEN,"Test"),
            color(bcolors.GREEN,"Parameter"),
            color(bcolors.GREEN,"Expected Value")]
        rows = []
        rows.append(label)
        number = 0
        for item in values:
            number += 1
            text = 'Test%d' % number
            for pos in range(9):
                rows.append([text, labels[pos], item[pos]])
        table.add_rows(rows)
        print(table.draw() + "\n")
Example #10
0
def cmd_list():
    imap = connectIMAP(CONFIG.accounts[0])
    # open readonly b/c otherwise messages will be marked as read '\\Seen'
    imap.select_folder(ARGS.mailbox, readonly=True)

    imap = connectIMAP(CONFIG.accounts[0])
    # open readonly b/c otherwise messages will be marked as read '\\Seen'
    imap.select_folder(ARGS.mailbox, readonly=True)
    try:
        msgs = iterMessages(imap)
        msgs = sorted(msgs, key=lambda m: m.date)
        ids = [m.id for m in msgs]
        table = Texttable()
        table.set_deco(Texttable.HEADER | Texttable.HLINES)
        table.header(
            ['Date', 'ID', 'Score', 'From', 'Subject', 'Flags', 'age (mins)'])
        table.set_cols_width([20, 10, 6, 30, 30, 12, 10])
        table.set_precision(1)
        for m in msgs:
            if m.score is not None and m.score < ARGS.score:
                if ARGS.verbose:
                    verbose(
                        'skipping message id=%d date=%s score=%s below threshold of %s'
                        % (m.id, m.date, m.scoreStr(), str(ARGS.score)))
                continue
            table.add_row([
                m.date, m.id,
                m.scoreStr(),
                m.headers.get('From', None),
                m.headers.get('Subject', None), m.flags,
                m.ageMinutes()
            ])
        info(table.draw())
    finally:
        imap.logout()
Example #11
0
def test_chaining():
    table = Texttable()
    table.reset()
    table.set_max_width(50)
    table.set_chars(list('-|+='))
    table.set_deco(Texttable.BORDER)
    table.set_header_align(list('lll'))
    table.set_cols_align(list('lll'))
    table.set_cols_valign(list('mmm'))
    table.set_cols_dtype(list('ttt'))
    table.set_cols_width([3, 3, 3])
    table.set_precision(3)
    table.header(list('abc'))
    table.add_row(list('def'))
    table.add_rows([list('ghi')], False)
    s1 = table.draw()
    s2 = (Texttable()
          .reset()
          .set_max_width(50)
          .set_chars(list('-|+='))
          .set_deco(Texttable.BORDER)
          .set_header_align(list('lll'))
          .set_cols_align(list('lll'))
          .set_cols_valign(list('mmm'))
          .set_cols_dtype(list('ttt'))
          .set_cols_width([3, 3, 3])
          .set_precision(3)
          .header(list('abc'))
          .add_row(list('def'))
          .add_rows([list('ghi')], False)
          .draw())
    assert s1 == s2
    def __str__(self):
        table = Texttable(max_width=0)
        table.set_deco(Texttable.HEADER)
        table.set_precision(1)

        header_row = ['Place', 'Name', 'Games', 'Points']
        for v in self.tiebreaks.values():
            header_row.append(v[0])
        table.header(header_row)

        col_alignments = []
        cols = len(self.table[0]) + 1
        for c in range(cols):
            col_alignments.append('c')
        table.set_cols_align(col_alignments)

        col_dtypes = ['i', 't', 'i', 't']
        for tiebreak in self.tiebreaks.values():
            col_dtypes.append(tiebreak[2])
        table.set_cols_dtype(col_dtypes)

        for rank, player in enumerate(self.table):
            cur_row = [rank + 1]
            for entry in player.values():
                cur_row.append(entry)
            table.add_row(cur_row)

        return table.draw()
Example #13
0
def createTable(headers, rows):
    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_precision(2)
    table.set_max_width(32)
    table.header(headers)
    for row in rows:
        table.add_row(row)
    return table
Example #14
0
def create_result_table(scores):
    t = Texttable()
    t.set_precision(6)
    t.add_row(['']+scores_names)
    for task, score in scores.items():
        if len(score)<len(scores_names):
            score += ['N/A'] * (len(scores_names)-len(score))
        t.add_row([task]+score)
    return t.draw()
Example #15
0
 def print_rating_questions_averages(self):
     questions = self.survey.get_all_questions()
     output_table = Texttable()
     output_table.set_precision(2)
     output_table.add_row(['Survey Question', 'Average Response'])
     for question in questions:
         if question.type == SurveyQuestionType.RATING.value:
             output_table.add_row(
                 [question.text,
                  question.get_average_response()])
     self.out.write(output_table.draw())
     self.out.write('\n')
Example #16
0
    def render_expense(self, expense):
        """Displays a single Expense in a table"""
        table = Texttable()
        table.set_cols_align(["l", "l"])
        table.set_precision(2)
        table.set_deco(Texttable.HLINES)
        table.add_row(["Id:", expense.get_expense_id()])
        table.add_row(["Name:", expense.get_name()])
        table.add_row(["Cost:", expense.get_cost()])
        table.add_row(["Deadline:", expense.get_deadline_string()])
        table.add_row(["Done:", expense.is_done_string()])

        print(table.draw())
Example #17
0
def draw_processes_table(processes):
    t = Texttable()
    t.set_precision(4)
    t.add_rows([
        list(Process._fields), *[list(x) for x in processes],
        [
            'Avg.', '', '', '',
            sum(p.T for p in processes) / len(processes),
            sum(p.E for p in processes) / len(processes),
            sum(p.I for p in processes) / len(processes)
        ]
    ])
    return t.draw()
Example #18
0
    def render_expenses(self, expenses):
        """Displays a list of Expenses in a table"""
        table = Texttable()
        table.set_cols_align(["r", "l", "r", "r"])
        table.header(["#", "Name", "Cost", "Deadline"])
        table.set_cols_dtype(["i", "t", "f", "t"])
        table.set_precision(2)
        table.set_deco(Texttable.HEADER | Texttable.HLINES)

        for index, expense in enumerate(expenses):
            table.add_row([index + 1, expense.get_name(), expense.get_cost(), 
                           expense.get_deadline_string()])

        print(table.draw())
Example #19
0
    def PrintRow(self, size, row, right):

        table = Texttable()
        table.set_precision(5)
        title = [[]]
        arr = [10 for i in range(size)]
        table.set_cols_width(arr)

        left = right
        for i in range(size):
            title[0].append(f'R({left},{right})')
            left += 1
        title.append(list(row))

        table.add_rows(title)
        print(table.draw())
Example #20
0
File: utils.py Project: JhyOnya/DCE
def tab_printer(args):
    """
    Function to print the logs in a nice tabular format.
    :param args: Parameters used for the model.
    """
    args = vars(args)
    keys = args.keys()
    # keys = sorted(args.keys())

    t = Texttable()
    t.set_precision(5)
    t.set_deco(Texttable.VLINES)
    t.set_cols_align(["r", "l"])
    # t.header(("Parameter", "Value"))
    t.add_rows([[k.replace("_", " ").capitalize(), args[k]] for k in keys],
               header=False)
    print(t.draw())
Example #21
0
def arguments_to_tables(args):
    """
    util function to print the logs in table format
    :param args: parameters
    :return:
    """
    args = vars(args)
    keys = sorted(args.keys())
    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_precision(width=10)
    table.set_cols_dtype(['t', 't'])
    table.set_cols_align(['l', 'l'])
    table.add_rows([["Parameter", "Value"]])
    for k in keys:
        table.add_row([k, args[k]])
    return table.draw()
Example #22
0
def report_evaluation(y_hat, y, yhat_raw=None):
    """
    Calculates evaluation metrics, logs them and saves them to a results file.

    :param y_hat: binary predictions matrix
    :param y: binary ground truth matrix
    :param yhat_raw: prediction scores matrix (floats)
    :return: None
    """
    eval_metrics = evaluation.all_metrics(y_hat, y, yhat_raw=yhat_raw)
    eval_keys = sorted(eval_metrics.keys())

    ordered_eval_metrics = OrderedDict()
    for metric in eval_keys:
        ordered_eval_metrics[metric] = eval_metrics[metric]

    logging.info(str(ordered_eval_metrics))

    config_dict = OrderedDict()
    classes = inspect.getmembers(constants, inspect.isclass)
    for class_ in classes:
        for vars_, val in vars(class_[1]).items():
            if "__" not in vars_ and \
                    class_[0] != "Keys" and \
                    class_[0] != "Tables":
                config_dict[class_[0] + "_" + vars_] = val

    t = Texttable()
    t.set_precision(5)
    t.add_rows([["Configuration", "Value"]] + list(config_dict.items()))

    t2 = Texttable()
    t2.set_precision(5)
    t2.add_rows([["Evaluation Metric", "Value"]] +
                list(ordered_eval_metrics.items()))

    out = t.draw() + "\n" + t2.draw()

    ts_now = 'results-{:%Y-%m-%d--%H:%M:%S}.txt'.format(
        datetime.datetime.now())
    res_path = os.path.join(constants.LOGS_DIR, ts_now)

    out_file = open(res_path, "w+")
    out_file.write(out)
    out_file.close()
Example #23
0
def print_node_probabilities(node_probabilities,
                             data_manager,
                             confidence,
                             detailed=False):
    color_nodes = dict()
    color_nodes['green'] = set()
    color_nodes['yellow'] = set()
    color_nodes['red'] = set()
    lt = (1 - confidence) * 0.5
    rt = 1 - lt
    confidence_interval = (lt, rt)
    for i, p in enumerate(node_probabilities):
        if i > 0:
            if p >= confidence_interval[1]:
                color_nodes['red'].add((i, p))
            elif p <= confidence_interval[0]:
                color_nodes['green'].add((i, p))
            else:
                color_nodes['yellow'].add((i, p))

    n_green = len(color_nodes['green'])
    n_yellow = len(color_nodes['yellow'])
    n_red = len(color_nodes['red'])
    print("\nNODE PROBABILITIES\n")
    print("Number of red nodes {}".format(n_red))
    print("Number of yellow nodes {}".format(n_yellow))
    print("Number of green nodes {}".format(n_green))

    node_qual = {'red': 'LY', 'green': 'LN', 'yellow': 'UN'}
    if detailed:
        my_table = Texttable()
        my_table.set_precision(6)
        header = ['Node', 'Probability', 'Classification']
        list_rows = list()
        list_rows.append(header)
        for key, val in color_nodes.iteritems():
            for nodeid, prob in val:
                name = data_manager.idx_to_node_name[nodeid]
                list_rows.append([name, prob, node_qual[key]])

        my_table.add_rows(list_rows)
        print my_table.draw()
Example #24
0
def eval_dir(path, markdown=False, dprefix=False,
             evalmethod=None, numlabel=False):
    """ Evaluate the results in the dir by MRR

        Argument:
            dirname -- the path to the diretory containing evaluation results
    """
    if evalmethod is None:
        ef = mrr
    else:
        ef = globals()[evalmethod]
    files = sorted(os.listdir(path))
    names = sorted(set([n.rsplit('.', 1)[0][3:] for n in files
                        if n.endswith('.res')]),
                   key=lambda item: (len(item), item))
    if dprefix:
        prefices = sorted(set([n[:2] for n in files]))
    else:
        prefices = PREFICES
    table = Texttable(max_width=0)
    if markdown:
        table.set_asmarkdown()
    else:
        table.set_deco(0)
    table.set_cols_dtype(['t'] + ['f'] * len(prefices))
    table.set_cols_align(['l'] + ['r'] * len(prefices))
    table.set_precision(4)
    table.add_rows([['', ] + prefices])
    for n in names:
        scores = list()
        for prefix in prefices:
            try:
                eva = NP.array([v for v in iterrank(
                    os.path.join(path, '%s_%s.res' % (prefix, n)))],
                    dtype=NP.float64)
                scores.append(ef(eva))
            except IOError:
                scores.append('N/A')
        if numlabel:
            n = ' '.join([m.group() for m in NUMBER.finditer(n)])
        table.add_row([n, ] + scores)
    print table.draw()
Example #25
0
def cmd_stats():
    msgs = iterMessages(CONFIG.accounts[0])
    months = {}
    for m in msgs:
        month = months.get(m.month(), [])
        month.append(m)
        months[m.month()] = month

    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_dtype(['t', 'i', 'f', 'f', 'f', 'f'])
    table.set_cols_align(['l', 'r', 'r', 'r', 'r', 'r'])
    table.set_precision(1)
    table.add_row(['month', 'count', 'min', 'max', 'median', 'mean'])
    for month in sorted(months.keys()):
        msgs = months[month]
        count, minval, maxval, med, avg = stats(msgs)
        table.add_row([month, count, minval, maxval, med, avg])

    info('monthly spam score stats on %s\n%s' % (ARGS.mailbox, table.draw()))
Example #26
0
def print_config(filename, default=None, mode="json"):
    if mode == "json":
        print("reading config file:", filename)
        with open(filename, "r") as f:
            config = json.load(f)
        table = Texttable()
        table.set_precision(6)
        table.set_deco(Texttable.BORDER | Texttable.VLINES | Texttable.HEADER)

        # for general infomation
        table.set_cols_dtype(['a', 'a'])
        table.set_cols_align(['c', 'c'])
        table.add_rows([["key", "value"]])
        for name_idx, name in enumerate(config.keys()):
            if name == "data info":
                continue
            table.add_row([name, config[name]])
        print(table.draw())

        # for data info
        if "data info" in config.keys():
            data_info = config["data info"]
            table = Texttable()
            table.set_deco(Texttable.BORDER | Texttable.VLINES
                           | Texttable.HEADER)
            table.set_cols_dtype(['t', 't', 'a', "a", "a", "a"])
            table.set_cols_align(['c', 'c', 'c', 'c', 'c', 'c'])
            table.add_rows(
                [["name", "format", "number", "dim", "active", "default"]])
            for item in data_info:
                if default is not None:
                    item["default"] = (default and item["default"])
                table.add_row([
                    item["name"], item["format"], item["num"], item["dim"],
                    item["active"], item["default"]
                ])
            print(table.draw())
            return config, data_info
        else:
            return config
    return -1
Example #27
0
def print_scenarios_probability(scenarios_container,
                                data_manager,
                                limit=20,
                                sorted=True,
                                confidence=1.0):
    my_table = Texttable()
    my_table.set_precision(6)
    #print "\nNUMBER OF SCENARIOS", len(scenarios_container)
    probabilities = [s.probability for s in scenarios_container]
    if sorted:
        scenario_ids = get_sorted_ids(scenarios_container)
    else:
        scenario_ids = range(len(scenarios_container))

    header = [
        'HID', 'SOURCE', 'START (min)', 'STOP (min)', 'PROBABILITY', 'MATCHES'
    ]
    list_rows = list()
    list_rows.append(header)
    accum = 0.0
    for j, scenario_id in enumerate(scenario_ids):
        if j < limit:
            scenario = scenarios_container[scenario_id]
            source = data_manager.idx_to_node_name[scenario.injection.source]
            hid = scenario.hid
            n_matches = scenario.matches
            n_unmatches = scenario.miss_matches
            probability = scenario.probability
            inj_start = int(scenario._injection.start_sec / 60)
            inj_end = int(scenario._injection.end_sec / 60)
            list_rows.append(
                [hid, source, inj_start, inj_end, probability, n_matches])
            accum += probability
            if sorted and accum > confidence:
                break
        else:
            break
    my_table.add_rows(list_rows)
    print my_table.draw()
Example #28
0
def print_evaluation(topk_list, recalls=None, ndcgs=None):
    n_cols = len(topk_list)
    cols_align = ["c"] + ["r"] * n_cols
    cols_name = ["dataset"]
    for k in topk_list:
        cols_name.append("@{}".format(k))
    if len(recalls) < 2 * n_cols:
        recalls + [0] * (2 * n_cols - len(recalls))
    if len(ndcgs) < 2 * n_cols:
        ndcgs + [0] * (2 * n_cols - len(ndcgs))
    table = Texttable(0)
    table.set_precision(6)
    table.set_deco(Texttable.HEADER | Texttable.BORDER)
    table.set_cols_align(cols_align)
    table.add_rows([
        cols_name,
        ["val_recall"] + recalls[:n_cols],
        ["test_recall"] + recalls[n_cols:],
        ["val_ncdg"] + ndcgs[:n_cols],  # update at 2018/4/15/14:49
        ["test_ncdg"] + ndcgs[n_cols:]
    ])
    print(table.draw())
    return table.draw()
Example #29
0
    def __init__(self):
        '''Shows a table in console with the output of relatives sizes ranges

        '''
        calculate = Calculate()
        values = calculate.get_relative_size_ranges()
        table = Texttable()
        table.set_cols_align(["l", "l", "l","l", "l", "l"])
        table.set_cols_valign(["m", "m", "m","m", "m", "m"])
        table.set_cols_dtype(['t', 'f', 'f', 'f', 'f','f'])
        table.set_precision(4)
        head = ['',
            color(bcolors.GREEN,"VS"),
            color(bcolors.GREEN,"S"),
            color(bcolors.GREEN,"M"),
            color(bcolors.GREEN,"L"),
            color(bcolors.GREEN,"VL")
        ]
        rows = []
        rows.append(head)
        [rows.append(element) for element in values]
        table.add_rows(rows)
        print(table.draw() + "\n")
Example #30
0
            by_status['none'].append(c)

    offset += per_page

total_monthly_revenue = []

for type, customers in by_status.iteritems():

    print '*' * 80
    print 'Subscriptions: ', type, ' - ', len(customers)
    print '*' * 80
    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_align(['l', 'r', 'l', 'r'])
    table.header(['Customer', 'Plan', 'Coupon', 'Monthly'])
    table.set_precision(2)

    for c in customers:
        row = []
        row.append(c.description or c.email)

        monthly = 0
        if c.subscription:
            amount = '$%d' % (c.subscription.quantity *
                              c.subscription.plan.amount / 100)
            if c.subscription.plan.interval == 'month':
                monthly = c.subscription.quantity * c.subscription.plan.amount
            elif c.subscription.plan.interval == 'year':
                amount += ' ANNUAL'
            else:
                amount += ' %s!!!' % c.subscription.plan.interval
Example #31
0
def main():
    parser = buildArgsParser()
    args = parser.parse_args()

    sort_by = args.sort

    names = []
    results_files = []
    hyperparams_files = []
    status_files = []
    for f in args.results:
        exp_folder = f
        if os.path.isfile(f):
            exp_folder = os.path.dirname(f)

        result_file = pjoin(exp_folder, "result.json")
        hyperparams_file = pjoin(exp_folder, "hyperparams.json")
        status_file = pjoin(exp_folder, "status.json")

        if not os.path.isfile(result_file):
            print 'Skip: {0} is not a file!'.format(result_file)
            continue

        if not os.path.isfile(hyperparams_file):
            print 'Skip: {0} is not a file!'.format(hyperparams_file)
            continue

        if not os.path.isfile(status_file):
            print 'Skip: {0} is not a file!'.format(status_file)
            continue

        name = os.path.basename(exp_folder)
        if 'hyperparams.json' in os.listdir(os.path.abspath(pjoin(exp_folder, os.path.pardir))):
            name = os.path.basename(os.path.abspath(pjoin(exp_folder, os.path.pardir)))

        names.append(name)

        results_files.append(result_file)
        hyperparams_files.append(hyperparams_file)
        status_files.append(status_file)

    if len([no for no in sort_by if no == 0]) > 0:
        parser.error('Column ID are starting at 1!')

    # Retrieve headers from hyperparams
    headers_hyperparams = set()
    headers_results = set()
    headers_status = set()

    for hyperparams_file, status_file, results_file in zip(hyperparams_files, status_files, results_files):
        hyperparams = load_dict_from_json_file(hyperparams_file)
        results = load_dict_from_json_file(results_file)
        status = load_dict_from_json_file(status_file)
        headers_hyperparams |= set(hyperparams.keys())
        headers_results |= set(results.keys())
        headers_status |= set(status.keys())

    headers_hyperparams = sorted(list(headers_hyperparams))
    headers_status = sorted(list(headers_status))
    # TODO: when generating result.json split 'trainset' scores in two key:
    #       'trainset' and 'trainset_std' (same goes for validset and testset).
    headers_results |= set(["trainset_std", "validset_std", "testset_std"])
    headers_results = sorted(list(headers_results))
    headers = headers_hyperparams + headers_status + ["name"] + headers_results

    # Build results table
    table = Texttable(max_width=0)
    table.set_deco(Texttable.HEADER)
    table.set_precision(8)
    table.set_cols_dtype(['a'] * len(headers))
    table.set_cols_align(['c'] * len(headers))

    # Headers
    table.header([str(i) + "\n" + h for i, h in enumerate(headers, start=1)])

    if args.only_header:
        print table.draw()
        return

    # Results
    for name, hyperparams_file, status_file, results_file in zip(names, hyperparams_files, status_files, results_files):
        hyperparams = load_dict_from_json_file(hyperparams_file)
        results = load_dict_from_json_file(results_file)
        status = load_dict_from_json_file(status_file)

        # Build results table row (hyperparams columns)
        row = []
        for h in headers_hyperparams:
            value = hyperparams.get(h, '')
            row.append(value)

        for h in headers_status:
            value = status.get(h, '')
            row.append(value)

        row.append(name)

        for h in headers_results:
            if h in ["trainset", "validset", "testset"]:
                value = results.get(h, '')[0]
            elif h in ["trainset_std", "validset_std", "testset_std"]:
                value = results.get(h[:-4], '')[1]
            else:
                value = results.get(h, '')
            row.append(value)

        table.add_row(row)

    # Sort
    for col in reversed(sort_by):
        table._rows = sorted(table._rows, key=sort_nicely(abs(col) - 1), reverse=col < 0)

    if args.out is not None:
        import csv

        results = []
        results.append(headers)
        results.extend(table._rows)

        with open(args.out, 'wb') as csvfile:
            w = csv.writer(csvfile)
            w.writerows(results)

    else:
        print table.draw()
Example #32
0
						counterFF86 = counterFF86 + end - start

					mFF86 = float(counterFF86)/max_times
					so_times.append(mFF86)

					if pcap == pcapAnd:
						aux = ['Android']
						for i in range(0,len(so_times)):
							aux = aux + [so_times[i]]
						t_data.append(aux)
					if pcap == pcapIph:
						aux = ['iPhone']
						for i in range(0,len(so_times)):
							aux = aux+[so_times[i]]
						t_data.append(aux)
					if pcap == pcapWP:
						aux = ['WindowsPhone']
						for i in range(0,len(so_times)):
							aux = aux+[so_times[i]]
						t_data.append(aux)

					####Decode the following packet        

					(hdr, data) = pcap.next()
				except pcapy.PcapError as pcap_error:
					(hdr, data) = (None, None)
		t.set_precision(6)
		t.add_rows(t_data)
		print t.draw()
	except IOError as err:
		print('File error: '+str(err))
Example #33
0
def main():
    # create command-line argument parser object
    parser = argparse.ArgumentParser(description="Execute the prescribed iterative methods")

    # add accepted positional arguments
    parser.add_argument("methods",
                        nargs='*', type=str, default='bisection',
                        choices=['bisection','halley','newton','secant','secant_swap','steffenson'],
                        help="Iterative methods to run")

    # add accepted optional arguments
    parser.add_argument("-c", "--csv",
                        metavar='CSVFILE', nargs=1, type=str,
                        default=None,
                        help="Output iterations to CSV file.")
    parser.add_argument("-f", "--func_vals", action='store_true',
                        help="Show function values for the iterates of each methods")
    parser.add_argument("-v", "--verbosity", action='count',
                        help="Increase output verbosity")

    # parse arguments
    args = parser.parse_args()

    # method parameters
    f = lambda x: x**2-20.0
    fp = lambda x: 2.0*x
    M = 1000
    a = 3
    b = 3.5
    x_0 = 3.0
    x_1 = 5.0
    eps = 0.0001
    delta = 0.0001

    #f = lambda x: 0.0005*exp(x) + tan(x) - cos(x**2-2.0)
    #fp = lambda x: 0.0005*exp(x) + 1.0/(cos(sqrt(x))**2) + 2.0*x*sin(x**2-2.0)
    #M = 1000
    #a = 3
    #b = 3.5
    #x_0 = 3.0
    #x_1 = 5.0
    #eps = 0.0001
    #delta = 0.0001

    #f = lambda x: (4.4*x**5 - exp(cos(x - 5.0)))/sqrt(5.0*pi*x)
    #fp = lambda x: (0.126257*exp(cos(5.0-x)-0.252313*x*sin(5.0-x)*exp(cos(5.0-x))+4.9958*x**5)/(x**(3.0/2.0)))
    #fpp = lambda x: 2.0
    #M = 1000
    #a = 0.1
    #b = 5.0
    #x_0 = 0.1
    #x_1 = 1.0
    #eps = 0.0001
    #delta = 0.0001

    #f = lambda x: (x*(x*(x*(x*(x+200)+275)+312)+380)+400)-1750
    #M = 1000
    #x_0 = 0.0
    #x_1 = 1.0
    #eps = 0.0001
    #delta = 0.0001

    # list of lists of iterates produced by the methods
    iterates = [ ]

    # texttable attributes
    header = [ 'Iteration' ]

    if 'bisection' in args.methods:
        a_n, b_n = rm.bisection_method(M,eps,delta,f,a,b)

        if args.verbosity >= 1:
            print "Bisection method:"
            print "\tNumber of iterations: " + str(len(a_n))
            print "\ta_"+str(len(a_n)-1)+"= "+str(a_n[-1])
            print "\tb_"+str(len(b_n)-1)+"= "+str(b_n[-1])
            print "\tf(a_"+str(len(a_n)-1)+") = "+str(f(a_n[-1]))
            print "\tf(b_"+str(len(a_n)-1)+") = "+str(f(b_n[-1]))

        iterates.append(a_n)
        iterates.append(b_n)
        header.append('Bisection: a_n')
        header.append('Bisection: b_n')
        
        if args.func_vals:
            # TODO: fix method to store lists of function values
            pass 
    #        iterates.append(fa_n)
    #        iterates.append(fb_n)
    #        header.append('Bisection: f(a_n)')
    #        header.append('Bisection: f(b_n)')

    if 'newton' in args.methods:
        x_n, f_n = rm.newtons_method(M,eps,delta,f,fp,x_0)

        if args.verbosity >= 1:
            print "\nNewton's method:"
            print "\tNumber of iterations: " + str(len(x_n))
            print "\tx_"+str(len(x_n)-1)+" = "+str(x_n[-1])
            print "\tf(x_"+str(len(f_n)-1)+") = "+str(f_n[-1])
        
        iterates.append(x_n)
        header.append("Newton's: x_n")
        
        if args.func_vals:    
            iterates.append(f_n)
            header.append("Newton's: f(x_n)")

    if 'halley' in args.methods:
        x_n, f_n = rm.halleys_method(M,eps,delta,f,fp,fpp,x_0)

        if args.verbosity >= 1:
            print "\nHalley's method:"
            print "\tNumber of iterations: " + str(len(x_n))
            print "\tx_"+str(len(x_n)-1)+" = "+str(x_n[-1])
            print "\tf(x_"+str(len(f_n)-1)+") = "+str(f_n[-1])
        
        iterates.append(x_n)
        header.append("Halley's: x_n")
        
        if args.func_vals:    
            iterates.append(f_n)
            header.append("Halley's: f(x_n)")

    if 'steffenson' in args.methods:
        x_n, f_n = rm.steffensons_method(M,eps,delta,f,x_0)

        if args.verbosity >= 1:
            print "\nSteffenson's method:"
            print "\tNumber of iterations: " + str(len(x_n))
            print "\tx_"+str(len(x_n)-1)+" = "+str(x_n[-1])
            print "\tf(x_"+str(len(f_n)-1)+") = "+str(f_n[-1])
        
        iterates.append(x_n)
        header.append("Steffenson's: x_n")
        
        if args.func_vals:    
            iterates.append(f_n)
            header.append("Steffenson's: f(x_n)")

    if 'secant' in args.methods:
        x_n, f_n = rm.secant_method(M,eps,delta,f,x_0,x_1)

        if args.verbosity >= 1:
            print "\nSecant method:"
            print "\tNumber of iterations: " + str(len(x_n))
            print "\tx_"+str(len(x_n)-1)+" = "+str(x_n[-1])
            print "\tf(x_"+str(len(f_n)-1)+") = "+str(f_n[-1])
        
        iterates.append(x_n)
        header.append('Secant: x_n')
        
        if args.func_vals:    
            iterates.append(f_n)
            header.append('Secant: f(x_n)')
        
    if 'secant_swap' in args.methods:
        x_n, f_n = rm.secant_method_swap(M,eps,delta,f,x_0,x_1)

        if args.verbosity >= 1:
            print "\nSecant method (swap):"
            print "\tNumber of iterations: " + str(len(x_n))
            print "\tx_"+str(len(x_n)-1)+" = "+str(x_n[-1])
            print "\tf(x_"+str(len(f_n)-1)+") = "+str(f_n[-1])
        
        iterates.append(x_n)
        header.append('Secant swap: x_n')

        if args.func_vals:    
            iterates.append(f_n)
            header.append('Secant swap: f(x_n)')

    # create a texttable and add the records
    table = Texttable()
    # set the table style
    table.set_deco(Texttable.HEADER)
    # set precision of floating point data type
    table.set_precision(7)
    # set column data types in table
    table.set_cols_dtype(['i']+['f' for i in iterates])
    # set the table column alignment
    table.set_cols_align(['r']+['r' for i in iterates])
    # add table column headers
    table.header(header)

    # add the records to the table
    i = 0
    for ROW in izip_longest(*iterates):
        table.add_row([i]+list(ROW))
        i=i+1

    # draw table
    print table.draw()

    if args.csv != None:
        # create CSV writer
        with open(args.csv, 'wb') as csvfile:
            writer = csv.writer(csvfile, delimiter=',',
                quotechar='|', quoting=csv.QUOTE_MINIMAL)
            writer.writerow(header)
            for RECORD in records:
                writer.writerow(RECORD)
Example #34
0
    offset += per_page


total_monthly_revenue = []

for type, customers in by_status.iteritems():

    print '*' * 80
    print 'Subscriptions: ', type, ' - ', len(customers)
    print '*' * 80
    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_align(['l', 'r', 'l', 'r'])
    table.header(['Customer', 'Plan', 'Coupon', 'Monthly'])
    table.set_precision(2)

    for c in customers:
        row = []
        row.append(c.description or c.email)

        monthly = 0
        if c.subscription:
            amount = '$%d' % (c.subscription.quantity * c.subscription.plan.amount / 100)
            if c.subscription.plan.interval == 'month':
                monthly = c.subscription.quantity * c.subscription.plan.amount
            elif c.subscription.plan.interval == 'year':
                if c.subscription.status == 'active':
                    monthly = c.subscription.quantity * c.subscription.plan.amount / 12
                amount += ' ANNUAL'
            else:
Example #35
0
File: main.py Project: denself/meo
        names.append(name)
        params = [float(i) for i in row[1:]]
        matrix.append(params)

n = len(matrix)
results_matrix = [[0]*n for i in range(n)]

for j in range(n-1):
    for i in range(j+1, n):
        row1 = matrix[i]
        row2 = matrix[j]
        score = [0, 0]
        for func in lpr:
            score[func([row1, row2])[2]] += 1
        if score[0] != score[1]:
            bigger = (i, j)[score.index(max(score))]
            smaller = (i, j)[score.index(min(score))]
            results_matrix[smaller][bigger] = 1

table = Texttable(max_width=150)
table.set_deco(Texttable.HEADER)
table.set_precision(1)
table.add_rows([['']+names])
for i in range(n):
    table.add_rows([[names[i]]+results_matrix[i]], header=False)
print table.draw()

print 'Best solutions:',
for i in range(n):
    if max(zip(*results_matrix)[i]) == 0:
        print names[i],