Ejemplo n.º 1
0
def create_Chef_kitch_cart(session):
    addr1 = "3734 live oak creek way, Ontario, CA"
    addr2 = "1600 Amphitheatre Parkway, Mountain View, CA"
    addr3 = "900 University Ave, Riverside, CA"
    addr4 = "1133 W Blaine St, Riverside, CA"

    chef1 = Chef(name="Chef Don Juan",
                 email="*****@*****.**",
                 cart=Cart(),
                 kitch=Kitch(),
                 address=addr1)
    chef2 = Chef(name="Cheffy Chef",
                 email="*****@*****.**",
                 cart=Cart(),
                 kitch=Kitch(),
                 address=addr2)
    chef3 = Chef(name="Netties",
                 email="*****@*****.**",
                 cart=Cart(),
                 kitch=Kitch(),
                 address=addr3)
    chef4 = Chef(name="Lil Chef Xennie",
                 email="*****@*****.**",
                 cart=Cart(),
                 kitch=Kitch(),
                 address=addr4)
    session.add(chef1)
    session.add(chef2)
    session.add(chef3)
    session.add(chef4)
    session.commit()
Ejemplo n.º 2
0
def search_library(query):
    """Search the music library for tracks and carts.

    :param query: search term
    """
    results = []

    try:
        res = requests.get(URL_STUDIOSEARCH, params={"query": query})
        results_res = res.json()

        for cart_res in results_res["carts"]:
            filename = LIBRARY_PREFIX + "carts/" + cart_res["filename"]

            cart = Cart(cart_res["cartID"], cart_res["title"],
                        cart_res["issuer"], cart_res["type"], filename)
            if cart.is_playable():
                results.append(cart)

        for track_res in results_res["tracks"]:
            filename = LIBRARY_PREFIX + track_res["file_name"]
            track_id = track_res["album_code"] + "-" + track_res["track_num"]

            track = Cart(track_id, track_res["track_name"],
                         track_res["artist_name"], track_res["rotation"],
                         filename)
            if track.is_playable():
                results.append(track)
    except requests.exceptions.ConnectionError:
        print "Error: Could not fetch search results."

    return results
Ejemplo n.º 3
0
def main():
    # read in and preprocess data
    with open("owls15.csv") as file:
        content = file.readlines()

    data = []

    for entry in content:
        readings = entry.rstrip("\n").split(",")
        attributes = [float(r) for r in readings[0:-1]]
        attributes.append(readings[-1])
        # add back in the classes
        data.append(attributes)

    # build and print CART decision tree
    Cart(data).visualise_model()

    # test accuracy 10 times and display the results
    acc_scores = []
    for i in range(0, 10):
        random.shuffle(data)
        split = len(data) * 2 // 3
        training_data = data[0:split]
        test_data = data[split:]
        cart = Cart(training_data)
        accuracy = cart.test_accuracy(test_data)
        print("Round {}, Accuracy is {:.4f}".format(i + 1, accuracy))
        acc_scores.append(accuracy)
        cart.save_actual_vs_predicted_results(test_data)

    print("")
    print("CART classifier has an accuracy of {:.2f}%, +/- {:.2f}%".format(
        mean(acc_scores) * 100,
        stdev(acc_scores) * 2 * 100))
 def testConstructor(self):
     #Test the creation of objects from the Cart class constructor for correctness
     self.setUp()
     driver.get("http://www.csueastbay.edu/")
     with self.assertRaises(ValueError):
         constructorTest1 = Cart(driver)
     driver.get("https://www-secure.target.com/co-cart")
     constructorTest2 = Cart(driver)
Ejemplo n.º 5
0
 def test_get_total_multiple_items_multiple_quantity(self):
     '''Correct total for multiple items with multiple quantities in
     cart.'''
     cart = Cart(self._create_product_store())
     cart.add('apple', 2)
     cart.add('kitkat', 3)
     self.assertEqual(cart.get_total(), float('6.30'))
Ejemplo n.º 6
0
def test_cart():
    c = Cart()
    p = Product("widget", 123)
    c.add_product(p, 100)
    item2 = Product("gadget", 45)
    c.add_product(item2, 1)
    assert c.get_total() == 12345  # 100x123=12300 + 1x45=45
    assert len(c.line_items) == 2
    assert c.line_items[0].get_extended_price() == 12300
    assert c.line_items[1].get_extended_price() == 45
    content = str(c)
    assert content.find("widget") != -1
    assert content.find("gadget") != -1
    assert content.find("123") != -1
    assert content.find("12300") != -1
    assert content.find("1") != -1
    assert content.find("45") != -1
    assert content.find("total") != -1
    assert content.find("12345") != -1
    display_cart(c)

    c.remove(2)
    c.update_quantity(1, 200)  # line number and quantity
    content = str(c)
    assert content.find("24600") != -1  # 123x200=24600

    display_cart(c)
