Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PAnTHer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
puma
client
PAnTHer
Commits
4fd84a35
Commit
4fd84a35
authored
2 months ago
by
Lucio Zambon
Browse files
Options
Downloads
Patches
Plain Diff
Update bl2d.js
parent
032598b8
No related branches found
Branches containing commit
No related tags found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bl2d.js
+98
-19
98 additions, 19 deletions
bl2d.js
with
98 additions
and
19 deletions
bl2d.js
+
98
−
19
View file @
4fd84a35
// jshint esversion: 6
const
data_stroke
=
{};
const
data_color
=
{};
const
data_value
=
{};
const
data_interlock
=
{};
let
alarms
=
-
1
;
let
interlocks
=
-
1
;
let
logs
=
-
1
;
let
summary
;
const
bl
=
document
.
location
.
search
.
split
(
'
machine=
'
)[
1
].
split
(
'
&
'
)[
0
].
split
(
'
_
'
)[
1
];
function
myid
(
name
)
{
return
name
.
split
(
'
'
).
join
(
'
_
'
).
split
(
'
.
'
).
join
(
'
_
'
);}
function
updateBl
(
blName
)
{
fetch
(
'
./updater.php?read&filename=elettrabl.1000.
'
+
blName
).
then
((
response
)
=>
{
return
response
.
text
();}).
then
((
data
)
=>
{
const
values
=
data
.
split
(
'
;
'
);
// console.log('./updater.php?read&filename=elettrabl'+bl+'.1000.'+blName);
fetch
(
'
./updater.php?read&filename=elettrabl
'
+
bl
+
'
.1000.
'
+
blName
).
then
((
response
)
=>
{
return
response
.
text
();}).
then
((
data
)
=>
{
const
values
=
data
.
split
(
'
:
'
).
slice
(
1
).
join
(
'
:
'
).
split
(
'
;
'
);
for
(
let
j
=
0
;
j
<
data_stroke
[
blName
].
length
;
j
++
)
{
// console.log(data_stroke[blName][j], values[data_stroke[blName][j][2]], values[data_stroke[blName][j][2]]==1);
$
(
'
#
'
+
myid
(
data_stroke
[
blName
][
j
][
0
])).
css
(
'
stroke
'
,
values
[
data_stroke
[
blName
][
j
][
2
]]
==
1
?
'
yellow
'
:
'
black
'
);
}
for
(
let
j
=
0
;
j
<
data_color
[
blName
].
length
;
j
++
)
{
// console.log("$('#"+data_color[blName][j][0]+"').css('fill',values[data_color[blName][j][2]]=='1'? 'red': 'limegreen')", data_color[blName][j][2], values[data_color[blName][j][2]]);
$
(
'
#
'
+
data_color
[
blName
][
j
][
0
]
.
replace
(
'
'
,
'
_
'
).
replace
(
'
.
'
,
'
_
'
)).
css
(
'
fill
'
,
values
[
data_color
[
blName
][
j
][
2
]]
==
'
1
'
?
'
red
'
:
'
limegreen
'
);
$
(
'
#
'
+
myid
(
data_color
[
blName
][
j
][
0
]
)).
css
(
'
fill
'
,
(
values
[
data_color
[
blName
][
j
][
2
]]
==
'
1
'
||
values
[
data_color
[
blName
][
j
][
2
]]
==
'
9
'
||
values
[
data_color
[
blName
][
j
][
2
]]
==
'
true
'
)?
'
red
'
:
(
values
[
data_color
[
blName
][
j
][
2
]]
==
''
||
values
[
data_color
[
blName
][
j
][
2
]]
==
null
?
'
orange
'
:
'
limegreen
'
)
)
;
}
// console.log(data_value);
for
(
let
j
=
0
;
j
<
data_value
[
blName
].
length
;
j
++
)
{
const
id
=
data_value
[
blName
][
j
][
0
]
.
replace
(
'
'
,
'
_
'
).
replace
(
'
.
'
,
'
_
'
)
+
'
value
'
;
const
id
=
myid
(
data_value
[
blName
][
j
][
0
])
+
'
value
'
;
if
(
$
(
'
#
'
+
id
)[
0
])
$
(
'
#
'
+
id
)[
0
].
innerHTML
=
''
;
}
for
(
let
j
=
0
;
j
<
data_value
[
blName
].
length
;
j
++
)
{
const
id
=
data_value
[
blName
][
j
][
0
].
replace
(
'
'
,
'
_
'
).
replace
(
'
.
'
,
'
_
'
)
+
'
value
'
;
console
.
log
(
"
$('#
"
+
id
+
"
')[0].innerHTML
"
,
data_value
[
blName
][
j
][
2
],
values
[
data_value
[
blName
][
j
][
2
][
0
]]);
const
id
=
myid
(
data_value
[
blName
][
j
][
0
])
+
'
value
'
;
for
(
let
i
=
0
;
i
<
data_value
[
blName
][
j
][
2
].
length
;
i
++
)
{
if
(
$
(
'
#
'
+
id
)[
0
])
$
(
'
#
'
+
id
)[
0
].
innerHTML
=
$
(
'
#
'
+
id
)[
0
].
innerHTML
+
'
'
+
values
[
data_value
[
blName
][
j
][
2
][
i
]];
// console.log('#'+id);
if
(
$
(
'
#
'
+
id
)[
0
])
$
(
'
#
'
+
id
)[
0
].
innerHTML
=
$
(
'
#
'
+
id
)[
0
].
innerHTML
+
'
<tspan x="0" dy="1.2em">
'
+
formatBl
(
values
[
data_value
[
blName
][
j
][
2
][
i
]]
-
0
,
data_value
[
blName
][
j
][
3
]?
data_value
[
blName
][
j
][
3
][
i
]:
''
)
+
'
</tspan>
'
;
}
}
// console.log('initBl()', data);
for
(
let
j
=
0
;
j
<
data_interlock
[
blName
].
length
;
j
++
)
{
const
id
=
myid
(
data_interlock
[
blName
][
j
][
0
])
+
'
_interlock
'
;
// if (id=='VALVE_L_03_interlock') console.log(id, data_interlock[blName][j][0], data_interlock[blName][j][2], values[data_interlock[blName][j][2]], values[data_interlock[blName][j][2]]=='true', $('#'+id));
if
(
values
[
data_interlock
[
blName
][
j
][
2
]]
==
'
true
'
)
$
(
'
#
'
+
id
).
show
();
else
$
(
'
#
'
+
id
).
hide
();
}
$
(
'
#alarms
'
).
html
(
values
[
alarms
]
==
''
?
'
---
'
:
values
[
alarms
]);
$
(
'
#interlocks
'
).
html
(
values
[
interlocks
]
==
''
?
'
---
'
:
values
[
interlocks
]);
const
lv
=
values
[
logs
].
split
(
'
,
'
);
let
log
=
''
;
for
(
let
i
=
0
;
i
*
3
<
lv
.
length
;
i
++
)
log
=
log
+
lv
.
slice
(
i
*
3
,
(
i
+
1
)
*
3
).
join
(
'
,
'
)
+
'
\n
'
;
$
(
'
#logs
'
).
html
(
log
);
});
}
function
formatBl
(
value
,
format
)
{
if
(
format
==
'
temperature
'
)
{
return
value
.
toFixed
(
2
)
+
'
°C
'
;}
if
(
format
==
'
pressure
'
)
{
/*console.log(value);*/
return
'
<tspan x="0" dy="1.2em">
'
+
Number
.
parseFloat
(
value
).
toExponential
(
2
)
+
'
</tspan> <tspan x="-1em" dy="1.2em">mbar </tspan>
'
;}
if
(
format
==
'
current
'
)
{
return
value
.
toFixed
(
2
)
+
'
mA
'
;}
if
(
format
==
'
energy
'
)
{
return
value
.
toFixed
(
2
)
+
'
GeV
'
;}
else
{
return
value
.
toFixed
(
2
);}
}
function
initBl
(
blName
)
{
fetch
(
'
./updater.php?read&filename=elettrabl.1000.
'
+
blName
+
'
.src
'
).
then
((
response
)
=>
{
return
response
.
text
();}).
then
((
data
)
=>
{
const
names
=
data
.
split
(
'
,
'
);
fetch
(
'
./updater.php?read&filename=elettrabl
'
+
bl
+
'
.1000.
'
+
blName
+
'
.src
'
).
then
((
response
)
=>
{
return
response
.
text
();}).
then
((
data
)
=>
{
const
names
=
data
.
substr
(
14
).
split
(
'
nullosp
'
).
join
(
'
nanosp
'
).
split
(
'
,
'
);
// console.log('names', names, './updater.php?read&filename=elettrabl'+bl+'.1000.'+blName+'.src');
for
(
let
i
=
0
;
i
<
names
.
length
;
i
++
)
{
for
(
let
j
=
0
;
j
<
data_stroke
[
blName
].
length
;
j
++
)
{
if
(
data_stroke
[
blName
][
j
][
1
]
==
names
[
i
])
{
data_stroke
[
blName
][
j
].
push
(
i
);
if
(
data_stroke
[
blName
][
j
][
0
])
$
(
'
#
'
+
myid
(
data_stroke
[
blName
][
j
][
0
])).
children
()[
0
].
textContent
=
data_stroke
[
blName
][
j
][
1
];
}
}
for
(
let
j
=
0
;
j
<
data_color
[
blName
].
length
;
j
++
)
{
if
(
data_color
[
blName
][
j
][
1
]
==
names
[
i
])
data_color
[
blName
][
j
].
push
(
i
);
if
(
data_color
[
blName
][
j
][
1
]
==
names
[
i
])
{
data_color
[
blName
][
j
].
push
(
i
);
if
(
data_color
[
blName
][
j
][
0
])
$
(
'
#
'
+
myid
(
data_color
[
blName
][
j
][
0
])).
children
()[
0
].
textContent
=
data_color
[
blName
][
j
][
1
];
}
}
for
(
let
j
=
0
;
j
<
data_value
[
blName
].
length
;
j
++
)
{
if
(
typeof
data_value
[
blName
][
j
][
2
]
==
'
undefined
'
)
data_value
[
blName
][
j
][
2
]
=
[];
for
(
let
k
=
0
;
k
<
data_value
[
blName
][
j
][
1
].
length
;
k
++
)
{
// if (names[i].indexOf('Pressure')>-1) console.log(data_value[blName][j][1][k] == names[i], i, j, names[i], data_value[blName][j][1][k], data_value[blName]);
if
(
data_value
[
blName
][
j
][
1
][
k
]
==
names
[
i
])
{
data_value
[
blName
][
j
][
2
].
push
(
i
);
console
.
log
(
i
,
j
,
names
[
i
],
data_value
[
blName
][
j
][
1
][
k
],
data_value
[
blName
]);
// console.log(i, j, names[i], data_value[blName][j][1][k], data_value[blName]);
if
(
data_value
[
blName
][
j
][
0
])
$
(
'
#
'
+
myid
(
data_value
[
blName
][
j
][
0
])
+
'
_g
'
).
children
()[
0
].
innerHTML
=
data_value
[
blName
][
j
][
1
];
}
}
}
for
(
let
j
=
0
;
j
<
data_interlock
[
blName
].
length
;
j
++
)
{
if
(
data_interlock
[
blName
][
j
][
1
]
==
names
[
i
])
{
data_interlock
[
blName
][
j
].
push
(
i
);
if
(
data_interlock
[
blName
][
j
][
0
])
{
const
id
=
myid
(
data_interlock
[
blName
][
j
][
0
]);
const
transform
=
$
(
'
#
'
+
id
+
'
_g
'
).
children
()[
1
].
outerHTML
.
split
(
'
transform="
'
)[
1
].
split
(
'
">
'
)[
0
];
appendSvg
(
'
rect
'
,
{
id
:
id
+
'
_interlock
'
,
fill
:
'
orange
'
,
x
:
'
-290
'
,
y
:
'
-200
'
,
height
:
"
30
"
,
width
:
"
220
"
,
transform
:
transform
},
false
,
'
<title>
'
+
data_interlock
[
blName
][
j
][
1
]
+
'
</title>
'
,
false
,
'
#
'
+
id
+
'
_g
'
);
}
}
}
if
(
names
[
i
].
indexOf
(
'
/geco/alarms
'
)
>-
1
)
alarms
=
i
;
if
(
names
[
i
].
indexOf
(
'
/geco/interlocks
'
)
>-
1
)
interlocks
=
i
;
if
(
names
[
i
].
indexOf
(
'
/geco/logs
'
)
>-
1
)
logs
=
i
;
}
console
.
log
(
'
initBl()
'
,
data
.
split
(
'
,
'
),
data_color
,
data_value
);
//
console.log('initBl()', data.split(','), data_color, data_value);
updateBl
(
blName
);
colorReader
=
setInterval
(
updateBl
,
5
000
,
blName
);
colorReader
=
setInterval
(
updateBl
,
1
000
,
blName
);
});
}
function
bl2d
(
lattice
)
{
// console.log('bl2d');
for
(
let
facility
in
lattice
)
{
if
(
facility
==
'
conf
'
)
continue
;
data_stroke
[
facility
]
=
[];
data_color
[
facility
]
=
[];
data_value
[
facility
]
=
[];
data_interlock
[
facility
]
=
[];
const
sections
=
lattice
[
facility
].
sections
;
for
(
let
section
=
0
;
section
<
sections
.
length
;
section
++
)
{
const
components
=
sections
[
section
].
components
;
// console.log(components, facility, section, sections[section]);
if
(
components
)
for
(
let
i
=
0
;
i
<
components
.
length
;
i
++
)
{
console
.
log
(
i
,
components
[
i
]);
// console.log(i, components[i]);
if
(
components
[
i
][
'
data-stroke
'
])
data_stroke
[
facility
].
push
([
components
[
i
].
name
,
components
[
i
][
'
data-stroke
'
]]);
if
(
components
[
i
][
'
data-interlock
'
])
data_interlock
[
facility
].
push
([
components
[
i
].
name
,
components
[
i
][
'
data-interlock
'
]]);
if
(
components
[
i
][
'
data-color
'
])
data_color
[
facility
].
push
([
components
[
i
].
name
,
components
[
i
][
'
data-color
'
]]);
if
(
components
[
i
][
'
data-value
'
])
{
data_value
[
facility
].
push
([
components
[
i
].
name
,
components
[
i
][
'
data-value
'
]]);
const
id
=
components
[
i
].
name
.
replace
(
'
'
,
'
_
'
)
+
'
value
'
;
console
.
log
(
"
$('#
"
+
id
+
"
)[0].style.display
'
"
);
data_value
[
facility
].
push
([
components
[
i
].
name
,
components
[
i
][
'
data-value
'
]
,
[],
components
[
i
][
'
data-unit
'
]
]);
const
id
=
myid
(
components
[
i
].
name
)
+
'
value
'
;
console
.
log
(
"
$('#
"
+
id
+
"
)[0].style.display
"
);
if
(
$
(
'
#
'
+
id
)[
0
])
$
(
'
#
'
+
id
)[
0
].
style
.
display
=
'
block
'
;
}
}
}
if
(
data_color
[
facility
].
length
>
0
)
initBl
(
facility
);
if
(
typeof
lattice
.
conf
.
summary
!=
undefined
)
{
summary
=
lattice
.
conf
.
summary
;
let
st
=
'
<div style="position: fixed; bottom: 5px; left: 5px;color: white; background-color: #333; border-radius: 5px; padding: 5px;"><div style="cursor:pointer;" onClick="$(
\'
#summary
\'
).toggle()">Summary</div><div id="summary" style="display:none;"><table><tr>
'
;
for
(
let
i
in
summary
)
{
// console.log(i, summary[i]);
st
=
st
+
'
<td>
'
+
i
.
toUpperCase
()
+
'
</td>
'
;
}
st
=
st
+
'
</tr><tr valign="top">
'
;
for
(
let
i
in
summary
)
{
st
=
st
+
'
<td><textarea id="
'
+
i
+
'
" title="
'
+
summary
[
i
][
'
data-value
'
]
+
'
" cols="
'
+
summary
[
i
].
cols
+
'
" rows="
'
+
summary
[
i
].
rows
+
'
" style="color: white; background-color: #222; border: 0;"></textarea></td>
'
;
}
const
sm
=
document
.
createElement
(
"
div
"
);
sm
.
innerHTML
=
st
+
'
</tr></table></div>
'
;
document
.
body
.
appendChild
(
sm
);
}
}
$
(
'
#talk
'
).
hide
();
for
(
let
i
=
4
;
i
<=
10
;
i
++
)
{
$
(
'
#lil-gui-name-
'
+
i
).
parent
().
hide
();
}
// console.log('data_color', data_color);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment