예제 #1
0
def test_contains():
    conn = setup_database()
    populate_database(conn)

    col, nic, bra = db.query_green(conn)
    sea, hip = db.query_blend(conn)
    contains = db.query_contains(conn)

    print(contains)
    #return
    assert (len(contains) == 4)

    numCol, numNic, numBra = 0, 0, 0
    numSea, numHip = 0, 0

    for item in contains:
        if item['green'] == col['id']:
            numCol += 1
        elif item['green'] == nic['id']:
            numNic += 1
        elif item['green'] == bra['id']:
            numBra += 1

        if item['blend'] == sea['id']:
            numSea += 1
        elif item['blend'] == hip['id']:
            numHip += 1

    assert (numCol == 2)
    assert (numNic == 1)
    assert (numBra == 1)
    assert (numHip == 2)
    assert (numSea == 2)
예제 #2
0
파일: gui.py 프로젝트: 626tomp/RoastingLog
def get_formatted_blends(conn):
    blends = db.query_blend(conn)
    formatted_blends = []
    for item in blends:
        formatted_blends.append(f"{item['id']}: {item['name']} = {item['quantity']}")

    return formatted_blends
예제 #3
0
def test_blends():
    conn = setup_database()

    db.insert_blend(conn, "Seasonal", 100, 0)
    blends = db.query_blend(conn)

    assert (len(blends) == 1)
    assert (blends[0]['name'] == 'Seasonal')
    assert (blends[0]['quantity'] == 100)

    db.update_blend_quantity(conn, blends[0]['id'], 50)
    blends = db.query_blend(conn)

    assert (len(blends) == 1)
    assert (blends[0]['name'] == 'Seasonal')
    assert (blends[0]['quantity'] == 50)
예제 #4
0
파일: gui.py 프로젝트: 626tomp/RoastingLog
def create_layout(conn):
    blends = db.query_blend(conn)
    layout = []

    for item in blends:
        layout.append([
            sg.Text(item['name']),
            sg.Button("-", size=(2, 1), key=f"-decrement_{item['id']}-"),
            sg.Input(item['quantity'], key=f"-QUANTITY_{item['id']}-"),
            sg.Button("+", size=(2, 1), key=f"-increment_{item['id']}-")
        ])

    layout.append([
            [sg.Listbox(values=[], enable_events=True, size=(40, 20), key="-BLEND LIST-"),
            sg.Button("Refresh", key="-REFRESH-"), sg.Button("Edit", key="-EDIT_ENTRY-")]
        ])

    return layout
예제 #5
0
def calculate_needed(conn):
    ''' 
    queries the db for cafes and blends. Returns a dictionary very similar to
    the db schema for the blends, but with the volume decremented by the amount
    of that blend needed for the cafes listed.
    '''

    cafes = db.query_cafe(conn)
    blends = db.query_blend(conn)

    for i in range(len(blends)):

        for cafe in cafes:
            print("here")
            if cafe['blend'] == blends[i]['id']:
                print("here")
                blends[i]['quantity'] -= cafe['volume']

    return blends
예제 #6
0
파일: gui.py 프로젝트: 626tomp/RoastingLog
    

    if len(sys.argv) >= 2 and sys.argv[1] == "full":
        layout = create_layout(conn)
        window = sg.Window("Roasting Log", layout)

        while True:             
            event, values = window.read()
            
            if event in (sg.WIN_CLOSED, 'Cancel'):
                break
            
            # increment
            x = re.findall("-increment_\d*-", event)
            if len(x) != 0:
                blends = db.query_blend(conn)
                x = int("".join(re.findall("\d", x[0]))) # regex to pull off id number
                db.update_blend_quantity(conn, x, blends[x-1]['quantity'] + 5)

            # decrement
            x = re.findall("-decrement_\d*-", event)
            if len(x) != 0:
                blends = db.query_blend(conn)
                x = int("".join(re.findall("\d", x[0]))) # regex to pull off id number
                # want to find a better way to get the id
                db.update_blend_quantity(conn, x, blends[x-1]['quantity'] - 5)
                print(f"-QUANTITY_{x}-  = {blends[x-1]['quantity'] - 5}")
                values[f"-QUANTITY_{x}-"] = blends[x-1]['quantity'] - 5

            # Refresh list
            if event == "-REFRESH-":
