def deleteSchedule(self): fId = int(input("Enter the flightId:")) mycursor = mydb.cursor() mycursor.execute("DELETE FROM bookings WHERE FlightId=" + str(fId)) mydb.commit() mycursor = mydb.cursor() mycursor.execute("DELETE FROM flight WHERE FlightId= " + str(fId)) mydb.commit() print(mycursor.rowcount, "record(s) deleted")
def bookFlight(self): allocatedSeats = 0 price = 0 Exit = 0 while (Exit != -1): fId = int(input("pls, Enter the flightID you have to book:")) uId = int(input("pls, Enter the your UserID:")) mycursor = mydb.cursor() sql = "SELECT * FROM flight WHERE FlightID=" + str(fId) mycursor.execute(sql) myresult = mycursor.fetchall() for i in myresult: maxNoOfSeats = i[4] price = i[5] allocatedSeats = i[6] aseats = (allocatedSeats / maxNoOfSeats) * 100 if (aseats < 50.0): pass elif (aseats < 40.0 and aseats > 10.0): tax = (price / 100) * 20 price = price + tax else: tax = (price / 100) * 50 price = price + tax if (allocatedSeats < maxNoOfSeats): mycursor = mydb.cursor() sql = "INSERT INTO bookings(userId,FlightId,finalPrice) VALUES(%s,%s,%s)" val = (uId, fId, str(price)) mycursor.execute(sql, val) mydb.commit() mycursor = mydb.cursor() allocatedSeats = allocatedSeats + 1 sql = 'UPDATE flight SET AllocatedSeats="' + str( allocatedSeats) + '"WHERE FlightID=' + str(fId) mycursor.execute(sql) mydb.commit() ch = input("Do you want to book more?, say y or n") if (ch == 'y' or ch == 'Y'): pass else: Exit = -1 else: print("Sorry Seats are not available :(") ch = input("Do you want to book another flight?, say y or n") if (ch == 'y' or ch == 'Y'): pass else: Exit = -1
def listAllFlightSchedule(self): mycursor = mydb.cursor() mycursor.execute("SELECT * FROM flight") myresult = mycursor.fetchall() for i in myresult: print(i) print("All the flightSchedules have been listed")
def viewAndCancelTickets(self): mycursor = mydb.cursor() print("Do you want to view") sql = "SELECT * FROM bookings" mycursor.execute(sql) myresult = mycursor.fetchall() for i in myresult: print(i) ch = input("Do you want to cancel? say y or n") if (ch == 'y' or ch == 'Y'): Exit = 0 while (Exit != -1): bid = int(input("Please Enter the booking ID:")) mycursor = mydb.cursor() sql = 'SELECT * FROM bookings WHERE BookingID=' + str(bid) mycursor.execute(sql) result = mycursor.fetchall() for i in result: fId = i[2] mycursor = mydb.cursor() sql = 'DELETE FROM bookings WHERE BookingId=' + str(bid) mycursor.execute(sql) mydb.commit() mycursor = mydb.cursor() sql = 'SELECT * FROM flight' mycursor.execute(sql) result = mycursor.fetchall() for i in result: allocatedSeats = i[6] allocatedSeats -= 1 mycursor = mydb.cursor() sql = 'UPDATE flight SET AllocatedSeats="' + str( allocatedSeats) + '"WHERE FlightID=' + str(fId) mycursor.execute(sql) mydb.commit() ch = input("Do you want to cancel more? say y or n") if (ch == 'n' or ch == 'N'): Exit = -1 else: pass
def createAFlightSchedule(self): mycursor = mydb.cursor() sql = "INSERT INTO flight(Source,Destination,TakeOffTiming,MaxNoOfSeats,Pricing,AllocatedSeats) VALUES(%s,%s,%s,%s,%s,%s)" source = input("Enter the Source:") destination = input("Enter the Destination:") takeOffTiming = input("Enter the TakeOffTime:") maxNoOfSeats = int(input("Enter the MaxNoOfSeats:")) pricing = float(input("Enter the Price of the ticket:")) allocatedSeats = 0 val = (source, destination, takeOffTiming, maxNoOfSeats, pricing, allocatedSeats) mycursor.execute(sql, val) mydb.commit() print(mycursor.rowcount, "Record inserted.")
def get(self): cur = mydb.cursor() parser = reqparse.RequestParser() parser.add_argument('key', type=str) parser.add_argument('groupId', type=int) args = parser.parse_args() sql = "SELECT * from user where mobileNumber like '%" + args[ 'key'] + "%'" # val = [args['groupId'], args['key']] cur.execute(sql) res = cur.fetchall() cur.close() print(res) return { "message": "results found" if len(res) > 0 else "empty", "code": 1 if len(res) > 0 else 0, "data": res }
def choose(self): mycursor = mydb.cursor() fId = int(input("Enter a flightID:")) mycursor.execute("SELECT * FROM flight WHERE FlightId= " + str(fId)) myResult = mycursor.fetchall() for i in myResult: print(i) print("Do you want to change TakeOffTime? say y or n") ans = input() if (ans == 'y' or ans == 'Y'): takeOffTiming = input("Enter the TakeOffTime:") mycursor.execute('UPDATE flight SET TakeOffTiming= "' + takeOffTiming + '" WHERE FlightId= ' + str(fId)) mydb.commit() else: pass print("Do you want to change the price? say y or n") ans = input() if (ans == 'y' or ans == 'Y'): pricing = input("Enter the price of the ticket:") mycursor.execute('UPDATE flight SET Pricing= "' + pricing + '" WHERE FlightId= ' + str(fId)) mydb.commit() else: pass print("Do you want to change maxNoOfSeats? say y or n") ans = input() if (ans == 'y' or ans == 'Y'): maxNoOfSeats = input("Enter the MaxNoOfSeats:") mycursor.execute('SELECT * FROM flight') result = mycursor.fetchall() for i in result: allocatedSeats = i[6] if (int(maxNoOfSeats) < allocatedSeats): print("U can't do the operation!") else: mycursor.execute('UPDATE flight SET MaxNoOfSeats= "' + maxNoOfSeats + '" WHERE FlightId= ' + str(fId)) mydb.commit()
from flask import Flask from flask_restful import reqparse, abort, Resource, Api, request from flask_restful.representations import json import calendar import time from connection import mydb dbCursor = mydb.cursor() app = Flask(__name__) api = Api(app) class Account(Resource): def get(self): parser = reqparse.RequestParser() parser.add_argument('mobileNumber', type=str) args = parser.parse_args() dbCursor.execute("select * from user where mobileNumber = {}".format( args['mobileNumber'])) res = dbCursor.fetchall() print(res) if (len(res) > 0): return { 'id': res[0][0], 'phoneNum': res[0][1], 'name': res[0][2], 'thumb': res[0][3], 'code': 1 }
def calibrateKamuli(): #Get data from database and create a dataframe temp = pd.read_sql( "select datetime, temp_wimea, temp_unma, station from uploads where station = 'Kamuli'", con=engine) print(temp) print('\n') press = pd.read_sql( "select datetime, press_wimea, press_unma, station from uploads where station = 'Kamuli'", con=engine) print(press) print('\n') #Collect X and Y X = temp['temp_wimea'].values Y = temp['temp_unma'].values D = temp['datetime'].values st = temp['station'].values X1 = press['press_wimea'].values Y1 = press['press_unma'].values D1 = press['datetime'].values st1 = press['station'].values #lines = plt.plot(D, X, D, Y) #plt.setp(lines, 'color', 'r', 'linewidth', 2.0) #plt.plot(D,X, linewidth=2.0) #plt.show() #Mean of X and Y mean_x = np.mean(X) mean_y = np.mean(Y) mean_x1 = np.mean(X1) mean_y1 = np.mean(Y1) #Total number of values a = len(X) a1 = len(X1) #Using formula to calculate m and c numer = 0 denom = 0 for i in range(a): numer += (X[i] - mean_x) * (Y[i] - mean_y) denom += (X[i] - mean_x)**2 m = numer / denom c = mean_y - (m * mean_x) numer1 = 0 denom1 = 0 for p in range(a1): numer1 += (X1[p] - mean_x1) * (Y1[p] - mean_y1) denom1 += (X1[p] - mean_x1)**2 m1 = numer1 / denom1 c1 = mean_y1 - (m1 * mean_x1) #Print coefficients print('\n') print("Coefficients:") print(m, c) print('\n') print("Calibrated values:") dependent = [] for i in range(a): dep = m * (X[i]) + c dependent.append(dep) #print(dependent) print(dependent) dependent1 = [] for p in range(a1): dep1 = m1 * (X1[p]) + c1 dependent1.append(dep1) #print(dependent) print(dependent1) #Confidence level ss_t = 0 ss_r = 0 for i in range(a): y_pred = c + m * X[i] ss_t += (Y[i] - mean_y)**2 ss_r += (Y[i] - y_pred)**2 r2 = 1 - (ss_r / ss_t) percent_r2 = r2 * 100 print('\n') print("Confidence level:") print(percent_r2) print('\n') ss_t1 = 0 ss_r1 = 0 for p in range(a1): y_pred1 = c1 + m1 * X1[p] ss_t1 += (Y1[p] - mean_y1)**2 ss_r1 += (Y1[p] - y_pred1)**2 r2a = 1 - (ss_r1 / ss_t1) percent_r2a = r2a * 100 print('\n') print("Confidence level:") print(percent_r2a) print('\n') datetime = pd.DataFrame(D) wimea_temp = pd.DataFrame(X) unma_temp = pd.DataFrame(Y) calibrated = pd.DataFrame(dependent) stations = pd.DataFrame(st) merge1 = pd.concat([datetime, wimea_temp], axis=1) merge2 = pd.concat([merge1, calibrated], axis=1) merge3 = pd.concat([merge2, unma_temp], axis=1) newtemp = pd.concat([merge3, stations], axis=1) newtemp.columns = [ 'datetime', 'wimea_original_temp', 'wimea_calibrated_temp', 'unma_original_temp', 'station' ] print(newtemp) datetime1 = pd.DataFrame(D1) wimea_press = pd.DataFrame(X1) unma_press = pd.DataFrame(Y1) calibrated1 = pd.DataFrame(dependent1) stations1 = pd.DataFrame(st1) merge1 = pd.concat([datetime, wimea_press], axis=1) merge2 = pd.concat([merge1, calibrated1], axis=1) merge3 = pd.concat([merge2, unma_press], axis=1) newpress = pd.concat([merge3, stations1], axis=1) newpress.columns = [ 'datetime', 'wimea_original_pressure', 'wimea_calibrated_pressure', 'unma_original_pressure', 'station' ] print(newpress) s_temp = "Kamuli_temperature" s_press = "Kamuli_pressure" cursor = mydb.cursor() sql = "INSERT INTO calibration_values (confidence_level, coefficient_m, coefficient_c, station_parameter) VALUES (%s, %s, %s, %s)" val = (str(percent_r2), str(m), str(c), s_temp) cursor.execute(sql, val) mydb.commit() cursor = mydb.cursor() sql1 = "INSERT INTO calibration_values (confidence_level, coefficient_m, coefficient_c, station_parameter) VALUES (%s, %s, %s, %s)" val1 = (str(percent_r2a), str(m1), str(c1), s_press) cursor.execute(sql1, val1) mydb.commit() newtemp.to_sql(name="temperaturecalibration_wimea_unma", con=engine, if_exists='append') newpress.to_sql(name="pressurecalibration_wimea_unma", con=engine, if_exists='replace')
def main(): Exit = 0 while (Exit != -1): print("1.SignUP User") print("2.DisplayAll User") print("3. Admin") print("4. User") print("5. Exit") try: typeUser = int(input()) print("You have selected option %d" % typeUser) if (typeUser == 1): """ create user panel """ mycursor = mydb.cursor() sql = "INSERT INTO user(role,username,password) VALUES(%s,%s,%s)" role = input("Enter the role of the user:"******"Enter username:"******"Enter password:"******"Record Inserted.") elif (typeUser == 2): """ display all user panel """ mycursor = mydb.cursor() mycursor.execute("SELECT * FROM user") myResult = mycursor.fetchall() for i in myResult: print(i) elif (typeUser == 3): """ Admin's Panel """ print("Entered as a Admin!!!") ids = int(input("Enter the UserId")) mycursor = mydb.cursor() sql = "SELECT * FROM user WHERE userId=" + str(ids) mycursor.execute(sql) result = mycursor.fetchall() for i in result: roles = i[1] uName = i[2] pWD = i[3] userName = input("Enter a username:"******"Enter a password:"******"admin" and uName == userName and pWD == passwd): print("Welcome " + uName + "!!!") admin() else: print("You doesn't have admin privileges!!!") elif (typeUser == 4): """ User's Panel """ print("Entered as a User!!!") ids = int(input("Enter the UserId:")) username = input("Enter the username:"******"Enter the password:"******"Welcome " + uName + "!!!") user() else: print( "You are not registered passengers!!, Please Signup..." ) elif (typeUser == 5): Exit = -1 else: print("Please Enter one of above listed options!!!") except: print("Enter the valid option!!")