#!/usr/bin/python3 # =================================================================== # generate "incoming" messages for the lookaside list demo # =================================================================== # lookaside list message format: # a. messages are CSV strings # b. the first field is the action to be taken # mod - modify message # dis - display message # del - delete message # add - add message # c. the second field is the record ID # d. subsequent fields are the record's data # =================================================================== # message stream percentages by type # modify - 80% # display - 10% # delete - 5% # add - 5% # =================================================================== # Note: test messages have nonsense data values for testing # =================================================================== import random seed = 19440309 random.seed(seed) def generate_message(id): ran = random.random() if ran < 0.80: # 80% - modify message msg = f'mod,{id},abc,def,102' elif ran < 0.90: # 10% - display message msg = f'dis,{id},ghi,jkl,753' elif ran < 0.95: # 5% - delete message msg = f'del,{id},mno,pqr,42' else: # 5% - add message msg = f'add,{id},stu,vwx,-13' return msg # ------------------------------------------------------------------- # ---- main # ---- For testing, pick a randon message type for a # ---- randomly selected record ID # ------------------------------------------------------------------- if __name__ == '__main__': # ---- record IDs for test messages id_lst = [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ] mod_count = 0 dis_count = 0 del_count = 0 add_count = 0 unk_count = 0 for _ in range(1000): id = random.choice(id_lst) msg = generate_message(id) ##print(f'[{i:02}] {msg}') lst = msg.split(',',1) typ = lst[0].strip() if typ == 'mod': mod_count += 1 elif typ == 'dis': dis_count += 1 elif typ == 'del': del_count += 1 elif typ == 'add': add_count += 1 else: unk_count += 1 #---- display statistics, etc. total = mod_count + dis_count + del_count + add_count + unk_count print() print(f'mod count = {mod_count}') print(f'dis count = {dis_count}') print(f'del count = {del_count}') print(f'add count = {add_count}') print(f'unk count = {unk_count}') print(f'total = {total}') print()