Skip to content

data

import_data(dataset_path='/home/runner/work/koolsla/koolsla/koolsla/dataset/dish.csv')

Imports dataset.

Parameters:

Name Type Description Default
dataset_path str

Path of dataset file.

'/home/runner/work/koolsla/koolsla/koolsla/dataset/dish.csv'

Returns:

Type Description
DataFrame

dataset (dataset values): Datas loaded from csv file.

Source code in koolsla/data.py
23
24
25
26
27
28
29
30
31
32
def import_data(dataset_path: str = dish_dataset_path) -> pandas.core.frame.DataFrame:
    """Imports dataset.
    Args:
      dataset_path (str): Path of dataset file.
    Returns:
      dataset (dataset values): Datas loaded from csv file.
    """

    dish_dataset = pandas.read_csv(dataset_path)
    return dish_dataset

list_of_dishes(length)

List the dishes with given length.

Parameters:

Name Type Description Default
length int

Length to display dishes.

required

Returns:

Type Description
int

length (int): Validated length of dishes to display.

Source code in koolsla/data.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def list_of_dishes(length: int) -> int:
    """List the dishes with given length.
    Args:
      length (int): Length to display dishes.
    Returns:
      length (int): Validated length of dishes to display.
    """

    # Check whether the input length is valid
    if validate_length(length):
        data = import_data()
        dataset = split_data(data)
        # Display the movie list
        for i in range(length):
            print_dish(name=dataset['names'][i],
                      dish_id=i,
                      color=yellow)
        return length
    return 0

search_dish(dish_id)

Prints the single dish name with given id.

Parameters:

Name Type Description Default
dish_id int

Dish id.

required

Returns:

Type Description
str

Dish name or None.

Source code in koolsla/data.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def search_dish(dish_id: int) -> str:
    """Prints the single dish name with given id.
    Args:
      dish_id (int): Dish id.
    Returns:
      Dish name or None.
    """

    # Check whether the dish id is valid
    if validate_dish_id(dish_id):
        # Search dish title by id
        data = import_data()
        dataset = split_data(data)
        # Display the search result
        print_dish(name=dataset['names'][dish_id],
                   dish_id=dish_id,
                   color=yellow)
        return dataset['names'][dish_id]
    return None

split_data(dish_dataset)

Splits dataset.

Parameters:

Name Type Description Default
dish_dataset Dict

Dataset.

required

Returns:

Type Description
Dict

names (dictionary): Dish names in a dictionary.

Source code in koolsla/data.py
35
36
37
38
39
40
41
42
43
44
45
46
def split_data(dish_dataset: Dict) -> Dict:
    """Splits dataset.
    Args:
      dish_dataset (Dict): Dataset.
    Returns:
      names (dictionary): Dish names in a dictionary.
    """

    # Get dish names
    dish_names = dish_dataset[['name']].values.flatten().tolist()
    # Pack and return the split data
    return {'names': dish_names}

validate_dish_id(dish_id)

Validates dish id.

Parameters:

Name Type Description Default
dish_id int

Dish id.

required

Returns:

Type Description
bool

is_valid (bool): True / False.

Source code in koolsla/data.py
49
50
51
52
53
54
55
56
57
58
59
60
61
def validate_dish_id(dish_id: int) -> bool:
    """Validates dish id.
    Args:
      dish_id (int): Dish id.
    Returns:
      is_valid (bool): True / False.
    """

    # Check whether the id is valid
    if not (isinstance(dish_id, int) and dish_id >= 0 and dish_id <= 424508):
        print_red('Input is not a valid integer between [0, 424508]')
        return False
    return True

validate_length(length)

Validates given length.

Parameters:

Name Type Description Default
length int

Length to display dishes.

required

Returns:

Type Description
bool

is_valid (bool): True / False.

Source code in koolsla/data.py
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def validate_length(length: int) -> bool:
    """Validates given length.
    Args:
      length (int): Length to display dishes.
    Returns:
      is_valid (bool): True / False.
    """

    # Check whether the list length is valid
    if (isinstance(length, int) and length >= 1 and length <= 424508):
        return True
    print_red('Invalid value for list length: "' + str(length) + '"')
    print_red('Input is not a valid integer between [1, 424508]')
    return False

validate_max_recommendation(recommendation_count)

Validates dish id.

Parameters:

Name Type Description Default
recommendation_count int

Max recommendation count given by user.

required

Returns:

Type Description
bool

is_valid (bool): True / False.

Source code in koolsla/data.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def validate_max_recommendation(recommendation_count: int) -> bool:
    """Validates dish id.
    Args:
      recommendation_count (int): Max recommendation count given by user.
    Returns:
      is_valid (bool): True / False.
    """

    # Check whether the recommendations count is valid
    if not (isinstance(recommendation_count, int)
            and recommendation_count >= 1 and recommendation_count <= 30):
        print_red('Invalid value for recommendations number: "' +
                 str(recommendation_count) + '"')
        print_red('Input is not a valid integer between [1, 30]')
        return False
    return True