chefboyrd.controllers package

Submodules

chefboyrd.controllers.booking_controller module

This module and its functions handle the logic for table reservations for the restaurant. It also handles moving data in and out of our database via the via our application models.

chefboyrd.controllers.booking_controller.book_restaurant_table(restaurant, booking_date_time, people, name, phone, minutes_slot=90)[source]

This method uses get_first_table_available to get the first table available, then it creates a Booking on the database.

Parameters:
  • restaurant – The id of the restaurant we want to make the booking for
  • booking_time_date – The starting time of the booking we want to make
  • people – The number of people that the booking is requesting
  • name – The name of the guest making the reservation
  • phone – The phone number of the guest making the reservation
  • minutes_slot – The amount of time that the reservation is made for. Default is 90 minutes

Returns: A dictionary with the booking id, and the table id. If there is no table available at the requested time None is returned.

chefboyrd.controllers.booking_controller.get_first_table_available(restaurant, booking_date_time, people, minutes_slot=90)[source]

This method returns the first available table of a restaurant, given a specific number of people and a booking date/time.

Parameters:
  • restaurant – The id of the restaurant we want to make the booking for
  • booking_time_date – The starting time of the booking we want to make
  • people – The number of people that the booking is requesting
  • minutes_slot – The amount of time that the reservation is made for. Default is 90 minutes
Returns:

The first table available. If there are no tables available we return None

chefboyrd.controllers.customer_controller module

Customer Controller

A controller houses all functions that has to do with taking arguments and modifying the underlying data store. The controllers also perform all of the data analysis that might be taking place.abs

Essentially controllers are for the ‘business logic’ of the application. Everything that goes here will somehow manipulate, calculate, store, modify or learn everything that we need.

All of the data and objects that we are working with will come from the models folder. Typically each Model will have a corresponding controller which will do all of the CRUD (create, read, update, deletion) from the database. It’s really a middle man from the flask functions to the database which contains all of the logic.

Other controllers which aren’t directly mapped to updating, reading, or writing models might perform actions like model training (machine learning) or scheduling jobs which may be run at specified times that aren’t necessarily completely dictated by user interaction.

Basically if you’ve got some code and it doesn’t interact with the models or the views, then it should be a controller.

chefboyrd.controllers.customer_controller.get_customers()[source]

Return a list with all customer names

chefboyrd.controllers.customer_controller.new_customer(name)[source]

Create a new customer :param name: the customer name :type name: str

chefboyrd.controllers.data_controller module

Used to get relevant data for the model controller and statistics dashboard

written by: Zachary Blanco, Richard Ahn tested by: Zachary Blanco, Richard Ahn debugged by: Zachary Blanco, Richard Ahn

chefboyrd.controllers.data_controller.clamp_rng(num, lo, hi)[source]

Forces a number to fall within min/max range by doing lo + (num % (hi-lo))

Hi and lo should always be positive. If num is < 0 then we take its absolute value and clamp that.

chefboyrd.controllers.data_controller.generate_data(num_days=10, num_tabs=50, order_per_tab=3, dt_start=None)[source]

Generates and stores data for the models in chefboyrd.models.statistics

Notes

  • Opening time is 7AM
  • Closing time is 10PM
  • Tabs are generated throughout the day UNEVENLY. Orders increase during the evening
Parameters:
  • num_days (int) – default=10, The number of days to generate data for
  • num_tabs (int) – default=50, The average number of tabs per day
  • order_per_tab (int) – default=3, Number of orders which exist on each tab
  • dt_start (datetime) – default=(datetime.now()), The datetime to start creating orders
Returns:

The number of new orders created in the DB.

Return type:

int

chefboyrd.controllers.data_controller.get_dollars_in_range(dt_min, dt_max)[source]

Returns the total sum of revenue from a range of dates

chefboyrd.controllers.data_controller.get_dotw_orders(dotw)[source]

Gets all orders on a given day of the week

Interesting challenge because we only have a datetime value.

Parameters:dotw (int) – An integer representing the day of the week. 0 for Monday, 6 for Sunday.
Returns:A list of all order models on a given day of the week.
Return type:list
chefboyrd.controllers.data_controller.get_meals_in_range(dt_min, dt_max)[source]

Returns the total sum of meals from a range of datetimes

Parameters:
  • dt_min (datetime) – Starting datetime
  • dt_max (datetime) – Ending datetime
Returns:

The total number of meals served in the range.

Return type:

int

chefboyrd.controllers.data_controller.get_orders_date_range(dt_min=None, dt_max=None)[source]

Gets a range of orders from one datetime to another datetime joined on Tabs.

If dt_min is None then all orders less than max will be returned. If dt_max is None then all orders greater than dt_min is returned If both are none then all orders are returned.

Parameters:
  • dt_min (datetime) – A datetime object for the range to begin at. (Inclusive)
  • dt_max (datetime) – A datetime object for the range end begin at. (Inclusive)
Returns:

An iterable of order models (peewee set).

Return type:

iterable

chefboyrd.controllers.data_controller.get_reservations_on_dotw(dotw)[source]

Gets the number of reservations on a given day of the week

Parameters:dotw (int) – Integer representing day of the week
Returns:Number of reservations on the day of the week.
Return type:int
chefboyrd.controllers.data_controller.get_tabs_range(dt_min=None, dt_max=None)[source]

Gets a range of tabs from one datetime to another datetime

If dt_min is None then all tabs less than max will be returned. If dt_max is None then all tabs greater than dt_min is None If both are none then all tabs are returned.

Parameters:
  • dt_min (datetime) – A datetime object for the range to begin at. (Inclusive)
  • dt_max (datetime) – A datetime object for the range end begin at. (Inclusive)
Returns:

An iterable of order models (peewee set).

Return type:

iterable

chefboyrd.controllers.data_controller.people_in_range(dt_min=None, dt_max=None)[source]

Gets the total number of people served in a range of dates

Parameters:
  • dt_min (datetime) – Beginning datetime in range
  • dt_max (datetime) – Ending datetime in range
Returns:

The total number of people served in a range of dates

Return type:

int

chefboyrd.controllers.data_controller.randbool()[source]

Return a random boolean (approx 50/50)

chefboyrd.controllers.feedback_controller module

Houses all the functions to add or delete sms objects into the database Includes the feedback analysis functions

written by: Seo Bo Shim, Jarod Morin tested by: Seo Bo Shim, Jarod Morin debugged by: Seo Bo Shim, Jarod Morin

chefboyrd.controllers.feedback_controller.delete_twilio_feedback(sidd)[source]

Wipes the message with the specified sid(s) on Twilio Will display response codes.

Parameters:sidd (str) – optional argument. Include a sid or a list of SMS sids to delete from the twilio DB
Returns:1 on success. 0 if the feedback could not be deleted
Return type:res(int)
Raises:ValueError – sms could not be found in database
chefboyrd.controllers.feedback_controller.feedback_analysis(inStr)[source]

Determines aspects of input string based on word content.

Extended description:

Parameters:inStr (str) – String containing words separated by spaces or non-apostrophe punctuation.
Returns:A list of integers representing whether the input string meets the necessary criteria to be flagged as positive, negative, food-related, service-related or contains an exception.
Return type:list (posFlag,negFlag,exceptionFlag,foodFlag,serviceFlag)
Throws:
TypeError: When argument is not a string.
chefboyrd.controllers.feedback_controller.process_incoming_sms(*one)[source]

Updates SMS table in database with the incoming SMS. Checks for the unique key to invalidate SMS or keep it.

Only for processing SMS in real time.

  • Precondition: A Twilio POST request is received.

TODO: Fix error with twilio, where the most recent message does not have a submission timep

Parameters:*one (int) – optional argument
Returns:1 on success. 0 on error
Return type:res(int)
Throws:
SystemError: When the Twilio Client cannot be started. Possibly invalid account_sid or auth_token
chefboyrd.controllers.feedback_controller.update_db(*date_from, **kwargs)[source]

