from __future__ import print_function, division, absolute_import

import datetime
import unittest
import tempfile
import shutil
import os

import numpy as np

import desisurvey.config
import desisurvey.progress

import surveysim.weather
import surveysim.simulator

class TestSurveySim(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        # Create a temporary directory.
        cls.tmpdir = tempfile.mkdtemp()
        # Write output files to this temporary directory.
        config = desisurvey.config.Configuration()
        config.set_output_path(cls.tmpdir)

    @classmethod
    def tearDownClass(cls):
        # Remove the directory after the test.
        shutil.rmtree(cls.tmpdir)
        # Reset our configuration.
        desisurvey.config.Configuration.reset()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_surveysim(self):
        gen = np.random.RandomState(123)
        start = datetime.date(2019,9,1)
        stop = datetime.date(2019,9,8)
        progress = desisurvey.progress.Progress()
        weather = surveysim.weather.Weather(start, stop, gen=gen)
        sim = surveysim.simulator.Simulator(
            start, stop, progress, weather, gen=gen)
        while sim.next_day():
            pass

        #- Confirm that observations occur only on survey dates.
        obs_table = progress.get_summary('observed')
        for obs in obs_table:
            night = desisurvey.utils.get_date(obs['mjd_min'])
            assert start <= night < stop


if __name__ == '__main__':
    unittest.main()

@@ -152,16 +152,38 @@
  as np%0A%0A
+import astropy.table%0A%0A
 import d
@@ -893,24 +893,24 @@
 f test_s
-urveysim
+imulator
 (self):%0A
@@ -1137,32 +1137,483 @@
  stop, gen=gen)%0A
+        # Initialize a table for efficiency stats tracking.%0A        stats = astropy.table.Table()%0A        config = desisurvey.config.Configuration()%0A        num_nights = (config.last_day() - config.first_day()).days%0A        stats%5B'available'%5D = np.zeros(num_nights)%0A        stats%5B'overhead'%5D = np.zeros(num_nights)%0A        stats%5B'delay'%5D = np.zeros(num_nights)%0A        stats%5B'dawn'%5D = np.zeros(num_nights)%0A        stats%5B'live'%5D = np.zeros(num_nights)%0A
         sim = su
@@ -1684,16 +1684,23 @@
 weather,
+ stats,
  gen=gen

Fix unit tests