示例#1
0
    def setUp(self):
        super(PeriodsTestCase, self).setUp()

        # setup some periods
        self.start = datetime(2000, 1, 1, 0)
        self.end   = self.start + timedelta(hours = 12)
        times = [(datetime(2000, 1, 1, 0), 5.0, "one", "S")
               , (datetime(2000, 1, 1, 5), 3.0, "two", "P")
               , (datetime(2000, 1, 1, 8), 4.0, "three", "S")
               ]
        self.ps = []
        for start, dur, name, st in times:
            s = create_sesshun()
            s.name = name
            s.save()
            scheduled = dur if st == "S" else 0.0
            pa = Period_Accounting(scheduled = scheduled)
            pa.save()
            state = Period_State.objects.get(abbreviation = st)
            p = Period( session    = s
                      , start      = start
                      , duration   = dur
                      , state      = state
                      , accounting = pa
                      )
            p.save()
            self.ps.append(p)
示例#2
0
    def test_update_from_post(self):

       # all zero times
        pa = Period_Accounting(scheduled = 0.0)
        pa.save()

        fields = pa.getFloatFields()
        for f in fields:
            self.assertEquals(0.0, pa.get_time(f))

        fdata = {}
        pa.update_from_post(fdata)
        for f in fields:
            self.assertEquals(0.0, pa.get_time(f))

        fdata = {"scheduled" : 4.0
               , "lost_time_weather" : 1.0
               , "lost_time_bill_project" : 1.0
               , "not_billable" : 1.0
                 }
        pa.update_from_post(fdata)
        nonzero = fdata.keys()
        nonzero.extend(["observed"
                      , "lost_time"
                      , "time_billed"])
        for f in fields:
            if f not in nonzero:
                self.assertEquals(0.0, pa.get_time(f))
        self.assertEquals(pa.get_time("scheduled"), 4.0)    
        self.assertEquals(pa.get_time("observed"),  3.0)    
        self.assertEquals(pa.get_time("time_billed"),  2.0)    
        self.assertEquals(pa.get_time("lost_time_weather"), 1.0)    
        self.assertEquals(pa.get_time("lost_time"), 1.0)
示例#3
0
    def setUp(self):
        super(TestProposal, self).setUp()

        # this project has no allotments!
        self.project = DSSProject.objects.order_by('pcode').all()[0]

        # setup some periods
        self.start = datetime(2000, 1, 1, 0)
        self.end   = self.start + timedelta(hours = 12)
        times = [(datetime(2000, 1, 1, 0), 5.0, "one")
               , (datetime(2000, 1, 1, 5), 3.0, "two")
               , (datetime(2000, 1, 1, 8), 4.0, "three")
               ]
        self.ps = []
        state = DSSPeriod_State.objects.get(abbreviation = 'P')
        for start, dur, name in times:
            # each session has grade 4, time = 3 
            s = create_sesshun()
            s.name = name
            s.save()
            pa = DSSPeriod_Accounting(scheduled = dur)
            pa.save()
            p = DSSPeriod( session    = s
                      , start      = start
                      , duration   = dur
                      , state      = state
                      , accounting = pa
                      )
            p.save()
            self.ps.append(p)


        # Okay, now set up the corresponding proposal
        now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        sqlResult = { 'PROP_ID' : self.project.pcode
                    , 'PROPOSAL_TYPE' : 'Regular'
                    , 'STATUS' : 'Draft'
                    , 'SUBMITTED_DATE' : now 
                    , 'CREATED_DATE' : now 
                    , 'MODIFIED_DATE' : now 
                    , 'TITLE' : 'Lynrd Sknyrd'
                    , 'ABSTRACT' : 'What song do you wanna hear?'
                    , 'proposal_id' : 0
                    , 'JOINT_PROPOSAL_TYPE' : 'Not a joint Proposal'
                    }
        proposal = Proposal.createFromSqlResult(sqlResult)
        proposal.dss_project = self.project
        proposal.setSemester(self.project.semester.semester)
        proposal.save()
        self.proposal = proposal

        self.ta = TimeAccounting()
