-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adding safeguards for NPEs and certain conditions #57
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash -e | ||
|
||
curl -s -X DELETE http://localhost:9200/ubi_queries,ubi_events | ||
|
||
curl -s -X POST http://localhost:9200/_plugins/ubi/initialize |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,25 +237,31 @@ private Map<String, Set<ClickthroughRate>> getClickthroughRate(final int maxRank | |
// We need to the hash of the query_id because two users can both search | ||
// for "computer" and those searches will have different query IDs, but they are the same search. | ||
final String userQuery = openSearchHelper.getUserQuery(ubiEvent.getQueryId()); | ||
// LOGGER.debug("user_query = {}", userQuery); | ||
|
||
// Get the clicks for this queryId from the map, or an empty list if this is a new query. | ||
final Set<ClickthroughRate> clickthroughRates = queriesToClickthroughRates.getOrDefault(userQuery, new LinkedHashSet<>()); | ||
// userQuery will be null if there is not a query for this event in ubi_queries. | ||
if(userQuery != null) { | ||
|
||
// Get the ClickthroughRate object for the object that was interacted with. | ||
final ClickthroughRate clickthroughRate = clickthroughRates.stream().filter(p -> p.getObjectId().equals(ubiEvent.getEventAttributes().getObject().getObjectId())).findFirst().orElse(new ClickthroughRate(ubiEvent.getEventAttributes().getObject().getObjectId())); | ||
// LOGGER.debug("user_query = {}", userQuery); | ||
|
||
if (EVENT_CLICK.equalsIgnoreCase(ubiEvent.getActionName())) { | ||
//LOGGER.info("Logging a CLICK on " + ubiEvent.getEventAttributes().getObject().getObjectId()); | ||
clickthroughRate.logClick(); | ||
} else { | ||
//LOGGER.info("Logging a VIEW on " + ubiEvent.getEventAttributes().getObject().getObjectId()); | ||
clickthroughRate.logEvent(); | ||
} | ||
// Get the clicks for this queryId from the map, or an empty list if this is a new query. | ||
final Set<ClickthroughRate> clickthroughRates = queriesToClickthroughRates.getOrDefault(userQuery, new LinkedHashSet<>()); | ||
|
||
// Get the ClickthroughRate object for the object that was interacted with. | ||
final ClickthroughRate clickthroughRate = clickthroughRates.stream().filter(p -> p.getObjectId().equals(ubiEvent.getEventAttributes().getObject().getObjectId())).findFirst().orElse(new ClickthroughRate(ubiEvent.getEventAttributes().getObject().getObjectId())); | ||
|
||
if (EVENT_CLICK.equalsIgnoreCase(ubiEvent.getActionName())) { | ||
//LOGGER.info("Logging a CLICK on " + ubiEvent.getEventAttributes().getObject().getObjectId()); | ||
clickthroughRate.logClick(); | ||
} else { | ||
//LOGGER.info("Logging a VIEW on " + ubiEvent.getEventAttributes().getObject().getObjectId()); | ||
clickthroughRate.logEvent(); | ||
} | ||
|
||
clickthroughRates.add(clickthroughRate); | ||
queriesToClickthroughRates.put(userQuery, clickthroughRates); | ||
// LOGGER.debug("clickthroughRate = {}", queriesToClickthroughRates.size()); | ||
clickthroughRates.add(clickthroughRate); | ||
queriesToClickthroughRates.put(userQuery, clickthroughRates); | ||
// LOGGER.debug("clickthroughRate = {}", queriesToClickthroughRates.size()); | ||
|
||
} | ||
|
||
} | ||
|
||
|
@@ -310,7 +316,7 @@ public Map<Integer, Double> getRankAggregatedClickThrough() throws Exception { | |
final SearchResponse searchResponse = client.search(searchRequest).get(); | ||
|
||
final Map<Integer, Double> clickCounts = new HashMap<>(); | ||
final Map<Integer, Double> viewCounts = new HashMap<>(); | ||
final Map<Integer, Double> impressionCounts = new HashMap<>(); | ||
|
||
final Terms actionTerms = searchResponse.getAggregations().get("By_Action"); | ||
final Collection<? extends Terms.Bucket> actionBuckets = actionTerms.getBuckets(); | ||
|
@@ -324,6 +330,7 @@ public Map<Integer, Double> getRankAggregatedClickThrough() throws Exception { | |
final Collection<? extends Terms.Bucket> positionBuckets = positionTerms.getBuckets(); | ||
|
||
for(final Terms.Bucket positionBucket : positionBuckets) { | ||
LOGGER.info("Inserting client event from position {} with click count {}", positionBucket.getKey(), (double) positionBucket.getDocCount()); | ||
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. will this be crazy verbose? |
||
clickCounts.put(Integer.valueOf(positionBucket.getKey().toString()), (double) positionBucket.getDocCount()); | ||
} | ||
|
||
|
@@ -336,16 +343,28 @@ public Map<Integer, Double> getRankAggregatedClickThrough() throws Exception { | |
final Collection<? extends Terms.Bucket> positionBuckets = positionTerms.getBuckets(); | ||
|
||
for(final Terms.Bucket positionBucket : positionBuckets) { | ||
viewCounts.put(Integer.valueOf(positionBucket.getKey().toString()), (double) positionBucket.getDocCount()); | ||
LOGGER.info("Inserting client event from position {} with click count {}", positionBucket.getKey(), (double) positionBucket.getDocCount()); | ||
impressionCounts.put(Integer.valueOf(positionBucket.getKey().toString()), (double) positionBucket.getDocCount()); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
for(final Integer x : clickCounts.keySet()) { | ||
//System.out.println("Position = " + x + ", Click Count = " + clickCounts.get(x) + ", Event Count = " + viewCounts.get(x)); | ||
rankAggregatedClickThrough.put(x, clickCounts.get(x) / viewCounts.get(x)); | ||
|
||
if(!(impressionCounts.get(x) == null)) { | ||
|
||
// Calculate the CTR by dividing the number of clicks by the number of impressions. | ||
LOGGER.info("Position = {}, Click Count = {}, Event Count = {}", x, clickCounts.get(x), impressionCounts.get(x)); | ||
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. just wondering if these .info are really .debug? 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. Yes, they are. Probably could use a good going-over to make sure level are appropriate. |
||
rankAggregatedClickThrough.put(x, clickCounts.get(x) / impressionCounts.get(x)); | ||
|
||
} else { | ||
// This will happen in the case where a document has a "click" event but not an "impression." This | ||
// likely should not happen, but we will protect against an NPE anyway by setting the CTR to zero. | ||
rankAggregatedClickThrough.put(x, (double) 0); | ||
} | ||
|
||
} | ||
|
||
if(parameters.isPersist()) { | ||
|
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.
so this is to go a lot deeper....?
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.
Yes, 20 was the original. 1 was for testing.