示例#1
0
def test_vertical_ascii():
    numpy.random.seed(123)
    sample = numpy.random.normal(size=1000)
    counts, bin_edges = numpy.histogram(sample, bins=40)
    fig = apl.figure()
    fig.hist(counts, bin_edges, force_ascii=True)
    # fig.show()

    string = fig.get_string()

    assert (
        string
        == """\
                  **
                ****
               ******
              ********  *
            * ***********
           ***************
          ******************
        **********************
      ************************
* ***********************************  *\
"""
    )
    return
示例#2
0
    def isLogged(self):
        # TODO: Check for something else , This is just for the
        # time beign.
        try:
            WebDriverWait(self._mDriver,
                          WEBDRIVER_SETTINGS['TimeToWait']).until(
                              EC.presence_of_element_located((By.ID, "page")))
            el = self._mDriver.find_element_by_id("page")
        except:
            return False

        try:
            soup = BeautifulSoup(
                self._mDriver.find_element_by_id("resulttable").get_attribute(
                    "outerHTML"), 'html.parser')
            data = [[[
                td.string.strip() for td in tr.find_all('td') if td.string
            ] for tr in table.find_all('tr')[1:]]
                    for table in soup.find_all('table')]

            LogINFO("showing student information... ")
            fig = apl.figure()
            fig.table(data)
            fig.show()
        except:
            return False

        return True
示例#3
0
def test_vertical():
    numpy.random.seed(123)
    sample = numpy.random.normal(size=1000)
    counts, bin_edges = numpy.histogram(sample, bins=40)
    fig = apl.figure()
    fig.hist(counts, bin_edges)
    fig.show()

    string = fig.get_string()

    assert (
        string
        == """\
                  ▆█
                ▄▄██
               ▃█████
              ▁██████▃  ▅
            ▂ ████████▇▅█
           ▂█▅████████████
          ▂███████████████▃▂
        ▂▃██████████████████▃▁
      ▁▂██████████████████████
▂ ▃▂▄▄█████████████████████████▅▃▁▂▁▁  ▁\
"""
    )
    return
示例#4
0
def test_horizontal():
    numpy.random.seed(123)
    sample = numpy.random.normal(size=1000)
    counts, bin_edges = numpy.histogram(sample)
    fig = apl.figure()
    fig.hist(counts, bin_edges, orientation="horizontal")
    # fig.show()
    string = fig.get_string()

    assert (
        string
        == """\
-3.23e+00 - -2.55e+00  [  7]  █
-2.55e+00 - -1.87e+00  [ 27]  ███▊
-1.87e+00 - -1.19e+00  [ 95]  █████████████▎
-1.19e+00 - -5.10e-01  [183]  █████████████████████████▋
-5.10e-01 - +1.70e-01  [286]  ████████████████████████████████████████
+1.70e-01 - +8.51e-01  [202]  ████████████████████████████▎
+8.51e-01 - +1.53e+00  [142]  ███████████████████▉
+1.53e+00 - +2.21e+00  [ 49]  ██████▉
+2.21e+00 - +2.89e+00  [  7]  █
+2.89e+00 - +3.57e+00  [  2]  ▎\
"""
    )
    return
    def iap(self):
        '''
        Inject and plot to terminal with ascii
        This is useful for debugging new backends, in bash big/fast command line orientated optimization routines.
        '''

        model = self.dtc_to_model()
        #new_tests['RheobaseTest']
        if type(self.tests) is type({'1':1}):
            if 'RheobaseTest' in self.tests.keys():
                uset_t = self.tests['RheobaseTest']
            else:
                uset_t = self.tests['RheobaseTestP']

        elif type(self.tests) is type(list):
            for t in self.tests:
                if t.name in str('RheobaseTest'):
                    uset_t = t
                    break

        pms = uset_t.params
        pms['injected_square_current']['amplitude'] = self.rheobase
        model.inject_square_current(pms['injected_square_current'])
        nspike = model.get_spike_train()
        vm = model.get_membrane_potential()
        t = [float(f) for f in vm.times]
        v = [float(f) for f in vm.magnitude]
        try:
            fig = apl.figure()
            fig.plot(t, v, label=str('observation waveform from inside dtc: ')+str(nspike), width=100, height=20)
            fig.show()
        except:
            import warnings
            print('ascii plot not installed')
        return vm
示例#6
0
def main():
    cols, rows = shutil.get_terminal_size((80, 20))
    y = [float(l) for l in sys.stdin.readlines()]
    x = list((range(1, len(y) + 1)))
    fig = apl.figure()
    fig.plot(x, y, width=cols, height=rows)
    fig.show()