Updates the sms in the database starting from the date_from specified (at time midnight) no param = updates the sms feedback in database with all message entries analyze feedback when sms is sent

Parameters:
  • date_from (Date) – a specified date, where we update db with sms sent after this date
  • update_from (str) – an optional argument. This should be “test” if messages are not coming from
  • but from the test_fb_data file (twilio,) –
Returns:

1 on success. 0 on error

Return type:

res(int)

Throws:
SystemError: When the Twilio Client cannot be started. Possibly invalid account_sid or auth_token
chefboyrd.controllers.feedback_controller.update_db_rating(rating)[source]

updates the dateabase with the rating specified. TODO: update the rating avarage on feedbackM view

Parameters:rating (Rating) – rating object that contains all the parameters
Returns:1 on success. 0 on error
Return type:res(int)
Throws:
N/A
chefboyrd.controllers.feedback_controller.word_freq_counter(inStr)[source]

Determines frequency of each word in input string.

Extended description:

Parameters:inStr (str) – String containing words separated by spaces or non-apostrophe punctuation.
Returns:
A list of dictionary elements mapping the each distinct word within inStr
to its number of occurrences in the input.
Return type:resultDict (dict(str))
Throws:
TypeError: When argument is not a string.

chefboyrd.controllers.model_controller module

ModelController

This is a preprocessor for the prediction_controller. Given data in the form of our local models, it converts it into numbers usable by the prediction controller.

chefboyrd.controllers.model_controller.get_earliest_datetime()[source]

Finds the minimum datetime in the orders database

chefboyrd.controllers.model_controller.get_last_datetime()[source]

Finds the maximum datetime in the orders database

chefboyrd.controllers.model_controller.orders_to_list(orders)[source]

Converts peewee query result set to a list of dictionary of lists

Parameters:orders (list) – Accepts a list of orders made from a query for peewee
chefboyrd.controllers.model_controller.polynomialModel(x, *params)[source]

This is the polynomial model that will be fit by our algorithm.

Parameters:
  • x – input matrix where the features are rows and each predictor(data point) is a column
  • params – the parameters for the model
Returns:

the output vector where each indice is a predictor

Return type:

sum

chefboyrd.controllers.model_controller.sinusoidalModel(x, *params)[source]

This is the sinusoidal model that will be fit by our algorithm.

Parameters:
  • x – input matrix where the features are rows and each predictor(data point) is a column
  • params – the parameters for the model
Returns:

list - the output vector where each indice is a predictor

chefboyrd.controllers.model_controller.train_regression(mealDict, modelType)[source]

This trains all of the meals and fits their data to their own set of parameters

Parameters:
  • mealDict – The meal dictionary containing order data created by orders_to_list
  • modelType – the type of model to use(sinusoidal, polynomial)
Returns:

a dictionary that contains the parameters for each corresponding meal

Return type:

mealsParams

chefboyrd.controllers.model_controller.train_regression_single(x, y, modelType)[source]

Trains a single meal and fits it to a model to find its parameters

Parameters:
  • x – The input vector(which is composed of rows 0 to 3 in the vector)
  • y – The expected output vector(the last row)
  • modelType – the type of model to use
Returns:

A list of parameters

Return type:

params

chefboyrd.controllers.prediction_controller module

This controller performs our machine learning algorithms using non-linear regression fits on the data.

written by: Richard Ahn tested by: Richard Ahn debugged by: Richard Ahn

chefboyrd.controllers.prediction_controller.predict_regression(regression_params, modelType, dt_min=None, dt_max=None)[source]

Predicts the usage of ingredients according to our regression model

Parameters:
  • regression_params – the parameters for our model
  • modelType – the type of model you’re using
  • range (date) – the two dates that you want to predict the regression for
Returns:

a dictionary of meals with associated usage amounts

Return type:

mealUsage

Module contents