Example #1
0
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]
Example #2
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..."
Example #3
0
def start():
    DELETE_MODE = "OFF"
    TARGET_DAYS = 70
    
    targetDay = KpiUtils.getTargetDayByDay(TARGET_DAYS)
    
    print "[DELETE_MODE]::::%s" % DELETE_MODE
    print "============================" 
    cleanUpTables(KpiMeta.targetTables, DELETE_MODE , targetDay)
#     cleanUpTables(KpiMeta.targetTablesWeekly, DELETE_MODE , targetDay)
#     cleanUpTables(KpiMeta.targetTablesMonthly, DELETE_MODE , targetDay)
#     cleanUpTables(KpiMeta.targetTablesYearly, DELETE_MODE , targetDay)
    
    KpiMeta.closeConnection(db)
def deleteRows(taret_date, version ):
    
    cql = """SELECT key, "Timestamp", "Version", "correlation_correlationId", payload_description, "payload_eventType"
        FROM com_cisco_bam_smartlocker_kpi
        WHERE "Timestamp" < %s AND "Version" = '%s' ALLOW FILTERING 
    """ % (KpiUtils.unix_time_millis(datetime.strptime(taret_date, '%Y-%m-%d %H:%M:%S')), version)
    
    rows = session.execute(cql)
   
    print "TOTAL ROWS : %d" % len(rows)
    print "--------------Selected keys--------------"
    
    for row in rows:
        print "%s, %s" %(row[0], 
                         datetime.fromtimestamp(int(row[1]/1000)).strftime('%Y-%m-%d %H:%M:%S'))
#         deleteRow(row[0])
    print "-------------------Done-------------------"
Example #5
0
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