Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/ewevu (20-Aug @ 00:08)

Syntax Highlighted Code

  1.  
  2. import uuid
  3. import time
  4. import random
  5.  
  6. importdir '/home/yourhomedir/imports'
  7.  
  8.  
  9. output_directory = importdir
  10. months_per_year = 12
  11. days_per_month = 30
  12. num_devices_per_client = 100
  13. channels_per_device = 12
  14.  
  15. def epoch_now_epoch():
  16.     return time.time()
  17.  
  18. def toEpochConverter(timestamp):
  19.     # see --> http://docs.python.org/library/time.html
  20.     return int(time.mktime(time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S +0000")))
  21.  
  22. def genEpochsFromRange(timestamp_range, seconds_increment=1):
  23.     """used for generating dummy EMAQ Entries"""
  24.     span = [toEpochConverter(item) for item in timestamp_range]
  25.     epoch_second = 1.0 # this calibrates seconds_increment to an epoch second
  26.     increment = seconds_increment * epoch_second
  27.     epoch_timespan = [toEpochConverter(item) for item in timestamp_range]
  28.     return [item for item in range(span[0], span[1], int(increment)) if item < span[1]]
  29.  
  30. def getFixedLengthTimeStamp():
  31.     return str(time.time())
  32.  
  33. chan_id_vals = [1,2,3,4,5,6,7,8,9,10,11,12]
  34. cust_id_vals = ['jbcnle', 'dukenrg', 'mgsinc', 'acmenrg', 'boronrg']
  35. active_nrg_vals = range(1000,12000)
  36. currentrms_vals = range(1,20)
  37. voltagerms_vals = range(1,500)
  38. totalnrg_vals = range(1,1000)
  39. reactivenrg_vals = range(1,1000)
  40. powerfactor_vals = range(1,2)
  41. board_id_vals = range(899,999)
  42.  
  43.  
  44. def clientDeviceIds(client):
  45.     ids = [ ]
  46.     for val in board_id_vals:
  47.         id = "MRK09CTST" + '_' + client + '_' + str(val)
  48.         ids.append(id)
  49.     return ids
  50.        
  51. def buildEntry( filename,
  52.                 client,
  53.                 device,
  54.                 num_devices_per_client=num_devices_per_client,
  55.                 channels_per_device=channels_per_device
  56.                ):
  57.  
  58.     chan_id_val     = str(random.choice(chan_id_vals))
  59.     cust_id_val     = str(random.choice(cust_id_vals))
  60.     active_nrg_val  = str(random.choice(active_nrg_vals))
  61.     currentrms_val  = str(random.choice(currentrms_vals))
  62.     voltagerms_val  = str(random.choice(voltagerms_vals))
  63.     totalnrg_val    = str( str(random.choice(totalnrg_vals)) )
  64.     data_format_val = '5'
  65.    
  66.     reactivenrg_val = str(str(random.choice(reactivenrg_vals)))
  67.     powerfactor_val = str( random.choice(powerfactor_vals) )
  68.    
  69.     root = ET.Element("MelrokEMAQ")
  70.     emu = ET.SubElement(root, "EMU")
  71.     board_id = ET.SubElement(emu, "BoardID")
  72.     board_id.text = device
  73.     customer_id = ET.SubElement(emu, "CustomerId")
  74.     customer_id.text = client
  75.     measurements = ET.SubElement(root, "Measurements")
  76.     #
  77.     current_channel = 1
  78.     #
  79.     while current_channel <= channels_per_device:
  80.         for val in range(0, channels_per_device):    
  81.             measurement = ET.SubElement(measurements, "Measurement")
  82.             measurement.set("channelId", str(val+1))
  83.             measurement.set("dataFormat", data_format_val)
  84.             timestamp = ET.SubElement(measurement, "Timestamp")
  85.             timestamp.text = getFixedLengthTimeStamp()
  86.             activenrg = ET.SubElement(measurement, "ActiveEnergy")
  87.             activenrg.text = active_nrg_val
  88.             currentrms = ET.SubElement(measurement, "CurrentRMS")
  89.             currentrms.text = currentrms_val
  90.             voltagerms = ET.SubElement(measurement, "VoltageRMS")
  91.             voltagerms.text = voltagerms_val
  92.             totalnrg = ET.SubElement(measurement, "TotalEnergy")
  93.             totalnrg.text = totalnrg_val
  94.             reactivenrg = ET.SubElement(measurement, "ReactiveEnergy")
  95.             reactivenrg.text = reactivenrg_val
  96.             powerfactor = ET.SubElement(measurement, "PowerFactor")
  97.             powerfactor.text = powerfactor_val
  98.             current_channel += 1
  99.  
  100.         tree = ET.ElementTree(root)
  101.         tree.write(filename)
  102.  
  103.        
  104. def createDummyData(timestamp_range, seconds_increment=1):
  105.     filecount = 0
  106.     for client in cust_id_vals:
  107.         print client
  108.         for device in clientDeviceIds(client):
  109.             epochs = genEpochsFromRange(timestamp_range, seconds_increment=seconds_increment)[:]
  110.             for epochstamp in epochs:
  111.                 filename = output_directory + str(epochstamp).replace('.', '') + client + '.xml'
  112.                 buildEntry(filename, client, device)
  113.                 filecount += 1
  114.     return filecount
  115.            
  116.  
  117. if __name__ == '__main__':
  118.     timestamp_range = ['Tue, 17 Aug 2010 07:00:00 +0000', 'Tue, 18 Aug 2010 07:00:00 +0000']
  119.     print createDummyData(timestamp_range, seconds_increment=15)
  120.  
  121. Plain Code
  122.  
  123. from xml.etree import ElementTree as ET
  124. import uuid
  125. import time
  126. import random
  127.  
  128. importdir '/home/yourhomedir/imports'
  129.  
  130.  
  131. output_directory = importdir
  132. months_per_year = 12
  133. days_per_month = 30
  134. num_devices_per_client = 100
  135. channels_per_device = 12
  136.  
  137. def epoch_now_epoch():
  138.     return time.time()
  139.  
  140. def toEpochConverter(timestamp):
  141.     # see --> http://docs.python.org/library/time.html
  142.     return int(time.mktime(time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S +0000")))
  143.  
  144. def genEpochsFromRange(timestamp_range, seconds_increment=1):
  145.     """used for generating dummy EMAQ Entries"""
  146.     span = [toEpochConverter(item) for item in timestamp_range]
  147.     epoch_second = 1.0 # this calibrates seconds_increment to an epoch second
  148.     increment = seconds_increment * epoch_second
  149.     epoch_timespan = [toEpochConverter(item) for item in timestamp_range]
  150.     return [item for item in range(span[0], span[1], int(increment)) if item < span[1]]
  151.  
  152. def getFixedLengthTimeStamp():
  153.     return str(time.time())
  154.  
  155. chan_id_vals = [1,2,3,4,5,6,7,8,9,10,11,12]
  156. cust_id_vals = ['jbcnle', 'dukenrg', 'mgsinc', 'acmenrg', 'boronrg']
  157. active_nrg_vals = range(1000,12000)
  158. currentrms_vals = range(1,20)
  159. voltagerms_vals = range(1,500)
  160. totalnrg_vals = range(1,1000)
  161. reactivenrg_vals = range(1,1000)
  162. powerfactor_vals = range(1,2)
  163. board_id_vals = range(899,999)
  164.  
  165.  
  166. def clientDeviceIds(client):
  167.     ids = [ ]
  168.     for val in board_id_vals:
  169.         id = "MRK09CTST" + '_' + client + '_' + str(val)
  170.         ids.append(id)
  171.     return ids
  172.        
  173. def buildEntry( filename,
  174.                 client,
  175.                 device,
  176.                 num_devices_per_client=num_devices_per_client,
  177.                 channels_per_device=channels_per_device
  178.                ):
  179.  
  180.     chan_id_val     = str(random.choice(chan_id_vals))
  181.     cust_id_val     = str(random.choice(cust_id_vals))
  182.     active_nrg_val  = str(random.choice(active_nrg_vals))
  183.     currentrms_val  = str(random.choice(currentrms_vals))
  184.     voltagerms_val  = str(random.choice(voltagerms_vals))
  185.     totalnrg_val    = str( str(random.choice(totalnrg_vals)) )
  186.     data_format_val = '5'
  187.    
  188.     reactivenrg_val = str(str(random.choice(reactivenrg_vals)))
  189.     powerfactor_val = str( random.choice(powerfactor_vals) )
  190.    
  191.     root = ET.Element("MelrokEMAQ")
  192.     emu = ET.SubElement(root, "EMU")
  193.     board_id = ET.SubElement(emu, "BoardID")
  194.     board_id.text = device
  195.     customer_id = ET.SubElement(emu, "CustomerId")
  196.     customer_id.text = client
  197.     measurements = ET.SubElement(root, "Measurements")
  198.     #
  199.     current_channel = 1
  200.     #
  201.     while current_channel <= channels_per_device:
  202.         for val in range(0, channels_per_device):    
  203.             measurement = ET.SubElement(measurements, "Measurement")
  204.             measurement.set("channelId", str(val+1))
  205.             measurement.set("dataFormat", data_format_val)
  206.             timestamp = ET.SubElement(measurement, "Timestamp")
  207.             timestamp.text = getFixedLengthTimeStamp()
  208.             activenrg = ET.SubElement(measurement, "ActiveEnergy")
  209.             activenrg.text = active_nrg_val
  210.             currentrms = ET.SubElement(measurement, "CurrentRMS")
  211.             currentrms.text = currentrms_val
  212.             voltagerms = ET.SubElement(measurement, "VoltageRMS")
  213.             voltagerms.text = voltagerms_val
  214.             totalnrg = ET.SubElement(measurement, "TotalEnergy")
  215.             totalnrg.text = totalnrg_val
  216.             reactivenrg = ET.SubElement(measurement, "ReactiveEnergy")
  217.             reactivenrg.text = reactivenrg_val
  218.             powerfactor = ET.SubElement(measurement, "PowerFactor")
  219.             powerfactor.text = powerfactor_val
  220.             current_channel += 1
  221.  
  222.         tree = ET.ElementTree(root)
  223.         tree.write(filename)
  224.  
  225.        
  226. def createDummyData(timestamp_range, seconds_increment=1):
  227.     filecount = 0
  228.     for client in cust_id_vals:
  229.         print client
  230.         for device in clientDeviceIds(client):
  231.             epochs = genEpochsFromRange(timestamp_range, seconds_increment=seconds_increment)[:]
  232.             for epochstamp in epochs:
  233.                 filename = output_directory + str(epochstamp).replace('.', '') + client + '.xml'
  234.                 buildEntry(filename, client, device)
  235.                 filecount += 1
  236.     return filecount
  237.            
  238.  
  239. if __name__ == '__main__':
  240.     timestamp_range = ['Tue, 17 Aug 2010 07:00:00 +0000', 'Tue, 18 Aug 2010 07:00:00 +0000']
  241.     print createDummyData(timestamp_range, seconds_increment=15)
  242.  
  243. Permalink: http://codedumper.com/ejemi#109
  244.  

Plain Code


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

Codedump Run

Permalink: http://codedumper.com/ewevu