testingAPIValues.js 5.58 KB
Newer Older
JOE Thunyathep S's avatar
update  
JOE Thunyathep S committed
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
function test() {
    var request = new XMLHttpRequest();
    request.open("GET", "test/response.json", false);
    request.send(null)
    var data = JSON.parse(request.responseText);
    //alert (my_JSON_object);

    var buildingsMAP = new Map()

    data.buildings.forEach(bu => {

        var partsArray = []
        var surefacesArray = []

        bu.parts.forEach(p =>
            p.surfaces.forEach(s =>
                surefacesArray.push(new Surface(s.id,
                    s.attributes.uValue))))

        bu.parts.forEach(p => partsArray.push(new Part(p.id,
            surefacesArray,
            p.attributes.volume,
            p.attributes.height,
            p.attributes.heatedVolume,
            p.attributes.yearOfConstruction,
            p.attributes.buildingFunction,
            p.attributes.monthlyHeating,
            p.attributes.monthlyCooling)))

30
        buildingsMAP.set(bu.id, new Building(bu.id, partsArray)) //puts buildings with parts and surfaces in a map
JOE Thunyathep S's avatar
update  
JOE Thunyathep S committed
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
103
104
105
106

    })

    var partHeightMAP = new Map()
    var partHeatedVolumeMAP = new Map()
    var partConstructionYearMAP = new Map()
    var partBuildingTypeMAP = new Map()
    var partMonthlyHeatingMAP = new Map()
    var partMonthlyCoolingMAP = new Map()
    var surfaceUValueMAP = new Map()

    //fill height, heated volume and construction year map
    buildingsMAP.forEach(b => {
        b.parts.forEach(part => {
            if (part.height !== undefined) {
                partHeightMAP.set(part.id, part.height)
            }
            if (part.heatedVolume !== undefined) {
                partHeatedVolumeMAP.set(part.id, part.heatedVolume)
            }
            if (part.yearOfConstruction !== undefined && part.yearOfConstruction <= "2020") {
                partConstructionYearMAP.set(part.id, part.yearOfConstruction)
            }
            if (part.buildingFunction !== undefined) {
                partBuildingTypeMAP.set(part.id, part.buildingFunction)
            }
            if (part.monthlyHeating !== undefined) {
                partMonthlyHeatingMAP.set(part.id, part.monthlyHeating)
            }
            if (part.monthlyCooling !== undefined) {
                partMonthlyCoolingMAP.set(part.id, part.monthlyCooling)
            }
            part.surfaces.forEach(s => {
                if (s.uValue !== undefined) {
                    surfaceUValueMAP.set(s.id, s.uValue)
                }
            })
        })
    })
    //sort maps
    const heightSort = new Map([...partHeightMAP.entries()].sort((a, b) => b[1] - a[1]));
    const heatedVolumeSort = new Map([...partHeatedVolumeMAP.entries()].sort((a, b) => b[1] - a[1]));
    const constructionYearSort = new Map([...partConstructionYearMAP.entries()].sort((a, b) => a[1] - b[1]));
    const uValueSort = new Map([...surfaceUValueMAP.entries()].sort((a, b) => b[1] - a[1]));

    const monthlyHeatingSort = new Map([...partMonthlyHeatingMAP.entries()].sort((a, b) => b[1] - a[1]));
    const monthlyCoolingSort = new Map([...partMonthlyCoolingMAP.entries()].sort((a, b) => b[1] - a[1]));

    //fill arrays needed for charts
    heightSort.forEach((value, key) => addHeightInfosToArrays(key, value))
    heatedVolumeSort.forEach((value, key) => addHeatedVolumeInfosToArrays(key, value))
    constructionYearSort.forEach((value) => yearOfConstructionValues.push(value))
    partBuildingTypeMAP.forEach((value) => buildingTypeValues.push(value))
    partMonthlyHeatingMAP.forEach((valueArray, key) => yearlyHeatingDemand(key, valueArray))
    partMonthlyCoolingMAP.forEach((valueArray, key) => yearlyCoolingDemand(key, valueArray))
    uValueSort.forEach((value, key) => {
        uValueSurfaces(key, value)
        uValuesAll.push(value)
    })

    monthlyHeatingSort.forEach((value, key) => addmonthlyHeatingInfosToArrays(key, value))
    monthlyCoolingSort.forEach((value, key) => addmonthlyCoolingInfosToArrays(key, value))

    //calculates year of construction frequency
    yearFrequency()

    //calculates building type frequency
    buildingTypeFrequency()

    //calculates uValue frequency
    uValueFrequency()

    //sorts yearly heating & cooling demand for charts
    sortMap()

    //color buildings with heating demand
107
    document.getElementById("checkbox2").addEventListener("change", function() {
JOE Thunyathep S's avatar
update  
JOE Thunyathep S committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        if (this.checked) {
            tileContent.forEach(t => {
                let tileID = t.getProperty("gml_parent_id")
                //console.log(tileID)
                let tileColor = heatingIDColorMAP.get(tileID)
                if (tileColor !== undefined) {
                    t.color = Cesium.Color.fromCssColorString(tileColor)
                } else {
                    t.color = new Cesium.Color(1, 1, 1, 1)
                }
            })
            console.log("colored")
        } else {
            tileContent.forEach(t => t.color = new Cesium.Color(1, 1, 1, 1))
            console.log("not colored")
        }
    })

    //color surfaces with uValue
127
    document.getElementById("checkbox1").addEventListener("change", function() {
JOE Thunyathep S's avatar
update  
JOE Thunyathep S committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
        if (this.checked) {
            tileContent.forEach(t => {
                let tileID = t.getProperty("gml_id")
                //console.log(tileID)
                let tileColor = surfaceIDColorMAP.get(tileID)
                if (tileColor !== undefined) {
                    t.color = Cesium.Color.fromCssColorString(tileColor)
                } else {
                    t.color = new Cesium.Color(1, 1, 1, 1)
                }
            })
            console.log("colored")
        } else {
            tileContent.forEach(t => t.color = new Cesium.Color(1, 1, 1, 1))
            console.log("not colored")
        }
    })
}