-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #796.
- Loading branch information
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# dedupe: filter out any cohorts whose inputs have already appeared at least once. | ||
|
||
require "json" | ||
require "set" | ||
|
||
STDERR.puts "[+] pass: dedupe" | ||
|
||
count = 0 | ||
seen = Set.new | ||
STDIN.each_line do |line| | ||
result = JSON.parse line, symbolize_names: true | ||
|
||
# add? returns nil if the element is already present, saving us | ||
# two separate operations (check + add). | ||
if seen.add?(result[:input]).nil? | ||
count += 1 | ||
next | ||
end | ||
|
||
STDOUT.puts result.to_json | ||
end | ||
|
||
STDERR.puts "[+] pass: dedupe done: #{count} filtered" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: dedupe | ||
desc: Filter out any duplicate cohorts (by input) | ||
run: dedupe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters