def receivers_schedule(request, *args, **kws): """ For a given period, specified by a start date and duration, show all the receiver changes. Receiver changes are aligned with maintenance days. """ # interpret the inputs startdate = request.GET.get("startdate", None) startdate = datetime.strptime(startdate, "%Y-%m-%d %H:%M:%S") if startdate else None duration = request.GET.get("duration", None) duration = int(duration) if duration else duration # use the input to get the basic rx schedule schedule = Receiver_Schedule.extract_schedule(startdate, duration) jsonschd = Receiver_Schedule.jsondict(schedule) # some clients also need the diff schedule diff = Receiver_Schedule.diff_schedule(schedule) jsondiff = Receiver_Schedule.jsondict_diff(diff).get("diff_schedule", None) # get the dates for maintenace that cover from the start of this # rcvr schedule. maintenance = [ TimeAgent.dt2str(p.start) for p in Period.objects.filter(session__observing_type__type="maintenance", start__gte=startdate).order_by( "start" ) ] # which receivers are temporarily unavailable? unavailable = [r.jsondict() for r in Receiver.objects.filter(available=False).order_by("freq_low")] # clients want to also know all the latest rcvrs rcvrs = [r.jsondict() for r in Receiver.objects.all().order_by("freq_low") if r.abbreviation != "NS"] return HttpResponse( json.dumps( { "schedule": jsonschd, "diff": jsondiff, "maintenance": maintenance, "unavailable": unavailable, "receivers": rcvrs, } ), mimetype="text/plain", )