Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. import pymysql.cursors
  2. from read_file import *
  3.  
  4.  
  5.  
  6.  
  7.  
  8. cnx = pymysql.connect(user='root', password='ptekm8n8', host='127.0.0.1', database='productdb')
  9. cursor = cnx.cursor()
  10.  
  11.  
  12.  
  13.  
  14. def sql_stuff(object):
  15.  
  16.  
  17. query = ('INSERT INTO company (time_capacity, company_name) VALUES (%s, "hej");')
  18. query1 = ('INSERT INTO productdb (name, unit_cost) VALUES (%s);')
  19.  
  20. cursor.execute(query, (Max_timer))
  21.  
  22.  
  23. for i, u, k in zip(VO, Timer_pr_enhed, name):
  24.  
  25. uquery = ('INSERT INTO productdb (unit_cost, time_produce_minutes, name) VALUES (%s, %s, %s);')
  26. cursor.execute(uquery, (i, u, k))
  27.  
  28. for i, u in zip(Salgspris1, Afsat1):
  29.  
  30. uquery = ('INSERT INTO productinfo (unit_value, amount, product_id) VALUES (%s, %s, 1);')
  31. cursor.execute(uquery, (i, u))
  32.  
  33. for i, u in zip(Salgspris2, Afsat2):
  34.  
  35. uquery = ('INSERT INTO productinfo (unit_value, amount, product_id) VALUES (%s, %s, 2);')
  36. cursor.execute(uquery, (i, u))
  37.  
  38. def udregninger(object):
  39.  
  40. DB1 = 0
  41. Time_product1 = 0
  42.  
  43. for u, i in zip(Salgspris1, Afsat1):
  44. OMS = u * i
  45. OMK = VO[0] * i
  46. DB = OMS - OMK
  47. Time_product = i * Timer_pr_enhed[0]
  48. DB_pr_time = DB / Time_product
  49.  
  50. Diff = (DB1 - DB) / (Time_product1 - Time_product)
  51. Hour = Time_product - Time_product1
  52. uquery = ('INSERT INTO product_data (Turnover, costs, margin, work_hours, difference_margin, difference_hours, margin_pr_hour, product_id) VALUES (%s, %s, %s, %s, %s, %s, %s, 1);')
  53. cursor.execute(uquery, (OMS, OMK, DB, Time_product, Diff, Hour, DB_pr_time))
  54. DB1 = DB
  55. Time_product1 = Time_product
  56.  
  57.  
  58. DB1 = 0
  59. Time_product1 = 0
  60.  
  61. for u, i in zip(Salgspris2, Afsat2):
  62. OMS = u * i
  63. OMK = VO[1] * i
  64. DB = OMS - OMK
  65. Time_product = i * Timer_pr_enhed[1]
  66. DB_pr_time = DB / Time_product
  67. Hour = Time_product - Time_product1
  68. Diff = (DB1 - DB) / (Time_product1 - Time_product)
  69.  
  70. uquery = ('INSERT INTO product_data (Turnover, costs, margin, work_hours, difference_margin, difference_hours, margin_pr_hour, product_id) VALUES (%s, %s, %s, %s, %s, %s, %s, 2);')
  71. cursor.execute(uquery, (OMS, OMK, DB, Time_product, Diff, Hour, DB_pr_time))
  72. DB1 = DB
  73. Time_product1 = Time_product
  74.  
  75. def result(object):
  76. k = 1
  77. query = ('SELECT product_id, margin_pr_hour from product_data ORDER BY margin_pr_hour DESC')
  78. cursor.execute(query)
  79. for (product_id, margin_pr_hour) in cursor:
  80. print('ID = {}, DB pr time = {}'.format(product_id, margin_pr_hour), 'Prioritet', k)
  81. k += 1
  82.  
  83.  
  84.  
  85. def reset_database(object):
  86.  
  87. reset = ('SET FOREIGN_KEY_CHECKS = 0; truncate company; truncate product_data; truncate productdb; truncate productinfo; SET FOREIGN_KEY_CHECKS = 0; commit')
  88. cursor.execute(reset)
  89.  
  90. reset_database(object)
  91. sql_stuff(object)
  92. udregninger(object)
  93. result(object)
  94.  
  95.  
  96.  
  97. cnx.commit()
  98. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement