tb3/dist-packages/tb3/repostate.py | 2 - tb3/dist-packages/tb3/scheduler.py | 19 ++++++---- tb3/tb3 | 7 ++- tb3/tests/tb3/repostate.py | 14 +++++++ tb3/tests/tb3/scheduler.py | 68 +++++++++++++++++++++++++++++++------ 5 files changed, 88 insertions(+), 22 deletions(-)
New commits: commit 0aea4f950ef89ee77c47fb17ac3c9d026daefdc3 Author: Bjoern Michaelsen <[email protected]> Date: Fri Jul 26 23:44:34 2013 +0200 tweaking the scoring diff --git a/tb3/dist-packages/tb3/scheduler.py b/tb3/dist-packages/tb3/scheduler.py index 474eecd..c2164ba 100644 --- a/tb3/dist-packages/tb3/scheduler.py +++ b/tb3/dist-packages/tb3/scheduler.py @@ -39,21 +39,25 @@ class Scheduler: if len(commit) == 40: commits.append( (len(commits), commit, self.repohistory.get_commit_state(commit)) ) return commits - def norm_results(self, proposals): + def norm_results(self, proposals, offset): maxscore = 0 #maxscore = functools.reduce( lambda x,y: max(x.score, y.score), proposals) for proposal in proposals: maxscore = max(maxscore, proposal.score) + multiplier = (len(proposals) + offset) / maxscore if maxscore > 0: for proposal in proposals: - proposal.score = proposal.score / maxscore * len(proposals) + proposal.score = proposal.score * multiplier def dampen_running_commits(self, commits, proposals, time): + reduce_all = 0 for commit in commits: if commit[2].state == 'RUNNING': running_time = max(datetime.timedelta(), time - commit[2].started) timedistance = running_time.total_seconds() / commit[2].estimated_duration.total_seconds() for idx in range(len(proposals)): - proposals[idx].score *= 1-1/((commit[0]-idx+timedistance)**2+1) + proposals[idx].score *= 1-1/((abs(commit[0]-idx)+timedistance)**2+1) + reduce_all -= math.exp(-(timedistance**2)) + return reduce_all def get_proposals(self, time): return [(0, None, self.__class__.__name__)] @@ -62,14 +66,15 @@ class HeadScheduler(Scheduler): head = self.repostate.get_head() last_build = self.repostate.get_last_build() proposals = [] + reduce_all = 0 if not last_build is None: commits = self.get_commits(last_build, head) for commit in commits: proposals.append(self.make_proposal(1-1/((len(commits)-float(commit[0]))**2+1), commit[1])) - self.dampen_running_commits(commits, proposals, time) + reduce_all = self.dampen_running_commits(commits, proposals, time) else: proposals.append(self.make_proposal(float(1), head)) - self.norm_results(proposals) + self.norm_results(proposals, reduce_all) return proposals class BisectScheduler(Scheduler): @@ -86,8 +91,8 @@ class BisectScheduler(Scheduler): proposals.append(self.make_proposal(1.0, commit[1])) for idx in range(len(proposals)): proposals[idx].score *= (1-1/(float(idx)**2+1)) * (1-1/((float(idx-len(proposals)))**2+1)) - self.dampen_running_commits(commits, proposals, time) - self.norm_results(proposals) + reduce_all = self.dampen_running_commits(commits, proposals, time) + self.norm_results(proposals, reduce_all) return proposals class MergeScheduler(Scheduler): diff --git a/tb3/tests/tb3/scheduler.py b/tb3/tests/tb3/scheduler.py index 17870c6..bf0e328 100755 --- a/tb3/tests/tb3/scheduler.py +++ b/tb3/tests/tb3/scheduler.py @@ -21,6 +21,14 @@ import tb3.repostate class TestScheduler(unittest.TestCase): def __resolve_ref(self, refname): return self.git('show-ref', refname).split(' ')[0] + def _show_log(self, commit): + for line in self.git("log", "--pretty=oneline", commit): + sys.stdout.write(line) + print + def _show_proposals(self, proposals): + for proposal in proposals: + sys.stdout.write("%f %s" %(proposal.score, self.git("log", "-1", "--pretty=oneline", proposal.commit))) + print def setUp(self): (self.testdir, self.git) = helpers.createTestRepo() self.state = tb3.repostate.RepoState('linux', 'master', self.testdir) @@ -36,30 +44,70 @@ class TestScheduler(unittest.TestCase): sh.rm('-r', self.testdir) class TestHeadScheduler(TestScheduler): - def test_get_proposals(self): + def test_with_running(self): + #self._show_log(self.head) self.scheduler = tb3.scheduler.HeadScheduler('linux', 'master', self.testdir) self.state.set_last_good(self.preb1) proposals = self.scheduler.get_proposals(datetime.datetime.now()) self.assertEqual(len(proposals), 9) + proposals = sorted(proposals, key = lambda proposal: -proposal.score) + #self._show_proposals(proposals) best_proposal = proposals[0] - for proposal in proposals: - if proposal.score > best_proposal.score: - best_proposal = proposal - self.assertEqual(proposal.scheduler, 'HeadScheduler') + self.assertEqual(best_proposal.scheduler, 'HeadScheduler') self.assertEqual(best_proposal.commit, self.head) self.assertEqual(best_proposal.score, 9) + for idx in range(len(proposals)-1): + self.assertEqual(self.git('merge-base', '--is-ancestor', proposals[idx+1].commit, proposals[idx].commit, _ok_code=[0,1]).exit_code, 0) self.updater.set_scheduled(self.head, 'box', datetime.timedelta(hours=2)) proposals = self.scheduler.get_proposals(datetime.datetime.now()) self.assertEqual(len(proposals), 9) - proposal = proposals[0] + #self._show_proposals(proposals) + proposals = sorted(proposals, key = lambda proposal: -proposal.score) best_proposal = proposals[0] - for proposal in proposals: - if proposal.score > best_proposal.score: - best_proposal = proposal - self.assertEqual(proposal.scheduler, 'HeadScheduler') + self.assertEqual(best_proposal.scheduler, 'HeadScheduler') + precommits = self.scheduler.count_commits(self.preb1, best_proposal.commit) + postcommits = self.scheduler.count_commits(best_proposal.commit, self.head) + self.assertLessEqual(abs(precommits-postcommits),1) + self.updater.set_scheduled(best_proposal.commit, 'box', datetime.timedelta(hours=2)) + last_proposal = best_proposal + proposals = self.scheduler.get_proposals(datetime.datetime.now()) + self.assertEqual(len(proposals), 9) + #self._show_proposals(proposals) + proposals = sorted(proposals, key = lambda proposal: -proposal.score) + best_proposal = proposals[0] + self.assertEqual(best_proposal.scheduler, 'HeadScheduler') + def test_with_should_have_finished(self): + #self._show_log(self.head) + self.scheduler = tb3.scheduler.HeadScheduler('linux', 'master', self.testdir) + self.state.set_last_good(self.preb1) + proposals = self.scheduler.get_proposals(datetime.datetime.now()) + self.assertEqual(len(proposals), 9) + proposals = sorted(proposals, key = lambda proposal: -proposal.score) + #self._show_proposals(proposals) + best_proposal = proposals[0] + self.assertEqual(best_proposal.scheduler, 'HeadScheduler') + self.assertEqual(best_proposal.commit, self.head) + self.assertEqual(best_proposal.score, 9) + for idx in range(len(proposals)-1): + self.assertEqual(self.git('merge-base', '--is-ancestor', proposals[idx+1].commit, proposals[idx].commit, _ok_code=[0,1]).exit_code, 0) + self.updater.set_scheduled(self.head, 'box', datetime.timedelta(hours=4)) + proposals = self.scheduler.get_proposals(datetime.datetime.now()+datetime.timedelta(hours=2)) + self.assertEqual(len(proposals), 9) + #self._show_proposals(proposals) + proposals = sorted(proposals, key = lambda proposal: -proposal.score) + best_proposal = proposals[0] + self.assertEqual(best_proposal.scheduler, 'HeadScheduler') precommits = self.scheduler.count_commits(self.preb1, best_proposal.commit) postcommits = self.scheduler.count_commits(best_proposal.commit, self.head) self.assertLessEqual(abs(precommits-postcommits),1) + self.updater.set_scheduled(best_proposal.commit, 'box', datetime.timedelta(hours=4)) + last_proposal = best_proposal + proposals = self.scheduler.get_proposals(datetime.datetime.now()+datetime.timedelta(hours=2)) + self.assertEqual(len(proposals), 9) + #self._show_proposals(proposals) + proposals = sorted(proposals, key = lambda proposal: -proposal.score) + best_proposal = proposals[0] + self.assertEqual(best_proposal.scheduler, 'HeadScheduler') class TestBisectScheduler(TestScheduler): def test_get_proposals(self): commit 0f9f3bedf75acb6e7ffdcbf87b85cb5bbb8f150f Author: Bjoern Michaelsen <[email protected]> Date: Fri Jul 26 19:46:45 2013 +0200 test time storage too diff --git a/tb3/tests/tb3/repostate.py b/tb3/tests/tb3/repostate.py index c40c60c..436c3f3 100755 --- a/tb3/tests/tb3/repostate.py +++ b/tb3/tests/tb3/repostate.py @@ -70,6 +70,13 @@ class TestRepoHistory(unittest.TestCase): self.history.set_commit_state(self.head, commitstate) commitstate = self.history.get_commit_state(self.head) self.assertEqual(commitstate.estimated_duration, datetime.timedelta(hours=3, minutes=14)) + def test_times(self): + now = datetime.datetime.now() + commitstate = tb3.repostate.CommitState(started=now, finished=now) + self.history.set_commit_state(self.head, commitstate) + commitstate = self.history.get_commit_state(self.head) + self.assertEqual(commitstate.started, now) + self.assertEqual(commitstate.finished, now) class TestRepoUpdater(unittest.TestCase): def __resolve_ref(self, refname): commit aa78bf36c75d2002b61d6a4d6e046a07cdf56b09 Author: Bjoern Michaelsen <[email protected]> Date: Fri Jul 26 19:31:23 2013 +0200 test duration store diff --git a/tb3/tests/tb3/repostate.py b/tb3/tests/tb3/repostate.py index f69c372..c40c60c 100755 --- a/tb3/tests/tb3/repostate.py +++ b/tb3/tests/tb3/repostate.py @@ -65,7 +65,12 @@ class TestRepoHistory(unittest.TestCase): self.assertEqual(self.history.get_commit_state(self.head), commitstate) with self.assertRaises(AttributeError): self.history.set_commit_state(self.head, tb3.repostate.CommitState('foo!')) - + def test_duration(self): + commitstate = tb3.repostate.CommitState(estimated_duration=datetime.timedelta(hours=3, minutes=14)) + self.history.set_commit_state(self.head, commitstate) + commitstate = self.history.get_commit_state(self.head) + self.assertEqual(commitstate.estimated_duration, datetime.timedelta(hours=3, minutes=14)) + class TestRepoUpdater(unittest.TestCase): def __resolve_ref(self, refname): return self.git('show-ref', refname).split(' ')[0] commit 80c0ea235f2d6130b98ce4fff7e7e7d602df8fd1 Author: Bjoern Michaelsen <[email protected]> Date: Fri Jul 26 19:12:35 2013 +0200 fix timing diff --git a/tb3/dist-packages/tb3/repostate.py b/tb3/dist-packages/tb3/repostate.py index dd4e877..aee3061 100644 --- a/tb3/dist-packages/tb3/repostate.py +++ b/tb3/dist-packages/tb3/repostate.py @@ -27,7 +27,7 @@ class StateDecoder(json.JSONDecoder): if value[0] == '__datetime__': obj[key] = datetime.datetime.utcfromtimestamp(value[1]) elif value[0] == '__timedelta__': - obj[key] = datetime.timedelta(float(value[1])) + obj[key] = datetime.timedelta(0, float(value[1])) return obj class RepoState: commit 801ba10d0c4dc3aa30d4edf8787291dfed9965a0 Author: Bjoern Michaelsen <[email protected]> Date: Thu Jul 25 22:31:02 2013 +0200 handle tb3-show-history command name diff --git a/tb3/tb3 b/tb3/tb3 index 9ad22a6..10ccf6f 100755 --- a/tb3/tb3 +++ b/tb3/tb3 @@ -134,6 +134,7 @@ if __name__ == '__main__': if not fullcommand: args['sync'] = commandname == 'tb3-sync' args['show_proposals'] = commandname == 'tb3-show-proposals' + args['show_history'] = commandname == 'tb3-show-history' args['show_state'] = commandname == 'tb3-show-state' execute(args) commit d21f797943805467a7151bfb3a0063ceb13738f5 Author: Bjoern Michaelsen <[email protected]> Date: Thu Jul 25 22:21:44 2013 +0200 fix proposal printer diff --git a/tb3/tb3 b/tb3/tb3 index cabd1cd..9ad22a6 100755 --- a/tb3/tb3 +++ b/tb3/tb3 @@ -60,7 +60,7 @@ def show_proposals(parms): print('') print('Proposals:') for proposal in proposals: - print(proposals) + print(proposal) else: print(json.dumps([p.__dict__ for p in proposals])) commit 7cfeccc863df394aceb7bb92b4d97cdabf032d63 Author: Bjoern Michaelsen <[email protected]> Date: Thu Jul 25 22:20:59 2013 +0200 check for existance of key diff --git a/tb3/tb3 b/tb3/tb3 index 52df868..cabd1cd 100755 --- a/tb3/tb3 +++ b/tb3/tb3 @@ -40,12 +40,12 @@ def set_commit_running(parms): get_updater(parms).set_scheduled(parms['set_commit_running'], parms['builder'], parms['estimated_duration']) def show_state(parms): - if parms['format'] == 'json': + if parms.has_key('format') and parms['format'] == 'json': raise NotImplementedError print(get_repostate(parms)) def show_history(parms): - if parms['format'] == 'json': + if parms.has_key('format') and parms['format'] == 'json': raise NotImplementedError history = tb3.repostate.RepoHistory(parms['platform'], parms['repo']) for (commit, state) in history.get_recent_commit_states(parms['branch'], parms['history_count']): _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
