Example #1
0
def compute():

    for x in xrange(50):

        p=product()
        a=['silver','gold','platinum']
        bids=random.randrange(0,20)
        c=customer(random.choice(a),bids)


        pmd=random.randrange(0,25)
        sales=random.randrange(500,2000)
        q=plot(sales,pmd)

        #random.normalvariate(random.randrange(500,1050,100),random.randrange(50,105,10))

        p.inventory.cur=random.randrange(random.randrange(1+(x%20),10+(x%20),2),random.randrange(22+(x%20),500+(x%20),7), random.randrange(1,3,1))

        p.inventory.maxi=random.randrange(random.randrange(1+(x%20),10+(x%20),2),random.randrange(22+(x%20),500+(x%20),7), random.randrange(1,3,1))

        p.number_items_dp=abs(p.inventory.maxi-p.inventory.cur)

        p.revenue.dp=random.normalvariate(random.randrange(500+(x%20),1550+(x%20),30),random.randrange(50+(x%20),105+(x%20),10))

        p.revenue.cp=random.normalvariate(random.randrange(500+(x%20),1550+(x%20),30),random.randrange(50+(x%20),105+(x%20),10))

        p.price.cost=random.normalvariate(random.randrange(500+(x%20),1550+(x%20),30),random.randrange(50+(x%20),105+(x%20),10))

        p.price.selling=random.normalvariate(random.randrange(600+(x%20),1650+(x%20),30),random.randrange(50+(x%20),105+(x%20),10))

        #p.bids.cur=random.randrange(0,5)

        # call to database for total number of bids made
        #p.bids.tot=p.bids.cur+random.randrange(0,5)

        #p.inventory.t0=p.inventory.cur + random.randrange(random.randrange(1+(x%20),10+(x%20),2),random.randrange(22+(x%20),500+(x%20),7), random.randrange(1,3,1))
        p.inventory.t0=p.inventory.cur
        #Inserting into the db
        print d.insert(db_name,'inventory',p.inventory.to_JSON())
        print d.insert(db_name,'revenue',p.revenue.to_JSON())
        print d.insert(db_name,'price',p.price.to_JSON())
        print d.insert(db_name,'bids',p.bids.to_JSON())
        print d.insert(db_name,'product',p.to_JSON())
        print d.insert(db_name,'customer',c.to_JSON())
        print d.insert(db_name,'plot',q.to_JSON())
        print d.insert(db_name,'customer',c.to_JSON())

        # print d.update_with_date_random(db_name,'revenue',p.revenue.to_JSON(),p.id-1)
        # print d.update_with_date_random(db_name,'price',p.price.to_JSON(),p.id-1)
        # print d.update_with_date_random(db_name,'bids',p.bids.to_JSON(),p.id-1)
        # print d.update_with_date_random(db_name,'product',p.to_JSON(),p.id-1)


    return
Example #2
0
def compute():

    for x in xrange(20):

        p = product()
        a = ['silver', 'gold', 'platinum']
        bids = random.randrange(0, 20)
        c = customer(random.choice(a), bids)

        pmd = random.randrange(0, 25)
        sales = random.randrange(500, 2000)
        q = plot(sales, pmd)

        p.inventory.cur = random.randrange(
            random.randrange(1 + (x % 20), 10 + (x % 20), 2),
            random.randrange(22 + (x % 20), 500 + (x % 20), 7),
            random.randrange(1, 3, 1))

        p.inventory.maxi = random.randrange(
            random.randrange(1 + (x % 20), 10 + (x % 20), 2),
            random.randrange(22 + (x % 20), 500 + (x % 20), 7),
            random.randrange(1, 3, 1))

        p.revenue.dp = random.normalvariate(
            random.randrange(500 + (x % 20), 1550 + (x % 20), 30),
            random.randrange(50 + (x % 20), 105 + (x % 20), 10))

        p.revenue.cp = random.normalvariate(
            random.randrange(500 + (x % 20), 1550 + (x % 20), 30),
            random.randrange(50 + (x % 20), 105 + (x % 20), 10))

        p.price.cost = random.normalvariate(
            random.randrange(500 + (x % 20), 1550 + (x % 20), 30),
            random.randrange(50 + (x % 20), 105 + (x % 20), 10))

        #p.price.selling=random.normalvariate(random.randrange(600+(x%20),1650+(x%20),30),random.randrange(50+(x%20),105+(x%20),10))

        p.inventory.t0 = p.inventory.cur
        #Inserting into the db
        print d.insert(db_name, 'inventory', p.inventory.to_JSON())
        print d.insert(db_name, 'revenue', p.revenue.to_JSON())
        print d.insert(db_name, 'price', p.price.to_JSON())
        print d.insert(db_name, 'bids', p.bids.to_JSON())
        print d.insert(db_name, 'product', p.to_JSON())
        print d.insert(db_name, 'customer', c.to_JSON())
        print d.insert(db_name, 'plot', q.to_JSON())
        print d.insert(db_name, 'customer', c.to_JSON())

        # print d.update_with_date_random(db_name,'revenue',p.revenue.to_JSON(),p.id-1)
        # print d.update_with_date_random(db_name,'price',p.price.to_JSON(),p.id-1)
        # print d.update_with_date_random(db_name,'bids',p.bids.to_JSON(),p.id-1)
        # print d.update_with_date_random(db_name,'product',p.to_JSON(),p.id-1)

    return
