def sail(self):
        """Runs every event, or the distance, to the town and adjusts according
        to the speed set by the player."""

        events = event.Library()

        # To do, figure out better way to manage speed
        for i in xrange(0, self.distance+carmine.speed):
            # Each river event costs the player's ship 5hp for wear & tear
            # in post-apocalyptic environments (everything is post-
            # apocalyptic... I think)
            carmine.change(hp=-5, place="River")
            tools.clear(5)
            print 'Day {} - Health: {}\n'.format(carmine.day,
                                                 carmine.hp)
            events.generate(self.odds)

            tools.next()
            carmine.change(day=1)

        carmine.change(place=self.name)
        tools.clear()
        print 'Day {} - Health: {}\n'.format(carmine.day, carmine.hp)
        result = self.enter()
        carmine.change(day=1)

        return result
Example #2
0
    def sail(self):
        """Runs every event, or the distance, to the town and adjusts according
        to the speed set by the player."""

        events = event.Library()

        # To do, figure out better way to manage speed
        for i in xrange(0, self.distance + carmine.speed):
            # Each river event costs the player's ship 5hp for wear & tear
            # in post-apocalyptic environments (everything is post-
            # apocalyptic... I think)
            carmine.change(hp=-5, place="River")
            tools.clear(5)
            print 'Day {} - Health: {}\n'.format(carmine.day, carmine.hp)
            events.generate(self.odds)

            tools.next()
            carmine.change(day=1)

        carmine.change(place=self.name)
        tools.clear()
        print 'Day {} - Health: {}\n'.format(carmine.day, carmine.hp)
        result = self.enter()
        carmine.change(day=1)

        return result
Example #3
0
    def ask(self, question, answers, prompt='> '):
        """Function to ask and process a question, 'answers' should be in a
        list object"""
        printme = question + '\n'

        # displays answers
        for i in xrange(0, len(answers)):
            printme += '[%(i)i] %(answer)s' % \
                {'i': i+1, 'answer': answers[i]} + '\n'

        printer.display(printme)

        # interprets the user's response, a valid response can be the integer
        # of the answer's position, OR the full answer typed out.
        while True:
            response = raw_input(prompt)

            try:
                if int(response)-1 < len(answers) and int(response) >= 0:
                    tools.clear(1)
                    return int(response)-1
            except ValueError:
                pass

            for i in xrange(0, len(answers)):
                if answers[i].lower().strip() == response.lower().strip():
                    tools.clear(1)
                    return i

            print self.invalid
 def display(self):
     if self.status:
         tools.clear()
         
         if self.status == 'left':
             print arrows.left()
         elif self.status == 'right':
             print arrows.right()
Example #5
0
 def __call__(self):
     while True:
         liste = list(self.__dict__.keys())
         liste.remove("username")
         clear()
         print(self)
         command = command_select(liste + ["end"], printer=True)
         if command == "end": break
         self.__dict__[command]()
    def display(self, text):
        """Takes a given prompt and fills the ui lines for proper printing."""
        # TO DO: Fix hardcoded numbers
        # This has to update player stats by rereading the whole dictionary
        # every time :/
        self._mkdict()
        tools.clear(self.clear)
        count = 1
        find = 0
        cont = False
        working = text

        while working:

            # find a line break (if any) including up to the very possible end,
            # hence the +1 anything beyond is certain to be a part of the next
            # line
            if '\n' in working[:self.length+1]:
                find = working.find('\n')
            else:
                find = self.length

            fillkey = 'line' + str(count)

            # set the line# with the string that should be under the max
            # character limit
            if self.fill.get(fillkey) == "":
                self.fill[fillkey] = working[:find]
            else:
                # if there is more text than available lines, we need
                # another box
                cont = True
                break

            # QUESTION, when break is called, it still removes the last
            # used statement, HOW?
            working = working[find:].lstrip('\n')
            count += 1

        print self.frame.format(**self.fill)

        if cont:
            tools.next()
            self.display(working)
Example #7
0
    def __call__(self):
        def methods_fetcher():
            toreturn = []
            method_list = [
                func for func in dir(self) if callable(getattr(self, func))
            ]
            for method in method_list:
                if "__" not in method:
                    toreturn.append(method)
            return toreturn + ["end"]

        while True:
            clear()
            self.data.sort()
            print(self)
            command = command_select(methods_fetcher(), printer=True)
            if command == "end":
                break
            getattr(self.__class__, command)(self)
Example #8
0
            for i in range(len(animation)):
                time.sleep(0.2)
                sys.stdout.write("\r" + animation[i % len(animation)])
                sys.stdout.flush()
            print("\n")
            time.sleep(5)
            subprocess.run('clear')
            restart()
        else:
            print(f'{C}[{Y}i{C}] Nenhuma atualizacao disponivel.')
            time.sleep(2)
except:
    pass

if login == 1:
    tools.clear()
    print(f'{C}{G}{result}{C}')
    user = input(f"{C}[{G}+{C}]USERNAME:  "******"{C}[{G}+{C}]PASSWORD:  "******"{C}[{G}*{C}] Acesso Liberado...")
        time.sleep(1)
        tools.clear()
    else:
        print(f"{C}[{R}ERROR{C}] Wrong Password....Yare Yare")
        time.sleep(1)
        os.system("python3 main.py")
        if anim == 1:
            time.sleep(1)
        exit()
    print("\n ")
    sys.exit(2)
for opt, arg in opts:
    if opt == '-i':
        input = arg
    elif opt == '-f':
        fromExt = arg
    elif opt == '-t':
        toExt = arg
        if toExt == 'jpg':
            format = 'JPEG'
        elif toExt == 'png':
            format = 'PNG'
    elif opt == '-p':
        processes = int(float(arg))

tools.clear("results/")

files = glob.glob(input + "*." + fromExt)
processedImages = len(files)

print "======================"
start = time()
atexit.register(endlog)

if processes == 1:
    for infile in files:
        processImage(infile)
else:
    pool = Pool(processes=processes)
    pool.map(processImage, files)
    pool.close()
Example #10
0
from user import user
from tools import command_select, clear

if __name__ == "__main__":
    clear()
    print("speedrun.com statistics fetcher, program written by Niamek")
    user = user(input("Who? "))
    user()
def linear_advection_parameter_comparation_with_error(errorType=2):
    
    number_of_params = 8
    
    alphas = np.linspace(-2.0, 2.0, number_of_params)
    
    betas = np.linspace(0.0, 2.0, number_of_params)
    
    gammas = np.linspace(4.0, 12.0, number_of_params)
    
    lams = np.linspace(16.0, 95.0, number_of_params)
    
#    params_list = [alphas]
    params_list = [alphas, betas, gammas, lams]
    
    
#    schemes = [[SCHEMES.TOPUS, 'alpha']]
    schemes = [[SCHEMES.TOPUS, 'alpha'],
               [SCHEMES.FSFL, 'beta'],
               [SCHEMES.SDPUS_C1, 'gamma'],
               [SCHEMES.EPUS, 'lambda']]
    
    #advection velocity
    a = 1
    
    cases = [2]
    
    ymins = [-0.1, -1.1]
    
    ymaxs = [1.1, 1.1]
    
    cfl = 0.9
    
    nx = 400
    
    v = 0.25
    
    domx = [-1, 1]
    
    domts = [[0.0, 0.25], [0, 0.125]]
    
    for case_index in range(len(cases)):
    
        case = cases[case_index]
        
        ymin = ymins[case_index]
        
        ymax = ymaxs[case_index]
        
        domt = domts[case_index]
                
        PATH = 'ERROR_param_compar_lin_ad_CASE=' + str(case) + '/'
        
        for scheme_index in range(len(schemes)):
            
            tools.clear()
            
            scheme = schemes[scheme_index]
            
            SCHEME = scheme[0]
            
            params = params_list[scheme_index]
            
            custom_path = str(SCHEME.__name__) + '_' + PATH
            
            analitic_sol = lambda x, t: analitic_linear_advection(x, u_0, t, a, case = case)
            
            ERRORS = []
            
            for param in params:
                                
                marker = None#param_[-1]
                
                SCHEME_LABEL = scheme[-1] + '=' + str(param)
                
                initial_cond_func = lambda x: initial_cond_func_Linear_Advection(x, case = case)
            
                error = solver.advection_difusion_equation_solver(nx, domx, domt, cfl, v,\
                                               initial_cond_func,\
                                               initial_cond_func(domx[0]),\
                                               initial_cond_func(domx[-1]),\
                                               SCHEME, param,\
                                               analitic_sol,\
                                               SCHEME_LABEL, marker = marker,\
                                               PATH = custom_path,\
                                               equation_type = solver.Equation_types.Linear_advection,\
                                               a = 1,\
                                               save_step_by_step = False, clean_plot = False,\
                                               ymin = ymin, ymax = ymax,
                                               generateError = True,
                                               errorType=errorType)
                
                ERRORS.append(error)
                
            tools.save_fig(params, ERRORS, PATH + scheme[0].__name__ + ".png", 
                           scheme[0].__name__ + " cfl = " + str(cfl),
                           None, xlabel = "parĂ¢metro " + scheme[-1],
                           ylabel = 'Erro')