示例#4
0
    def test_1(self):
       # all zero times
        pa = Period_Accounting(scheduled = 0.0)
        pa.save()

        fields = pa.getFloatFields()
        for f in fields:
            self.assertEquals(0.0, pa.get_time(f))

        # just scheduled time
        pa.set_changed_time("scheduled", 4.0)
        pa.save()
        nonzero = ["scheduled", "observed", "time_billed"]
        for f in fields:
            if f not in nonzero:
                self.assertEquals(0.0, pa.get_time(f))
        for f in nonzero:        
            self.assertEquals(4.0, pa.get_time(f))

        # now lose some time
        pa.set_changed_time("lost_time_weather", 1.0)    
        self.assertEquals((True, None), pa.validate())
        pa.save()
        nonzero.extend(["lost_time_weather", "lost_time"])
        for f in fields:
            if f not in nonzero:
                self.assertEquals(0.0, pa.get_time(f))
        self.assertEquals(pa.get_time("scheduled"), 4.0)    
        self.assertEquals(pa.get_time("observed"),  3.0)    
        self.assertEquals(pa.get_time("time_billed"),  3.0)    
        self.assertEquals(pa.get_time("lost_time_weather"), 1.0)    
        self.assertEquals(pa.get_time("lost_time"), 1.0)    

        # loss too much time
        pa.set_changed_time("lost_time_weather", 100.0)    
        msg = (False, 'time_billed cannot be negative.  Please check times.')
        self.assertEquals(msg, pa.validate())
        pa.set_changed_time("lost_time_weather", 1.0)

        # misc
        pa.lost_time_bill_project = 1.0
        pa.not_billable = 1.0
        self.assertEquals((True, None), pa.validate())
        pa.save()
        nonzero.extend(["lost_time_bill_project", "not_billable"])
        for f in fields:
            if f not in nonzero:
                self.assertEquals(0.0, pa.get_time(f))
        self.assertEquals(pa.get_time("scheduled"), 4.0)    
        self.assertEquals(pa.get_time("observed"),  3.0)    
        self.assertEquals(pa.get_time("time_billed"),  2.0)    
        self.assertEquals(pa.get_time("lost_time_weather"), 1.0)    
        self.assertEquals(pa.get_time("lost_time"), 1.0)
示例#5
0
    def from_post(self, fdata, tz):
        # only update the score if something in the period has changed
        update_score = False
        if not update_score:
            update_score = self.period.id is None
        # if newly created then start with a default 
        if update_score:
            self.period.reinit_score()
        handle = fdata.get("handle", "")
        if handle:
            new_session = Sesshun.handle2session(handle)
            if not update_score:
                update_score = self.period.session != new_session
            self.period.session = new_session
        else:
            try:
                maintenance = Project.objects.get(pcode='Maintenance')
                self.period.session = Sesshun.objects.get(project=maintenance)
            except:
                self.period.session  = Sesshun.objects.get(id=fdata.get("session", 1))
        now           = TimeAgent.quarter(datetime.utcnow())
        date          = fdata.get("date", None)
        time          = fdata.get("time", "00:00")
        if date is None:
            self.period.start = now
        else:
            new_start = TimeAgent.quarter(strStr2dt(date, time + ':00'))
            if tz == 'ET':
                new_start = TimeAgent.est2utc(self.period.start)
            if not update_score:
                update_score = self.period.start != new_start
            self.period.start = new_start
        new_duration = TimeAgent.rndHr2Qtr(float(fdata.get("duration", "1.0")))
        if not update_score:
            update_score = self.period.duration != new_duration
        self.period.duration = new_duration
        
        # if the score needs to be updated, then prepare it for this
        if update_score and now < self.period.start:
            self.period.reinit_score()
        self.period.backup   = True if fdata.get("backup", None) == 'true' else False
        stateAbbr = fdata.get("state", "P")
        self.period.state = Period_State.objects.get(abbreviation=stateAbbr)
        self.period.moc_ack = fdata.get("moc_ack", self.period.moc_ack)

        # elective? 
        eId = fdata.get("elective_id", None)
        if eId is not None:
            self.period.elective_id = eId

        # window?    
        wId = fdata.get("window_id", None)
        if wId is not None:
            self.period.window_id = wId
            try:
                win = Window.objects.get(id = wId)
            except Window.DoesNotExist:
                pass
            else:
                end = win.last_date()
                if end and date is None:
                    self.period.start = datetime(end.year, end.month, end.day)
                    self.period.duration = 1
                    
        elif self.period.session.isWindowed() and self.period.window_id is None:
            # just because the window id wasn't specified doesn't mean
            # we don't want to assign this a window:
            # for instance, if this period was created outside of the 
            # Windowed Period Explorer, we'll have to assign a window
            self.period.assign_a_window()

        # is this period a default period for a window?
        default = fdata.get("wdefault", None)
        if default is not None: #
            if default == "true" and self.period.window is not None:
                # assign this period as a default
                self.period.window.default_period = self.period
                self.period.window.save()
            elif default == "false" and self.period.window is not None:
                # unassign this period as a default
                self.period.window.default_period = None
                self.period.window.save()
            
        # how to initialize scheduled time? when they get published!
        # so, only create an accounting object if it needs it.
        if self.period.accounting is None:
            schd = self.period.duration if self.period.isScheduled() else 0.0 
            pa = Period_Accounting(scheduled = schd)
            pa.save()
            self.period.accounting = pa

        self.period.accounting.update_from_post(fdata)

        self.period.save()

        # now that we have an id (from saving), we can specify the relation
        # between this period and assocaited rcvrs
        self.update_rcvrs_from_post(fdata)