예제 #7
0
def get_simple_layout(conn, completedToday):
    blends = db.query_blend(conn)
    layout = [[
        sg.Text("Name", size = (10, 2)),
        sg.Text("KG Needed", size = (6, 2)),
        sg.Text("Remove Roast", size=(6, 2)),
        sg.Text("Roasts Left ", size = (5, 2)),
        sg.Text("Roasts Done", size = (5, 2)),
        sg.Text("Add Roast", size=(5, 2))
    ], [sg.HorizontalSeparator()]]

    totalRoasts = {}
    colour = True
    for item in blends:
        id = str(item['id'])
        if not id in completedToday:
            completedToday[id] = 0
        
        if colour: background = BACKGROUND_ALTERNATE_COLOUR
        else: background = BACKGROUND_COLOUR 

        if item['postRoast']:
            numRoasts = ceil(item['quantity'] / 16)
            totalRoasts[id] = numRoasts
            if numRoasts <= completedToday[id]:
                completedToday[id] = numRoasts
            numRoasts -= completedToday[id]

            currFrame = []
            currFrame.append([
                sg.Text(item['name'], size = (10, 1), background_color=background),
                sg.Input(item['quantity'], size = (6, 1), key=f"-QUANTITY-{id}-"),
                sg.Button("-", size=(6, 1), key=f"-decrement-{id}-"),
                sg.Text(numRoasts, key=f"-numRoasts-{id}-", size = (5, 1), background_color=background),
                sg.Text(completedToday[id], key=f"-compToday-{id}-", size = (5, 1), background_color=background),
                sg.Button("+", size=(5, 1), key=f"-increment-{id}-")
            ])

            layout.append([sg.Frame("", currFrame, background_color=background, border_width=0)])
        
        else:
            
            contains = db.get_blend_contains(conn, item['id'])
            parent_id = id
            roast_sum = 0
            components = []
            for component in contains:
                id = "G" + str(component['id']) + "_" + parent_id
                if not id in completedToday:
                    completedToday[id] = 0
                componentQuantity = item['quantity'] * (component['percentage'] / 100)
                numRoasts = ceil(componentQuantity / 16)
                totalRoasts[id] = numRoasts
                if numRoasts <= completedToday[id]:
                    completedToday[id] = numRoasts
                numRoasts -= completedToday[id]
                roast_sum += completedToday[id]

                components.append([
                    sg.Text("  -  " + component['name'], size = (10, 1), background_color=background),
                    sg.Input(componentQuantity, size = (6, 1), key=f"-QUANTITY-{id}-"),
                    sg.Button("-", size=(6, 1), key=f"-decrement-{id}-"),
                    sg.Text(numRoasts, key=f"-numRoasts-{id}-", size = (5, 1), background_color=background),
                    sg.Text(completedToday[id], key=f"-compToday-{id}-", size = (5, 1), background_color=background),
                    sg.Button("+", size=(5, 1), key=f"-increment-{id}-")
                ])

            completedToday[parent_id] = roast_sum
            numRoasts = ceil(item['quantity'] / 16)
            totalRoasts[parent_id] = numRoasts
            if numRoasts <= completedToday[parent_id]:
                completedToday[parent_id] = numRoasts
            numRoasts -= completedToday[parent_id]

            currFrame = []
            currFrame.append([
                sg.Text(item['name'], size = (10, 1), background_color=background),
                sg.Input(item['quantity'], size = (6, 1), key=f"-QUANTITY-{parent_id}-"),
                sg.Button("-", size=(6, 1), button_color=DISABLED_BUTTON_COLOUR,  disabled=True, key=f"-decrement-{parent_id}-"),
                sg.Text(numRoasts, key=f"-numRoasts-{parent_id}-", size = (5, 1), background_color=background),
                sg.Text(completedToday[parent_id], key=f"-compToday-{parent_id}-", size = (5, 1), background_color=background),
                sg.Button("+", size=(5, 1), button_color=DISABLED_BUTTON_COLOUR,disabled=True, key=f"-increment-{parent_id}-")
            ])
            for item in components:
                currFrame.append(item)

            layout.append([sg.Frame("", currFrame, background_color=background, border_width=0)])

        colour = not colour # alternate colour of each row
            
    layout.append([sg.Text("Add New"), sg.Button("+", key="ADDBLEND")])
                
    roasts_rem = get_roasts_left(totalRoasts, completedToday)
    time_rem = get_time_left(roasts_rem)
    layout.append([sg.Button("Update", key="UPDATE"), sg.Button("Predict", key="PREDICT"), sg.Button("Reset", key="RESET"), 
    sg.Text(f"Roasts Left: {roasts_rem}", key="ROASTSLEFT"), 
    sg.Text(f"Time Left: {time_rem[0]}:{time_rem[1]:02d}", key="TIMELEFT")])
    return blends, completedToday, totalRoasts, layout