def linear_advection_schemes_comparation():
    
    alpha = 2.0
    
    beta = 2.0
    
    gamma = 12.0
    
    lam = 95.0
    
    params = [alpha, beta, gamma, lam]
    
    schemes = [[SCHEMES.TOPUS, 'TOPUS alpha'],
               [SCHEMES.FSFL, 'FSFL beta'],
               [SCHEMES.SDPUS_C1, 'SDPUS-C1 gamma'],
               [SCHEMES.EPUS, 'EPUS lambda']]
    
    #advection velocity
    a = 1
    
    cases = [2, 3]
    
    ymins = [-0.1, -1.1]
    
    ymaxs = [1.1, 1.1]
    
    cfl = 0.05
    
    nx = 400
    
    v = 0.25
    
    domx = [-1, 1]
    
    domts = [[0.0, 0.25], [0, 0.125]]
    
    dx = (domx[-1] - domx[0]) / (nx-1)

    x_axes = [domx[0] + i*dx for i in range(nx)]

    save_analitic = True

    for case_index in range(len(cases)):
    
        tools.clear()
        
        case = cases[case_index]
        
        ymin = ymins[case_index]
        
        ymax = ymaxs[case_index]
        
        domt = domts[case_index]
        
        t = domt[-1]
        
        PATH = 'schemes_compar_lin_ad_CASE=' + str(case) + '/'
        
        for scheme_index in range(len(schemes)):
                        
            scheme = schemes[scheme_index]
            
            SCHEME = scheme[0]
            
            param = params[scheme_index]
            
            custom_path = PATH
            
            if scheme_index == 0 and save_analitic:
        
                time_precision = 4
            
                time_string = "{:." + str(time_precision) + "f}"
                
                fileName = custom_path + 'result'\
                + '_time=' + time_string.format(t)\
                + '_v=' + str(v)\
                + '_cfl=' + str(cfl) + '.png'
                
                analitic = [analitic_linear_advection(domx[0] + i*dx, u_0, t, a, case = case)\
                            for i in range(nx)]
                
                tools.save_fig(x_axes, analitic, fileName, 'analitica', 'analitica',\
                        marker = None,\
                        xlabel = 'x', ylabel = 'y',\
                        clean_plot = False, margin = 0.1, ymin = ymin, ymax = ymax)
                
            marker = None#param_[-1]
            
            SCHEME_LABEL = scheme[-1] + '=' + str(param)
            
            initial_cond_func = lambda x: initial_cond_func_Linear_Advection(x, case = case)
        
            solver.advection_difusion_equation_solver(nx, domx, domt, cfl, v,\
                                           initial_cond_func,\
                                           initial_cond_func(domx[0]),\
                                           initial_cond_func(domx[-1]),\
                                           SCHEME, param,\
                                           None,\
                                           SCHEME_LABEL, marker = marker,\
                                           PATH = custom_path,\
                                           equation_type = solver.Equation_types.Linear_advection,\
                                           a = 1,\
                                           save_step_by_step = False, clean_plot = False,\
                                           ymin = ymin, ymax = ymax)
