Facebook
From Ivory Terrapin, 4 Years ago, written in Python.
This paste is a reply to Untitled from Obese Mosquito - go back
Embed
Viewing differences between Untitled and Re: Untitled
\nimport json
import math
from bottle import get, post, run, template, request


class Summary:
    def __init__(self, template):
        self.CUTTING = 1


class Costs:
    def __init__(self, template):
        self.CUTTING = 1
        self.GLUING = 2.5
        self.currency = 'zl'
        self.template = template

    def costOfGluing(self):
        return (math.ceil(float(self.template.sumGlue() / float(1000)))*self.GLUING)


class FurnitureBoard:
    def __init__(self):
        self.width = 2800
        self.height = 2070
        self.weight = 7.3
        self.area = self.width * self.height
        self.thickness = 18


class RawTemplate:
    def __init__(self, id, width, height, unit, veneer):
        self.id = id
        if(unit == 'cm'):
            self.width = int(width * 10)
            self.height = int(height * 10)
            self.unit = 'mm'
        else:
            self.width = int(width)
            self.height = int(height)
            self.unit = unit
        self.area = self.width * self.height
        self.glues = []
        self.sumOfSides = 2 * self.width + 2 * self.height
        self.areaWithWaste = float(1.1 * self.area)

        if veneer["top"] == True:
            self.glues.append(self.width)
        if veneer["left"] == True:
            self.glues.append(self.height)
        if veneer["bottom"] == True:
            self.glues.append(self.width)
        if veneer["right"] == True:
            self.glues.append(self.height)

    def sumGlue(self):
        return int(sum(self.glues))

    def __str__(self):
        return '''---------------
        Id: {}
        Height: {}
        Width: {}
        Unit: {}
        Glue: {}
        Area: {}\n'''.{}n'''.format(self.id, self.height, self.width, self.unit, self.glues, self.area)


@post('/api/save/order')
def save_order():

    order = request.json
    # create user detail variable
    firstName = order['firstName']
    lastName = order['lastName']

    # table that contain areas for each template
    areas = []
    # contains  border lenghts which will be taped
    border = []

    sumGlues = []
    # container for templates objects
    templates = []

    for p in order['templates']:
        template = RawTemplate(p['id'], p['width'],
                               p['height'], p['unit'], p['veneer'])
        templates.append(template)
        cost = Costs(template)
        # get area form thah template which is calculated in object
        area = template.area
        # adding area of that template to table
        areas.append(area)
        # add sum of border which will be taped on that template
        sumGlues.append(template.sumGlue())
        # print("Venree cost: " +
        #       str(int(math.ceil(float(template.sumOfSides / float(1000))))))
        print("Venree cost: " + str(cost.costOfGluing()))

    # summary value of each templte areas
    furnitureBoard = FurnitureBoard()
    sumOfAreas = float(sum(areas))
    areasWithWaste = sumOfAreas * 1.1
    boardToBuy = math.ceil(float(areasWithWaste / float(furnitureBoard.area)))
    summaryWeight = boardToBuy * furnitureBoard.weight

    print(areas)
    print("Sum of areas including waste: " + str(sumOfAreas))
    print(furnitureBoard.area)
    print(float(sumOfAreas / float(furnitureBoard.area)))
    print()
    for o in templates:
        print(o)

    with open("order.json", "w") as json_file:
        json.dump(order, json_file)


run(host='localhost', port=3000)