Facebook
From Ivory Terrapin, 4 Years ago, written in Python.
This paste is a reply to Untitled from Obese Mosquito - view diff
Embed
Download Paste or View Raw
Hits: 261
  1. import json
  2. import math
  3. from bottle import get, post, run, template, request
  4.  
  5.  
  6. class Summary:
  7.     def __init__(self, template):
  8.         self.CUTTING = 1
  9.  
  10.  
  11. class Costs:
  12.     def __init__(self, template):
  13.         self.CUTTING = 1
  14.         self.GLUING = 2.5
  15.         self.currency = 'zl'
  16.         self.template = template
  17.  
  18.     def costOfGluing(self):
  19.         return (math.ceil(float(self.template.sumGlue() / float(1000)))*self.GLUING)
  20.  
  21.  
  22. class FurnitureBoard:
  23.     def __init__(self):
  24.         self.width = 2800
  25.         self.height = 2070
  26.         self.weight = 7.3
  27.         self.area = self.width * self.height
  28.         self.thickness = 18
  29.  
  30.  
  31. class RawTemplate:
  32.     def __init__(self, id, width, height, unit, veneer):
  33.         self.id = id
  34.         if(unit == 'cm'):
  35.             self.width = int(width * 10)
  36.             self.height = int(height * 10)
  37.             self.unit = 'mm'
  38.         else:
  39.             self.width = int(width)
  40.             self.height = int(height)
  41.             self.unit = unit
  42.         self.area = self.width * self.height
  43.         self.glues = []
  44.         self.sumOfSides = 2 * self.width + 2 * self.height
  45.         self.areaWithWaste = float(1.1 * self.area)
  46.  
  47.         if veneer["top"] == True:
  48.             self.glues.append(self.width)
  49.         if veneer["left"] == True:
  50.             self.glues.append(self.height)
  51.         if veneer["bottom"] == True:
  52.             self.glues.append(self.width)
  53.         if veneer["right"] == True:
  54.             self.glues.append(self.height)
  55.  
  56.     def sumGlue(self):
  57.         return int(sum(self.glues))
  58.  
  59.     def __str__(self):
  60.         return '''---------------
  61.        Id: {}
  62.        Height: {}
  63.        Width: {}
  64.        Unit: {}
  65.        Glue: {}
  66.        Area: {}n'''.format(self.id, self.height, self.width, self.unit, self.glues, self.area)
  67.  
  68.  
  69. @post('/api/save/order')
  70. def save_order():
  71.  
  72.     order = request.json
  73.     # create user detail variable
  74.     firstName = order['firstName']
  75.     lastName = order['lastName']
  76.  
  77.     # table that contain areas for each template
  78.     areas = []
  79.     # contains  border lenghts which will be taped
  80.     border = []
  81.  
  82.     sumGlues = []
  83.     # container for templates objects
  84.     templates = []
  85.  
  86.     for p in order['templates']:
  87.         template = RawTemplate(p['id'], p['width'],
  88.                                p['height'], p['unit'], p['veneer'])
  89.         templates.append(template)
  90.         cost = Costs(template)
  91.         # get area form thah template which is calculated in object
  92.         area = template.area
  93.         # adding area of that template to table
  94.         areas.append(area)
  95.         # add sum of border which will be taped on that template
  96.         sumGlues.append(template.sumGlue())
  97.         # print("Venree cost: " +
  98.         #       str(int(math.ceil(float(template.sumOfSides / float(1000))))))
  99.         print("Venree cost: " + str(cost.costOfGluing()))
  100.  
  101.     # summary value of each templte areas
  102.     furnitureBoard = FurnitureBoard()
  103.     sumOfAreas = float(sum(areas))
  104.     areasWithWaste = sumOfAreas * 1.1
  105.     boardToBuy = math.ceil(float(areasWithWaste / float(furnitureBoard.area)))
  106.     summaryWeight = boardToBuy * furnitureBoard.weight
  107.  
  108.     print(areas)
  109.     print("Sum of areas including waste: " + str(sumOfAreas))
  110.     print(furnitureBoard.area)
  111.     print(float(sumOfAreas / float(furnitureBoard.area)))
  112.     print()
  113.     for o in templates:
  114.         print(o)
  115.  
  116.     with open("order.json", "w") as json_file:
  117.         json.dump(order, json_file)
  118.  
  119.  
  120. run(host='localhost', port=3000)
  121.