Esempio n. 1
0
    def plot(self, schedules):
        plt = self.fig.add_subplot(111)
        plt.set_title('Nightly Schedules')
        plt.set_ylabel('Time (min)')
        ind = np.arange(len(schedules))
        date_list = []
        sched_minutes = []
        unsched_minutes = []
        for schedule in schedules:
            date_list.append(schedule.start_time.strftime('%Y-%m-%d'))
            time_avail = schedule.stop_time - schedule.start_time
            time_avail_minutes = time_avail.total_seconds() / 60.0
            time_waste_minutes = qsim.eval_schedule(
                schedule).time_waste_sec / 60.0
            sched_minutes.append(time_avail_minutes - time_waste_minutes)
            unsched_minutes.append(time_waste_minutes)
        self.logger.debug('ind %s' % ind)
        self.logger.debug('date_list %s' % date_list)
        self.logger.debug('sched_minutes %s' % sched_minutes)
        self.logger.debug('unsched_minutes %s' % unsched_minutes)
        sched_bar = plt.bar(ind, sched_minutes, self.barWidth, color='g')
        unsched_bar = plt.bar(ind,
                              unsched_minutes,
                              self.barWidth,
                              color='darkred',
                              bottom=sched_minutes)
        plt.set_xticks(ind + self.barWidth / 2.)
        plt.set_xticklabels(date_list, rotation=45, ha='right')
        plt.legend((unsched_bar, sched_bar),
                   ('Delay+Unscheduled', 'Scheduled'),
                   prop=self.legendFont)

        self.draw()
