Exemplo n.º 1
0
 def __init__(self, db, table_name='places'):
     self.db = db
     self.cursor = db.cursor()
     self.place_id = 0
     number_of_record = 50
     clearTable(self.cursor, table_name, 'place_id')
     db.commit()
     for i in range(number_of_record):
         self.populateData()
Exemplo n.º 2
0
 def __init__(self, db, table_name='spinbike'):
     self.db = db
     self.cursor = db.cursor()
     self.serial_no = 100
     self.spin_bike_data = {}
     number_of_record = 30
     list_of_tables = getTables(self.cursor)
     clearTable(self.cursor, "spin_bike_usage", 'serial_no')
     clearTable(self.cursor, table_name, 'serial_no')
     db.commit()
     for i in range(number_of_record):
         self.populateData()
    def __init__(self, db, table_name='Spin_Bike_Users'):
        cursor = db.cursor()
        list_of_tables = getTables(cursor)
        clearTable(cursor, 'spin_bike_users', 'user_email')
        db.commit()

        # Read from CSV
        csvReadaer_fn = csv.reader(open('first_name.csv', newline=''),
                                   delimiter=' ',
                                   quotechar='|')
        csvReadaer_ln = csv.reader(open('first_name.csv', newline=''),
                                   delimiter=' ',
                                   quotechar='|')
        first_name_list = [row for row in csvReadaer_fn]
        last_name_list = [row for row in csvReadaer_ln]

        first_name_list_len = len(first_name_list)
        last_name_list_len = len(last_name_list)

        email_ending = [
            "@gmail.com", "@mail.mcgill.ca", "@mcgill.com", "@outlook.com",
            "@spinbiek.com"
        ]
        email_ending_len = len(email_ending)

        for i in range(num_of_records):

            # randomly select the name and email
            first_name = ''
            last_name = ''
            length_check = False
            while (not length_check):
                first_name = ''.join(
                    first_name_list[random.randrange(first_name_list_len)])
                last_name = ''.join(
                    last_name_list[random.randrange(last_name_list_len)])
                # length check
                if len(first_name + last_name) < name_length:
                    length_check = True
            # Full name
            user_name = first_name + ' ' + last_name
            user_email = first_name + '.' + last_name + email_ending[
                random.randrange(email_ending_len)]

            cursor.execute(
                """INSERT INTO spin_bike_users (user_email, user_name) VALUES (%s, %s);""",
                (user_email, user_name))

        db.commit()
Exemplo n.º 4
0
    def __init__(self, db, spin_bike_data, table_name="spin_bike_usage"):
        self.db = db
        self.cursor = db.cursor()
        self.spin_bike_data = spin_bike_data
        clearTable(self.cursor, table_name, 'serial_no')
        number_of_record = 200
        self.db.commit

        self.serial_no_list = []
        self.serial_no_list_len = 0

        # find the serial number
        for k, v in self.spin_bike_data.items():
            if v[2] == "yes":
                self.serial_no_list.append(k)
                self.serial_no_list_len += 1

        for i in range(200):
            self.populate_data()
Exemplo n.º 5
0
    def __init__(self, db, table_name='booking'):
        cursor = db.cursor()
        list_of_tables = getTables(cursor)
        clearTable(cursor, 'booking', 'serial_no')
        db.commit()

        # Read from CSV
        csvReadaer_fn = csv.reader(open('first_name.csv', newline=''), delimiter=' ', quotechar='|')
        csvReadaer_ln = csv.reader(open('first_name.csv', newline=''), delimiter=' ', quotechar='|')
        first_name_list = [row for row in csvReadaer_fn]
        last_name_list = [row for row in csvReadaer_ln]

        first_name_list_len = len(first_name_list)
        last_name_list_len = len(last_name_list)

        email_ending = ["@gmail.com","@mail.mcgill.ca", "@mcgill.com", "@outlook.com", "@spinbiek.com"]
        email_ending_len = len(email_ending)

        for i in range(num_of_records):

            cursor.execute("select user_email from spin_bike_users;")
            user_email = cursor.fetchall()[random.randrange(100)][0]

            # Random time
            booking_time = datetime.datetime(2018, 1, 1, 0, 0, 0) + \
                         timedelta(days=random.randrange(30)) + \
                         timedelta(hours=random.randrange(24)) + \
                         timedelta(minutes=random.randrange(60)) + \
                         timedelta(seconds=random.randrange(60))

            cursor.execute("""INSERT INTO booking (booking_time , user_email , serial_no) VALUES (%(b_id)s, %(email)s, %(s_no)s);""" ,
                           {'b_id': booking_time,
                            'email': user_email,
                            's_no': random.randint(101,130)})

            db.commit()
    def __init__(self, db, table_name='bikemanagers'):
        cursor = db.cursor()
        list_of_tables = getTables(cursor)
        clearTable(cursor, 'administrator', 'bmemail')
        clearTable(cursor, 'caretaker', 'bmemail')
        clearTable(cursor, table_name, 'bmemail')

        # Read from CSv
        csvReadaer_fn = csv.reader(open('first_name.csv', newline=''),
                                   delimiter=' ',
                                   quotechar='|')
        csvReadaer_ln = csv.reader(open('first_name.csv', newline=''),
                                   delimiter=' ',
                                   quotechar='|')
        first_name_list = [row for row in csvReadaer_fn]
        last_name_list = [row for row in csvReadaer_ln]

        first_name_list_len = len(first_name_list)
        last_name_list_len = len(last_name_list)

        email_ending = [
            "@gmail.com", "@mail.mcgill.ca", "@mcgill.com", "@outlook.com",
            "@spinbiek.com"
        ]
        email_ending_len = len(email_ending)

        for i in range(num_of_records):

            # randomly select the name and email
            first_name = ''
            last_name = ''
            length_check = False
            while (not length_check):
                first_name = ''.join(
                    first_name_list[random.randrange(first_name_list_len)])
                last_name = ''.join(
                    last_name_list[random.randrange(last_name_list_len)])
                # length check
                if len(first_name + last_name) < name_length:
                    length_check = True
            # Full name
            bmname = first_name + ' ' + last_name
            bmemail = first_name + '.' + last_name + email_ending[
                random.randrange(email_ending_len)]
            bmpassword = self.randompassword()
            #print((bmname), (bmemail))

            cursor.execute(
                """INSERT INTO bikemanagers (bmemail , bmname , bmpassword) VALUES (%s, %s, %s);""",
                (bmemail, bmname, bmpassword))
            db.commit()
            select_role = random.randrange(10)
            if 0 <= select_role <= 2:
                cursor.execute(
                    """INSERT INTO administrator (bmemail) VALUES (%s);""",
                    (bmemail, ))
            if 3 <= select_role <= 7:
                cursor.execute(
                    """INSERT INTO caretaker (bmemail) VALUES (%s);""",
                    (bmemail, ))
            db.commit()


# # Connection to the database
# db = psycopg2.connect(host="comp421.cs.mcgill.ca",database="cs421", user="******", password="******")
#
# # Prepare a cursor object using cursor() method
# cursor = db.cursor()
#

#
#
# # disconnect from server
# db.close()