-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Historical lookup indexed db #1048
Changes from 23 commits
e3a129c
c9d7217
7bd4b21
d7b6f5b
824e3dd
139cb51
34415ef
df36999
85a96f0
95c1ae0
1e87456
3c69ae3
2a63ff5
e6b634c
93e794a
8e6d165
5b4d507
ebbac68
82974d5
697cd95
ed2f086
e325e3d
7e4898a
af85cd4
f7e6e14
8145d9e
7711eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,14 @@ OF ANY KIND, either express or implied. See the License for the specific languag | |
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const QUALIFIED_EVENT_TYPE = "decisioning.propositionQualified"; | ||
import { PropositionEventType } from "../Personalization/constants/propositionEventType"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't allow importing between components in Alloy. If this needs to be shared between the two components, put it into |
||
|
||
export default ({ eventRegistry }) => { | ||
const recordQualified = item => { | ||
const { id } = item; | ||
const recordQualified = id => { | ||
if (!id) { | ||
return undefined; | ||
} | ||
return eventRegistry.addEvent(item, QUALIFIED_EVENT_TYPE, id); | ||
return eventRegistry.addEvent({}, PropositionEventType.TRIGGER, id); | ||
}; | ||
|
||
return { recordQualified }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,16 +33,22 @@ export default ({ eventRegistry }) => { | |
} | ||
}; | ||
|
||
const evaluate = (context = {}) => | ||
Object.values(payloads) | ||
.map(payload => payload.evaluate(context)) | ||
.filter(payload => payload.items.length > 0); | ||
const evaluate = (context = {}) => { | ||
return new Promise(resolve => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wrapping |
||
Promise.all( | ||
Object.values(payloads).map(payload => payload.evaluate(context)) | ||
).then(consequences => { | ||
resolve(consequences.filter(payload => payload.items.length > 0)); | ||
}); | ||
}); | ||
}; | ||
|
||
const addPayloads = personalizationPayloads => { | ||
personalizationPayloads.forEach(addPayload); | ||
}; | ||
|
||
return { | ||
// TODO: remove addPayload below if unsed from outside of this file. | ||
addPayload, | ||
addPayloads, | ||
evaluate | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,11 @@ import { | |
JSON_CONTENT_ITEM, | ||
RULESET_ITEM | ||
} from "../Personalization/constants/schema"; | ||
import { DISPLAY } from "../Personalization/constants/eventType"; | ||
import { PropositionEventType } from "../Personalization/constants/propositionEventType"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before. If it needs to be shared across components, then it should be in the |
||
|
||
import flattenArray from "../../utils/flattenArray"; | ||
import createConsequenceAdapter from "./createConsequenceAdapter"; | ||
import { getActivityId } from "./utils"; | ||
|
||
const isRulesetItem = item => { | ||
const { schema, data } = item; | ||
|
@@ -42,6 +43,7 @@ const isRulesetItem = item => { | |
|
||
export default (payload, eventRegistry, decisionHistory) => { | ||
const consequenceAdapter = createConsequenceAdapter(); | ||
const activityId = getActivityId(payload); | ||
const items = []; | ||
|
||
const addItem = item => { | ||
|
@@ -59,31 +61,51 @@ export default (payload, eventRegistry, decisionHistory) => { | |
}; | ||
|
||
const evaluate = context => { | ||
const displayEvent = eventRegistry.getEvent(DISPLAY, payload.id); | ||
|
||
const displayedDate = displayEvent | ||
? displayEvent.firstTimestamp | ||
: undefined; | ||
|
||
const qualifyingItems = flattenArray( | ||
items.map(item => item.execute(context)) | ||
) | ||
.map(consequenceAdapter) | ||
.map(item => { | ||
const { | ||
firstTimestamp: qualifiedDate | ||
} = decisionHistory.recordQualified(item); | ||
|
||
return { | ||
...item, | ||
data: { ...item.data, qualifiedDate, displayedDate } | ||
}; | ||
}); | ||
|
||
return { | ||
...payload, | ||
items: qualifyingItems | ||
}; | ||
return new Promise(resolve => { | ||
let consequencesFlattened = []; | ||
Promise.all(items.map(item => item.execute(context))) | ||
.then(consequences => { | ||
consequencesFlattened = flattenArray(consequences).map( | ||
consequenceAdapter | ||
); | ||
if (!consequencesFlattened || consequencesFlattened.length === 0) { | ||
resolve({ | ||
...payload, | ||
items: [] | ||
}); | ||
return; | ||
} | ||
|
||
decisionHistory.recordQualified(activityId); | ||
}) | ||
.then(() => | ||
Promise.all([ | ||
eventRegistry.getEventsFirstTimestamp( | ||
PropositionEventType.DISPLAY, | ||
activityId | ||
), | ||
eventRegistry.getEventsFirstTimestamp( | ||
PropositionEventType.TRIGGER, | ||
activityId | ||
) | ||
]) | ||
) | ||
.then(dates => { | ||
const displayedDate = dates[0]; | ||
const qualifiedDate = dates[1]; | ||
const qualifyingItems = consequencesFlattened.map(item => { | ||
return { | ||
...item, | ||
data: { ...item.data, qualifiedDate, displayedDate } | ||
}; | ||
}); | ||
|
||
resolve({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before. Wrapping it in |
||
...payload, | ||
items: qualifyingItems | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
if (Array.isArray(payload.items)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,12 @@ const validateOptions = ({ options }) => { | |
|
||
export default ({ contextProvider, decisionProvider }) => { | ||
const run = ({ renderDecisions, decisionContext, applyResponse }) => { | ||
return applyResponse({ | ||
renderDecisions, | ||
propositions: decisionProvider.evaluate( | ||
contextProvider.getContext(decisionContext) | ||
) | ||
return new Promise(resolve => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
decisionProvider | ||
.evaluate(contextProvider.getContext(decisionContext)) | ||
.then(propositions => { | ||
resolve(applyResponse({ renderDecisions, propositions })); | ||
}); | ||
}); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for local e2e test, will add dependency once rule engine changes are approved & published.