示例#7
0
def test_plot_lim():
    x = numpy.linspace(0, 2 * numpy.pi, 10)
    y = numpy.sin(x)

    fig = apl.figure()
    fig.plot(
        x,
        y,
        label="data",
        width=50,
        height=15,
        xlim=[-1, 1],
        ylim=[-1, 1],
        xlabel="x vals",
        title="header",
    )
    string = fig.get_string()

    ref = """                       header

    1 +---------------------------------------+
      |                               ********|
  0.5 |                          ************ |
      |                      ****             |
    0 |                   ***                 |
      |                                       |
 -0.5 |                                       |
      |                                       |
   -1 +---------------------------------------+
     -1       -0.5        0        0.5        1
                       x vals"""

    assert string == ref
    return
示例#8
0
def test_padding_2():
    fig = apl.figure(padding=(1, 2))
    fig.aprint("abc")
    string = fig.get_string()
    assert (string == """
  abc
""")
    return
示例#9
0
 def preview_plot(self):
     x = []
     y = []
     for count, event in enumerate(self.last_values):
         x.append(float(count))
         y.append(float(event[1][0]))
     fig = apl.figure()
     fig.plot(x, y, label="ch0", width=25, height=6)
     fig.show()
示例#10
0
def test_padding_4():
    fig = apl.figure(padding=(1, 2, 3, 4))
    fig.aprint("abc")
    string = fig.get_string()
    assert (string == """
    abc


""")
    fig.show()
    return
    def plot_obs(self,ow):
        '''
        assuming a waveform exists (observed waved-form) plot to terminal with ascii
        This is useful for debugging new backends, in bash big/fast command line orientated optimization routines.
        '''

        t = [float(f) for f in ow.times]
        v = [float(f) for f in ow.magnitude]
        fig = apl.figure()
        fig.plot(t, v, label=str('observation waveform from inside dtc: '), width=100, height=20)
        fig.show()
示例#12
0
def createPlot(topW, numberWords):

    labels = []
    numbers = []
    for l, n in topW:
        labels.append(l)
        numbers.append(n)

    print('\n[TOP ' + str(numberWords) + ' WORDS IN BILL]\n')
    fig = apl.figure()
    fig.barh(numbers, labels, force_ascii=True)
    fig.show()
示例#13
0
def plot_to_notebook(time_sec, in_signal, n_samples, out_signal=None):
    fig = apl.figure()
    fig.plot(time_sec[:n_samples] * 1e6,
             in_signal[:n_samples],
             label='Input signal',
             width=150,
             height=45)
    if out_signal is not None:
        fig.plot(time_sec[:n_samples] * 1e6,
                 out_signal[:n_samples],
                 label='FIR output',
                 width=150,
                 height=45)
    fig.show()
示例#14
0
def hbar(h1, width=80, show_values=False):
    if ENABLE_ASCIIPLOTLIB:
        data = h1.frequencies
        edges = h1.numpy_bins
        fig = asciiplotlib.figure()
        fig.hist(data, edges, orientation="horizontal")
        fig.show()
    else:
        data = (h1.normalize().frequencies * width).round().astype(int)
        for i in range(h1.bin_count):
            if show_values:
                print("#" * data[i], h1.frequencies[i])
            else:
                print("#" * data[i])
示例#15
0
def test_noborder():
    numpy.random.seed(0)
    data = [
        [["a", "bb", "ccc"]],
        [[1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]],
    ]

    fig = apl.figure()
    fig.table(data, border_style=None, padding=0)
    string = fig.get_string()

    assert (string == """a              bb             ccc
1              2              3
613.23236243236613.23236243236613.23236243236""")
    return
示例#16
0
def test_table_alignment():
    numpy.random.seed(0)
    data = [[1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]]

    fig = apl.figure()
    fig.table(data, force_ascii=True, alignment="lcr")
    string = fig.get_string()

    assert (
        string == """+-----------------+-----------------+-----------------+
| 1               |        2        |               3 |
+-----------------+-----------------+-----------------+
| 613.23236243236 | 613.23236243236 | 613.23236243236 |
+-----------------+-----------------+-----------------+""")
    return
示例#17
0
def test_table_mixed():
    numpy.random.seed(0)
    data = [[0, 0.123], [1, 2.13], [2, 613.2323]]

    fig = apl.figure()
    fig.table(data, border_style="thin", force_ascii=True)
    string = fig.get_string()

    assert (string == """+---+----------+
| 0 | 0.123    |
+---+----------+
| 1 | 2.13     |
+---+----------+
| 2 | 613.2323 |
+---+----------+""")
    return
