예제 #1
0
def results(request):
    language = request.POST['language']
    currency = request.POST['currency']
    number = request.POST['number'].strip()

    return render(request, 'converter/index.html',
                  {'engine': Engine(language, currency, number)})
예제 #2
0
def main():
    """Invoke Engine() class by passing in the input filepath and the directory
    will the final output file will be pushed."""
    parser = argparse.ArgumentParser(
        prog='Field Tag Comparator',
        description='Accept input directories for files.')
    parser.add_argument('string1',
                        metavar='input file #1',
                        type=str,
                        help='a file directory for holding the first input')
    parser.add_argument('string2',
                        metavar='input file #2',
                        type=str,
                        help='a file directory for holding the second input')
    args = vars(parser.parse_args())
    file_one = args['string1']
    file_two = args['string2']
    if argument_file_exists([file_one, file_two]):
        compare = Engine(file_one, file_two, r"./outputs/")
        compare.save_output()
예제 #3
0
def init(args):
    """Initialize a new core server. """
    from django.core.management import call_command

    config_text = '''\
    """Online Lab core configuration. """

    import os as _os

    try:
        HOME
    except NameError:
        HOME, _ = _os.path.split(__file__)

    DATABASE_ENGINE    = 'sqlite3'
    DATABASE_NAME      = _os.path.join(HOME, 'onlinelab.db')
    DATABASE_USER      = ''
    DATABASE_PASSWORD  = ''
    DATABASE_HOST      = ''
    DATABASE_PORT      = ''

    SESSION_EXPIRE_AT_BROWSER_CLOSE = False
    '''

    if not os.path.exists(args.home):
        os.makedirs(args.home)

    if args.config_file is not None:
        config_file = args.config_file
    else:
        config_file = os.path.join(args.home, 'settings.py')

    if os.path.exists(config_file) and not args.force:
        print "warning: '%s' exists, use --force to overwrite it" % config_file
    else:
        with open(config_file, 'w') as conf:
            conf.write(textwrap.dedent(config_text))

    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.sessions',
        'django.contrib.contenttypes',
        'onlinelab.core',
    )

    settings = configure(args, installed_apps=INSTALLED_APPS)
    call_command('syncdb', interactive=False)

    from models import Engine

    print "Added default 'Python' engine to the database."
    engine = Engine(name='Python')
    engine.save()

    if not os.path.exists(settings.logs_path):
        os.makedirs(settings.logs_path)

    if not os.path.exists(settings.data_path):
        os.makedirs(settings.data_path)

    if not os.path.exists(settings.static_path):
        os.makedirs(settings.static_path)

    for elem in ['js', 'css', 'img', 'external']:
        static_path_elem = os.path.join(settings.static_path, elem)

        if not os.path.exists(static_path_elem):
            os.makedirs(static_path_elem)

            ui_path_elem = os.path.join(args.ui_path, elem)

            for ui_elem in os.listdir(ui_path_elem):
                dst = os.path.join(static_path_elem, ui_elem)
                src = os.path.join(ui_path_elem, ui_elem)
                os.symlink(src, dst)

    if not os.path.exists(settings.templates_path):
        os.makedirs(settings.templates_path)

        template_ui_path = os.path.join(args.ui_path, 'templates')

        for template_elem in os.listdir(template_ui_path):
            dst = os.path.join(settings.templates_path, template_elem)
            src = os.path.join(template_ui_path, template_elem)
            os.symlink(src, dst)

    print "Done."
