From 621ea24cd4234bf1339ecf391c84ed17d62f0f05 Mon Sep 17 00:00:00 2001
From: "chad.hanna" <crh184@psu.edu>
Date: Sat, 15 Sep 2018 07:50:48 -0700
Subject: [PATCH] gstlal: add new summary page code

---
 gstlal-ugly/share/dataserver/gstlal | 160 ++++++++++++++++++++++++++++
 1 file changed, 160 insertions(+)
 create mode 100755 gstlal-ugly/share/dataserver/gstlal

diff --git a/gstlal-ugly/share/dataserver/gstlal b/gstlal-ugly/share/dataserver/gstlal
new file mode 100755
index 0000000000..066bd1390d
--- /dev/null
+++ b/gstlal-ugly/share/dataserver/gstlal
@@ -0,0 +1,160 @@
+#!/usr/bin/python
+
+import os,sys
+import cgi
+import cgitb
+cgitb.enable()
+form = cgi.parse()
+import time
+from collections import namedtuple
+
+def charts_named_tuple():
+	ChartInfo = namedtuple("ChartInfo", ["div", "drawfunc", "name"])
+
+	def toCamelCase(x):
+		return x.replace("_", " ").title().replace(" ","")
+	def toName(x):
+		return x.replace("_", " ").title()
+
+	out = {}
+	# omitted horizon_table, and all gauges
+	for tag in ("latency_status_by_nodes", "latency_history", "snr_status_by_nodes", "snr_history", "likelihood_status_by_nodes", "likelihood_history", "far_status_by_nodes", "far_history", "horizon", "psd", "noise", "up_time", "dropped", "ram_status", "time_since_last", "time_since_trigger", "vt", "far_inj_history"):
+		out[tag] = ChartInfo(tag + "_wrapper", "draw" + toCamelCase(tag), toName(tag))
+	return out
+
+
+def parse_form(form = form):
+	if "GPS" in form:
+		gps = form["GPS"][0]
+		if float(gps) > 0:
+			refresh =     0
+			longrefresh = 0
+		else:
+			refresh =     5
+			longrefresh = 30
+	else:
+		gps = "-1"
+		refresh =     5
+		longrefresh = 30
+
+
+	if "Duration" in form:
+		duration = form["Duration"][0]
+	else:
+		duration = "3600"
+
+	#if "dir" in form:
+	if "Directory" in form:
+		#analysis_path = form["dir"][0]
+		analysis_path = form["Directory"][0]
+	else:
+		analysis_path = "/home/gstlalcbc/observing/3/online/sept_opa/trigs" 
+	if "id" in form:
+		job_ids = form["id"][0]
+	else:
+		job_ids = "0000,0033"
+	if "livecharts" in form:
+		chart_divs = form["livecharts"]
+	else:
+		chart_divs = ["latency_status_by_nodes", "time_since_last"]
+
+	ifos = "H1,L1,V1"
+
+	return gps, refresh, longrefresh, duration, analysis_path, job_ids, chart_divs, ifos
+
+def doc_header():
+	return "Content-type: text/html\nCache-Control: max-age=10\n"
+
+def google_onload(gps, duration, refresh, analysis_path, job_ids, func, ifos):
+	return " google.charts.setOnLoadCallback(function(){ %s(%s,%s,%d,'%s','%s','%s') });" % (func, gps, duration, refresh, analysis_path, job_ids, ifos)
+
+def html_head(gps, duration, refresh, longrefresh, analysis_path, job_ids, functions = []):
+	out ="""
+	<head>
+		<title>gstlal CBC</title>
+		<link href="https://fonts.googleapis.com/css?family=M+PLUS+Rounded+1c" rel="stylesheet">
+		<link rel="stylesheet" type="text/css" href="../gstlal.css">
+		<script type="text/javascript">var refresh=%f; var longrefresh=%f;</script>
+		<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
+		<script type="text/javascript" src="../jquery-3.1.1.min.js"></script>
+		<script type="text/javascript" src="../gstlal.js"></script>
+		<script type="text/javascript">
+			google.charts.load('current', {'packages':['corechart', 'table', 'gauge']});""" % (refresh, longrefresh)
+	out +="\n"
+
+	for func in functions:
+		out += "\t\t\t%s\n" % google_onload(gps, duration, refresh, analysis_path, job_ids, func, ifos)
+
+	out += "\t\t</script>\n\t</head>"
+	return out
+
+
+def nav_bar(gps, duration, analysis_path, chart_wrappers = []):
+	chart_string = ", ".join(chart_wrappers)
+	selected_option = {"/home/gstlalcbc/observing/3/online/sept_opa/trigs": ["selected", "", "", ""], "/home/gstlalcbc/observing/3/online/trigs.firwhitener": ["", "selected", "", ""], "/home/gstlalcbc/observing/2/online/trigs_feb_release": ["", "", "selected", ""], "/home/gstlalcbc/observing/2/online/test_virgo/trigs": ["", "", "", "selected"]}
+	return """
+		<form>
+			<ul class="tab">
+				<li><img style="margin-left:-40px; margin-top:5px; width:100" src="../gstlal.png"></li>
+				<li><a href="#summary" class="tablinks" onclick="openGstlalTab(event, 'Summary')">Results</a></li>
+				<li><a href="#status" class="tablinks" onclick="openGstlalTab(event, 'LiveCharts', %s)">Live Charts</a></li>
+				<li><a href="#shifts" class="tablinks" onclick="openGstlalTab(event, 'Shifts')">Shifts</a></li>
+				<li><a href="#doc" class="tablinks" onclick="openGstlalTab(event, 'About')">About</a></li>
+				<li>
+				<input type="text" name="GPS" value="%s" size=10 >
+				<input type="text" name="Duration" value="%s" size=10 >
+				<select value="Directory" name="Directory" class="styled-select blue semi-square">
+					<option value="/home/gstlalcbc/observing/3/online/sept_opa/trigs" %s>/home/gstlalcbc/observing/3/online/sept_opa/trigs</option>
+					<option value="/home/gstlalcbc/observing/3/online/trigs.firwhitener" %s>/home/gstlalcbc/observing/3/online/trigs.firwhitener</option>
+					<option value="/home/gstlalcbc/observing/2/online/trigs_feb_release" %s>/home/gstlalcbc/observing/2/online/trigs_feb_release</option>
+					<option value="/home/gstlalcbc/observing/2/online/test_virgo/trigs" %s>/home/gstlalcbc/observing/2/online/test_virgo/trigs</option>
+				</select>
+				<input type="submit" value="Submit" class="styled-select blue semi-square" style="width:100px;">
+				</li>
+				<div id="clock" style="padding-top: 15px; text-align: right; color: darkblue"></div>
+			</ul>
+		""" % (chart_string, gps, duration, selected_option[analysis_path][0], selected_option[analysis_path][1], selected_option[analysis_path][2], selected_option[analysis_path][3])
+		#FIXME Have dropdown menu default to directory webpage currently showing
+		#FIXME The directory currently gets reset when picking new live charts
+
+
+def charts_div(charts, gps, duration, analysis_path, selected_chart_divs = []):
+	out = '\t\t<div id="LiveCharts", class="tabcontent">\n'
+	for chart_div in selected_chart_divs:
+		out += '\t\t\t<div class=gchart id="%s"></div><br>\n' % chart_div
+	for key, chart in charts.items():
+		if chart.div in selected_chart_divs:
+			out += '\t\t\t\t<input type="checkbox" name="livecharts" value="%s" checked>%s\n' % (key, chart.name)
+		else:
+			out += '\t\t\t\t<input type="checkbox" name="livecharts" value="%s">%s\n' % (key, chart.name)
+	#out += '\t\t\t\t<input type="hidden" name="GPS=%s&Duration=%s&Directory=%s">' % (gps, duration, analysis_path)
+	out += '\t\t\t\t<input type="hidden" name="GPS" value="%s">' % gps
+	out += '\t\t\t\t<input type="hidden" name="Duration" value="%s">' % duration
+	out += '\t\t\t\t<input type="hidden" name="Directory" value="%s">' % analysis_path
+	out += '\t\t</div>'
+	out += '\t\t</form>\n'
+	return out
+
+
+gps, refresh, longrefresh, duration, analysis_path, job_ids, selected_charts, ifos = parse_form(form)
+#selected_charts = ["latency_status_by_nodes", "time_since_last"] 
+charts = charts_named_tuple()
+chart_wrappers = [charts[x].div for x in selected_charts]
+
+print doc_header()	
+print "<html>"
+print html_head(gps, duration, refresh, longrefresh, analysis_path, job_ids, functions = [charts[x].drawfunc for x in selected_charts])
+print """\t<body onload="openGstlalTab(event, 'LiveCharts', %s)">""" % ", ".join(chart_wrappers) 
+print nav_bar(gps, duration, analysis_path, chart_wrappers = chart_wrappers)
+print charts_div(charts, gps, duration, analysis_path, selected_chart_divs = [charts[x].div for x in selected_charts])
+print """
+	<div id="Summary" class="tabcontent" style="padding-top: 0px; padding-bottom: 0px; padding-right: 0px; padding-left: 0px; box-shadow: none; width: 100%; height: 100%">
+		<iframe src="https://ldas-jobs.ligo.caltech.edu/~gstlalcbc/observing/3_lite" width=100% height=100%></iframe>
+	</div>
+
+	<div id="About" class="tabcontent">
+		<iframe width=100% height=100% src="https://docs.google.com/document/d/12wJjCz8L1UczqRm86q3-EFnpnIZ2FHPSwKR_kym2L5g/pub?embedded=true"></iframe>
+	</div>
+"""
+
+print "\t</body>\n</html>"
-- 
GitLab