def linear_advection_parameter_comparation(folderPathSubName = "", cases = [2, 3]):
    
    number_of_params = 3
    
    alphas = np.linspace(-2.0, 2.0, number_of_params)
    alphas = [float('%.2f' % el) for el in alphas]
    
    betas = np.linspace(0.0, 2.0, number_of_params)
    betas = [float('%.2f' % el) for el in betas]
    
    gammas = np.linspace(4.0, 12.0, number_of_params)
    gammas = [float('%.2f' % el) for el in gammas]
    
    lams = np.linspace(16.0, 95.0, number_of_params)
    lams = [float('%.2f' % el) for el in lams]
    
    params_list = [alphas]
#    params_list = [alphas, betas, gammas, lams]
    
    
    schemes = [[SCHEMES.TOPUS, 'alpha']]
#    schemes = [[SCHEMES.TOPUS, 'alpha'],
#               [SCHEMES.FSFL, 'beta'],
#               [SCHEMES.SDPUS_C1, 'gamma'],
#               [SCHEMES.EPUS, 'lambda']]
    
    #advection velocity
    a = 1
    
    ymins = [-1, -1.1]
    
    ymaxs = [2, 1.1]
    
    cfl = 0.9
    
    nx = 400
    
    v = 0.25
    
    domx = [-1, 1]
    
    domts = [[0.0, 0.25], [0, 0.125]]
    
    dx = (domx[-1] - domx[0]) / (nx-1)

    x_axes = [domx[0] + i*dx for i in range(nx)]

    save_analitic = True
    
    setters = ['.', '+', '3']

    for case_index in range(len(cases)):
    
        case = cases[case_index]
        
        ymin = ymins[case_index]
        
        ymax = ymaxs[case_index]
        
        domt = domts[case_index]
        
        t = domt[-1]
        
        PATH = 'param_compar_lin_ad_CASE=' + str(case) + '/'
        
        
        for scheme_index in range(len(schemes)):
            
            tools.clear()
            
            scheme = schemes[scheme_index]
            
            SCHEME = scheme[0]
            
            params = params_list[scheme_index]
            
            setter_index = -1
            for param in params:
                setter_index = setter_index + 1
                
                setter = setters[setter_index]
#                param = param_[0]
                
                marker = None#param_[-1]
                
                SCHEME_LABEL = scheme[-1] + '=' + str(param)
                
                initial_cond_func = lambda x: initial_cond_func_Linear_Advection(x, case = case)
            
#                omitPlot = not (param == params[0] or param == params[-1])
            
                custom_path = folderPathSubName + "_" + str(SCHEME.__name__) + '=' + str(param) + '_' + PATH
            
                if save_analitic:
            
                    time_precision = 4
                
                    time_string = "{:." + str(time_precision) + "f}"
                    
                    fileName = custom_path + 'result'\
                    + '_time=' + time_string.format(t)\
                    + '_v=' + str(v)\
                    + '_cfl=' + str(cfl) + '.png'
                    
                    analitic = [analitic_linear_advection(domx[0] + i*dx, u_0, t, a, case = case)\
                                for i in range(nx)]
                    
                    tools.save_fig(x_axes, analitic, fileName, 'analitica', 'analitica',\
                            marker = None,\
                            xlabel = 'x', ylabel = 'y',\
                            clean_plot = False, margin = 0.1, ymin = ymin, ymax = ymax)
            
                solver.advection_difusion_equation_solver(nx, domx, domt, cfl, v,\
                                               initial_cond_func,\
                                               initial_cond_func(domx[0]),\
                                               initial_cond_func(domx[-1]),\
                                               SCHEME, param,\
                                               None,\
                                               SCHEME_LABEL, marker = marker,\
                                               PATH = custom_path,\
                                               equation_type = solver.Equation_types.Linear_advection,\
                                               a = 1,\
                                               save_step_by_step = False, clean_plot = True,\
                                               ymin = ymin, ymax = ymax,
                                               traced = True)
