Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@

# URL to access the PV archiver
$archive_url = '';
# PV to check for beam / no beam, and values that correspond to beam
$beam_mode_pv = 'CS-CS-MSTAT-01:MODE';
$beam_mode_pv_beam_on_values = array(4, 5);

# URL to access elog logbook
$elog_base_url = '';
Expand Down
2 changes: 1 addition & 1 deletion api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ function _get_archive($pv, $s, $e)
{
$vs = $vals[$i];
$v = $vs->val;
$t = $vs->secs - 3600;
$t = $vs->secs;
$inputTZ = new \DateTimeZone($timezone);
$transitions = $inputTZ->getTransitions($t, $t);
if ($transitions[0]['isdst'])
Expand Down
65 changes: 32 additions & 33 deletions api/src/Page/Vstat.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function __construct()
function _visit_breakdown()
{
ini_set('memory_limit', '512M');
global $beam_mode_pv, $beam_mode_pv_beam_on_values;

if ($this->has_arg('visit')) {
$info = $this->_check_visit();
Expand Down Expand Up @@ -341,36 +342,35 @@ function _visit_breakdown()
}

// Beam status
$bs = $this->_get_archive('CS-CS-MSTAT-01:MODE', strtotime($info['ST']), strtotime($info['EN']));
$bs = $this->_get_archive($beam_mode_pv, strtotime($info['ST']), strtotime($info['EN']));


$lastv = 0;
$ex = 3600 * 1000;
$st = $this->jst($info['ST']);

foreach ($bs as $i => $b) {
$v = $b[1] != 4;
$c = $b[0] * 1000;
$v = !in_array($b[1], $beam_mode_pv_beam_on_values);
$c = max($b[0] * 1000, $st);

if (($v != $lastv) && $v) {
$st = $c;
}
if ($v != $lastv) {
if ($v) {
$st = $c;
} else {
array_push($data, array('data' => array(
array($st, 5, $st),
array($c, 5, $st)
), 'color' => 'black', 'status' => ' Beam Dump', 'type' => 'nobeam'));
}

if ($lastv && ($v != $lastv)) {
array_push($data, array('data' => array(
array($st + $ex, 5, $st + $ex),
array($c + $ex, 5, $st + $ex)
), 'color' => 'black', 'status' => ' Beam Dump', 'type' => 'nobeam'));
$lastv = $v;
}

$lastv = $v;
}

// in case visit ends with no beam
if ($lastv && $this->jst($info['EN']) > $st + $ex) {
if ($lastv && $this->jst($info['EN']) > $st) {
array_push($data, array('data' => array(
array($st + $ex, 5, $st + $ex),
array($this->jst($info['EN']), 5, $st + $ex)
array($st, 5, $st),
array($this->jst($info['EN']), 5, $st)
), 'color' => 'black', 'status' => ' Beam Dump', 'type' => 'nobeam'));
}

Expand All @@ -396,6 +396,7 @@ function _visit_breakdown()

function _pies()
{
global $beam_mode_pv, $beam_mode_pv_beam_on_values;
$args = array($this->proposalid);
$where = ' WHERE p.proposalid=:1';

Expand Down Expand Up @@ -484,30 +485,28 @@ function _pies()
$d['FAULT'] = 0;

// Beam status
$bs = $this->_get_archive('CS-CS-MSTAT-01:MODE', strtotime($d['ST']), strtotime($d['EN']));
$bs = $this->_get_archive($beam_mode_pv, strtotime($d['ST']), strtotime($d['EN']));

$lastv = 0;
$ex = 3600 * 1000;
$st = $this->jst($d['ST']);
$total_no_beam = 0;
foreach ($bs as $i => $b) {
$v = $b[1] != 4;
$c = $b[0] * 1000;

if (($v != $lastv) && $v) {
$st = $c;
}

if ($lastv && ($v != $lastv)) {
$total_no_beam += ($c - $st) / 1000;
$v = !in_array($b[1], $beam_mode_pv_beam_on_values);
$c = max($b[0] * 1000, $st);

if ($v != $lastv) {
if ($v) {
$st = $c;
} else {
$total_no_beam += ($c - $st) / 1000;
}
$lastv = $v;
}

$lastv = $v;
}

// in case visit ends with no beam
if ($lastv && $this->jst($d['EN']) > ($ex + $st)) {
$total_no_beam += ($this->jst($d['EN']) - ($ex + $st)) / 1000;
if ($lastv && $this->jst($d['EN']) > $st) {
$total_no_beam += ($this->jst($d['EN']) - $st) / 1000;
}

$d['NOBEAM'] = $total_no_beam / 3600;
Expand Down Expand Up @@ -725,7 +724,7 @@ function _get_logbook_from_beamline($bl)
{
if ($type['name'] == $bl)
{
$logbook = $type['logbook'];
$logbook = $type['logbook'] ?? null;
break;
}
}
Expand Down
Loading