示例#18
0
def test_barh_ascii():
    fig = apl.figure()
    fig.barh([3, 10, 5, 2], ["Cats", "Dogs", "Cows", "Geese"], force_ascii=True)
    # fig.show()
    string = fig.get_string()

    assert (
        string
        == """\
Cats   [ 3]  ************
Dogs   [10]  ****************************************
Cows   [ 5]  ********************
Geese  [ 2]  ********\
"""
    )
    return
示例#19
0
def plot_entropy(binary_file_path: str):
    entropy_per_buffer, buffer_chunk_size = binary_entropy(binary_file_path)

    average_entropy = sum(entropy_per_buffer) / len(entropy_per_buffer)
    if average_entropy >= 0.8:
        average_entropy = f_red(average_entropy)
    else:
        average_entropy = f_green(average_entropy)
    print('Average entropy: {}'.format(average_entropy))

    fig = apl.figure()
    x = np.linspace(0,
                    len(entropy_per_buffer) * buffer_chunk_size,
                    len(entropy_per_buffer))
    fig.plot(x, entropy_per_buffer, label="Entropy(E)", width=200, height=30)
    fig.show()
示例#20
0
def test_barh():
    fig = apl.figure()
    fig.barh([3, 10, 5, 2], ["Cats", "Dogs", "Cows", "Geese"])
    # fig.show()
    string = fig.get_string()

    assert (
        string
        == """\
Cats   [ 3]  ████████████
Dogs   [10]  ████████████████████████████████████████
Cows   [ 5]  ████████████████████
Geese  [ 2]  ████████\
"""
    )
    return
示例#21
0
def test_header():
    data = [
        [["a", "bb", "ccc"]],
        [[1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]],
    ]

    fig = apl.figure()
    fig.table(data, alignment="lcr")
    string = fig.get_string()

    assert (
        string == """┌─────────────────┬─────────────────┬─────────────────┐
│ a               │       bb        │             ccc │
╞═════════════════╪═════════════════╪═════════════════╡
│ 1               │        2        │               3 │
├─────────────────┼─────────────────┼─────────────────┤
│ 613.23236243236 │ 613.23236243236 │ 613.23236243236 │
└─────────────────┴─────────────────┴─────────────────┘""")
    return
示例#22
0
def test_table_double():
    numpy.random.seed(0)
    data = numpy.random.rand(5, 2)

    fig = apl.figure()
    fig.table(data, border_style="double")
    string = fig.get_string()

    assert (string == """╔════════════════════╦════════════════════╗
║ 0.5488135039273248 ║ 0.7151893663724195 ║
╠════════════════════╬════════════════════╣
║ 0.6027633760716439 ║ 0.5448831829968969 ║
╠════════════════════╬════════════════════╣
║ 0.4236547993389047 ║ 0.6458941130666561 ║
╠════════════════════╬════════════════════╣
║ 0.4375872112626925 ║ 0.8917730007820798 ║
╠════════════════════╬════════════════════╣
║ 0.9636627605010293 ║ 0.3834415188257777 ║
╚════════════════════╩════════════════════╝""")
    return
示例#23
0
def test_table():
    numpy.random.seed(0)
    data = numpy.random.rand(5, 2)

    fig = apl.figure()
    fig.table(data)
    string = fig.get_string()

    assert (string == """┌────────────────────┬────────────────────┐
│ 0.5488135039273248 │ 0.7151893663724195 │
├────────────────────┼────────────────────┤
│ 0.6027633760716439 │ 0.5448831829968969 │
├────────────────────┼────────────────────┤
│ 0.4236547993389047 │ 0.6458941130666561 │
├────────────────────┼────────────────────┤
│ 0.4375872112626925 │ 0.8917730007820798 │
├────────────────────┼────────────────────┤
│ 0.9636627605010293 │ 0.3834415188257777 │
└────────────────────┴────────────────────┘""")
    return
示例#24
0
def test_header_ascii():
    numpy.random.seed(0)
    data = [
        [["a", "bb", "ccc"]],
        [[1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]],
    ]

    fig = apl.figure()
    fig.table(data, force_ascii=True, alignment="lcr")
    string = fig.get_string()

    assert (
        string == """+-----------------+-----------------+-----------------+
| a               |       bb        |             ccc |
+=================+=================+=================+
| 1               |        2        |               3 |
+-----------------+-----------------+-----------------+
| 613.23236243236 | 613.23236243236 | 613.23236243236 |
+-----------------+-----------------+-----------------+""")
    return
示例#25
0
def test_header_thick():
    numpy.random.seed(0)
    data = [
        [["a", "bb", "ccc"]],
        [[1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]],
    ]

    fig = apl.figure()
    fig.table(data, border_style=("thin", "thick"), alignment="lcr")
    string = fig.get_string()

    assert (
        string == """┌─────────────────┬─────────────────┬─────────────────┐
│ a               │       bb        │             ccc │
┝━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━┥
│ 1               │        2        │               3 │
├─────────────────┼─────────────────┼─────────────────┤
│ 613.23236243236 │ 613.23236243236 │ 613.23236243236 │
└─────────────────┴─────────────────┴─────────────────┘""")
    return
