Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql.cursors
- from read_file import *
- cnx = pymysql.connect(user='root', password='ptekm8n8', host='127.0.0.1', database='productdb')
- cursor = cnx.cursor()
- def sql_stuff(object):
- query = ('INSERT INTO company (time_capacity, company_name) VALUES (%s, "hej");')
- query1 = ('INSERT INTO productdb (name, unit_cost) VALUES (%s);')
- cursor.execute(query, (Max_timer))
- for i, u, k in zip(VO, Timer_pr_enhed, name):
- uquery = ('INSERT INTO productdb (unit_cost, time_produce_minutes, name) VALUES (%s, %s, %s);')
- cursor.execute(uquery, (i, u, k))
- for i, u in zip(Salgspris1, Afsat1):
- uquery = ('INSERT INTO productinfo (unit_value, amount, product_id) VALUES (%s, %s, 1);')
- cursor.execute(uquery, (i, u))
- for i, u in zip(Salgspris2, Afsat2):
- uquery = ('INSERT INTO productinfo (unit_value, amount, product_id) VALUES (%s, %s, 2);')
- cursor.execute(uquery, (i, u))
- def udregninger(object):
- DB1 = 0
- Time_product1 = 0
- for u, i in zip(Salgspris1, Afsat1):
- OMS = u * i
- OMK = VO[0] * i
- DB = OMS - OMK
- Time_product = i * Timer_pr_enhed[0]
- DB_pr_time = DB / Time_product
- Diff = (DB1 - DB) / (Time_product1 - Time_product)
- Hour = Time_product - Time_product1
- 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);')
- cursor.execute(uquery, (OMS, OMK, DB, Time_product, Diff, Hour, DB_pr_time))
- DB1 = DB
- Time_product1 = Time_product
- DB1 = 0
- Time_product1 = 0
- for u, i in zip(Salgspris2, Afsat2):
- OMS = u * i
- OMK = VO[1] * i
- DB = OMS - OMK
- Time_product = i * Timer_pr_enhed[1]
- DB_pr_time = DB / Time_product
- Hour = Time_product - Time_product1
- Diff = (DB1 - DB) / (Time_product1 - Time_product)
- 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);')
- cursor.execute(uquery, (OMS, OMK, DB, Time_product, Diff, Hour, DB_pr_time))
- DB1 = DB
- Time_product1 = Time_product
- def result(object):
- k = 1
- query = ('SELECT product_id, margin_pr_hour from product_data ORDER BY margin_pr_hour DESC')
- cursor.execute(query)
- for (product_id, margin_pr_hour) in cursor:
- print('ID = {}, DB pr time = {}'.format(product_id, margin_pr_hour), 'Prioritet', k)
- k += 1
- def reset_database(object):
- reset = ('SET FOREIGN_KEY_CHECKS = 0; truncate company; truncate product_data; truncate productdb; truncate productinfo; SET FOREIGN_KEY_CHECKS = 0; commit')
- cursor.execute(reset)
- reset_database(object)
- sql_stuff(object)
- udregninger(object)
- result(object)
- cnx.commit()
- cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement