Commit f046e0b4 authored by Nico Vermaas's avatar Nico Vermaas

adding 'time used' pie chart presentation based on new ATDB query

parent 3b16656d
......@@ -396,4 +396,43 @@ def do_speeds_plot(title, y_axis_title, subtitle, annotate, datapoints):
#plt.plot(ingest_error_x[i:i], 'r.',label='ingest error')
plt.legend(loc='upper right')
plt.show()
def do_time_used_plot(title, subtitle, data):
"""
:param title: Title of Plot
:param x: dict with data for x-axis (time)
:param y: dict with data for y_axix (usage)
:return:
"""
total_minutes = data['total_minutes']
time_on_sky = data['time-on-sky-overview']['was_archived']
imaging_minutes = time_on_sky['imaging_minutes']
arts_minutes = time_on_sky['arts_minutes']
system_minutes = time_on_sky['system_minutes']
imaging_fraction = int(imaging_minutes / total_minutes * 100)
arts_fraction = int(arts_minutes / total_minutes * 100)
system_fraction = int(system_minutes / total_minutes * 100)
idle_fraction = 100 - (imaging_fraction + arts_fraction + system_fraction)
# Pie chart, where the slices will be ordered and plotted counter-clockwise:
fig = plt.figure(figsize=(12, 6))
labels = 'Imaging (archived)', 'ARTS (archived)', 'other', 'system'
sizes = [imaging_fraction, arts_fraction, idle_fraction, system_fraction]
explode = (0.1, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
#fig1, ax1 = plt.subplots()
plt.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.title(title)
plt.grid(True,alpha=0.3)
plt.legend(loc='upper right')
plt.show()
\ No newline at end of file
......@@ -370,6 +370,38 @@ def do_speeds(args):
atdb_plot.do_speeds_plot(args.title, args.y_axis_title, args.subtitle, args.annotate, datapoints)
@timeit
def do_time_used(args):
# The request header
ATDB_HEADER = {
'content-type': "application/json",
'cache-control': "no-cache",
'authorization': "Basic YWRtaW46YWRtaW4="
}
# input parameters
url = args.atdb_host + "/time-used?" + str(args.query)
# do the request to the ATDB backend
print('request to '+url)
response = requests.request("GET", url, headers=ATDB_HEADER)
# parse the response
try:
json_response = json.loads(response.text)
time_used_data = json_response["time_used_data"]
except Exception as err:
print("Exception : " + str(err))
raise (Exception(
"ERROR: " + str(response.status_code) + ", " + str(response.reason) + ', ' + str(response.content)))
# plot the results
atdb_plot.do_time_used_plot(args.title, args.y_axis_title,time_used_data)
def get_arguments(parser):
"""
Gets the arguments with which this application is called and returns the parsed arguments.
......@@ -563,6 +595,9 @@ def main():
elif presentation=="speeds":
do_speeds(args)
elif presentation=="time_used":
do_time_used(args)
if args.remote_post_command != None:
execute_remote_command(args.atdb_host, args.remote_post_command)
......
--presentation=time_used
--atdb_host=http://192.168.22.22/atdb
--title=APERTIF On Sky - July 2019
--subtitle=July 2019
--query=from=2019-07-01&to=2019-07-30
\ No newline at end of file
--presentation=time_used
--atdb_host=http://192.168.22.22/atdb
--title=APERTIF Observing Times - June 2019
--subtitle=June 2019
--query=from=2019-06-01&to=2019-06-30
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment