Exemplo n.º 1
0
def __plot_complete_mix():
    '''
    Plots all TS of a mix in a single image using multiple axis
    '''
    
    # Connect with times
    connection = times_client.connect()
    
    plot_mix = pdata.mix_2
    cols = 5
    rows = len(plot_mix) / cols + 1 
    index = 0
    print rows
    
    fig = plt.figure()
    fig.set_figheight(20)
    fig.set_figwidth(40)
    
    for desc in plot_mix:  
        name = desc.name
        timeSeries = connection.load(__times_name(True, name, POSTFIX_USER))
        _, demand = util.to_array(timeSeries)
        
        index += 1
        ax = fig.add_subplot(rows, cols, index)
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
        ax.plot(range(0, len(demand)), demand)

    plt.savefig(configuration.path('mix_overlay', 'png'))
    
    # Close times connection
    times_client.close()
Exemplo n.º 2
0
def __dump_to_csv():
    connection = times_client.connect()
    
    demands = []
    for desc in selected:
        timeSeries = connection.load(__times_name(True, desc.name, POSTFIX_NORM))
        _, demand = util.to_array(timeSeries)
        demands.append((desc.name, demand))
        
    import csv
    with open(configuration.path('traces', 'csv'), 'wb') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter='\t')
        
        row = []
        for demand in demands:
            row.append(demand[0])
        spamwriter.writerow(row)
        
        l = len(demands[0][1])
        for i in xrange(0, l):
            row = []
            for demand in demands:
                if i < len(demand[1]): 
                    row.append(demand[1][i])
                else:
                    print 'warn'
                    row.append(0)
                    
            spamwriter.writerow(row)
        
    times_client.close()
Exemplo n.º 3
0
def __dump_user_profile_maxes():
    '''
    Used to verify that all user profiles have user values below MAX_USERS
    '''
    # Connect with times
    connection = times_client.connect()
    
    for name in connection.find('.*%s$' % (POSTFIX_USER)):
        result = util.to_array(connection.load(name))[1]
        if np.max(result) > MAX_USERS: 
            print '%s - %i' % (name, np.max(result))
    
    times_client.close()
Exemplo n.º 4
0
def __plot_overlay_mix():
    '''
    Plots all TS of a mix in a single axis graph
    '''
    # Connect with times
    connection = times_client.connect()
    
    # Plot selected
    selected_mix0 = ['O2_retail_ADDORDER', 'SIS_163_cpu', 'SIS_393_cpu']
    selected_mix1 = ['SIS_222_cpu', 'SIS_213_cpu', 'SIS_387_cpu']
    plot_mix = selected_mix1
    
    # Plot all from a set
#    plot_mix = []
#    for i in xrange(a, a + 100):
#        print selected[i].name
#        plot_mix.append(selected[i].name)
    
    fig = plt.figure()
    
    ax = fig.add_subplot(111)
    ax.set_xlim([0, 300])
    
    for name in plot_mix:
        timeSeries = connection.load(__times_name(True, name, POSTFIX_USER))
        print timeSeries
        _, demand = util.to_array(timeSeries)
        demand = demand[7:289 + 7]
        ax.plot(range(0, len(demand)), demand, linewidth=0.7)

    
    xt = [(t * 60 / 5) for t in xrange(0, 25)]
    xl = [t for t in xrange(0, 25)]
    
    ax.set_xticks(xt)
    ax.set_xticklabels(xl)
    
    ax.set_xlabel('Time in hours')
    ax.set_ylabel('Load in number of users')
    
#    plt.show()
    plt.savefig(configuration.path('overlay', 'png'))
    plt.savefig(configuration.path('mix1', 'pdf'))
    
    # Close times connection
    times_client.close()
