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

Replies to Untitled rss

Title Name Language When
Re: Untitled Ivory Terrapin python 4 Years ago.