Skip to content
Snippets Groups Projects
Commit 6cd054da authored by Jameson Rollins's avatar Jameson Rollins
Browse files

web: main simplification

* move online_status into main
* remove unnecessary event_summary function
* remove other superfulous code
parent 002a5a6d
No related branches found
No related tags found
No related merge requests found
......@@ -53,36 +53,29 @@ def query_parse(query):
return out_query
def event_summary(gps):
try:
event = LocklossEvent(gps)
except (ValueError, OSError) as e:
bottle.abort(404, 'Unknown event: {}'.format(gps))
def online_status():
"""HTML-formatted online status information
"""
stat_file = os.path.join(config.CONDOR_ONLINE_DIR, 'stat')
if not os.path.exists(stat_file):
return '<span style="color:red">ONLINE ANALYSIS NOT RUNNING</span>'
stat = os.stat(stat_file)
dt = datetime.fromtimestamp(stat.st_mtime)
dtnow = datetime.now()
age = dtnow - dt
tsecs = age.total_seconds()
if tsecs > 60:
color = 'red'
else:
try:
online_status = utils.online_status()
except OSError: ### no online jobs
online_status = None
sat_channels = []
csv_path = event.path('saturations.csv')
if os.path.exists(csv_path):
with open(csv_path, 'r') as f:
for line in f:
sat_channels.append(line.split())
return bottle.template(
'event.tpl',
IFO=config.IFO,
web_script=WEB_SCRIPT,
date=datetime.now(),
is_home=False,
event=event,
tags=utils.tag_buttons(event.list_tags()),
sat_channels=sat_channels,
online_status=online_status,
)
color = 'green'
wcroot = os.path.join(config.WEB_ROOT, 'events', '.condor_online')
return '<span style="color: {}">online last update: {:0.1f} min ago ({}) [<a href="{}">log</a>]</span>'.format(
color,
tsecs/60,
dt,
os.path.join(wcroot, 'out'),
)
##################################################
......@@ -92,7 +85,7 @@ app = bottle.Bottle()
@app.route("/tag/<tag>")
def index(tag='all'):
if bottle.request.query.format and bottle.request.query.format == 'json':
if bottle.request.query.format == 'json':
if 'event' in bottle.request.query:
gps = bottle.request.query.get('event')
try:
......@@ -110,29 +103,39 @@ def index(tag='all'):
elif 'event' in bottle.request.query:
gps = bottle.request.query.get('event')
return event_summary(gps)
try:
event = LocklossEvent(gps)
except (ValueError, OSError) as e:
bottle.abort(404, 'Unknown event: {}'.format(gps))
else:
query = query_parse(bottle.request.query)
sat_channels = []
csv_path = event.path('saturations.csv')
if os.path.exists(csv_path):
with open(csv_path, 'r') as f:
for line in f:
sat_channels.append(line.split())
if not query:
is_home = True
else:
is_home = False
return bottle.template(
'event.tpl',
IFO=config.IFO,
web_script=WEB_SCRIPT,
online_status=online_status(),
is_home=False,
event=event,
tags=utils.tag_buttons(event.list_tags()),
sat_channels=sat_channels,
)
try:
online_status = utils.online_status()
except OSError: ### no online jobs
online_status = None
else:
query = query_parse(bottle.request.query)
return bottle.template(
'index.tpl',
IFO=config.IFO,
web_script=WEB_SCRIPT,
date=datetime.now(),
is_home=is_home,
online_status=online_status(),
is_home=not bool(query),
query=query,
online_status=online_status,
)
......
......@@ -14,7 +14,6 @@
<div class="container">
<h2></h2>
<h2><a href="{{web_script}}">{{IFO}} lock losses</a></h2>
<h6>{{date}}</h6>
{{!online_status}}
<br />
......
% rebase('base.tpl', IFO=IFO, web_script=web_script, date=date, online_status=online_status)
% rebase('base.tpl', IFO=IFO, web_script=web_script, online_status=online_status)
% import os
% from datetime import timedelta
......
% rebase('base.tpl', IFO=IFO, web_script=web_script, date=date, online_status=online_status)
% rebase('base.tpl', IFO=IFO, web_script=web_script, online_status=online_status)
% from datetime import timedelta
% from locklost.web import utils
......
......@@ -17,31 +17,6 @@ def event_gen(query):
yield event
def online_status():
"""HTML-formatted online status information
"""
stat_file = os.path.join(config.CONDOR_ONLINE_DIR, 'stat')
if not os.path.exists(stat_file):
return '<span style="color:red">ONLINE ANALYSIS NOT RUNNING</span>'
stat = os.stat(stat_file)
dt = datetime.fromtimestamp(stat.st_mtime)
dtnow = datetime.now()
age = dtnow - dt
tsecs = age.total_seconds()
if tsecs > 60:
color = 'red'
else:
color = 'green'
wcroot = os.path.join(config.WEB_ROOT, 'events', '.condor_online')
return '<span style="color: {}">online last update: {:0.1f} min ago ({}) [<a href="{}">log</a>]</span>'.format(
color,
tsecs/60,
dt,
os.path.join(wcroot, 'out'),
)
def analysis_status_button(event):
"""HTML-formated event analysis status button
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment