Exemplo n.º 1
0
def load_graph(recipes_file: str) -> Graph:
    """Return a recipes graph corresponding to the given datasets.

    The recipes graph stores one vertex for each ingredient and recipe in the datasets.
    Each vertex stores as its item either a recipe ID or ingredient. Use the "kind"
    _Vertex attribute to differentiate between the two vertex types.

    In this graph, each edge represents the use of an ingredient in a recipe.

    Preconditions:
        - recipes_file is the path to a CSV file corresponding to the recipes data
    """
    graph = Graph()  # start of a Graph
    data = data_reading.read_recipes(recipes_file)
    data_reading.clean_ingredients(data)

    for recipe in data:
        graph.add_vertex(recipe, 'recipe')  # add recipe ID

        for ingredient in data[recipe][7]:
            graph.add_vertex(ingredient.strip(), 'ingredient')
            graph.add_edge(recipe, ingredient.strip())

    return graph
Exemplo n.º 2
0
    def __init__(self) -> None:
        """Initializes ingredients selection window."""
        super().__init__()

        self.third_page = None
        self.setStyleSheet("background-color: rgb(240, 225, 204)")
        self.setWindowIcon(QIcon('visuals/L&C Icon.PNG'))

        self.lbl_selected = QLabel("Your List", self)
        self.lbl_selected.setFont(QFont('Georgia', 12,
                                        weight=QtGui.QFont.Bold))
        self.lbl_selected.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_selected.setFixedSize(200, 25)
        self.lbl_selected.move(80, 100)

        self.max_add_label = QLabel("(10 ingredients max.)", self)
        self.max_add_label.setFont(QFont('Georgia', 9))
        self.max_add_label.setStyleSheet('color: rgb(35, 87, 77)')

        self.max_time_label = QLabel("Enter the max. cooking time (min):",
                                     self)
        self.max_time_label.setFont(QFont('Georgia', 12, QFont.Bold))
        self.max_time_label.setStyleSheet('color: rgb(211, 104, 80)')
        self.max_time_label.setFixedSize(250, 80)
        self.max_time_label.setWordWrap(True)

        self.lbl_all = QLabel("All Ingredients", self)
        self.lbl_all.setFont(QFont('Georgia', 12, QFont.Bold))
        self.lbl_all.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_all.setFixedSize(200, 25)
        self.lbl_all.move(375, 100)

        self.lbl_select = QLabel("Select your ingredients!", self)
        self.lbl_select.setFont(QFont('Georgia', 17, QFont.Bold))
        self.lbl_select.setStyleSheet('color: rgb(210, 146, 68)')
        self.lbl_select.setFixedSize(400, 40)
        self.lbl_select.move(180, 40)

        self.time = QSpinBox(self)
        self.time.setStyleSheet('color: rgb(35, 87, 77)')
        self.time.setFont(QFont('Georgia', 10))
        self.time.setRange(0, 50000)

        self.ing1 = QLineEdit(self)
        self.ing1.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing1.setFont(QFont('Georgia', 10))
        self.ing2 = QLineEdit(self)
        self.ing2.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing2.setFont(QFont('Georgia', 10))
        self.ing3 = QLineEdit(self)
        self.ing3.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing3.setFont(QFont('Georgia', 10))
        self.ing4 = QLineEdit(self)
        self.ing4.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing4.setFont(QFont('Georgia', 10))
        self.ing5 = QLineEdit(self)
        self.ing5.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing5.setFont(QFont('Georgia', 10))
        self.ing6 = QLineEdit(self)
        self.ing6.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing6.setFont(QFont('Georgia', 10))
        self.ing7 = QLineEdit(self)
        self.ing7.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing7.setFont(QFont('Georgia', 10))
        self.ing8 = QLineEdit(self)
        self.ing8.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing8.setFont(QFont('Georgia', 10))
        self.ing9 = QLineEdit(self)
        self.ing9.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing9.setFont(QFont('Georgia', 10))
        self.ing10 = QLineEdit(self)
        self.ing10.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ing10.setFont(QFont('Georgia', 10))

        self.ing = [
            self.ing1, self.ing2, self.ing3, self.ing4, self.ing5, self.ing6,
            self.ing7, self.ing8, self.ing9, self.ing10
        ]

        self.list = QListWidget()
        self.list.setFont(QFont('Georgia', 10))
        self.list.setStyleSheet('color: rgb(35, 87, 77)')
        data = data_reading.read_recipes(data_reading.RECIPES_FILE)
        data_reading.clean_ingredients(data)
        self.clean = sorted(list(data_reading.get_ingredients(data)))

        for i in range(len(self.clean)):
            self.list.insertItem(i, self.clean[i])
        # self.list.setResizeMode(QListView_ResizeMode=)

        self.title = "Look and Cook - Ingredients Selection"
        self.left = 500
        self.top = 200
        self.width = 700
        self.height = 700
        self.init_window()
        self.center()
        self.setFixedSize(700, 700)

        self.line_edit = None
        self.user_input = None
    def __init__(self, user_ingredients: list, time: int,
                 previous_window: QDesktopWidget):
        """Class representing third window of program which displays the recipes filtered by the
        ingredients inputted by the user.
        """
        super().__init__()
        self.display_recipe_dialogue = None
        self.previous_window = previous_window

        # Items imported from ingredients_dialogue
        self.user_ingredients = user_ingredients
        self.time = time

        # Added All the widgets needed
        self.lbl_title = QLabel("We found some recipes for you!", self)
        self.lbl_title.setFont(QFont('Tisa', 17, QFont.Bold))
        self.lbl_title.setStyleSheet('color: rgb(210, 146, 68)')
        self.lbl_title.setFixedSize(475, 40)
        self.lbl_title.move(125, 20)

        self.lbl_sort = QLabel("Sort by:", self)
        self.lbl_sort.setFont(QFont('Tisa', 12, QFont.Bold))
        self.lbl_sort.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_sort.setFixedSize(100, 25)
        self.lbl_sort.move(150, 80)

        self.lbl_recipe = QLabel("Enter a recipe name", self)
        self.lbl_recipe.setFont(QFont('Tisa', 12, QFont.Bold))
        self.lbl_recipe.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_recipe.setFixedSize(205, 25)

        # Creates dependent combo-boxes for time and ingredient sort.
        self.combo_type = QComboBox(self)
        self.combo_type.addItem('Ingredients', [])  # index 0
        self.combo_type.addItem('Time', ['Ascending', 'Descending'])  # index 1
        self.combo_type.move(250, 80)
        self.combo_type.resize(145, 30)
        self.combo_type.setFont(QFont('Tisa', 12))
        self.combo_type.setStyleSheet('color: rgb(35, 87, 77)')

        self.combo_option = QComboBox(self)
        self.combo_option.move(405, 80)
        self.combo_option.resize(145, 30)
        self.combo_option.setFont(QFont('Tisa', 12))
        self.combo_option.setStyleSheet('color: rgb(35, 87, 77)')

        self.combo_type.currentIndexChanged.connect(self.update_combo_option)
        self.update_combo_option(self.combo_type.currentIndex())

        # Getting all the recipes needed
        self.data = data_reading.read_recipes(data_reading.RECIPES_FILE)
        data_reading.clean_ingredients(self.data)
        self.graph = data_type.load_graph("data/clean_recipes.csv")
        ingredient_sorted_recipes = sort_search_results.ingredients_sort(
            self.data, self.user_ingredients, self.graph)

        # varied options for viewing recipes
        self.sorted_by_ingredient = sort_search_results.time_bound(
            ingredient_sorted_recipes, self.time)
        self.sorted_by_time_asc = sort_search_results.time_sort(
            self.sorted_by_ingredient, False)
        self.sorted_by_time_des = sort_search_results.time_sort(
            self.sorted_by_ingredient, True)

        # Displays all the sorted recipes in a list
        self.available_recipes = []
        self.recipe_list = QListWidget()
        self.recipe_names = [x[1][0] for x in self.sorted_by_ingredient]

        # for i in range(len(self.sorted_by_ingredient)):
        #     self.recipes.insertItem(i, self.sorted_by_ingredient[i][1][0])
        # self.recipe_list = QListWidget()
        # self.recipe_names = [x[1][0] for x in self.sorted_by_ingredient]

        for i in range(len(self.recipe_names)):
            self.recipe_list.insertItem(i, self.recipe_names[i])
            self.available_recipes.append(self.recipe_names[i])
        self.recipe_list.setFont(QFont('Tisa', 10))
        self.recipe_list.setStyleSheet('color: rgb(35, 87, 77)')

        self.recipe_of_choice = QLineEdit(self)

        self.color_change = {x: False for x in self.recipe_names}

        # Sets up the screen with all the needed elements
        self.title = "Look and Cook"
        self.left = 500
        self.top = 200
        self.width = 700
        self.height = 700
        self.init_window()
        self.center()
        self.setFixedSize(700, 700)
        self.setStyleSheet("background-color: rgb(240, 225, 204)")
        self.setWindowIcon(QIcon('visuals/L_C_Icon.PNG'))
Exemplo n.º 4
0
    def __init__(self, recipe_name: str,
                 previous_window: QDesktopWidget) -> None:
        """Initialize an instance of the IndividualRecipe window.
        """
        super().__init__()
        self.display_reviews_dialogue = None
        self.recipe_name = recipe_name
        self.previous_window = previous_window

        self.recipe_title = QLabel(self.recipe_name, self)
        self.recipe_title.setFont(QFont('Tisa', 14, QFont.Bold))
        self.recipe_title.setStyleSheet('color: rgb(210, 146, 68)')
        self.recipe_title.setFixedSize(600, 40)
        self.recipe_title.move(50, 40)

        self.selected_recipe = QLineEdit()  # get recipe id, if possible
        self.data = data_reading.read_recipes(data_reading.RECIPES_FILE)
        data_reading.clean_ingredients(self.data)

        self.id = 0

        for x in self.data:
            if self.data[x][0] == self.recipe_name:
                self.id = x

        self.lbl_time_author = QLabel(
            'Cook Time: ' + self.data[self.id][6] + '   |   Author: ' +
            self.data[self.id][3], self)
        self.lbl_time_author.setFont(QFont('Tisa', 10))
        self.lbl_time_author.setStyleSheet('color: rgb(35, 87, 77)')
        self.lbl_time_author.setFixedSize(600, 40)
        self.lbl_time_author.move(50, 75)

        all_ratings = data_reading.get_review_scores("data/clean_reviews.csv")

        if self.id in all_ratings:
            rating = all_ratings[self.id]

            self.lbl_stars = QLabel(str(rating) + '⭐' * round(rating), self)
            self.lbl_stars.setFont(QFont('Tisa', 10, QFont.Bold))
            self.lbl_stars.setStyleSheet('color: rgb(211, 104, 80)')
            self.lbl_stars.setFixedSize(600, 40)
            self.lbl_stars.move(50, 108)

        else:
            self.lbl_stars = QLabel('Rating unavailable ⭐', self)
            self.lbl_stars.setFont(QFont('Tisa', 10, QFont.Bold))
            self.lbl_stars.setStyleSheet('color: rgb(211, 104, 80)')
            self.lbl_stars.setFixedSize(600, 40)
            self.lbl_stars.move(50, 108)

        url_image = self.data[self.id][2]
        image = QImage()
        image.loadFromData(requests.get(url_image).content)

        self.lbl_image = QLabel(self)
        self.lbl_image.setPixmap(QPixmap(image).scaled(300, 300, 2))

        self.lbl_ingredients = QLabel('Ingredients', self)
        self.lbl_ingredients.setFont(QFont('Tisa', 12, QFont.Bold))
        self.lbl_ingredients.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_ingredients.setFixedSize(600, 40)

        self.lbl_direction = QLabel('Directions', self)
        self.lbl_direction.setFont(QFont('Tisa', 12, QFont.Bold))
        self.lbl_direction.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_direction.setFixedSize(600, 40)

        self.ingredients_names = data_reading.get_ing_amounts(
            "data/recipes.csv")[self.id]

        self.lst_ingredients = QListWidget()
        for i in range(len(self.ingredients_names)):
            self.lst_ingredients.insertItem(i, self.ingredients_names[i])
        self.lst_ingredients.setFont(QFont('Tisa', 10))
        self.lst_ingredients.setStyleSheet('color: rgb(35, 87, 77)')
        self.lst_ingredients.setWordWrap(True)

        self.directions = list(self.data[self.id][8])
        self.lst_directions = QListWidget()
        for i in range(len(self.directions)):
            self.lst_directions.insertItem(
                i,
                str(i + 1) + '. ' + self.directions[i])
        self.lst_directions.setFont(QFont('Tisa', 10))
        self.lst_directions.setStyleSheet('color: rgb(35, 87, 77)')
        self.lst_directions.setWordWrap(True)

        self.title = "Look and Cook"
        self.left = 500
        self.top = 200
        self.width = 700
        self.height = 700
        self.init_window()
        self.center()
        self.setFixedSize(700, 700)
        self.setStyleSheet("background-color: rgb(240, 225, 204)")
        self.setWindowIcon(QIcon('visuals/L_C_Icon.PNG'))

        self.line_edit = None
        self.user_input = None