def driver(x_1, y_1, z_1, x_2, y_2, z_2, x_3, y_3, z_3, k_x_1, k_y_1, k_z_1,
           k_x_2, k_y_2, k_z_2, k_x_3, k_y_3, k_z_3):
    principal_moments = [4, 10, 8]
    theta = [5, 12.3, -20.7]
    engine = Engine(mass=170, principal_moments=principal_moments, theta=theta)

    mount_1 = Mount(x=x_1,
                    y=y_1,
                    z=z_1,
                    k_x=k_x_1,
                    k_y=k_y_1,
                    k_z=k_z_1,
                    n_x=0.1,
                    n_y=0.1,
                    n_z=0.1)
    k_matrix_1 = mount_1.k_matrix()
    mount_2 = Mount(x=x_2,
                    y=y_2,
                    z=z_2,
                    k_x=k_x_2,
                    k_y=k_y_2,
                    k_z=k_z_2,
                    n_x=0.1,
                    n_y=0.1,
                    n_z=0.1)
    k_matrix_2 = mount_2.k_matrix()
    mount_3 = Mount(x=x_3,
                    y=y_3,
                    z=z_3,
                    k_x=k_x_3,
                    k_y=k_y_3,
                    k_z=k_z_3,
                    n_x=0.1,
                    n_y=0.1,
                    n_z=0.1)
    k_matrix_3 = mount_3.k_matrix()

    objective_function_values = []
    time = 0
    for i in range(0, 20):
        time = time + i * 0.1
        phasor_angle_1 = np.zeros([6, 1])
        phasor_angle_1[2] = -3
        phasor_angle_1[3] = 1.8
        phasor_angle_1[4] = 3.0
        force_phasor_1 = ForcePhasor(angular_frequency=194,
                                     phasor_angle=phasor_angle_1,
                                     f_z=220,
                                     m_x=85,
                                     m_y=3.0)
        force_matrix_1 = force_phasor_1.force_phasor_matrix(time=time)

        phasor_angle_2 = np.zeros([6, 1])
        phasor_angle_2[2] = 0.35
        phasor_angle_2[3] = 1.6
        phasor_angle_2[4] = 3.0
        force_phasor_2 = ForcePhasor(angular_frequency=388,
                                     phasor_angle=phasor_angle_1,
                                     f_z=33,
                                     m_x=44,
                                     m_y=2.9)
        force_matrix_2 = force_phasor_2.force_phasor_matrix(time=time)

        phasor_angle_3 = np.zeros([6, 1])
        phasor_angle_3[3] = 1.5
        force_phasor_3 = ForcePhasor(angular_frequency=582,
                                     phasor_angle=phasor_angle_1,
                                     m_x=15)
        force_matrix_3 = force_phasor_3.force_phasor_matrix(time=time)

        combined_k_matrix = np.concatenate(
            (k_matrix_1, k_matrix_2, k_matrix_3), axis=1)
        combined_force_matrix = np.concatenate(
            (force_matrix_1, force_matrix_2, force_matrix_3), axis=1)
        angular_frequencies = np.array([
            force_phasor_1.angular_frequency, force_phasor_2.angular_frequency,
            force_phasor_3.angular_frequency
        ])

        com_displacement = utils.calculate_center_of_masss_displacement(
            combined_k_matrix=combined_k_matrix,
            mass_matrix=engine.mass_matrix(),
            angular_frequencies=angular_frequencies,
            combined_force_phasors=combined_force_matrix,
            num_phasors=3)

        mount_array = [mount_1, mount_2, mount_3]
        objective_function_values.append(
            utils.calculate_objective_function(
                com_displacement=com_displacement,
                num_mounts=3,
                mounts=mount_array))

    return (-1) * max(objective_function_values)
예제 #5
0
def init(args):
    """Initialize a new core server. """
    from django.core.management import call_command

    config_text = '''\
    """Online Lab core configuration. """

    import os as _os

    try:
        HOME
    except NameError:
        HOME, _ = _os.path.split(__file__)

    DATABASE_ENGINE    = 'sqlite3'
    DATABASE_NAME      = _os.path.join(HOME, 'onlinelab.db')
    DATABASE_USER      = ''
    DATABASE_PASSWORD  = ''
    DATABASE_HOST      = ''
    DATABASE_PORT      = ''

    SESSION_EXPIRE_AT_BROWSER_CLOSE = False
    '''

    if not os.path.exists(args.home):
        os.makedirs(args.home)

    if args.config_file is not None:
        config_file = args.config_file
    else:
        config_file = os.path.join(args.home, 'settings.py')

    if os.path.exists(config_file) and not args.force:
        print "warning: '%s' exists, use --force to overwrite it" % config_file
    else:
        with open(config_file, 'w') as conf:
            conf.write(textwrap.dedent(config_text))

    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.sessions',
        'django.contrib.contenttypes',
        'onlinelab.core',
    )

    settings = configure(args, installed_apps=INSTALLED_APPS)
    call_command('syncdb', interactive=False)

    from models import Engine

    print "Added default 'Python' engine to the database."
    engine = Engine(name='Python')
    engine.save()

    if not os.path.exists(settings.logs_path):
        os.makedirs(settings.logs_path)

    if not os.path.exists(settings.data_path):
        os.makedirs(settings.data_path)

    if not os.path.exists(settings.static_path):
        os.makedirs(settings.static_path)

    for elem in ['js', 'css', 'img', 'external']:
        static_path_elem = os.path.join(settings.static_path, elem)

        if not os.path.exists(static_path_elem):
            os.makedirs(static_path_elem)

            ui_path_elem = os.path.join(args.ui_path, elem)

            for ui_elem in os.listdir(ui_path_elem):
                dst = os.path.join(static_path_elem, ui_elem)
                src = os.path.join(ui_path_elem, ui_elem)
                os.symlink(src, dst)

    if not os.path.exists(settings.templates_path):
        os.makedirs(settings.templates_path)

        template_ui_path = os.path.join(args.ui_path, 'templates')

        for template_elem in os.listdir(template_ui_path):
            dst = os.path.join(settings.templates_path, template_elem)
            src = os.path.join(template_ui_path, template_elem)
            os.symlink(src, dst)

    print "Done."
