import uuid import time import random importdir '/home/yourhomedir/imports' output_directory = importdir months_per_year = 12 days_per_month = 30 num_devices_per_client = 100 channels_per_device = 12 def epoch_now_epoch(): return time.time() def toEpochConverter(timestamp): # see --> http://docs.python.org/library/time.html return int(time.mktime(time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S +0000"))) def genEpochsFromRange(timestamp_range, seconds_increment=1): """used for generating dummy EMAQ Entries""" span = [toEpochConverter(item) for item in timestamp_range] epoch_second = 1.0 # this calibrates seconds_increment to an epoch second increment = seconds_increment * epoch_second epoch_timespan = [toEpochConverter(item) for item in timestamp_range] return [item for item in range(span[0], span[1], int(increment)) if item < span[1]] def getFixedLengthTimeStamp(): return str(time.time()) chan_id_vals = [1,2,3,4,5,6,7,8,9,10,11,12] cust_id_vals = ['jbcnle', 'dukenrg', 'mgsinc', 'acmenrg', 'boronrg'] active_nrg_vals = range(1000,12000) currentrms_vals = range(1,20) voltagerms_vals = range(1,500) totalnrg_vals = range(1,1000) reactivenrg_vals = range(1,1000) powerfactor_vals = range(1,2) board_id_vals = range(899,999) def clientDeviceIds(client): ids = [ ] for val in board_id_vals: id = "MRK09CTST" + '_' + client + '_' + str(val) ids.append(id) return ids def buildEntry( filename, client, device, num_devices_per_client=num_devices_per_client, channels_per_device=channels_per_device ): chan_id_val = str(random.choice(chan_id_vals)) cust_id_val = str(random.choice(cust_id_vals)) active_nrg_val = str(random.choice(active_nrg_vals)) currentrms_val = str(random.choice(currentrms_vals)) voltagerms_val = str(random.choice(voltagerms_vals)) totalnrg_val = str( str(random.choice(totalnrg_vals)) ) data_format_val = '5' reactivenrg_val = str(str(random.choice(reactivenrg_vals))) powerfactor_val = str( random.choice(powerfactor_vals) ) root = ET.Element("MelrokEMAQ") emu = ET.SubElement(root, "EMU") board_id = ET.SubElement(emu, "BoardID") board_id.text = device customer_id = ET.SubElement(emu, "CustomerId") customer_id.text = client measurements = ET.SubElement(root, "Measurements") # current_channel = 1 # while current_channel <= channels_per_device: for val in range(0, channels_per_device): measurement = ET.SubElement(measurements, "Measurement") measurement.set("channelId", str(val+1)) measurement.set("dataFormat", data_format_val) timestamp = ET.SubElement(measurement, "Timestamp") timestamp.text = getFixedLengthTimeStamp() activenrg = ET.SubElement(measurement, "ActiveEnergy") activenrg.text = active_nrg_val currentrms = ET.SubElement(measurement, "CurrentRMS") currentrms.text = currentrms_val voltagerms = ET.SubElement(measurement, "VoltageRMS") voltagerms.text = voltagerms_val totalnrg = ET.SubElement(measurement, "TotalEnergy") totalnrg.text = totalnrg_val reactivenrg = ET.SubElement(measurement, "ReactiveEnergy") reactivenrg.text = reactivenrg_val powerfactor = ET.SubElement(measurement, "PowerFactor") powerfactor.text = powerfactor_val current_channel += 1 tree = ET.ElementTree(root) tree.write(filename) def createDummyData(timestamp_range, seconds_increment=1): filecount = 0 for client in cust_id_vals: print client for device in clientDeviceIds(client): epochs = genEpochsFromRange(timestamp_range, seconds_increment=seconds_increment)[:] for epochstamp in epochs: filename = output_directory + str(epochstamp).replace('.', '') + client + '.xml' buildEntry(filename, client, device) filecount += 1 return filecount if __name__ == '__main__': timestamp_range = ['Tue, 17 Aug 2010 07:00:00 +0000', 'Tue, 18 Aug 2010 07:00:00 +0000'] print createDummyData(timestamp_range, seconds_increment=15) Plain Code from xml.etree import ElementTree as ET import uuid import time import random importdir '/home/yourhomedir/imports' output_directory = importdir months_per_year = 12 days_per_month = 30 num_devices_per_client = 100 channels_per_device = 12 def epoch_now_epoch(): return time.time() def toEpochConverter(timestamp): # see --> http://docs.python.org/library/time.html return int(time.mktime(time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S +0000"))) def genEpochsFromRange(timestamp_range, seconds_increment=1): """used for generating dummy EMAQ Entries""" span = [toEpochConverter(item) for item in timestamp_range] epoch_second = 1.0 # this calibrates seconds_increment to an epoch second increment = seconds_increment * epoch_second epoch_timespan = [toEpochConverter(item) for item in timestamp_range] return [item for item in range(span[0], span[1], int(increment)) if item < span[1]] def getFixedLengthTimeStamp(): return str(time.time()) chan_id_vals = [1,2,3,4,5,6,7,8,9,10,11,12] cust_id_vals = ['jbcnle', 'dukenrg', 'mgsinc', 'acmenrg', 'boronrg'] active_nrg_vals = range(1000,12000) currentrms_vals = range(1,20) voltagerms_vals = range(1,500) totalnrg_vals = range(1,1000) reactivenrg_vals = range(1,1000) powerfactor_vals = range(1,2) board_id_vals = range(899,999) def clientDeviceIds(client): ids = [ ] for val in board_id_vals: id = "MRK09CTST" + '_' + client + '_' + str(val) ids.append(id) return ids def buildEntry( filename, client, device, num_devices_per_client=num_devices_per_client, channels_per_device=channels_per_device ): chan_id_val = str(random.choice(chan_id_vals)) cust_id_val = str(random.choice(cust_id_vals)) active_nrg_val = str(random.choice(active_nrg_vals)) currentrms_val = str(random.choice(currentrms_vals)) voltagerms_val = str(random.choice(voltagerms_vals)) totalnrg_val = str( str(random.choice(totalnrg_vals)) ) data_format_val = '5' reactivenrg_val = str(str(random.choice(reactivenrg_vals))) powerfactor_val = str( random.choice(powerfactor_vals) ) root = ET.Element("MelrokEMAQ") emu = ET.SubElement(root, "EMU") board_id = ET.SubElement(emu, "BoardID") board_id.text = device customer_id = ET.SubElement(emu, "CustomerId") customer_id.text = client measurements = ET.SubElement(root, "Measurements") # current_channel = 1 # while current_channel <= channels_per_device: for val in range(0, channels_per_device): measurement = ET.SubElement(measurements, "Measurement") measurement.set("channelId", str(val+1)) measurement.set("dataFormat", data_format_val) timestamp = ET.SubElement(measurement, "Timestamp") timestamp.text = getFixedLengthTimeStamp() activenrg = ET.SubElement(measurement, "ActiveEnergy") activenrg.text = active_nrg_val currentrms = ET.SubElement(measurement, "CurrentRMS") currentrms.text = currentrms_val voltagerms = ET.SubElement(measurement, "VoltageRMS") voltagerms.text = voltagerms_val totalnrg = ET.SubElement(measurement, "TotalEnergy") totalnrg.text = totalnrg_val reactivenrg = ET.SubElement(measurement, "ReactiveEnergy") reactivenrg.text = reactivenrg_val powerfactor = ET.SubElement(measurement, "PowerFactor") powerfactor.text = powerfactor_val current_channel += 1 tree = ET.ElementTree(root) tree.write(filename) def createDummyData(timestamp_range, seconds_increment=1): filecount = 0 for client in cust_id_vals: print client for device in clientDeviceIds(client): epochs = genEpochsFromRange(timestamp_range, seconds_increment=seconds_increment)[:] for epochstamp in epochs: filename = output_directory + str(epochstamp).replace('.', '') + client + '.xml' buildEntry(filename, client, device) filecount += 1 return filecount if __name__ == '__main__': timestamp_range = ['Tue, 17 Aug 2010 07:00:00 +0000', 'Tue, 18 Aug 2010 07:00:00 +0000'] print createDummyData(timestamp_range, seconds_increment=15) Permalink: http://codedumper.com/ejemi#109