Exemplo n.º 5
0
    def __init__(self) -> None:
        """Initialize an instance of the ingredients window
        """
        super().__init__()

        # Set up the screen background
        self.recipes_dialogue = None
        self.setStyleSheet("background-color: rgb(240, 225, 204)")
        self.setWindowIcon(QIcon('visuals/L_C_Icon.PNG'))

        # Initialized all widgets needed
        self.lbl_list = QLabel("Your List", self)
        self.lbl_list.setFont(QFont('Georgia', 12, QFont.Bold))
        self.lbl_list.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_list.setFixedSize(200, 25)
        self.lbl_list.move(80, 100)

        self.lbl_max_ingredients = QLabel("(10 ingredients max.)", self)
        self.lbl_max_ingredients.setFont(QFont('Georgia', 9))
        self.lbl_max_ingredients.setStyleSheet('color: rgb(35, 87, 77)')
        self.lbl_max_ingredients.move(57, 125)
        self.lbl_max_ingredients.resize(200, 20)

        self.lbl_max_time = QLabel("Maximum cooking time in minutes (optional):", self)
        self.lbl_max_time.setFont(QFont('Georgia', 12, QFont.Bold))
        self.lbl_max_time.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_max_time.setFixedSize(250, 80)
        self.lbl_max_time.setWordWrap(True)

        self.lbl_all_ingredients = QLabel("All Ingredients", self)
        self.lbl_all_ingredients.setFont(QFont('Georgia', 12, QFont.Bold))
        self.lbl_all_ingredients.setStyleSheet('color: rgb(211, 104, 80)')
        self.lbl_all_ingredients.setFixedSize(200, 25)
        self.lbl_all_ingredients.move(375, 100)

        self.lbl_select_items = QLabel("Select your ingredients!", self)
        self.lbl_select_items.setFont(QFont('Georgia', 17, QFont.Bold))
        self.lbl_select_items.setStyleSheet('color: rgb(210, 146, 68)')
        self.lbl_select_items.setFixedSize(400, 40)
        self.lbl_select_items.move(180, 40)

        self.time_selected = QSpinBox(self)
        self.time_selected.setStyleSheet('color: rgb(35, 87, 77)')

        self.time_selected.setFont(QFont('Georgia', 10))
        self.time_selected.setRange(0, 50000)

        self.all_ingredients = QListWidget()
        self.all_ingredients.setFont(QFont('Georgia', 10))
        self.all_ingredients.setStyleSheet('color: rgb(35, 87, 77)')

        self.line_edit = None
        self.user_input = None

        self.disabled_color2 = QGraphicsColorizeEffect()
        self.disabled_color2.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color3 = QGraphicsColorizeEffect()
        self.disabled_color3.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color4 = QGraphicsColorizeEffect()
        self.disabled_color4.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color5 = QGraphicsColorizeEffect()
        self.disabled_color5.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color6 = QGraphicsColorizeEffect()
        self.disabled_color6.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color7 = QGraphicsColorizeEffect()
        self.disabled_color7.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color8 = QGraphicsColorizeEffect()
        self.disabled_color8.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color9 = QGraphicsColorizeEffect()
        self.disabled_color9.setColor(QColor.fromRgb(240, 225, 204))

        self.disabled_color10 = QGraphicsColorizeEffect()
        self.disabled_color10.setColor(QColor.fromRgb(240, 225, 204))

        # Sets up all the line edits
        self.ingredient1 = QLineEdit(self)
        self.ingredient1.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient1.setFont(QFont('Georgia', 10))
        self.ingredient2 = QLineEdit(self)
        self.ingredient2.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient2.setFont(QFont('Georgia', 10))
        self.ingredient2.setGraphicsEffect(self.disabled_color2)
        self.ingredient3 = QLineEdit(self)
        self.ingredient3.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient3.setFont(QFont('Georgia', 10))
        self.ingredient3.setGraphicsEffect(self.disabled_color3)
        self.ingredient4 = QLineEdit(self)
        self.ingredient4.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient4.setFont(QFont('Georgia', 10))
        self.ingredient4.setGraphicsEffect(self.disabled_color4)
        self.ingredient5 = QLineEdit(self)
        self.ingredient5.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient5.setFont(QFont('Georgia', 10))
        self.ingredient5.setGraphicsEffect(self.disabled_color5)
        self.ingredient6 = QLineEdit(self)
        self.ingredient6.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient6.setFont(QFont('Georgia', 10))
        self.ingredient6.setGraphicsEffect(self.disabled_color6)
        self.ingredient7 = QLineEdit(self)
        self.ingredient7.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient7.setFont(QFont('Georgia', 10))
        self.ingredient7.setGraphicsEffect(self.disabled_color7)
        self.ingredient8 = QLineEdit(self)
        self.ingredient8.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient8.setFont(QFont('Georgia', 10))
        self.ingredient8.setGraphicsEffect(self.disabled_color8)
        self.ingredient9 = QLineEdit(self)
        self.ingredient9.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient9.setFont(QFont('Georgia', 10))
        self.ingredient9.setGraphicsEffect(self.disabled_color9)
        self.ingredient10 = QLineEdit(self)
        self.ingredient10.setStyleSheet(
            'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)')
        self.ingredient10.setFont(QFont('Georgia', 10))
        self.ingredient10.setGraphicsEffect(self.disabled_color10)

        # Gets all the ingredients from the data
        self.ingredient = [self.ingredient1, self.ingredient2, self.ingredient3, self.ingredient4,
                           self.ingredient5, self.ingredient6, self.ingredient7,
                           self.ingredient8, self.ingredient9, self.ingredient10]

        self.disabled_color = [self.disabled_color2, self.disabled_color3, self.disabled_color4,
                               self.disabled_color5, self.disabled_color6, self.disabled_color7,
                               self.disabled_color8, self.disabled_color9, self.disabled_color10]
        data = data_reading.read_recipes(data_reading.RECIPES_FILE)
        data_reading.clean_ingredients(data)
        self.clean = sorted(list(data_reading.get_ingredients(data)))
        for i in range(len(self.clean)):
            self.all_ingredients.insertItem(i, self.clean[i])

        # Sets up the screen with all the needed elements
        self.title = "Look and Cook"
        self.left = 500
        self.top = 200
        self.width = 700
        self.height = 700
        self.init_window()
        self.center()
        self.setFixedSize(700, 700)