Skip to content
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

Export view/download statistics from Redis #3648

Open
2 tasks
pgwillia opened this issue Nov 25, 2024 · 3 comments
Open
2 tasks

Export view/download statistics from Redis #3648

pgwillia opened this issue Nov 25, 2024 · 3 comments
Assignees

Comments

@pgwillia
Copy link
Member

UofA would like to talk about options for importing statistics into DSpace with Scholaris. A dump of statistics data would help inform that conversation.

Desired outcome:

  • export of dev environment redis data as csv or json
  • export of test/production environment redis data as csv or json
@pgwillia
Copy link
Member Author

pgwillia commented Dec 4, 2024

Some additional context about stats https://github.com/ualbertalib/jupiter/blob/main/docs/stats.md

@pgwillia
Copy link
Member Author

pgwillia commented Dec 16, 2024

Q: how to export?
https://redis.io/docs/latest/commands/hgetall/
redis-cli --csv hgetall mykey > stdout.csv
Q: what key?
config.redis_key_prefix = "jupiter.#{Rails.env}."
#{Rails.configuration.redis_key_prefix}uniquehll.#{action}.#{id}"
"#{Rails.configuration.redis_key_prefix}counter.#{action}.#{id}"

@pgwillia pgwillia self-assigned this Dec 16, 2024
@pgwillia
Copy link
Member Author

redis = Jupiter::Redis.current # gets an instance of https://github.com/redis-rb/redis-client
=> #<ConnectionPool::Wrapper:0x00007f86bcd72388 @pool=#<ConnectionPool:0x00...

counters = redis.keys("jupiter.staging.counter*") # gets all the counter keys
=> 
["jupiter.staging.counter.view.2667339e-fa5e-4516-9f80-c9d601ae1767",
...

count = redis.get(counters.first) # is the number of views/downloads for that counter key
=> "1"

So really not anything different than
https://gist.github.com/pgwillia/eed7dd858e17a9a67f9d90cb1d703adb#file-atmire_statistics_data-csv

CSV.open('atmire_statistics_data.csv', 'wb') do |csv|
    csv << ['id', 'type', 'views', 'downloads']
    Item.find_each do |item|
      csv << [item.id, item.class, Statistics.for(item_id: item.id)].flatten
    end
    Thesis.find_each do |item|
      csv << [item.id, item.class, Statistics.for(item_id: item.id)].flatten
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant