#🔒 Databases Help

34 messages · Page 1 of 1 (latest)

jaunty crypt
#

I'm working on an assignment for my Databases class and I need help with the populating tables and querying after defining my schemas. Does anyone here happen to have sufficient knowledge to help out? thanks.

orchid cradleBOT
#

@jaunty crypt

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

high dagger
#

ask your question first :)

#

we won't know what is sufficient for you

#

and can only determind it if you ask the question first

jaunty crypt
#

instructions:
Option 1. Food Delivery Service Database
Objective: Design a database to support a food delivery app’s logistics and orders.

Schema design: The app lists several restaurants of different cousines. Each retaurant has a different menu comprising items and prices (and calories if you like). The database represents customers with a home address, identified by their cell phone. Customer place orders to a specific restaurant selecting items from the menu and their quantity. The database matches delivery drivers (identified by their cellphones too) to orders. A delivery is initiated from an order and once completed contains the delivery status, and tip amount. Upon each delivery, the customer and the driver give each other star rankings 1-5.

Generate data: Populate at least three restaurants with at least ten menu items each. Populate at least 20 customers and 5 drivers. Generate at least 100 orders and deliveries.

Tips:

Potential tables: Restaurant, Menu, MenuItem, Customer, Driver, Order, OrderItem, Delivery
You may use faker to generate test data
You make ask ChatGPT (or your AI of choice) to generate more interesting data such as menus and prices.
Queries

List all restaurants, including their average menu item price
Pick a customer and list all the orders that he or she has placed in the past month, including the total amount on each order and the tip.
Show all restaurants with their total numbers of orders and total sales amounts.
Show all customers with who tip more than 15% on average and have 4-star rating or better.
Pick a driver and list all the customers that have given him 2-star rating or worse.
Come up with your own fancy query and explain it.

#

my code so far:

#
import datajoint as dj
from faker import Faker
import random

# Setup the connection and database
dj.conn()

# Define tables

class Restaurant(dj.Manual):
    definition = """
    restaurant_id: int unsigned
    ---
    name: varchar(255)
    cuisine_type: varchar(255)
    """

class Menu(dj.Manual):
    definition = """
    menu_id: int unsigned
    -> Restaurant
    """

class MenuItem(dj.Manual):
    definition = """
    menu_item_id: int unsigned
    -> Menu
    name: varchar(255)
    price: float
    calories: int
    """

class Customer(dj.Manual):
    definition = """
    customer_id: int unsigned
    ---
    phone_number: varchar(15)
    home_address: varchar(255)
    """

class Driver(dj.Manual):
    definition = """
    driver_id: int unsigned
    ---
    phone_number: varchar(15)
    """

class Order(dj.Manual):
    definition = """
    order_id: int unsigned
    -> Customer
    -> Restaurant
    order_date: datetime
    """

class OrderItem(dj.Manual):
    definition = """
    order_item_id: int unsigned
    -> Order
    -> MenuItem
    quantity: int
    """

class Delivery(dj.Manual):
    definition = """
    delivery_id: int unsigned
    -> Order
    -> Driver
    status: enum('initiated', 'in-progress', 'completed', 'cancelled')
    tip: float
    customer_rating: int
    driver_rating: int
    """

```|
orchid cradleBOT
#

Hey @jaunty crypt!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
high dagger
#

and the specific issue you have with it?

jaunty crypt
#

I need help with populating the tables

high dagger
#

please provide the name of the package that you installed to use ìmport datajoint

jaunty crypt
#

it worked for me

high dagger
#

oh right I used the wrong command lmao

#

!pip datajoint

orchid cradleBOT
high dagger
jaunty crypt
#

the link didn't work

high dagger
#

hmm, weird, why my browser add that

#

oh nvm, I forgot to put a space

jaunty crypt
#

ohhh

#

thanks

#

lol

#

idk how to populate though

jaunty crypt
#

thanks

orchid cradleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.