Example #3
0
def showModelGraph(
):  #Funcion to run main.py to run and train LSTM model, accuracy score is displayed in console
    index = main.split_data(stockEntry.get())
    result = main.train_test(1, index[0], index[1], index[2], index[3],
                             index[4], index[5])
    plot_result = main.plot(result[0], result[1], result[2], result[3])

    fig = plt.figure(figsize=(10.75, 4.5))  #Graph size and resolution
    graph = FigureCanvasTkAgg(fig, window)
    graph.draw()
    graph.get_tk_widget().place(
        x=500, y=410)  #Where the graph is placed on the window
    plt.xlabel('Time Step', fontsize=18)
    plt.ylabel('Close Price', fontsize=18)  #X and Y axis
    plt.plot(plot_result[0], "-b", label="Training Data")
    plt.plot(plot_result[1], "-r", label="Test Data")
    plt.legend(loc="upper right"
               )  #Legends for colour coding the training and test data
Example #4
0
def RClusterAlg(sr_info_ogn, G_ogn, PL, dist, N_kq, params, ClusterParams,
                GreedyParams):
    '''
	Call the cluster-based robust gateway placement algorithm

	Args:
		sr_info: original read-only sensor placement and configuration
		G: original read-only gateway placement
		PL: path loss matrix between sensors and potential gateways
		dist: distance matrix between sensors and potential gateways
		params: important parameters
		N_kq: a dictionary recording traffic allocation
		ClusterParams: parameters for clustering
		GeneticParams: parameters for this greedy algorithms

	Returns:
		sr_info: sensor configuration
		G: resulted gateway placement
	'''
    sr_info = np.copy(sr_info_ogn)
    G = np.copy(G_ogn)
    gw_cnt = G.shape[0]
    n_clusters = 1
    labels = np.zeros_like(sr_info[:, 0])
    m_gateway = np.zeros_like(sr_info[:, 0])

    # Clustering
    if GreedyParams.cluster:
        db = DBSCANAlg(sr_info[:, :2], ClusterParams)
        labels = db.labels_
        print(labels.shape)
        n_clusters = len(set(labels))
        labels = np.array([x if x != -1 else n_clusters - 1
                           for x in labels])  # Convert -1 to the last cluster
        plotClusters(sr_info[:, :2], labels, db.core_sample_indices_,
                     n_clusters)

    # Perform gateway placement in each cluster
    for ic in range(n_clusters):
        # Extract the points in this cluster
        sr_info_mask = (labels == ic)
        sr_info_blob = np.copy(sr_info[sr_info_mask, :])
        sr_cnt_blob = sr_info_blob.shape[0]

        gw_mask = np.zeros_like(G[:, 2], dtype=bool)
        for j in range(gw_cnt):
            if G[j, 2]:  # A gateway has been placed
                continue

            for i in range(sr_cnt_blob):
                if propagation.GetRSSI(
                        params.Ptx_max,
                        PL[sr_info_mask, :][i, j]) >= params.RSSI_k[-1]:
                    # If the RSSI under max tx power exceeds the minimum RSSI threshold,
                    # we reckon this gateway has the probability of covering end devices
                    # in this cluster
                    # print(propagation.GetRSSI(params.Ptx_max, PL[i, j]))
                    gw_mask[j] = True
                    break
        G_blob = np.copy(G[gw_mask, :])
        PL_blob = PL[sr_info_mask, :][:, gw_mask]
        logging.info('Size of this blob: sr: {} gw: {} PL: {}'.format(sr_cnt_blob, \
         G_blob.shape[0], PL_blob.shape))
        G_blob_plot = np.copy(G_blob)
        G_blob_plot[:, 2] = 1
        main.plot(sr_info_blob, G_blob_plot, 'cluster_{}pre'.format(ic))

        # Call greedy algorithm for this cluster
        sr_info_blob, G_blob, m_gateway_blob, N_kq = \
         RGreedy.RGreedyAlg(sr_info_blob, G_blob, PL_blob, dist, N_kq, params, GreedyParams)

        print(m_gateway.shape, m_gateway_blob.shape)

        # Fill the cluster result back into the original arrays
        sr_info[sr_info_mask, :] = sr_info_blob
        G[gw_mask, :] = G_blob
        m_gateway[sr_info_mask] += m_gateway_blob

        main.plot(sr_info, G, 'cluster_{}post'.format(ic))
    return sr_info, G, m_gateway, N_kq