diff --git a/atdb_statistics/atdb_plot.py b/atdb_statistics/atdb_plot.py index 0123cdaee60272ed106992509691dbe70296a062..5d010859af350cdd11eec99abcb85d9c2c5267e2 100644 --- a/atdb_statistics/atdb_plot.py +++ b/atdb_statistics/atdb_plot.py @@ -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 diff --git a/atdb_stats.py b/atdb_stats.py index ff0ab41bf1f3d3a6f0aec315a0de4d85c9316fe4..751136ddef5ddd85519778be506c41c701a021dd 100644 --- a/atdb_stats.py +++ b/atdb_stats.py @@ -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) diff --git a/data/time_used_july_vm.args b/data/time_used_july_vm.args new file mode 100644 index 0000000000000000000000000000000000000000..8cbcf317180b907e20ad916abf875a9aca89fd54 --- /dev/null +++ b/data/time_used_july_vm.args @@ -0,0 +1,5 @@ +--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 diff --git a/data/time_used_june_vm.args b/data/time_used_june_vm.args new file mode 100644 index 0000000000000000000000000000000000000000..56b19e30ad2da7bf19b516949ac51f915586825a --- /dev/null +++ b/data/time_used_june_vm.args @@ -0,0 +1,5 @@ +--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