Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.72 KB | None | 0 0
  1. import os
  2. import psycopg2
  3. import time
  4.  
  5. def copyDB(countCashBox):
  6.     db_host = 'localhost'
  7.     db_name = 'down'
  8.     db_user = 'postgres'
  9.     db_password = '1'
  10.     dsn = "host={} dbname={} user={} password={}".format(db_host, db_name, db_user, db_password)
  11.     conn = psycopg2.connect(dsn)
  12.     cur = conn.cursor()
  13.     delete_product = "delete from product_pos_{}"
  14.     delete_barcode = "delete from barcode_pos_{}"
  15.     delete_price = "delete from price_pos_{}"
  16.     delete_inventorycount = "delete from inventorycount_pos_{}"
  17.     update_product = "copy product_pos_{} from '/home/tester/fm/query/1' using delimiters ','"
  18.     update_barcode = "update barcode_pos_{}  set modified  = 1"
  19.     update_inventorycount = "update inventorycount_pos_{}  set modified  = 1"
  20.     update_price = "update price_pos_{}  set modified  = 1"
  21.     cur.execute("Begin;")
  22.     start_time = time.time()
  23.     for i in range(1, countCashBox + 1):
  24.         cur.execute(delete_product.format(i))
  25.         cur.execute(delete_barcode.format(i))
  26.         cur.execute(delete_price.format(i))
  27.         cur.execute(delete_inventorycount.format(i))
  28.         cur.execute(update_product.format(i))
  29.         cur.execute(update_barcode.format(i))
  30.         cur.execute(update_price.format(i))
  31.         cur.execute(update_inventorycount.format(i))
  32.     cur.execute("COMMIT;") 
  33.     print 'Time to update DB '
  34.     print time.time() - start_time
  35.     cur.close()
  36.     conn.close()
  37.    
  38. def startServer():
  39.     os.system("pkill FmService")
  40.     os.system("/home/tester/fm/FmService 2>/dev/null &")
  41.     print 'FmServer Started'
  42. def stopServer():
  43.     os.system("pkill FmService")   
  44.  
  45. def startFakepos(countCashBox):
  46.     os.system("sshpass -p '1' ssh tester@192.168.63.122 '/home/tester/tools/fakepossd/start_ssd %s'" %countCashBox)
  47.  
  48. def stopFakepos():
  49.     os.system("sshpass -p '1' ssh tester@192.168.63.122 'pkill fakepossd'")
  50.  
  51. def countSelles(countCashBox):
  52.     db_host = 'localhost'
  53.     db_name = 'down'
  54.     db_user = 'postgres'
  55.     db_password = '1'
  56.     file = 'result'
  57.     my_file = open(file, 'a')
  58.     dsn = "host={} dbname={} user={} password={}".format(db_host, db_name, db_user, db_password)
  59.     conn = psycopg2.connect(dsn)
  60.     cur = conn.cursor()
  61.     select_product = "select count(*) from product_pos_{} where  modified  = 0"
  62.     select_barcode = "select count(*) from  barcode_pos_{} where  modified  = 0"
  63.     select_inventorycount = "select count(*)from  inventorycount_pos_{} where  modified  = 0"
  64.     select_price = "select count(*) from price_pos_{}  where  modified  = 0"
  65.     cur.execute("Begin;")
  66.     start_time = time.time()
  67.     count_row_product = 0
  68.     count_row_barcode = 0
  69.     count_row_price = 0
  70.     count_row_inventorycount = 0
  71.     for i in range(1, countCashBox + 1):
  72.         cur.execute(select_product.format(i))
  73.         count_row_product +=  int(cur.fetchone()[0])
  74.         cur.execute(select_barcode.format(i))
  75.         count_row_barcode +=  int(cur.fetchone()[0])
  76.         cur.execute(select_price.format(i))
  77.         count_row_price +=  int(cur.fetchone()[0])
  78.         cur.execute(select_inventorycount.format(i))
  79.         count_row_inventorycount +=  int(cur.fetchone()[0])
  80.     cur.execute("COMMIT;") 
  81.     print 'Time to count row'
  82.     print time.time() - start_time
  83.     cur.close()
  84.     conn.close()
  85.     my_file.write('loop N {}\n'.format(str(countCashBox)))
  86.     my_file.write('{:.5} Mb \n'.format(str(count_row_product * 1.82 / 1024 + count_row_barcode * 0.24 / 1024 + count_row_price * 0.24 / 1024 + count_row_inventorycount * 0.19 / 1024)))
  87.     my_file.write('{0} products \n{1} barcode \n{2} price \n{3} inventorycount \n'.format(str(count_row_product), str(count_row_barcode), str(count_row_price), str(count_row_inventorycount)))
  88.     my_file.close
  89.  
  90.    
  91. cashboxlist = [200, 500, 1000]
  92.  
  93. stopServer()
  94. stopFakepos()
  95. for element in cashboxlist:
  96.     print ('Cashbox N {}'.format(str(element)))
  97.     copyDB(element)
  98.     startServer()
  99.     startFakepos(element)
  100.     time.sleep(3600)
  101.     stopFakepos()
  102.     stopServer()
  103.     countSelles(element)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement