def insertData(): retainTime = random.randint(1000,9999) overallAvgRetainedTime = random.randint(1000,9999) # tradsactionDate = randomDate("1/1/2015 1:30 PM", "3/1/2015 4:50 AM", random.random()) tradsactionDate = KpiUtils.getRandomDate("2015-1-1 1:30:00", "2015-3-28 1:30:00", random.random()) site = 'site' + str(random.randint(1,5)) bank = 'bank' + str(random.randint(1,2)) print "retainTime::: %d" % retainTime print "overallAvgRetainedTime::: %d" % overallAvgRetainedTime print "tradsactionDate::: %s" % tradsactionDate # Prepare SQL query to INSERT a record into the database. sql = """INSERT INTO kpi_capacity_utilization_retained_period_vs_all(avgRetainedTime, overallAvgRetainedTime, transactionDate, site, bank) VALUES (%d, %d, '%s', '%s', '%s' )""" % (retainTime, overallAvgRetainedTime, tradsactionDate, site, bank) print sql try: # Execute the SQL command # cursor.execute(sql) # Commit your changes in the database # db.commit() print "Insert completed" except: # Rollback in case there is any error db.rollback() print "Insert failed, Reason : %s" % sys.exc_info()[0]
def insertData(): correlationId = random.randint(100000,999999) tempDate = KpiUtils.getRandomDate("2015-1-1 1:30:00", "2015-3-28 1:30:00", random.random()) tradsactionDate = KpiUtils.unix_time_millis(datetime.strptime(tempDate, '%Y-%m-%d %H:%M:%S')) event = random.choice(eventList) key ="%d:::%d" %(tradsactionDate, random.randint(0,999999)) cql = """ insert into com_cisco_bam_smartlocker_kpi (key, "Timestamp", "Version", "correlation_correlationId", payload_description, "payload_eventType") values ('%s', %s, '%s', '%s', '%s', %s) """ % (key, tradsactionDate, "2.0.0",correlationId, event.event_description, event.eventType) print cql session.execute(cql) print "insert completed..."
import random import sys from common import KpiUtils from datetime import datetime class Event: def __init__(self, event_description, eventType): self.event_description = event_description self.eventType = eventType eventList = [] eventList.append(Event("EMPLOYEE_LOGIN", 30)) eventList.append(Event("EMPLOYEE_LOGOUT", 31)) eventList.append(Event("EMPLOYEE_DEPOSIT", 32)) eventList.append(Event("EMPLOYEE_RETRIEVAL", 33)) eventList.append(Event("CUSTOMER_DEPOSIT", 34)) eventList.append(Event("CUSTOMER_RETRIEVAL", 35)) correlationId = random.randint(100000,999999) tempDate = KpiUtils.getRandomDate("2015-1-1 1:30:00", "2015-3-28 1:30:00", random.random()) tradsactionDate = KpiUtils.unix_time_millis(datetime.strptime(tempDate, '%Y-%m-%d %H:%M:%S')) event = random.choice(eventList) print correlationId print tradsactionDate print event.event_description print event.eventType