File size: 4,126 Bytes
6bc379e
9c306e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bc379e
9c306e9
 
 
 
 
 
 
 
 
 
 
 
 
 
6bc379e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Editable Word equations with compact legends for cost and depreciation."""
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Pt, RGBColor

from .formatters.paragraph import criar_paragrafo_formatado


def _run(text, variable=False):
    run = OxmlElement('m:r')
    props = OxmlElement('m:rPr')
    style = OxmlElement('m:sty'); style.set(qn('m:val'), 'i' if variable else 'p')
    props.append(style); run.append(props)
    font_props = OxmlElement('w:rPr')
    font = OxmlElement('w:rFonts')
    font.set(qn('w:ascii'), 'Cambria Math'); font.set(qn('w:hAnsi'), 'Cambria Math')
    font_props.append(font)
    size = OxmlElement('w:sz'); size.set(qn('w:val'), '28'); font_props.append(size)
    run.append(font_props)
    value = OxmlElement('m:t'); value.text = text
    value.set(qn('xml:space'), 'preserve'); run.append(value)
    return run


def _fraction(numerator, denominator):
    fraction = OxmlElement('m:f')
    for name, children in [('num', numerator), ('den', denominator)]:
        node = OxmlElement('m:' + name)
        for child in children: node.append(child)
        fraction.append(node)
    return fraction


def _script(kind, base, script):
    node = OxmlElement('m:' + kind)
    for name, child in [('e', base), ('sup' if kind=='sSup' else 'sub', script)]:
        content = OxmlElement('m:' + name); content.append(child); node.append(content)
    return node


def _formula_blocks(doc, formulas):
    for index,(elements, legend) in enumerate(formulas):
        paragraph = doc.add_paragraph()
        paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
        paragraph.paragraph_format.space_before = Pt(10)
        paragraph.paragraph_format.space_after = Pt(4)
        paragraph.paragraph_format.keep_with_next = True
        paragraph.paragraph_format.keep_together = True
        math = OxmlElement('m:oMath')
        for element in elements: math.append(element)
        paragraph._p.append(math)
        note = criar_paragrafo_formatado(doc,legend,tamanho=8,cor=RGBColor(70,70,70),
                                        alinhamento=WD_ALIGN_PARAGRAPH.LEFT,espaco_depois=8)
        note.paragraph_format.keep_together = True
        note.paragraph_format.keep_with_next = index < len(formulas)-1


def cost_equations(doc):
    _formula_blocks(doc,[
        ([_run('CUNIT'),_run(' = '),_run('CUB'),_run(' × '),
          _fraction([_run('% CUB')],[_run('100')])],
         'CUNIT: custo unitário após a adequação (R$/m²); CUB: custo unitário básico histórico (R$/m²); % CUB: percentual de adequação aplicado ao CUB.'),
        ([_run('VC'),_run(' = '),_run('A',True),_run(' × '),_run('CUNIT'),_run(' × (1 + '),
          _fraction([_run('BDI')],[_run('100')]),_run(') × '),_script('sSub',_run('K',True),_run('d',True))],
         'VC: valor da construção após a depreciação (R$); A: área de cálculo (m²); CUNIT: custo unitário após a adequação (R$/m²); BDI: benefícios e despesas indiretas, em percentual; Kd: fator remanescente com consideração do valor residual.'),
    ])


def depreciation_equations(doc):
    formulas = [
        ([_run('Ross',True), _run(' = '), _fraction([_run('q',True), _run(' + '), _script('sSup',_run('q',True),_run('2'))],[_run('2')])],
         'Ross: parcela de depreciação associada à idade; q: fração de vida útil consumida, obtida dividindo o percentual de vida útil consumida por 100.'),
        ([_run('K',True),_run(' = 1 − (1 − '),_run('Ross',True),_run(') × (1 − '),_run('H',True),_run(')')],
         'K: coeficiente de depreciação de Ross-Heidecke; H: coeficiente correspondente ao estado de conservação adotado.'),
        ([_script('sSub',_run('K',True),_run('d',True)),_run(' = '),_run('R',True),_run(' + (1 − '),_run('K',True),_run(') × (1 − '),_run('R',True),_run(')')],
         'Kd: fator remanescente aplicado ao custo de reedição, com consideração do valor residual; R: valor residual em forma decimal (percentual ÷ 100); K: coeficiente de depreciação.'),
    ]
    _formula_blocks(doc,formulas)