Esempio n. 2
0
    def add_schedule(self, schedule):
        res = qsim.eval_schedule(schedule)

        start_time = schedule.start_time
        sdlr = self.model.get_scheduler()
        t = start_time.astimezone(sdlr.timezone)
        ndate = t.strftime("%Y-%m-%d")
        filters = ', '.join(schedule.data.filters)

        if six.PY2:
            out_f = BytesIO()
        else:
            out_f = StringIO()

        out_f.write("--- NIGHT OF %s --- filters: %s\n" % (
            ndate, filters))
        out_f.write("Queue prepared at: %s\n" % (
            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        out_f.write("%-16.16s  %-8.8s  %-10.10s %12.12s  %5.5s  %5.5s %7.7s %-10.10s %-6.6s  %3.3s  %s\n" % (
            'Date', 'ObsBlk', 'Code', 'Program', 'Grade', 'Rank', 'Time',
            'Target', 'Filter', 'AM', 'Comment'))

        targets = {}
        for slot in schedule.slots:

            t = slot.start_time.astimezone(sdlr.timezone)
            date = t.strftime("%Y-%m-%d %H:%M")
            ob = slot.ob
            if ob != None:
                t_prog = slot.start_time + timedelta(0, ob.total_time)
                comment = ob.comment
                if not ob.derived:
                    # not an OB generated to serve another OB
                    key = (ob.target.ra, ob.target.dec)
                    targets[key] = ob.target

                out_f.write("%-16.16s  %-8.8s  %-10.10s %12.12s  %5.5s  %5.2f %7.2f %-10.10s %-6.6s  %3.1f  %s\n" % (
                    date, str(ob), ob.name, ob.program, ob.program.grade, ob.program.rank,
                    ob.total_time / 60, ob.target.name,
                    ob.inscfg.filter, ob.envcfg.airmass,
                    comment))
            else:
                out_f.write("%-16.16s  %-8.8s\n" % (date, str(ob)))

        out_f.write("\n")
        time_avail = (schedule.stop_time - schedule.start_time).total_seconds() / 60.0
        waste = res.time_waste_sec / 60.0
        out_f.write("%d targets  %d filter exch  Time: avail=%.2f sched=%.2f unsched=%.2f min\n" % (
            len(targets), res.num_filter_exchanges, time_avail, (time_avail - waste), waste))
        out_f.write("\n")

        self.schedules[schedule] = Bunch.Bunch(report=out_f.getvalue())
        out_f.close()

        return True
Esempio n. 3
0
    def add_schedule(self, schedule):
        res = qsim.eval_schedule(schedule)

        start_time = schedule.start_time
        sdlr = self.model.get_scheduler()
        t = start_time.astimezone(sdlr.timezone)
        ndate = t.strftime("%Y-%m-%d")
        filters = ', '.join(schedule.data.filters)

        if six.PY2:
            out_f = BytesIO()
        else:
            out_f = StringIO()

        out_f.write("--- NIGHT OF %s --- filters: %s\n" % (
            ndate, filters))
        out_f.write("Queue prepared at: %s\n" % (
            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        out_f.write("%-16.16s  %-8.8s  %-10.10s %12.12s  %5.5s %7.7s %-10.10s %-6.6s  %3.3s  %s\n" % (
            'Date', 'ObsBlk', 'Code', 'Program', 'Rank', 'Time',
            'Target', 'Filter', 'AM', 'Comment'))

        targets = {}
        for slot in schedule.slots:

            t = slot.start_time.astimezone(sdlr.timezone)
            date = t.strftime("%Y-%m-%d %H:%M")
            ob = slot.ob
            if ob != None:
                t_prog = slot.start_time + timedelta(0, ob.total_time)
                comment = ob.comment
                if not ob.derived:
                    # not an OB generated to serve another OB
                    key = (ob.target.ra, ob.target.dec)
                    targets[key] = ob.target

                out_f.write("%-16.16s  %-8.8s  %-10.10s %12.12s  %5.2f %7.2f %-10.10s %-6.6s  %3.1f  %s\n" % (
                    date, str(ob), ob.name, ob.program, ob.program.rank,
                    ob.total_time / 60, ob.target.name,
                    ob.inscfg.filter, ob.envcfg.airmass,
                    comment))
            else:
                out_f.write("%-16.16s  %-8.8s\n" % (date, str(ob)))

        out_f.write("\n")
        time_avail = (schedule.stop_time - schedule.start_time).total_seconds() / 60.0
        waste = res.time_waste_sec / 60.0
        out_f.write("%d targets  %d filter exch  Time: avail=%.2f sched=%.2f unsched=%.2f min\n" % (
            len(targets), res.num_filter_exchanges, time_avail, (time_avail - waste), waste))
        out_f.write("\n")

        self.schedules[schedule] = Bunch.Bunch(report=out_f.getvalue())
        out_f.close()

        return True
Esempio n. 4
0
    def plot(self, sldr, completed, uncompleted, schedules):
        plt = self.fig.add_subplot(111)
        total_time_avail = 0.
        total_time_waste = 0.
        propID_alloc_minutes = {}
        grades_dict = {}
        for grade in self.grades:
            grades_dict[grade] = []
        for schedule in schedules:
            time_avail = schedule.stop_time - schedule.start_time
            time_avail_minutes = time_avail.total_seconds() / 60.0

            sched_eval_res = qsim.eval_schedule(schedule)
            time_waste_minutes = sched_eval_res.time_waste_sec / 60.0
            total_time_avail += time_avail_minutes
            total_time_waste += time_waste_minutes
            for propID, seconds in six.iteritems(
                    sched_eval_res.proposal_total_time_sec):
                if propID not in grades_dict[sldr.programs[propID].grade]:
                    grades_dict[sldr.programs[propID].grade].append(propID)
                if propID in propID_alloc_minutes:
                    propID_alloc_minutes[propID] += seconds / 60.0
                else:
                    propID_alloc_minutes[propID] = seconds / 60.0

        total_time_sched = total_time_avail - total_time_waste
        self.logger.debug('propID_alloc_minutes %s' % propID_alloc_minutes)
        self.logger.debug('total_time_avail %f min' % total_time_avail)
        self.logger.debug('total_time_sched %f min' % total_time_sched)
        self.logger.debug('total_time_waste %f min' % total_time_waste)

        # For the pie chart, we want all proposals grouped into their
        # "grade" category and then, within that category, sort the
        # proposals by their proposal ID.
        labels = []
        sizes = []
        colors = []
        for grade in self.grades:
            for propID in sorted(grades_dict[grade]):
                labels.append(propID)
                sizes.append(propID_alloc_minutes[propID])
                colors.append(self.grade_colors[grade])

        labels.append('Unscheduled')
        sizes.append(total_time_waste)
        colors.append('darkred')
        plt.pie(sizes,
                labels=labels,
                colors=colors,
                autopct='%2.0f%%',
                shadow=True)
        if '-' in labels[0]:
            # TODO: title if nothing can be scheduled
            semester, ident = labels[0].split('-')
            plt.set_title('Total for Semester = %5.0f Hours' %
                          (total_time_avail / 60.0))

        # Create some matplotlib "Patches" so that we can use them in
        # the legend
        legend_patches = []
        legend_titles = []
        for grade in self.grades:
            legend_patches.append(
                mpatches.Patch(color=self.grade_colors[grade]))
            legend_titles.append(grade)

        plt.legend(legend_patches,
                   legend_titles,
                   prop=self.legendFont,
                   title='Grades',
                   loc='upper right',
                   bbox_to_anchor=(1, 1),
                   handlelength=1)

        self.draw()