Skip to content

Commit

Permalink
Merge pull request #94 from diggyk/master
Browse files Browse the repository at this point in the history
Tracking closing fate, and other minor fixes
  • Loading branch information
gmjosack committed Nov 13, 2015
2 parents 488b9fb + f163857 commit 559fbcf
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 17 deletions.
16 changes: 10 additions & 6 deletions bin/hermes-notify
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ def generate_plain_mesg(info, open_quests, owner, tags):
msg += "Machines with labors:\n"

for hostname in sorted(info[owner][quest_id]):
msg += " {} ({})\n".format(
hostname, (", ".join(tags[hostname]))
)
if tags[hostname]:
tags_str = "{}".format((", ".join(tags[hostname])))
else:
tags_str = "no services"
msg += " {} ({})\n".format(hostname, tags_str)

msg += "\n\n"

Expand Down Expand Up @@ -250,9 +252,11 @@ def generate_html_mesg(info, open_quests, owner, tags):

msg += "<pre style='margin-left: 10px; font-size: 1.2em'>"
for hostname in sorted(info[owner][quest_id]):
msg += "{} ({})\n".format(
hostname, (", ".join(tags[hostname]))
)
if tags[hostname]:
tags_str = "{}".format((", ".join(tags[hostname])))
else:
tags_str = "no services"
msg += "{} ({})\n".format(hostname, tags_str)

msg += "</pre></div>"

Expand Down
5 changes: 5 additions & 0 deletions db/update_to_0511.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE `labors` ADD `closing_fate_id` INT(11) DEFAULT NULL AFTER `fate_id`;
ALTER TABLE `labors` ADD INDEX `ix_labors_closing_fate_id` (`closing_fate_id`);

UPDATE `labors` SET `closing_fate_id`=5;
ALTER TABLE `labors` ADD FOREIGN KEY (`closing_fate_id`) REFERENCES `fates` (`id`);
33 changes: 28 additions & 5 deletions hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,12 @@ def question_the_fates(cls, session, events, quest=None, starting_fates=None):
if new_labor_dict not in all_new_labors:
all_new_labors.append(new_labor_dict)

# Now we can look at the open labors and see if the fate that
# created it has a child fate. If so, we will create the next
# labor. If not, we will close this labor.
# Now let's see if we should be closing any labors.
# We will see what fate created a labor, then examine all the fates
# that come after it. If the fates that come after have a creation
# event type that matches this events type, we know we should be
# transitioning on and should therefore close this labor (and
# possible create a new one).
if host.id in labors_by_hostid:
for labor in labors_by_hostid[host.id]:
creating_fate = all_fates[labor.fate_id]
Expand All @@ -770,7 +773,8 @@ def question_the_fates(cls, session, events, quest=None, starting_fates=None):
):
all_achieved_labors.append({
"labor": labor,
"event": event
"event": event,
"fate": fate,
})

# Since this Fate closes this Labor, let's see
Expand Down Expand Up @@ -1415,6 +1419,7 @@ class Labor(Model):
id: the unique database id
starting_labor_id: the database id of the labor that started chain of intermediate labors
fate_id: the fate that lead to the creation of this labor
closing_fate_id: the fate that lead to the closing of this labor
quest: the Quest to this this Labor belongs
host: the Host to which this Labor pertains
for_creator: if true, the labor will be designated for the quest creator
Expand All @@ -1440,7 +1445,16 @@ class Labor(Model):
fate_id = Column(
Integer, ForeignKey("fates.id"), nullable=False, index=True
)
fate = relationship(Fate, lazy="joined")
fate = relationship(
Fate, lazy="joined", foreign_keys=[fate_id]
)

closing_fate_id = Column(
Integer, ForeignKey("fates.id"), nullable=True, index=True
)
closing_fate = relationship(
Fate, lazy="joined", foreign_keys=[closing_fate_id]
)

quest_id = Column(
Integer, ForeignKey("quests.id"), nullable=True, index=True
Expand Down Expand Up @@ -1535,8 +1549,10 @@ def achieve_many(cls, session, labor_dicts):
for labor_dict in labor_dicts:
labor = labor_dict["labor"]
event = labor_dict["event"]
fate = labor_dict["fate"]
labor.update(
completion_event=event, completion_time=datetime.utcnow(),
closing_fate_id=fate['id'],
flush=False, commit=False
)

Expand Down Expand Up @@ -1653,6 +1669,7 @@ def to_dict(self, base_uri=None, expand=None):
"questId": self.quest_id,
"hostId": self.host_id,
"fateId": self.fate_id,
"closingFateId": self.closing_fate_id,
"forCreator": self.for_creator,
"forOwner": self.for_owner,
"creationTime": str(self.creation_time),
Expand All @@ -1671,6 +1688,12 @@ def to_dict(self, base_uri=None, expand=None):

if "fates" in expand:
out['fate'] = self.fate.to_dict(base_uri=base_uri, expand=set(expand))
if self.closing_fate:
out['closingFate'] = self.closing_fate.to_dict(
base_uri=base_uri, expand=set(expand)
)
else:
out['closingFate'] = None

if "quests" in expand:
if self.quest:
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.10"
__version__ = "0.5.11"
18 changes: 15 additions & 3 deletions hermes/webapp/src/js/controllers/laborStatusCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@

function pageSetting(page) {
if (angular.isDefined(page)) {
vm.offset = (page - 1) * vm.limit;
if (!isNaN(vm.limit)) {
vm.offset = (page - 1) * vm.limit;
} else {
vm.offset = 0;
}
} else {
return "" + (vm.offset / vm.limit + 1);
if (!isNaN(vm.limit)) {
return "" + (vm.offset / vm.limit + 1);
} else {
return 1;
}
}
}

Expand Down Expand Up @@ -280,7 +288,11 @@
}
}

vm.offset = index - (index % vm.limit);
if (!isNaN(vm.limit)) {
vm.offset = index - (index % vm.limit);
} else {
vm.offset = 0;
}

getHostTags();
}).catch(function(error) {
Expand Down
1 change: 1 addition & 0 deletions hermes/webapp/src/js/controllers/questStatusCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
}

function newQuestSelection(quest) {
vm.errorMessage = null;
var detailsDiv = document.getElementById('quest-details');
smoothScroll(detailsDiv, {duration: 700, easing: 'easeInOutQuad', offset: 100});
vm.selectedQuest = quest;
Expand Down
4 changes: 2 additions & 2 deletions hermes/webapp/src/js/directives/questProgressChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* directive for building quest progress bars with Raphael
*/
(function() {
function questProgressChart ($timeout, $window) {
function questProgressChart (hermesService, $timeout, $window) {
return {
restrict: 'A',
scope: {
Expand Down Expand Up @@ -189,5 +189,5 @@
}

angular.module('hermesApp').directive('questProgressChart', questProgressChart);
questProgressChart.$inject = ['$timeout', '$window'];
questProgressChart.$inject = ['HermesService', '$timeout', '$window'];
})();
7 changes: 7 additions & 0 deletions tests/api_tests/test_labors.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_creation(sample_data1_server):
"labors": [{"ackTime": None,
"ackUser": None,
"fateId": 1,
"closingFateId": None,
"completionEventId": None,
"creationEventId": 3,
"targetTime": str(target_time),
Expand All @@ -88,6 +89,7 @@ def test_creation(sample_data1_server):
"forOwner": True,
"forCreator": False,
"fateId": 1,
"closingFateId": None,
"id": 2,
"startingLaborId": None,
"questId": 1},
Expand All @@ -100,6 +102,7 @@ def test_creation(sample_data1_server):
"forOwner": True,
"forCreator": False,
"fateId": 1,
"closingFateId": None,
"id": 3,
"startingLaborId": None,
"questId": 1}],
Expand Down Expand Up @@ -159,6 +162,7 @@ def test_update(sample_data1_server):
"forOwner": True,
"forCreator": False,
"fateId": 1,
"closingFateId": None,
"id": 4,
"startingLaborId": None,
"questId": None
Expand All @@ -184,6 +188,7 @@ def test_update(sample_data1_server):
"targetTime": None,
"hostId": 1,
"fateId": 1,
"closingFateId": None,
"forOwner": True,
"forCreator": False,
"id": 4,
Expand Down Expand Up @@ -316,6 +321,7 @@ def test_quest_expansion(sample_data1_server):
'hostId': 1,
'id': 1,
'fateId': 1,
"closingFateId": None,
'quest': {
'completionTime': None,
'creator': 'johnny@example.com',
Expand All @@ -337,6 +343,7 @@ def test_quest_expansion(sample_data1_server):
'hostId': 2,
'id': 2,
'fateId': 1,
"closingFateId": None,
'quest': None,
'questId': None,
'startingLaborId': None
Expand Down

0 comments on commit 559fbcf

Please sign in to comment.