Generate random time columns
This commit is contained in:
parent
ce1e594913
commit
869a2092a6
@ -2,8 +2,8 @@ CREATE TABLE `test` (
|
||||
`id` bigint(20) NOT NULL,
|
||||
`test_value` int(11) NOT NULL,
|
||||
`test_string` varchar(255) DEFAULT NULL,
|
||||
`starting_date` date DEFAULT NULL,
|
||||
`ending_date` date DEFAULT NULL,
|
||||
`local_date` date DEFAULT NULL,
|
||||
`local_time` time DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
||||
|
||||
|
@ -55,10 +55,21 @@ def generate_random_column(sql_column: SQLColumn, generated_values: List[ColumnV
|
||||
endingDate = datetime.datetime.strptime(value.value, "%Y-%m-%d").date()
|
||||
return generate_random_date(min_date, endingDate, sql_column)
|
||||
return generate_random_date(min_date, max_date, sql_column)
|
||||
elif sql_column.columnType == SQLColumnType.TIME:
|
||||
print("Time")
|
||||
return generate_random_time(sql_column)
|
||||
|
||||
|
||||
def generate_random_date(start_date, end_date, sql_column):
|
||||
delta = end_date - start_date
|
||||
random_days = random.randrange(delta.days + 1)
|
||||
random_date = start_date + datetime.timedelta(days=random_days)
|
||||
return ColumnValue(str(random_date), ValueType.STRING, sql_column)
|
||||
return ColumnValue(str(random_date), ValueType.STRING, sql_column)
|
||||
|
||||
|
||||
def generate_random_time(sql_column, start_time=datetime.time(0,0,0), end_time=datetime.time(23, 59, 59)):
|
||||
hours = random.randint(start_time.hour, end_time.hour)
|
||||
minutes = random.randint(start_time.minute, end_time.minute)
|
||||
seconds = random.randint(start_time.second, end_time.second)
|
||||
random_time = datetime.time(hours, minutes, seconds)
|
||||
return ColumnValue(str(random_time), ValueType.STRING, sql_column)
|
||||
|
@ -6,6 +6,7 @@ class SQLColumnType(Enum):
|
||||
INT = 'int(11)'
|
||||
VARCHAR = 'varchar(255)'
|
||||
DATE = 'date'
|
||||
TIME = 'time'
|
||||
|
||||
class SQLColumn:
|
||||
|
||||
|
@ -72,6 +72,8 @@ def get_column_type(column_definition: str):
|
||||
return SQLColumn.SQLColumnType.VARCHAR
|
||||
elif column_definition_characteristic == 'date':
|
||||
return SQLColumn.SQLColumnType.DATE
|
||||
elif column_definition_characteristic == 'time':
|
||||
return SQLColumn.SQLColumnType.TIME
|
||||
|
||||
|
||||
def get_column_name(column_definition: str):
|
||||
|
Loading…
Reference in New Issue
Block a user