示例#26
0
def test_table_ascii():
    numpy.random.seed(0)
    data = numpy.random.rand(5, 2)

    fig = apl.figure()
    fig.table(data, border_style="thin", force_ascii=True)
    string = fig.get_string()

    assert (string == """+--------------------+--------------------+
| 0.5488135039273248 | 0.7151893663724195 |
+--------------------+--------------------+
| 0.6027633760716439 | 0.5448831829968969 |
+--------------------+--------------------+
| 0.4236547993389047 | 0.6458941130666561 |
+--------------------+--------------------+
| 0.4375872112626925 | 0.8917730007820798 |
+--------------------+--------------------+
| 0.9636627605010293 | 0.3834415188257777 |
+--------------------+--------------------+""")
    return
示例#27
0
def test_horizontal_ascii():
    numpy.random.seed(123)
    sample = numpy.random.normal(size=1000)
    counts, bin_edges = numpy.histogram(sample)
    fig = apl.figure()
    fig.hist(counts, bin_edges, orientation="horizontal", force_ascii=True)
    string = fig.get_string()

    assert (string == """\
-3.23e+00 - -2.55e+00  [  7]  *
-2.55e+00 - -1.87e+00  [ 27]  ****
-1.87e+00 - -1.19e+00  [ 95]  **************
-1.19e+00 - -5.10e-01  [183]  **************************
-5.10e-01 - +1.70e-01  [286]  ****************************************
+1.70e-01 - +8.51e-01  [202]  *****************************
+8.51e-01 - +1.53e+00  [142]  ********************
+1.53e+00 - +2.21e+00  [ 49]  *******
+2.21e+00 - +2.89e+00  [  7]  *
+2.89e+00 - +3.57e+00  [  2]  *\
""")
    return
示例#28
0
def test_vertical_strip():
    numpy.random.seed(20)
    sample = numpy.random.normal(size=10000)
    counts, bin_edges = numpy.histogram(sample)
    fig = apl.figure()
    fig.hist(counts, bin_edges, grid=[5, 8], strip=True)
    string = fig.get_string()

    assert (string == """\
   ▉▆
   ▉█
   ▉█
  ▁▉█
  █▉█
  █▉██
  █▉██
 ▁█▉██
 ██▉██▃
▃██▉██▉▂\
""")
    return
示例#29
0
 def callback(stream_id, msg_line):
     fh.write(msg_line + '\n')
     if display == 'log':
         print(msg_line)
     outputlines_list.append(msg_line)
     try:
         msg = json.loads(msg_line)
     except:
         return
     results_kernel_dict = results_dict[kernel][threads]
     if msg['log'] == 'BEST_TIME':
         if bodies not in results_kernel_dict.keys():
             results_kernel_dict[bodies] = msg['value']
         elif results_kernel_dict[bodies] != msg['value']:
             results_kernel_dict[bodies] = msg['value']
         else:
             return
     else:
         return
     if display != 'plot':
         return
     x = sorted(list(results_kernel_dict.keys()))
     y = [results_kernel_dict[n] for n in x]
     t = shutil.get_terminal_size((80, 20))
     fig = apl.figure()
     fig.plot(x,
              y,
              label='{kernel}@{threads}'.format(kernel=kernel,
                                                threads=threads),
              width=t.columns,
              height=t.lines,
              extra_gnuplot_arguments=[
                  'set logscale x 2',
                  'set format y "10^{%L}"',
                  'set logscale y 10',
              ])
     fig.show()
示例#30
0
def print_project_status(details: Dict) -> None:
    formatters = {
        'HEADER': '\033[95m',
        'GREEN': '\033[92m',
        'BOLD': '\033[1m',
        'END': '\033[0m',
    }

    output = """
{BOLD}{HEADER}Status{END}
- {GREEN}phrases{END}: {phrases}
- {GREEN}words{END}: {words}
        """\
        .format(
            phrases=details['phrases'],
            words=details['words'],
            **formatters)

    language_list = list(
        map(
            lambda language: [
                language['code'], "{value} ({progress}%)".format(
                    value=language['translated']['phrases'],
                    progress=language['translated']['progress']),
                "{value} ({progress}%)".format(
                    value=language['approved']['phrases'],
                    progress=language['approved']['progress'])
            ], details['languages']))

    data = [[['languages', 'translated', 'approved']], language_list]

    fig = apl.figure()
    fig.table(data, border_style="thin", padding=(0, 1))

    print(output)
    fig.show()