Exemplo n.º 1
0
 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
Exemplo n.º 2
0
def forgot_password():
    """This custom function updates the new encrypted password to the db
    """
    user_mail = valid.email_validation(
        input('enter user mail : ').strip().lower())
    query = "select mail_id from user where mail_id =%s;"
    if cursor.execute(query, (user_mail)):
        otp = otp_generation()
        print(otp)
        mail_generation(otp, user_mail)
        check_otp = input('enter 6 digit otp sent your mail : ')
        if check_otp == otp:
            new_pass = password_match()
            cursor.execute('update user set password= %s where mail_id = %s',
                           (new_pass, user_mail))
            mydb.commit()
            print('password changed')
        else:
            print('incorrect OTP \n')
            forgot_password()
    else:
        print("User Not Found")
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 def delete(self):
     args = request.get_json()
     sql = "DELETE FROM user where id = " + int(args['id'])
     dbCursor.execute(sql)
     mydb.commit()
     return {"message": 'Account deleted', 'code': 1}
Exemplo n.º 5
0
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')
Exemplo n.º 6
0
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!!")