def get_error_update(request, instrument): """ Ajax call to get updates behind the scenes @param instrument: instrument name @param ipts: experiment name """ since = request.GET.get('since', '0') try: since = int(since) last_error_id = get_object_or_404(Error, id=since) except: last_error_id = None instrument_id = get_object_or_404(Instrument, name=instrument.lower()) # Get last experiment and last run data_dict = view_util.get_current_status(instrument_id) err_list = [] if last_error_id is not None: errors = Error.objects.filter(run_status_id__run_id__instrument_id=instrument_id, id__gt=last_error_id.id).order_by('run_status_id__created_on') if len(errors) > 0: last_error_id_number = None for e in errors: if last_error_id_number is None: last_error_id_number = e.id if last_error_id.run_status_id.created_on < e.run_status_id.created_on: localtime = timezone.localtime(e.run_status_id.created_on) df = dateformat.DateFormat(localtime) err_dict = {"run":e.run_status_id.run_id.run_number, "ipts":e.run_status_id.run_id.ipts_id.expt_name, "description":e.description, "created_on":df.format(settings.DATETIME_FORMAT), "timestamp":e.run_status_id.created_on.isoformat(), "error_id":e.id, } err_list.append(err_dict) data_dict['last_error_id'] = last_error_id_number data_dict['errors'] = err_list data_dict['refresh_needed'] = '1' if len(err_list) > 0 else '0' response = HttpResponse(json.dumps(data_dict), content_type="application/json") response['Connection'] = 'close' return response
def get_experiment_update(request, instrument, ipts): """ Ajax call to get updates behind the scenes @param instrument: instrument name @param ipts: experiment name """ # Get instrument instrument_id = get_object_or_404(Instrument, name=instrument.lower()) # Get experiment ipts_id = get_object_or_404(IPTS, expt_name=ipts, instruments=instrument_id) # Get last experiment and last run data_dict = view_util.get_current_status(instrument_id) data_dict = dasmon.view_util.get_live_runs_update(request, instrument_id, ipts_id, **data_dict) response = HttpResponse(json.dumps(data_dict), content_type="application/json") response['Connection'] = 'close' return response
def get_instrument_update(request, instrument): """ Ajax call to get updates behind the scenes @param instrument: instrument name """ since = request.GET.get('since', '0') try: since = int(since) since_expt_id = get_object_or_404(IPTS, id=since) except: since = 0 since_expt_id = None # Get the instrument instrument_id = get_object_or_404(Instrument, name=instrument.lower()) # Get last experiment and last run data_dict = view_util.get_current_status(instrument_id) expt_list = IPTS.objects.filter(instruments=instrument_id, id__gt=since).order_by('created_on') update_list = [] if since_expt_id is not None and len(expt_list) > 0: data_dict['last_expt_id'] = expt_list[0].id for e in expt_list: if since_expt_id.created_on < e.created_on: localtime = timezone.localtime(e.created_on) df = dateformat.DateFormat(localtime) expt_dict = {"ipts":e.expt_name.upper(), "n_runs":e.number_of_runs(), "created_on":df.format(settings.DATETIME_FORMAT), "timestamp": e.created_on.isoformat(), "ipts_id":e.id, } update_list.append(expt_dict) data_dict['expt_list'] = update_list data_dict['refresh_needed'] = '1' if len(update_list) > 0 else '0' response = HttpResponse(json.dumps(data_dict), content_type="application/json") response['Connection'] = 'close' return response