Generate pairs of time
This commit is contained in:
parent
869a2092a6
commit
805d72a593
@ -3,7 +3,8 @@ CREATE TABLE `test` (
|
||||
`test_value` int(11) NOT NULL,
|
||||
`test_string` varchar(255) DEFAULT NULL,
|
||||
`local_date` date DEFAULT NULL,
|
||||
`local_time` time DEFAULT NULL,
|
||||
`starting_time` time DEFAULT NULL,
|
||||
`ending_time` time DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
||||
|
||||
|
@ -17,6 +17,9 @@ max_int = 2147483647
|
||||
min_date = datetime.date(2023, 1, 1)
|
||||
max_date = datetime.date(2024, 12, 31)
|
||||
|
||||
min_time = datetime.time(0,0,0)
|
||||
max_time = datetime.time(23, 59, 59)
|
||||
|
||||
|
||||
def generate_random_insert(sql_table: SQLTable):
|
||||
columnValues = []
|
||||
@ -56,8 +59,17 @@ def generate_random_column(sql_column: SQLColumn, generated_values: List[ColumnV
|
||||
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)
|
||||
if "end" in sql_column.columnName or "max" in sql_column.columnName:
|
||||
for value in generated_values:
|
||||
if "start" in value.sqlColumn.columnName or "min" in sql_column.columnName:
|
||||
startingTime = datetime.datetime.strptime(value.value, "%H:%M:%S").time()
|
||||
return generate_random_time(startingTime, max_time, sql_column)
|
||||
elif "start" in sql_column.columnName or "min" in sql_column.columnName:
|
||||
for value in generated_values:
|
||||
if "end" in value.sqlColumn.columnName or "max" in sql_column.columnName:
|
||||
endingTime = datetime.datetime.strptime(value.value, "%H:%M:%S").time()
|
||||
return generate_random_time(min_time, endingTime, sql_column)
|
||||
return generate_random_time(min_time, max_time, sql_column)
|
||||
|
||||
|
||||
def generate_random_date(start_date, end_date, sql_column):
|
||||
@ -67,7 +79,7 @@ def generate_random_date(start_date, end_date, 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)):
|
||||
def generate_random_time(start_time, end_time, sql_column):
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user