-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvert.html
102 lines (82 loc) · 2.83 KB
/
convert.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<h2>Convert heatloss.js export to SAP.js data</h2>
<p>Paste heatloss.js export:</p>
<textarea id="heatlossjs-data" style="width:800px; height:300px">
</textarea>
<br><br>
<button id="convert">Convert</button>
<br><br>
<p>SAP.js data:</p>
<textarea id="sapjs-data" style="width:800px; height:300px">
</textarea>
<script>
var sap = {};
$.getJSON( "openBEM/blank.json?v=1", function( result ) {
sap = result;
$("#sapjs-data").html(JSON.stringify(sap, null, 2))
});
$("#convert").click(function(){
var heatlossjsdata = JSON.parse($("#heatlossjs-data").val());
sap.fabric.library = {}
for (var name in heatlossjsdata.element_type) {
if (name.toLowerCase().includes("loft")) {
sap.fabric.library[name] = {
type: "loft",
uvalue: heatlossjsdata.element_type[name].uvalue,
kvalue: 50
}
}
else if (name.toLowerCase().includes("floor")) {
sap.fabric.library[name] = {
type: "floor",
uvalue: heatlossjsdata.element_type[name].uvalue,
kvalue: 110
}
}
else if (name.toLowerCase().includes("wall")) {
sap.fabric.library[name] = {
type: "wall",
uvalue: heatlossjsdata.element_type[name].uvalue,
kvalue: 150
}
}
else if (name.toLowerCase().includes("glazing") || name.toLowerCase().includes("window") || name.toLowerCase().includes("door")) {
sap.fabric.library[name] = {
type: "window",
uvalue: heatlossjsdata.element_type[name].uvalue,
kvalue: 0,
g: 0.76,
gL: 0.8,
ff: 0.7
}
}
else {
sap.fabric.library[name] = {
type: "wall",
uvalue: heatlossjsdata.element_type[name].uvalue,
kvalue: 150
}
}
}
var id = 1;
for (var room in heatlossjsdata.rooms) {
for (var elementIndex in heatlossjsdata.rooms[room].elements) {
var element = heatlossjsdata.rooms[room].elements[elementIndex];
if (element.boundary=="external" || element.boundary=="ground" || element.boundary=="unheated") {
sap.fabric.elements.push({
"id": ucfirst(room)+" "+element.orientation+" e"+elementIndex,
"lib": element.type,
"l": element.width,
"h": element.height
});
}
id ++;
}
}
$("#sapjs-data").html(JSON.stringify(sap, null, 2))
});
function ucfirst(s)
{
return s && s[0].toUpperCase() + s.slice(1);
}
</script>