Ejemplo n.º 7
0
    def test_remove_item_from_cart(self):
        cart = Cart()
        with self.assertRaises(TypeError):
            cart.removeItem(2)

        with self.assertRaises(ValueError):
            cart.removeItem("This item does not exist")
 def testPlusMinusButtons(self):
     #Adds an item to target.com's shopping cart. Calls the Cart class increment function to add one additional quanity of that item to shopping cart.
     #Test the change in target.com's shopping cart item# value for correctness--expects 2. Calls the Cart class decrement function to subtract one
     #  additional quanity of that item same item from shopping cart. Again, test target.com's shopping cart item# value for correctness--expects 1
     #Added sleep statments before each count_item() and assert call to keep the tests consistent with Target's bad load times
     self.setUp()
     driver.get("http://www.target.com/p/gopro-hero-chdha-301/-/A-16399081")
     WebDriverWait(
         driver, 15
     ).until(lambda driver: driver.find_element_by_xpath(
         "/html/body/div[2]/div[4]/div/aside/div[2]/div[4]/div[3]/div/div/div[1]/div/button"
     )).click()
     WebDriverWait(
         driver, 15
     ).until(lambda driver: driver.find_element_by_xpath(
         "/html/body/div[2]/div[4]/div/div[5]/div[2]/div[2]/div/div[2]/div/div[1]/div[4]/button"
     )).click()
     cart = Cart(driver)
     cart.increment_item(1, 2)
     time.sleep(5)
     countTest = cart.count_items()
     self.assertEqual(2, countTest)
     cart.decrement_item(1, 2)
     time.sleep(5)
     countTest = cart.count_items()
     self.assertEqual(1, countTest)
Ejemplo n.º 9
0
def delete_cart(request, id):
    cart = Cart(request)
    cart.delete(id)
    if request.META.get('HTTP_X_REQUESTED_WITH', '') == 'XMLHttpRequest':
        return HttpResponse(cart.serialize())
    else:
        return redirect(reverse('show_cart'))
Ejemplo n.º 10
0
def checkout(request):
    # 订单号
    out_trade_no = baseutil.time_hash()

    cart = Cart(request)
    # 关闭cart购物车,防止付款之前购物车内内容改变
    cart.cart.checked_out = True
    cart.cart.save()
    # 记录transaction
    now = datetime.datetime.now()
    Transaction.objects.create(out_trade_no=out_trade_no,user=request.user,\
            cart=cart.cart,payed_fee=0,trade_time=now)

    # What you want the button to do.
    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": (cart.total_fee) / 5,  # exchange rate is 5
        "item_name": "Bluessh ssh+vpn fee",
        "invoice": out_trade_no,  # 本站订单号
        "notify_url": "%s%s" % (settings.SITE_URL, '/paypal/ipn_pengzhao/'),
        "return_url": "%s/usercenter/" % settings.SITE_URL,
        "currency_code": "USD",  # 人民币CNY,美元USD
        "charset": "utf-8",
    }

    paypal_form = PayPalPaymentsForm(initial=paypal_dict)
    submit_js = "<script>document.forms['paypalsubmit'].submit()</script>"
    return render(request, 'usercenter/checkout.html', {
        'content': paypal_form.render(),
        'submit_js': submit_js
    })
Ejemplo n.º 11
0
def remove_from_cart(request, product_id):
    product = Product.objects.get(custom_id=product_id)
    cart = Cart(request)
    cart.remove(product)
    print "REMOVE: %s" % (product_id)
    #return render(request, 'index.html', {'cart' : cart})
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Ejemplo n.º 12
0
 def process_request(self, request):
     try:
         cart = request.session[Cart.SESSION_KEY]
     except KeyError:
         cart = Cart()
         request.session[Cart.SESSION_KEY] = cart
     setattr(request, 'cart', cart)
Ejemplo n.º 13
0
def get_playlist(show_id):
    """Get the playlist from a past show.

    :param show_id: show ID
    """
    playlist = []

    try:
        res = requests.get(URL_AUTOLOAD, params={"showid": show_id})
        playlist_res = res.json()

        for track_res in playlist_res:
            # TODO: move pathname building to Track constructor
            filename = LIBRARY_PREFIX + track_res["file_name"]
            track_id = track_res["lb_album_code"] + "-" + track_res[
                "lb_track_num"]

            track = Cart(track_id, track_res["lb_track_name"],
                         track_res["artist_name"], track_res["rotation"],
                         filename)

            if track.is_playable():
                playlist.append(track)
    except requests.exceptions.ConnectionError:
        print "Error: Could not fetch playlist."

    return playlist
Ejemplo n.º 14
0
    def attend(self, conn, addr):
        connection_id = addr[0] + ":" + str(
            addr[1])  # Defining uniqueness by ip:port duplet

        print(f'[Server][{connection_id}] Connection established')

        self.cart = Cart()  # A new cart object is created for the new customer
        try:
            # On a loop, the server (in this case, "attendant") receives every request from client.
            # it then processes the request on the cart using the cart.process_request()
            # And returns the current status of the cart.
            while True:
                request_from_client = conn.recv(1).decode()
                print(
                    f'[Server][{connection_id}] Received {request_from_client}'
                )

                # answer is a dictionary with keys:
                #    - "response" informing about the successful addition of the request
                #    - "current cart" a straight forward compute of the cart
                answer = json.dumps(
                    self.cart.process_request(request_from_client, verbose))

                conn.sendall((f'{answer}\nEOM').encode())

                # if request is to exit, we exit the loop
                if request_from_client == '0':
                    break

        # In all cases, we finalize the connection after serving the client
        finally:
            print(f'[Server][{connection_id}] Connection finished by client')
            conn.close()
            return False
Ejemplo n.º 15
0
def remove_from_cart(request):
    menu_id = request.POST.get('menu_id')
    menu_item = MenuItem.objects.get(id=menu_id)
    cart = Cart(request)
    cart.remove(menu_item)
    data = {'success': 'true'}
    return HttpResponse(json.dumps(data), content_type="application/json")