Skip to content

Commit f761e06

Browse files
committed
fix: better handling of constraints
1 parent 724f458 commit f761e06

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/phase-management/PhaseAdvancer.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ class PhaseAdvancer {
7777
};
7878

7979
const phaseSpecificFacts = await this.#challengeDomain.getPhaseFacts(phaseSpecificFactRequest);
80-
console.log("phase-specific-facts", JSON.stringify(phaseSpecificFacts, null, 2));
81-
8280
const facts = {
8381
name: phase.name,
8482
isOpen: phase.isOpen,
@@ -108,7 +106,7 @@ class PhaseAdvancer {
108106

109107
async advancePhase(challengeId, legacyId, phases, operation, phaseName) {
110108
const matchedPhases = phases
111-
.filter((phase) => phase.actualEndDate == null && phase.name === phaseName)
109+
// .filter((phase) => phase.actualEndDate == null && phase.name === phaseName)
112110
.sort((a, b) => new Date(a.scheduledStartDate) - new Date(b.scheduledStartDate));
113111

114112
if (matchedPhases.length === 0) {
@@ -132,17 +130,23 @@ class PhaseAdvancer {
132130
)
133131
.map((constraint) => ({
134132
name: `Constraint: ${constraint.name}`,
135-
fact: normalizeName(constraint.name),
136-
operator: "greaterOrEqual",
137-
value: constraint.value,
133+
conditions: {
134+
all: [
135+
{
136+
fact: this.#rules.constraintNameFactMap[normalizeName(constraint.name)],
137+
operator: "greaterThanInclusive",
138+
value: constraint.value,
139+
},
140+
],
141+
},
142+
event: {
143+
type: `can${operation.toLowerCase()}`,
144+
},
138145
})) || [];
139146

140147
const rules = [...essentialRules, ...constraintRules];
141148
const facts = await this.#generateFacts(challengeId, legacyId, phases, phase, operation);
142149

143-
console.log("rules", JSON.stringify(rules, null, 2));
144-
console.log("facts", JSON.stringify(facts, null, 2));
145-
146150
for (const rule of rules) {
147151
const ruleExecutionResult = await this.#executeRule(rule, facts);
148152

@@ -190,9 +194,6 @@ class PhaseAdvancer {
190194
}
191195

192196
async #open(challengeId, phases, phase) {
193-
console.log(`Opening phase ${phase.name} for challenge ${challengeId}`);
194-
console.log("Phases", phases);
195-
console.log("Phase", phase);
196197
phase.isOpen = true;
197198
const actualStartDate = new Date();
198199
phase.actualStartDate = actualStartDate.toISOString();
@@ -365,7 +366,6 @@ class PhaseAdvancer {
365366
async #executeRule(rule, facts) {
366367
const ruleEngine = new Engine();
367368
ruleEngine.addRule(rule);
368-
369369
const result = await ruleEngine.run(facts);
370370

371371
const failureReasons = result.failureResults.map((failureResult) => ({

src/phase-management/phase-rules.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,5 +365,9 @@
365365
"constraintRules": {
366366
"Registration": ["NumberofRegistrants"],
367367
"Submission": ["NumberofSubmissions"]
368+
},
369+
"constraintNameFactMap": {
370+
"NumberofRegistrants": "registrantCount",
371+
"NumberofSubmissions": "submissionCount"
368372
}
369373
}

0 commit comments

Comments
 (0)