from TestingUtils import *

if __name__ == '__main__':
    add_source_folder()

    from models.Engine import *
    from common.Timer import *

    def on_tick():
        print 'tick'
    
    def init_audio(event, **kwargs):
        timer = Timer()
        timer.on('tick', on_tick)
        timer.start(engine, 2000, interval=1000)
        
    engine = Engine()
    engine.on("init", init_audio, memory=True)
    engine.start()
    add_resource_folder()
    
    from models.Engine import *
    from models.ImageModels import *

    from ResourceLoader import *

    def on_init(event, **kwargs):
        engine = kwargs['emitter']
        resource = ResourceLoader().load_resource_by_name_and_type('pixelland', 'image')
        print resource
        print resource.type
        print resource.name
        print resource.path
        
        model = SpriteSheetModel(resource)
        print model
        
        view = SpriteSheetView(model)
        print view
        view.scale_x = 2.4
        view.scale_y = 2.4
        
        engine.on('render', view.on_render)

    
    engine = Engine()
    engine.set_caption('Sprite Sheet Testing')
    engine.on('init', on_init, memory=True)
    engine.start()
예제 #8
0
# Importar clases Car y Engine del módulo models
from models import Car, Engine

fiat_multiple = Car("Fiat", "Múltipla", "light grey", 1.2, 55, 900)

print(fiat_multiple.manufacturer + " " + fiat_multiple.model)

engine_gti = Engine("GTI", 2.3, 240)

print(engine_gti.version, engine_gti.cc, engine_gti.cv)
예제 #9
0
def index(request):
    return render(request, 'converter/index.html', {'engine': Engine()})
from TestingUtils import *

if __name__ == '__main__':
    add_source_folder()

    from models.Engine import *

    def on_event(event, **kwargs):
        print event, kwargs
    
    
    engine = Engine()
    engine.set_caption('Engine Debug Testing')
    engine.on('tick', on_event)
    engine.on('render', on_event)
    engine.start()
from TestingUtils import *

if __name__ == '__main__':
    add_source_folder()
    add_resource_folder()

    from models.Engine import *
    from models.AnimationModels import *
    from models.ImageModels import *
    from controllers.AnimationControllers import *
    from views.AnimationViews import *
    from ResourceLoader import *
    
    def init_animation():
        animation_timer = AnimationController.init(engine)
        
        spritesheet_resource = ResourceLoader().load_resource_by_name_and_type('explosion', 'image')
        animation_model = AnimationModel(spritesheet_resource, (0, 0), (282, 238), 10, interval=70) # 70 makes it look cooler
        animation_controller = AnimationController(animation_model)
        animation_view = AnimationView(animation_model)
        
        animation_controller.start()

        engine.on("render", animation_view.on_render)

    engine = Engine()
    engine.on("init", init_animation, memory=True)

    engine.start()
예제 #12
0
def create_engines(engine_json):
    for eng in engine_json:
        engine_model = Engine(eng['name'], eng['cylinder'], eng['fuel_type'],
                              eng['horsepower'], eng['torque'])
        db.session.add(engine_model)
        db.session.commit()