punching_bag
Version, currently 0.01.022 versions
- 1.0.0latestDec 15, 2024
- 0.01.02not indexedJan 21, 2026
github.com/dcalixto/punching_bag
A Crystal shard for tracking and analyzing hit counts, trending items, time and location analytics for PostgreSQL
Nothing has been indexed for 0.01.02 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
punching_bag:
github: dcalixto/punching_bag
version: ~> 0.01.02Then run:
shards installshard.yml
No shard.yml has been indexed for 0.01.02. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
Punching Bag

A Crystal shard for tracking and analyzing hit counts, trending items, and time-based analytics.
Features
- Total hit count tracking
- Most hit items tracking
- Time-based hit analytics
- Lightweight and fast
Requirements
- Crystal >= 1.0.0
Installation
- Add Punching Bag to your
shard.yml:
dependencies:
punching_bag:
github: dcalixto/punching_bag
- Install dependencies:
shards install
- Run the setup command:
crystal run bin/punching_bag.cr -- setup
If the setup has already been completed, you will see the following message in your terminal:
Setup already completed.
Usage
Import the library
require "punching_bag"
Then in your application code, you can set it up like:
Initialize database connection
database = DB.open(DATABASE_URL)
PunchingBag.db = database
Initialize the Bag
bag = PunchingBag.new
Record a hit
bag.punch("Article", 1)
Record multiple hits
bag.punch("Article", 1, hits: 5)
Record hit with timestamp
bag.punch("Article", 1, timestamp: Time.utc - 1.day)
Analytics
Get total hits for an item
total = bag.total_hits("Article", 1)
Get most hit items since last week
trending = bag.most_hit(Time.utc - 1.week)
Get top 10 most hit items since last month
top_items = bag.most_hit(Time.utc - 1.month, limit: 10)
Get average time for hits
avg_time = bag.average_time("Article", 1)
Clear all recorded hits
bag.clear
Example Integration
Here’s an example of integrating Punching Bag into an application.
require "punching_bag"
require "db/serializable"
class Article
include DB::Serializable
property id : Int64
property title : String
def self.db=(database : DB::Database)
@@db = database
end
def self.db
@@db.not_nil!
end
def track_view
bag = PunchingBag.new(@@db.not_nil!)
bag.punch("Article", id.not_nil!)
end
def total_views
bag = PunchingBag.new(@@db.not_nil!)
bag.total_hits("Article", id.not_nil!)
end
def self.trending(since = Time.utc - 1.week, limit = 10)
bag = PunchingBag.new(@@db.not_nil!)
bag.most_hit(since, limit: limit)
end
end
The Routes
get "/articles/:id" do |env|
if article = Article.find(env.params.url["id"].to_i64)
article.track_view
render "article/show.ecr"
else
env.redirect "/articles"
end
end
View
To display the total view count in your view, use the following HTML:
<div class="views-count">
Views: <%= article.total_views %>
</div>
Development
crystal spec
Contributing
- Fork it (https://github.com/dcalixto/punching_bag/fork)
- Create your feature branch (
git checkout -b my-feature) - Commit your changes (
git commit -am 'Add feature') - Push to the branch (
git push origin my-feature) - Create a new Pull Request
Contributors
Daniel Calixto - creator and maintainer
License
MIT License. See LICENSE for details.
TODO
Run the setup as follows:
require "./punching_bag/setup"
PunchingBag::Setup.run
Output Example:
Setting up development database...
Database already exists.
Creating tables and indexes...
Punches table created or already exists.
Indexes created or already exist.
Setup completed successfully.
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.01.02- Tagged
- Jan 21, 2026
- Commit
3dc56b68c00e- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/dcalixto/punching_bag
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 16, 2026
- Synced
- Aug 15, 2026
- Versions
- 2