Exemplo n.º 5
0
    def __renter(self,showTable=True):

        if showTable : 
            # clear()
            self.__print()
         
        print()
        print("+------------------------------------------+")
        print("+ Ingrese los numeros separados por coma,  +")
        print("+ como en este ejemplo: 1,8,7,6            +")
        print("+------------------------------------------+")
        print()
        print("  Presione:")
        print("   1.- Para un nuevo juego")
        print("   2.- Para ver instrucciones")
        print("   3.- Ver tablero")
        print("   0.- Para salir")
        inp = to_array(input("Ingrese su opcion: "))

        if(inp == 0):#Salir del juego
            exit()
        elif(inp == 1):#Reiniciamos el juego
            self.begin()
        elif(inp == 2):#Mostramos las instrucciones
            self.__instruc()
        elif(inp == 3):#Mostramos el tablero con el menu
            self.__renter()
        elif type(inp) is list: #Ingrasamos los valores 

            #Validamos que no se guarde en el tablero
            #Varias veces los mismos valores
            if self.codebreaker.addTurn(inp):
                self.__update(inp)
            else:
                print()
                print("+------------------------------------------+")
                print("+ Ya se han ingreso esto valores:          +")
                print("+    {0},{1},{2},{3}                               +".format(*inp))
                print("+------------------------------------------+")
                self.__renter(False)
        else:#Mostrar otra vez el menu
            self.__renter()
Exemplo n.º 6
0
    def __winner(self,win=True):
        if win: 
            self.__print()
            print()
            print("+------------------------------------------+")
            print("+ Felicitaciones has GANADO!!!!            +")
            print("+------------------------------------------+")
        else :
            print()
            print("+------------------------------------------+")
            print("+ Has PERDIDO!!!! :( :( :( :(              +")
            print("+------------------------------------------+")
        print()
        print("  Presione:")
        print("   1.- Para un nuevo juego")
        print("   0.- Para salir")
        inp = to_array(input("Ingrese su opcion: "))

        if(inp == 0):#Salir de juego
            exit()
        elif(inp == 1):#Reiniciar el juego
            self.begin()
        else:#Mostrar otra vez el menu
            self.__winner(win)
def process_trace(connection, name, cycle_time):
    timeSeries = connection.load(name)
    time, demand = util.to_array(timeSeries)
    return __extract_profile(time, demand, timeSeries.frequency, cycle_time)
    # Get the longest period
    ret = np.max(periods)
    return ret, acf, ped
        

if __name__ == '__main__':
    import matplotlib.pyplot as plt
    
    # Connect and load TS
    connection = times_client.connect()
    ll = connection.find('RAW_O2_.*')
    
    for name in ll: 
        timeSeries = connection.load(name)
        time, demand = util.to_array(timeSeries)

        period, acf, ped = __period_calc(timeSeries.frequency, demand, time)
        
        # Calculate profile
        freq, profile = __extract_profile(time, demand, timeSeries.frequency, period, hour(1), lambda x: np.mean(x))
        freq, profile_upper = __extract_profile(time, demand, timeSeries.frequency, period, hour(1), lambda x: np.percentile(x, 95)) 
        freq, profile_lower = __extract_profile(time, demand, timeSeries.frequency, period, hour(1), lambda x: np.percentile(x, 15))

        # Plotting
        fig = plt.figure()
        folder = 'C:/temp/'
        ax = fig.add_subplot(111)
        ax.fill_between(xrange(len(profile)), profile_lower, profile_upper, interpolate=True, facecolor='lightgray', lw=0)
        ax.plot(range(len(profile)), profile)
        plt.savefig('%s/%s_profile.png' % (folder, name), dpi=30)
Exemplo n.º 9
0
def process_trace(connection, name, modifier, additive, scale, shift):
    timeSeries = connection.load(name)
    time, demand = util.to_array(timeSeries)
    interval = timeSeries.frequency
    return timeSeries.frequency, __add_modifier(time, demand, interval, modifier, additive, scale, shift)
Exemplo n.º 10
0
def process_trace(connection, name, cycle_time, day):
    timeSeries = connection.load(name)
    time, demand = util.to_array(timeSeries)
    return __sample_day(time, demand, timeSeries.frequency, cycle_time, period=day)
Exemplo n.º 11
0
def __load(name):
    timeSeries = connection.load(name)
    _, demand = util.to_array(timeSeries)
    return timeSeries.frequency, demand
Exemplo n.º 12
0
def process_trace(connection, name, ifreq, cycle_time, day):
    timeSeries = connection.load(name)
    time,demand = util.to_array(timeSeries)        
    return sample_day(name, time, demand, ifreq, cycle_time, day=day)