def create_col_enum_list(inCount): # the enum width is independent from the # of choices widthChoice = random.randint(MIN_ENUM_WIDTH, MAX_ENUM_WIDTH) MAX_CHOICES = 4 weights = [1.0] numChoiceList = [2] # always need 2 choices since we do == and not equal for i in range(3, MAX_CHOICES): print "weights:", weights # each choice is 1/2th the previous w = weights[-1]/2.0 assert w!=0 weights.append(w) numChoiceList.append(i) print "numChoiceList", numChoiceList colEnumList = [] for col in range(inCount): numChoice = numChoiceList[h2o_util.weighted_choice(weights)] print "numChoice:", numChoice # create the per-column choice lists enumList = create_enum_list(n=numChoice, minWidth=MIN_ENUM_WIDTH, maxWidth=widthChoice, quoteChars=quoteChars) colEnumList.append(enumList) return colEnumList
def create_col_enum_list(inCount): # the enum width is independent from the # of choices widthChoice = random.randint(MIN_ENUM_WIDTH, MAX_ENUM_WIDTH) MAX_CHOICES = 4 weights = [1.0] numChoiceList = [2] # always need 2 choices since we do == and not equal for i in range(3, MAX_CHOICES): print "weights:", weights # each choice is 1/2th the previous w = weights[-1] / 2.0 assert w != 0 weights.append(w) numChoiceList.append(i) print "numChoiceList", numChoiceList colEnumList = [] for col in range(inCount): numChoice = numChoiceList[h2o_util.weighted_choice(weights)] print "numChoice:", numChoice # create the per-column choice lists enumList = create_enum_list(n=numChoice, minWidth=MIN_ENUM_WIDTH, maxWidth=widthChoice, quoteChars=quoteChars) colEnumList.append(enumList) return colEnumList
def getRandomDate(): # assume leading zero is option day = days[h2o_util.weighted_choice(dayWeights)] if random.randint(0,1) == 1: day = day.zfill(2) year = random.choice(years) if random.randint(0,1) == 1: year = year.zfill(2) # randomly decide on number or translation for month ### if random.randint(0,1) == 1: # FIX! H2O currently only supports the translate months if 1==1: month = random.choice(months[h2o_util.weighted_choice(monthWeights)]) else: month = str(random.randint(1,12)) if random.randint(0,1) == 1: month = month.zfill(2) a = "%s-%s-%s" % (day, month, year) return a
def getRandomTimeStamp(): # assume leading zero is option day = days[h2o_util.weighted_choice(dayWeights)] # may or may not leading zero fill the day # if random.randint(0,1) == 1: # day = day.zfill(2) # yy year timestampFormat = random.randint(0,3) if timestampFormat==0: # 1 or 2 digit year = str(random.randint(0, 99)) # may or may not leading zero fill the year if random.randint(0,1) == 1: year = year.zfill(2) # yyyy year else: # always 4 digit year = str(random.randint(1900, 2016)) # randomly decide on overall format ### if random.randint(0,1) == 1: # FIX! H2O currently only supports the translate months timestampFormat = random.randint(0,5) if timestampFormat==0: # once we pick the month, we have to pick from the choices for the name of the month month = random.choice(months[h2o_util.weighted_choice(monthWeights)]) else: month = str(random.randint(1,12)) # may or may not leading zero fill the month # if random.randint(0,1) == 1: # month = month.zfill(2) # may or may not leading zero fill the hour hour = str(random.randint(0,23)) if random.randint(0,1) == 1: hour = hour.zfill(2) minute = str(random.randint(0,59)) if random.randint(0,1) == 1: minute = minute.zfill(2) second = str(random.randint(0,59)) if random.randint(0,1) == 1: second = second.zfill(2) milli = str(random.randint(0,999)) # can be zero filled to 2 if <= 99 r = random.randint(0,2) == 1 if r==1: milli = milli.zfill(2) elif r==2: milli = milli.zfill(3) # "dd-MMM-yy" # "yyyy-MM-dd", # "yyyy-MM-dd HH:mm:ss" }; # "yyyy-MM-dd HH:mm:ss.SSS", if timestampFormat==0: a = "%s-%s-%s" % (day, month, year) elif timestampFormat==1: a = "%s-%s-%s" % (year, month, day) elif timestampFormat==2: a = "%s-%s-%s %s:%s:%s" % (year, month, day, hour, minute, second) # elif timestampFormat==3: else: a = "%s-%s-%s %s:%s:%s:%s" % (year, month, day, hour, minute, second, milli) return a
def getRandomTimeStamp(): # assume leading zero is option day = days[h2o_util.weighted_choice(dayWeights)] # may or may not leading zero fill the day # if random.randint(0,1) == 1: # day = day.zfill(2) # yy year timestampFormat = random.randint(0,5) timestampFormat = 0 # always 4 digit yearInt = random.randint(1970, 2016) yearStr = str(yearInt) if timestampFormat==0: # may or may not leading zero fill the year if random.randint(0,1) == 1: if str(yearStr[-2])=='0': # drop the leading zero year = int(str(yearStr)[-1:]) else: # keep leading zzero year = int(str(yearStr)[-2:]) else: # last two digits. (always zero filled) year = int(str(yearStr)[-2:]) # yyyy year else: year = yearInt if timestampFormat==0: # once we pick the month, we have to pick from the choices for the name of the month # monthIndex = range(1,13)[h2o_util.weighted_choice(monthWeights)] monthIndex = random.randint(1,12) month = random.choice(months[monthIndex]) else: month = str(random.randint(1,12)) # may or may not leading zero fill the month # if random.randint(0,1) == 1: # month = month.zfill(2) # use calendar to make sure the day is legal for that month/year import calendar legalDays = calendar.monthrange(yearInt, monthIndex)[1] if day > legalDays: day = legalDays # may or may not leading zero fill the hour hour = str(random.randint(0,23)) if random.randint(0,1) == 1: hour = hour.zfill(2) minute = str(random.randint(0,59)) if random.randint(0,1) == 1: minute = minute.zfill(2) second = str(random.randint(0,59)) if random.randint(0,1) == 1: second = second.zfill(2) milli = str(random.randint(0,999)) # can be zero filled to 2 if <= 99 r = random.randint(0,2) == 1 if r==1: milli = milli.zfill(2) elif r==2: milli = milli.zfill(3) # "dd-MMM-yy" # "yyyy-MM-dd", # "yyyy-MM-dd HH:mm:ss" }; # "yyyy-MM-dd HH:mm:ss.SSS", if timestampFormat==0: a = "%s-%s-%02d" % (day, month, year) elif timestampFormat==1: a = "%04d-%s-%s" % (year, month, day) elif timestampFormat==2: a = "%04d-%s-%s %s:%s:%s" % (year, month, day, hour, minute, second) # elif timestampFormat==3: else: a = "%04d-%s-%s %s:%s:%s:%s" % (year, month, day, hour, minute, second, milli) return a