def schemes_comparation_boundary_layer_equation_test():
    
    tools.clear()
    
    ymin = -0.1
    ymax = 1.1
    
    alpha = 2.0
    
    beta = 2.0
    
    gamma = 12.0
    
    lam = 95.0
    
    params = [alpha, beta, gamma, lam]
    
    schemes = [[SCHEMES.TOPUS, 'TOPUS alpha'],
               [SCHEMES.FSFL, 'FSFL beta'],
               [SCHEMES.SDPUS_C1, 'SDPUS-C1 gamma'],
               [SCHEMES.EPUS, 'EPUS lambda']]
        
    domx = [0, 1]
    
    domt = [0, 0.5]
 
    PATH = 'camada_limite_schemes_comp_'
    
    vs_nxs = [[1, 10], [0.1, 80], [0.01, 640]]
#    vs_nxs = [[1, 10]]
    
    save_analitic = True
    
    for v_nx in vs_nxs:
        
        v = v_nx[0]
    
        if save_analitic:
            
            time_precision = 4
                
            time_string = "{:." + str(time_precision) + "f}"
            
            fileName = PATH + '/' + 'result'\
                        + '_time=' + time_string.format(domt[-1])\
                        + '.png'
            
            x_axes = np.linspace(domx[0], domx[-1], 640)
            
            analitic = [analitic_boundary_layer_equation(x_axes[i], v)\
                        for i in range(640)]
            
            tools.save_fig(x_axes, analitic, fileName, 'analitica', 'analitica_v=' + str(v),\
                    marker = None,\
                    xlabel = 'x', ylabel = 'y',\
                    clean_plot = False, margin = 0.1, ymin = ymin, ymax = ymax)
    
    t = domt[-1]
    
    for scheme_index in range(len(schemes)):
        
        scheme = schemes[scheme_index]
                
        custom_path = PATH + '/'
        
        fileName = custom_path + 'result'\
                    + '_time=' + time_string.format(t)\
                    + '.png'
                    
        title = 'tempo = ' + str(t)
        
        for v_nx in vs_nxs:
            
            initial_cond_func = lambda x: initial_cond_func_Boundary_Layer(x)
            
            v = v_nx[0]
                           
            param = params[scheme_index]
            
            marker = '.'#_param[1]
            
            SCHEME = scheme[0]
            
            SCHEME_LABEL = 'v=' + str(v) + ' ' + scheme[-1] + '=' + str(param)
            
            nx = v_nx[-1]
            
            dx = (domx[-1] - domx[0]) / (nx-1)

            dt = 0.01 / float(nx)
            
            cfl = dt / dx
            
            solver.advection_difusion_equation_solver(nx, domx, domt, cfl, v,\
                                           initial_cond_func,\
                                           initial_cond_func(domx[0]),\
                                           1.0,\
                                           SCHEME, param,\
                                           None,\
                                           SCHEME_LABEL, marker = marker,\
                                           PATH = custom_path,\
                                           equation_type = solver.Equation_types.Boundary_layer,\
                                           a = 1,\
                                           save_step_by_step = False, clean_plot = False,\
                                           ymin = ymin, ymax = ymax,
                                           customFileName = fileName,
                                           customTitle = title,
                                           outsideLegend=True)
Example #15
0
def linear_advection_parameter_comparation_with_error(errorType=2):
    
    number_of_params = 8
    
    alphas = np.linspace(-2.0, 2.0, number_of_params)
    
    betas = np.linspace(0.0, 2.0, number_of_params)
    
    gammas = np.linspace(4.0, 12.0, number_of_params)
    
    lams = np.linspace(16.0, 95.0, number_of_params)
    
#    params_list = [alphas]
    params_list = [alphas, betas, gammas, lams]
    
    
