This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Triggered after a INSERT operation on "Students" table | |
CREATE TRIGGER my_trigger AFTER INSERT ON Students FOR EACH ROW | |
BEGIN | |
-- ... instructions to be performed ... -- | |
END; | |
-- Triggered before a DELETE operation on "Teachers" table | |
CREATE TRIGGER my_trigger BEFORE DELETE ON Teachers FOR EACH ROW | |
BEGIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET GLOBAL event_scheduler = ON; -- ensures that the MySQL event scheduler is on | |
-- One-time events | |
CREATE EVENT IF NOT EXISTS my_event | |
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 12 HOUR -- the event will be run in 12h and then will be deleted | |
DO | |
DELETE * FROM Logs; -- something random | |
CREATE EVENT IF NOT EXISTS my_event | |
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 24 MINUTE -- the event will be run in 24 minutes... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use an Ubuntu image as base image | |
FROM ubuntu:latest | |
# Metadata for the container | |
LABEL description="This is a dummy container" author="Guillermo Barreiro" | |
# Set the working directory inside the container for the following Dockerfile instructions | |
WORKDIR /root | |
# Use an argument sent to the "docker build" command inside the Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.8" | |
services: | |
database: | |
image: mysql:latest | |
volumes: | |
- db-data:/var/lib/mysql/data | |
command: --default-authentication-plugin=mysql_native_password # run this command in the container | |
networks: | |
- database-api | |
restart: always # the container must be always on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the dependencies | |
import pandas as pd | |
import requests | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
mpl.style.use(['seaborn']) | |
# Foursquare API credentials and endpoint | |
CLIENT_ID = # your client ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
restaurants = pd.DataFrame(columns=['City', 'Cuisine', 'Number of restaurants']) # define the DataFrame where the results will be stored | |
for city in cities: | |
for cuisine_name, category_id in cuisines.items(): | |
# For each city, retrieve the top restaurants from Foursquare for each cuisine... | |
query = requests.get("{url}&near={city}&categoryId={category_id}".format(url=URL, city=city, category_id=category_id)) | |
if query.status_code == 200: | |
number = query.json() | |
restaurants = restaurants.append({ | |
'City': city, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One-hot encoding | |
restaurants_onehot = pd.get_dummies(restaurants['Cuisine'], prefix="", prefix_sep="") | |
restaurants_onehot = restaurants_onehot.multiply(restaurants['Number of restaurants'], axis=0) | |
restaurants_onehot = pd.concat([restaurants['City'], restaurants_onehot], axis=1) | |
# Group by city | |
cuisines_city = restaurants_onehot.groupby('City').sum().reset_index() | |
cuisines_city = cuisines_city.set_index(keys='City') | |
# Normalize the numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = plt.figure() | |
for index, city in enumerate(cities): | |
# For each city, get the top 10 cuisines and plot them in a horizontal bar graph | |
ax = fig.add_subplot(3, 3, index+1) | |
# Get the top 10 cuisines for the city | |
cuisines = cuisines_city_normalized.loc[city] | |
cuisines = cuisines.sort_values(ascending=False).head(10).sort_values(ascending=True) | |
# Plot in red the bar with the local cuisine, plot in blue the rest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = plt.figure() | |
for index, cuisine in enumerate(city_local_cuisines.values()): | |
# For the selected cuisine, plot a bar graph with the cities where there are more restaurants of that cuisine | |
ax = fig.add_subplot(3, 3, index+1) | |
cuisine_cities = cuisines_city_normalized[cuisine] | |
cuisine_cities = cuisine_cities.sort_values(ascending=True).head(9) | |
# Plot in red the bar with the city where this cuisine is local, plot in blue the rest | |
color = '' | |
for i in cuisine_cities.keys(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
percentages = {} | |
for city, cuisine in city_local_cuisines.items(): | |
# For each city, get the percentage of local cuisine restaurants | |
percentage = cuisines_city_normalized.at[city, cuisine] | |
percentages[city] = percentage | |
# Plot the data in a bar graph | |
df_percentages = pd.Series(percentages).sort_values(ascending=True) | |
df_percentages.plot(kind='barh') | |
plt.xlabel('% of local cuisine restaurants') |