Exemple #1
0
def testSort():
    s = numpy.random.randint(0, 1000, N)
    t = time.process_time()
    user.sort(s)
    dt = time.process_time() - t
    print('Sorting time: ', dt)
    checkResult(s)
Exemple #2
0
    def test2(self):

        orderedTransaction = []

        orderedTransactionTmp = Transaction.objects.all()
        for transactionobjects in orderedTransactionTmp:
            if transactionobjects.status == "confirmed":
                orderedTransaction.append(transactionobjects.sender_game)
                orderedTransaction.append(transactionobjects.receiver_game)


        #orderedTransaction.order_by('name')
        sort(orderedTransaction, 'name', 'desc')


        topRatedGames = []

        i = 0
        while (i != 4):
            j = 0
            maxCount = 0
            startIndex = 0
            tmp = 0
            while (j < len(orderedTransaction) - 1):
                tmp = 1
                while (orderedTransaction[j] == orderedTransaction[j+1]):

                    tmp = tmp + 1
                    j = j + 1

                    if j == len(orderedTransaction) - 1:
                        break

                if (tmp > maxCount):
                    maxCount = tmp
                    startIndex = j - maxCount + 1

                j = j + 1
       
            topRatedGames.append(orderedTransaction[startIndex].name)

            while (maxCount != 0):
                orderedTransaction.remove(orderedTransaction[startIndex])
                maxCount = maxCount - 1


            i = i + 1
   

        self.assertEquals(topRatedGames[0], "Starcraft")
        self.assertEquals(topRatedGames[1], "CallOfDuty")
        self.assertEquals(topRatedGames[2], "Portal")
        self.assertEquals(topRatedGames[3], "Halo")
Exemple #3
0
    def test4(self):

        orderedListing = []
        orderedListing = Game.objects.all()
        sort(orderedListing, 'num_of_listings', 'desc')
        topRatedGames = []
        j = 0

        while (j < len(orderedListing) - 1):
            
            topRatedGames.append(orderedListing[j].name)
            j = j + 1
   
        self.assertEquals(topRatedGames[0], "Portal")
        self.assertEquals(topRatedGames[1], "Halo")
Exemple #4
0
    def test3(self):

        orderedWishlist = []
        orderedWishlistTmp = Wishlist.objects.all()
        #orderedWishlistTmp.order_by('wishlist_game')
        #orderedWishlist = list(orderedWishlistTmp)
        for wishlistobjects in orderedWishlistTmp:
            orderedWishlist.append(wishlistobjects.wishlist_game)

        sort(orderedWishlist, 'name', 'desc')

        topRatedWishlist = []

        m = 0
        while (m != 5):
            n = 0
            maxCount = 0
            startIndex = 0
            tmp = 0
            while (n < len(orderedWishlist) - 1):
                tmp = 1
                while (orderedWishlist[n] == orderedWishlist[n+1]):

                    tmp = tmp + 1
                    n = n + 1

                    if n == len(orderedWishlist) - 1:
                        break

                if (tmp > maxCount):
                    maxCount = tmp
                    startIndex = n - maxCount + 1

                n = n + 1

            topRatedWishlist.append(orderedWishlist[startIndex])

            while (maxCount != 0):
                orderedWishlist.remove(orderedWishlist[startIndex])
                maxCount = maxCount - 1

            m = m + 1

        self.assertEquals(topRatedWishlist[0].name, "Halo")
        self.assertEquals(topRatedWishlist[1].name, "Starcraft")
        self.assertEquals(topRatedWishlist[2].name, "AssassinsCreed")
        self.assertEquals(topRatedWishlist[3].name, "CallOfDuty")
        self.assertEquals(topRatedWishlist[4].name, "Portal")
Exemple #5
0
def getMostTradedGames():
    i = 0
    orderedTransaction = []
    if Transaction.objects.all().count() != 0:
        orderedTransactionTmp = Transaction.objects.all()
        for transactionobjects in orderedTransactionTmp:
            if transactionobjects.status == "confirmed":
                orderedTransaction.append(transactionobjects.sender_game)
                orderedTransaction.append(transactionobjects.current_listing.game_listed)

    sort(orderedTransaction, 'name', 'desc')
    prevorderedTransactionSize = len(orderedTransaction)
    topRatedGames = []

    i = 0
    while ((len(topRatedGames) != 4 and i < prevorderedTransactionSize) and (len(orderedTransaction) != 0)):
        j = 0
        maxCount = 0
        startIndex = 0
        tmp = 0
        while (j < len(orderedTransaction)):
            tmp = 1
            while (j != len(orderedTransaction) - 1) and (orderedTransaction[j] == orderedTransaction[j+1]):

                tmp = tmp + 1
                j = j + 1

                if j == len(orderedTransaction) - 1:
                    break

            if (tmp >= maxCount):
                maxCount = tmp
                startIndex = j - maxCount + 1

            j = j + 1
   
        topRatedGames.append(orderedTransaction[startIndex])

        while (maxCount != 0):
            orderedTransaction.remove(orderedTransaction[startIndex])
            maxCount = maxCount - 1


        i = i + 1
    return topRatedGames
Exemple #6
0
def getMostWishlistedGames():

    orderedWishlist = []
    if Wishlist.objects.count() != 0:
        orderedWishlistTmp = Wishlist.objects.all()
        for wishlistobjects in orderedWishlistTmp:
            orderedWishlist.append(wishlistobjects.wishlist_game)

    sort(orderedWishlist, 'name', 'desc')
    prevorderedWishlistSize = len(orderedWishlist)
    topRatedWishlist = []

    m = 0
    while ((len(topRatedWishlist) != 4 and m < prevorderedWishlistSize) and (len(orderedWishlist) != 0)):
        n = 0
        maxCount = 0
        startIndex = 0
        tmp = 0
        while (n < len(orderedWishlist)):
            tmp = 1

            while (n != len(orderedWishlist) - 1) and (orderedWishlist[n] == orderedWishlist[n+1]):

                tmp = tmp + 1
                n = n + 1

            # if n == len(orderedWishlist) - 1:
            

            if (tmp >= maxCount):
                maxCount = tmp
                startIndex = n - maxCount + 1

            n = n + 1

        topRatedWishlist.append(orderedWishlist[startIndex])

        while (maxCount != 0):
            orderedWishlist.remove(orderedWishlist[startIndex])
            maxCount = maxCount - 1

        m = m + 1

    return topRatedWishlist