#    schemes = [[SCHEMES.TOPUS, 'alpha']]
    schemes = [[SCHEMES.TOPUS, 'alpha'],
               [SCHEMES.FSFL, 'beta'],
               [SCHEMES.SDPUS_C1, 'gamma'],
               [SCHEMES.EPUS, 'lambda']]
    
    #advection velocity
    a = 1
    
    cases = [2]    
    
    cfl = 0.05
    
    nx = 400
    
    v = 0.25
    
    domx = [-1, 1]
    
    domts = [[0.0, 0.25], [0, 0.125]]
    
    for case_index in range(len(cases)):
    
        case = cases[case_index]
        
        domt = domts[case_index]
                
        folderName = 'ERROR_param_compar_lin_ad_CASE=' + str(case)
        
        for scheme_index in range(len(schemes)):
            
            tools.clear()
            
            scheme = schemes[scheme_index]
            
            SCHEME = scheme[0]
            
            params = params_list[scheme_index]
                        
            analitic_sol = lambda x, t: analitic_linear_advection(x, u_0, t, a, case = case)
            
            ERRORS = []
            
            for param in params:
                                                                
                initial_cond_func = lambda x: initial_cond_func_Linear_Advection(x, case = case)
            
                error = solver.advection_difusion_equation_solver(nx, domx, domt, cfl, v,\
                                       initial_cond_func,\
                                       initial_cond_func(domx[0]), 
                                       initial_cond_func(domx[-1]),
                                       SCHEME, param,\
                                       analitic_sol,\
                                       folderName,\
                                       equation_type = solver.Equation_types.Linear_advection,\
                                       a = 1,\
                                       step_interval = 1,\
                                       errorType = 2)
                
                ERRORS.append(error)
                
            plt.grid(True, linestyle='--')
            plt.title('Esquema ' + SCHEME.__name__)
            plt.xlabel(r'$' + '\\'+ scheme[1] + '$')
            plt.ylabel('Erro')
            plt.ylim([0.1575, 0.1750])
            plt.tight_layout()
            plt.plot(params, ERRORS, marker='*')
            plt.savefig(folderName + '/' + SCHEME.__name__ + 'cfl=' + str(cfl) + '.png', dpi=200)
            plt.cla()
            plt.clf()
Example #16
0
def linear_advection_parameter_comparation(cases = [2, 3]):
    
    folderName = "RESULTADOS_DATA"
    
    number_of_params = 3
    
    alphas = np.linspace(-2.0, 2.0, number_of_params)
    alphas = [float('%.2f' % el) for el in alphas]
    
    betas = np.linspace(0.0, 2.0, number_of_params)
    betas = [float('%.2f' % el) for el in betas]
    
    gammas = np.linspace(4.0, 12.0, number_of_params)
    gammas = [float('%.2f' % el) for el in gammas]
    
    lams = np.linspace(16.0, 95.0, number_of_params)
    lams = [float('%.2f' % el) for el in lams]
    
#    params_list = [alphas]
    params_list = [alphas, betas, gammas, lams]
    
    
#    schemes = [[SCHEMES.TOPUS, 'alpha']]
    schemes = [[SCHEMES.TOPUS, 'alpha'],
               [SCHEMES.FSFL, 'beta'],
               [SCHEMES.SDPUS_C1, 'gamma'],
               [SCHEMES.EPUS, 'lambda']]
    
    #advection velocity
    a = 1
    
    cfl = 0.05
    
    nx = 400
    
    v = 0.25
    
    domx = [-1, 1]
    
    domts = [[0.0, 0.25], [0, 0.125]]

    for case_index in range(len(cases)):
    
        case = cases[case_index]
        
        domt = domts[case_index]
                
        for scheme_index in range(len(schemes)):
            
            tools.clear()
            
            scheme = schemes[scheme_index]
            
            SCHEME = scheme[0]
            
            params = params_list[scheme_index]
            
            setter_index = -1
            for param in params:
                setter_index = setter_index + 1
                
                initial_cond_func = lambda x: initial_cond_func_Linear_Advection(x, case = case)
                                    
                analitic_sol_func = lambda x, t: analitic_linear_advection(x, u_0, t, a, case = case)
            
                SCHEME_LABEL = SCHEME.__name__ + "_" + scheme[-1] + '=' + str(param)
                folderName = "RESULTADOS_DATA_" + SCHEME_LABEL
            
                solver.advection_difusion_equation_solver(nx, domx, domt, cfl, v,\
                                       initial_cond_func,\
                                       initial_cond_func(domx[0]), initial_cond_func(domx[-1]), SCHEME, param,\
                                       analitic_sol_func,\
                                       folderName,\
                                       equation_type = solver.Equation_types.Linear_advection,\
                                       a = 1,\
                                       step_interval = 0.05,\
                                       errorType = 2)