-
Notifications
You must be signed in to change notification settings - Fork 0
/
problems.php
executable file
·194 lines (187 loc) · 5.83 KB
/
problems.php
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!doctype html><html><head>
<?php include'imports.php'?>
<script>
//count all variables (inputs and outputs)
function countVariables(obj) {
obj=obj||Global;
var n=0;
for(var field in obj) {
switch(typeof(obj[field])) {
case 'number': case 'function':
n++
break;
case 'object':
n+=countVariables(obj[field])
break;
}
}
return n;
}
function findInexisting(obj) {
(function() {
var inex=[];
if(obj instanceof Array) {
for(var i in obj) {
if(locateVariable(obj[i])==false) inex.push(obj[i]);
}
}
else if(typeof(obj)=="object") {
for(var field in obj) {
if(locateVariable(field)==false) inex.push(field);
}
}
else return [];
if(inex.length==0) { document.write("<tr><td class=allok></td>") }
return inex;
})().forEach(function(field) {
document.write("<tr><td style=background:red>"+field);
});
}
</script>
<style>
div#main table {
display:inline-block;
vertical-align:top;
margin:2px 1px;
}
td.allok {
background:lightgreen;
font-style:italic;
}
td.allok:before {content:"All OK"}
</style>
<script>
function init() {
Caption.listeners();
}
</script>
</head><body onload=init()><center>
<!--sidebar--><?php include'sidebar.php'?>
<!--navbar--><?php include'navbar.php'?>
<!--linear--><?php include'linear.php'?>
<!--caption--><?php include'caption.php'?>
<!--title--><h1><a href=development.php>Development</a> › Debugging utility</h1></center>
<!--note: issues were moved to github-->
<p style=text-align:center>
Issues were moved to <a href='https://github.com/holalluis/ecam/issues'>github issues</a>
</p>
<!--problems-->
<div style="max-width:50%;border:1px solid #ccc;padding:0.5em;margin:2px auto">
<!--not used inputs-->
<div class=inline style="max-width:20%">
<table><tr><th>Inputs not used in any<br><b>Outputs</b><br> and<br> <b>Benchmarks</b>
<script>
//get unused inputs
function getUnused(obj) {
obj=obj||Global;
var unused=[];
for(var field in obj) {
switch(typeof(obj[field])) {
case 'number':
var n=Formulas.outputsPerInput(field).length;
if(n==0) unused.push(field);
break;
case 'function':
if(field.search(/^c_/)==0) {
var n=Formulas.outputsPerInput(field).length;
if(n==0) unused.push(field);
}
break;
case 'object':
unused=unused.concat(getUnused(obj[field]));
break;
}
}
return unused;
}
//quick fix to see if fields are used in benchmarks also
['Water','Waste','Energy'].forEach(function(level) {
var unused=getUnused(Global[level])
unused.forEach(function(field) {
//is used in benchmark?
if(Utils.usedInBenchmarks(field).length==0) {
var color=field.search('ww')==-1 ? "" : "#bf5050";
try{
document.write("<tr><td>");
document.write("<a caption='"+translate(field+"_descr")+"' style=color:"+color+" href=variable.php?id="+field+">"+field+"</a>");
} catch(e) {
document.write("<tr><td colspan=3>"+field+" need to be removed. Reset chaché")
}
}
});
});
</script>
</table>
</div>
<!--questions-->
<div class=inline style="max-width:20%">
<table><tr><th>Inexisting variable codes that appear in questions.js
<script>
for(var q in Questions) {
if(typeof(Questions[q])=="function") continue;
findInexisting(Questions[q].variables)
}
</script>
</table>
</div>
<!--rest of data structures-->
<div class=inline style="max-width:60%">
<table id=vawomu><tr><th>Variables without magnitude/unit
<tr><td class=allok>
<script>
(function(){
function listUnitless(obj) {
for(var field in obj) {
if(typeof(obj[field])=="object"){return};
if(Info[field]==undefined) {
document.querySelector("#vawomu td.allok").style.display='none';
var loc=locateVariable(field);
var link = "edit.php?level="+loc.level;
if(loc.sublevel)link+="&sublevel="+loc.sublevel;
document.write("<tr><td><a href='"+link+"'>"+field+"</a>");
}
}
}
listUnitless(Global.Water);
listUnitless(Global.Water.Abstraction);
listUnitless(Global.Water.Treatment);
listUnitless(Global.Water.Distribution);
listUnitless(Global.Waste.Collection);
listUnitless(Global.Waste.Treatment);
listUnitless(Global.Waste.Discharge);
})()
</script>
</table>
<table><tr><th>Inexisting that appear in info.js <script>findInexisting(Info)</script> </table>
<table><tr><th>Inexisting that appear in refValues.js (Benchmarking) <script>findInexisting(RefValues)</script> </table>
<table><tr><th>Inexisting that appear in averagedVariables.js <script>findInexisting(Averaged.list)</script> </table>
<table><tr><th>Inexisting that appear in level2only.js <script>findInexisting(Level2only.list)</script> </table>
<table><tr><th>Inexisting that appear in level2Warnings.js <script>findInexisting(Level2Warnings)</script> </table>
<table><tr><th>Inexisting that appear in level3variables.js <script>findInexisting(Level3.list)</script> </table>
<table><tr><th>Repeated variables in questions.js
<script>
var repeated=Questions.findRepeated()
repeated.forEach(function(variable){
document.write("<tr><td style=background:red>"+variable)
})
if(repeated.length==0)document.write("<tr><td class=allok>")
</script>
</table>
<table><tr><th>Not used constants
<script>
var j=0;
for(var constant in Cts)
{
var i=0;
Formulas.outputsPerInput(constant).forEach(function(equation)
{
i++;
})
if(i==0){ document.write("<tr><td style=background:red><a href=constant.php?id="+constant+">"+constant+"</a>");j++; }
}
if(j==0)document.write("<tr><td class=allok>")
</script>
</table>
</div>
</div>
<!--CURRENT JSON--><?php include'currentJSON.php'?>