Пример #1
0
    def test_unused_converter(self):
        assert_equal(True, False)
        c = StringIO()
        c.writelines(['1 21\n', '3 42\n'])
        c.seek(0)
        data = iopro.loadtxt(c, usecols=(1,),
                          converters={0: lambda s: int(s, 16)})
        assert_array_equal(data, [21, 42])

        c.seek(0)
        data = iopro.loadtxt(c, usecols=(1,),
                          converters={1: lambda s: int(s, 16)})
        assert_array_equal(data, [33, 66])
Пример #2
0
    def get(self, handler, *args, **kwargs):
        f = StringIO()
        for timestamp, predictions in handler.server.server.events_queue:
            data = {
                'timestamp': '{:%Y-%m-%d %H:%M:%S}'.format(timestamp),
                'predictions': predictions
            }
            f.writelines(self.render_template('event.html', **data))

        response = f.getvalue()
        f.close()

        handler.send_response(http_client.OK)
        handler.send_header('Content-type', 'text/html')
        handler.end_headers()
        handler.wfile.write(response.encode())
Пример #3
0
 def _test_bdf_slash(self):
     """tests a / in a deck"""
     lines = [
         '$ DEC/CMS REPLACEMENT HISTORY, Element D10912R.DAT',
         '$ *1    15-JUN-1990 17:41:35 CMSMGR "66B PLUS/G 66B/ Initial installation of TPL test problems"',
         '$ DEC/CMS REPLACEMENT HISTORY, Element D10912R.DAT',
         'RESTART VERSION=LAST,KEEP $ RESTART FROM D10911R DBS=D10911D',
         'ID EDS, D10912R  $',
         '$ID EDS, D2712R   $',
         '$ID EDS,D27D12R',
         'SOL 109 $',
         '$SOL 27,0',
         '$DIAG 8,14',
         'TIME 5',
         '$READ 10 $ D27D11',
         'CEND',
         'TITLE=NEW RIGID FORMATS - CANTILEVER BEAM                      D10912R',
         'SUBTITLE=DIRECT TRANSIENT',
         'SET 1000=10,30,40',
         'SET 2000=111,200',
         'METHOD=1',
         'DISP(SORT2)=2000',
         'SPC=200',
         'MPC=100',
         'TSTEP=100',
         'FORCE=1000',
         'SUBCASE 1',
         'DLOAD=10',
         'BEGIN BULK',
         '/       47',
         'TLOAD1,10,2,0,0,10',
         'ENDDATA',
     ]
     bdf_file = StringIO()
     bdf_file.writelines(lines)
     bdf_file.seek(0)
     #with self.assertRaises(NotImplementedError):
     unused_model = read_bdf(bdf_file,
                             validate=True,
                             xref=True,
                             punch=False,
                             skip_cards=None,
                             read_cards=None,
                             encoding=None,
                             log=None,
                             debug=True,
                             mode='msc')
Пример #4
0
 def render(self, mode='human'):
     out = []
     # output current play chart
     border = '+--' * 5 + '+\n'
     outfile = StringIO() if mode == 'ansi' else sys.stdout
     matrix = np.reshape(self.state[:-1], (5, 5))
     for row in matrix:
         out.append(border)
         line = '|'.join(
             ['{0:>2}'.format(col + 1) if col else '  ' for col in row])
         line = '|' + line + '|\n'
         out.append(line)
     out.append(border)
     # output next dice result if not done yet
     if not self.done:
         out.append(
             f'next dice: {self.d1}+{self.d2}={self.state[25] + 1}\n')
     out.append('\n\n')
     outfile.writelines(out)
Пример #5
0
    def test_split_cbars_by_pin_flag_2(self):
        """real pin flag test"""
        lines = [
            'SOL 101\n',
            'CEND\n',
            'SUBCASE 10\n',
            '    LOAD = 10\n',
            '    SPC = 123456\n',
            '    DISP(PLOT) = ALL\n',
            '    STRESS(PLOT) = ALL\n',
            'BEGIN BULK\n',
            'ENDDATA',
        ]
        model = BDF(debug=False)
        with self.assertRaises(NotImplementedError):
            model.read_bdf(bdf_filename=lines,
                           validate=True,
                           xref=True,
                           punch=False,
                           read_includes=True,
                           encoding=None)

        model.add_grid(1, [0., 0., 0.])
        model.add_grid(2, [1., 0., 0.])
        model.add_grid(3, [2., 0., 0.])
        model.add_grid(4, [3., 0., 0.])

        pid = 1000
        mid = 1000
        Type = 'BAR'
        dim = [1., 2.]
        model.add_pbarl(pid, mid, Type, dim)
        E = 3.0e7
        G = 3.0e6
        nu = None
        model.add_mat1(mid, E, G, nu)

        x = [0., 1., 0.]
        g0 = None
        model.add_cbar(1,
                       pid, [1, 2],
                       x,
                       g0,
                       offt='GGG',
                       pa=0,
                       pb=0,
                       wa=None,
                       wb=None,
                       comment='reaction')
        model.add_cbar(2,
                       pid, [2, 3],
                       x,
                       g0,
                       offt='GGG',
                       pa=0,
                       pb=456,
                       wa=None,
                       wb=None,
                       comment='End B')
        model.add_cbar(3,
                       pid, [3, 4],
                       x,
                       g0,
                       offt='GGG',
                       pa=456,
                       pb=0,
                       wa=None,
                       wb=None,
                       comment='End A')
        sid = 10
        node = 4
        mag = 1.
        xyz = [1., 1., 0.]
        model.add_force(sid, node, mag, xyz)
        model.add_spc1(123456, '123456', 1)
        model.validate()

        bdf_file = StringIO()
        bdf_file.writelines(lines)
        bdf_file.seek(0)
        model.read_bdf(bdf_filename=bdf_file,
                       validate=True,
                       xref=False,
                       punch=False,
                       read_includes=True,
                       encoding=None)
        #model.write_bdf('spike.bdf')

        split_cbars_by_pin_flag(model,
                                pin_flags_filename='pin_flags.csv',
                                bdf_filename_out='pin_flags.bdf',
                                debug=False)
        os.remove('pin_flags.csv')
        os.remove('pin_flags.bdf')