CREATE TABLE Bikes ( id INTEGER PRIMARY KEY, name TEXT, city_id INTEGER REFERENCES Cities ); CREATE TABLE Cities ( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE Stops ( id INTEGER PRIMARY KEY, name TEXT, city_id INTEGER REFERENCES Cities ); CREATE TABLE Trips ( id INTEGER PRIMARY KEY, from_id INTEGER REFERENCES Stops, to_id INTEGER REFERENCES Stops, user_id INTEGER REFERENCES Users, bike_id INTEGER REFERENCES Bikes, day TEXT, duration INTEGER, -- minuutit distance INTEGER -- metrit ); CREATE TABLE Users ( id INTEGER PRIMARY KEY, name TEXT );
Tehtäväsi on laatia Pythonilla moduuli bikes.py, joka tarjoaa seuraavat funktiot:
bikes.py
distance_of_user(user)
speed_of_user(user)
duration_in_each_city(day)
users_in_city(city)
trips_on_each_day(city)
most_popular_start(city)
main.py
import bikes print("Test 1:", bikes.distance_of_user("user123")) print("Test 2:", bikes.speed_of_user("user123")) print("Test 3:", bikes.duration_in_each_city("2021-06-01")) print("Test 4:", bikes.users_in_city("city5")) print("Test 5:", bikes.trips_on_each_day("city5")) print("Test 6:", bikes.most_popular_start("city5"))
Test 1: 130160 Test 2: 17.35 Test 3: [('city1', 58655), ('city10', 59296), ('city2', 60947), ('city3', 59470), ('city4', 57488), ('city5', 59829), ('city6', 59925), ('city7', 57403), ('city8', 59354), ('city9', 59749)] Test 4: 43102 Test 5: [('2021-06-01', 3362), ('2021-06-02', 3345), ('2021-06-03', 3313), ('2021-06-04', 3276), ('2021-06-05', 3376), ('2021-06-06', 3365), ('2021-06-07', 3351), ('2021-06-08', 3355), ('2021-06-09', 3284), ('2021-06-10', 3324), ('2021-06-11', 3272), ('2021-06-12', 3399), ('2021-06-13', 3308), ('2021-06-14', 3287), ('2021-06-15', 3266), ('2021-06-16', 3376), ('2021-06-17', 3321), ('2021-06-18', 3390), ('2021-06-19', 3320), ('2021-06-20', 3319), ('2021-06-21', 3303), ('2021-06-22', 3429), ('2021-06-23', 3234), ('2021-06-24', 3305), ('2021-06-25', 3260), ('2021-06-26', 3350), ('2021-06-27', 3196), ('2021-06-28', 3222), ('2021-06-29', 3252), ('2021-06-30', 3439)] Test 6: ('stop419', 1073)
import bikes print("Test 1:", bikes.distance_of_user("user555")) print("Test 2:", bikes.speed_of_user("user555")) print("Test 3:", bikes.duration_in_each_city("2021-06-15")) print("Test 4:", bikes.users_in_city("city7")) print("Test 5:", bikes.trips_on_each_day("city7")) print("Test 6:", bikes.most_popular_start("city7"))
The deadline for this task has passed but you can still check your answers