-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from hathitrust/DEV-573-bugfix
DEV-573: Fix broken phase lookup for Shared Print reporting purposes
- Loading branch information
Showing
12 changed files
with
477 additions
and
108 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
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
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
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require "mongo_updater" | ||
|
||
# This is an outer wrapper for a MongoUpdater call. | ||
# Objective: based on commitments.committed_date, set commitments.phase. | ||
# Usage: bundle exec ruby get_by_date.rb <date_str> <phase> | ||
# E.g. : bundle exec ruby get_by_date.rb "2023-01-31 00:00:00 UTC" 3 | ||
|
||
class PhaseUpdater | ||
def initialize(date, phase) | ||
# Get input | ||
@date = date | ||
@phase = phase | ||
|
||
validate! | ||
puts "Get commitments with committed_date #{@date}." | ||
puts "Set phase to #{@phase}." | ||
end | ||
|
||
# Make sure date and phase look like they should. | ||
def validate! | ||
date_rx = /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s[A-Z]{3}$/ | ||
raise ArgumentError, "bad date: #{@date}" unless date_rx.match?(@date) | ||
|
||
@phase = @phase.to_i | ||
raise ArgumentError, "bad phase: #{@phase}" unless [0, 1, 2, 3].include?(@phase) | ||
rescue ArgumentError => e | ||
puts "ERROR: Failed validation: #{e.message}" | ||
exit | ||
end | ||
|
||
# Pass on call to MongoUpdater which does all the lifting. | ||
def run | ||
puts "Started: #{Time.now.utc}" | ||
res = MongoUpdater.update_embedded( | ||
clusterable: "commitments", | ||
matcher: {committed_date: @date}, | ||
updater: {phase: @phase} | ||
) | ||
puts res.inspect | ||
puts "Finished: #{Time.now.utc}" | ||
end | ||
end | ||
|
||
if $0 == __FILE__ | ||
date = ARGV.shift | ||
phase = ARGV.shift | ||
PhaseUpdater.new(date, phase).run | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "basic_query_report" | ||
|
||
# Aggregate query to get all committed_date from db. | ||
query = [ | ||
{"$match": {"commitments.0": {"$exists": 1}}}, | ||
{"$unwind": "$commitments"}, | ||
{"$project": {commitments: 1}}, | ||
{"$group": {_id: {date: "$commitments.committed_date"}}} | ||
] | ||
|
||
BasicQueryReport.new.aggregate(query) do |res| | ||
puts res["_id"]["date"] | ||
end | ||
|
||
# 2023-01-31 00:00:00 UTC | ||
# 2022-01-01 00:00:00 UTC | ||
# 2021-01-01 05:00:00 UTC | ||
# 2017-09-30 04:00:00 UTC | ||
# 2019-02-28 05:00:00 UTC | ||
# 1970-01-01 00:00:01 UTC |
Oops, something went wrong.