Skip to content

Commit 2e44653

Browse files
author
dcalixto
committed
added release workflow
1 parent f76f497 commit 2e44653

File tree

4 files changed

+68
-44
lines changed

4 files changed

+68
-44
lines changed

.github/workflows/release.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
8+
jobs:
9+
build:
10+
name: Create Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Crystal
17+
uses: crystal-lang/install-crystal@v1
18+
with:
19+
crystal: latest
20+
21+
- name: Install dependencies
22+
run: shards install
23+
24+
- name: Create Release
25+
id: create_release
26+
uses: comnoco/[email protected]
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
tag_name: ${{ github.ref_name }}
31+
release_name: Version ${{ github.ref_name }}
32+
body_path: .github/latest_release_body.md
33+
draft: false
34+
prerelease: false

README.md

+33-43
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
![Punch Bag](./src/punching-bag.gif)
44

5-
A Crystal shard for tracking and analyzing hit counts, trending items, and time-based analytics.
5+
A Crystal shard for tracking and analyzing hit counts, trending items, time and location analytics for PostgreSQL.
66

77
[![Crystal Test](https://github.com/dcalixto/punching_bag/actions/workflows/crystal-test.yml/badge.svg?branch=master)](https://github.com/dcalixto/punching_bag/actions/workflows/crystal-test.yml)
88

99
## Features
1010

11-
- Total hit count tracking
12-
- Most hit items tracking
13-
- Time-based hit analytics
11+
- Timezone-aware tracking using PostgreSQL's TIMESTAMPTZ
12+
- Location-based analytics support
13+
- Configurable hit counting
14+
- Time-based popularity tracking
15+
- Efficient indexing for fast queries
1416
- Lightweight and fast
1517

1618
## Requirements
@@ -58,64 +60,73 @@ require "punching_bag"
5860
Initialize database connection
5961

6062
```crystal
61-
database = DB.open(DATABASE_URL)
62-
PunchingBag.db = database
63+
PunchingBag.configure do |config|
64+
config.database_url = "postgres://localhost/your_database"
65+
end
6366
```
6467

65-
## Initialize the Bag
68+
## Initialize the tracker
6669

6770
```crystal
68-
bag = PunchingBag.new
71+
# Initialize tracker
72+
tracker = PunchingBag::Tracker.new(PunchingBag.db)
6973
```
7074

7175
Record a hit
7276

7377
```crystal
74-
bag.punch("Article", 1)
78+
tracker.punch("Article", 1)
79+
```
80+
81+
Track hits with custom timestamp and timezone
82+
83+
```crystal
84+
timestamp = Time.local(timezone: Time::Location.load("America/New_York"))
85+
tracker.punch("Article", 1, hits: 1, timestamp: timestamp)
7586
```
7687

7788
Record multiple hits
7889

7990
```crystal
80-
bag.punch("Article", 1, hits: 5)
91+
tracker.punch("Article", 1, hits: 5)
8192
```
8293

8394
Record hit with timestamp
8495

8596
```crystal
86-
bag.punch("Article", 1, timestamp: Time.utc - 1.day)
97+
tracker.punch("Article", 1, timestamp: Time.utc - 1.day)
8798
```
8899

89100
## Analytics
90101

91102
Get total hits for an item
92103

93104
```crystal
94-
total = bag.total_hits("Article", 1)
105+
total = tracker.total_hits("Article", 1)
95106
```
96107

97108
Get most hit items since last week
98109

99110
```crystal
100-
trending = bag.most_hit(Time.utc - 1.week)
111+
trending = tracker.most_hit(Time.utc - 1.week)
101112
```
102113

103114
Get top 10 most hit items since last month
104115

105116
```crystal
106-
top_items = bag.most_hit(Time.utc - 1.month, limit: 10)
117+
top_items = tracker.most_hit(Time.utc - 1.month, limit: 10)
107118
```
108119

109120
Get average time for hits
110121

111122
```crystal
112-
avg_time = bag.average_time("Article", 1)
123+
avg_time = tracker.average_time("Article", 1)
113124
```
114125

115126
Clear all recorded hits
116127

117128
```crystal
118-
bag.clear
129+
tracker.clear
119130
```
120131

121132
## Example Integration
@@ -141,18 +152,18 @@ class Article
141152
end
142153
143154
def track_view
144-
bag = PunchingBag.new(@@db.not_nil!)
145-
bag.punch("Article", id.not_nil!)
155+
tracker = PunchingBag.new(@@db.not_nil!)
156+
tracker.punch("Article", id.not_nil!)
146157
end
147158
148159
def total_views
149-
bag = PunchingBag.new(@@db.not_nil!)
150-
bag.total_hits("Article", id.not_nil!)
160+
tracker = PunchingBag.new(@@db.not_nil!)
161+
tracker.total_hits("Article", id.not_nil!)
151162
end
152163
153164
def self.trending(since = Time.utc - 1.week, limit = 10)
154-
bag = PunchingBag.new(@@db.not_nil!)
155-
bag.most_hit(since, limit: limit)
165+
tracker = PunchingBag.new(@@db.not_nil!)
166+
tracker.most_hit(since, limit: limit)
156167
end
157168
end
158169
@@ -202,24 +213,3 @@ Daniel Calixto - creator and maintainer
202213
## License
203214

204215
MIT License. See LICENSE for details.
205-
206-
## TODO
207-
208-
Run the setup as follows:
209-
210-
```crystal
211-
require "./punching_bag/setup"
212-
213-
PunchingBag::Setup.run
214-
```
215-
216-
## Output Example:
217-
218-
```crystal
219-
Setting up development database...
220-
Database already exists.
221-
Creating tables and indexes...
222-
Punches table created or already exists.
223-
Indexes created or already exist.
224-
Setup completed successfully.
225-
```

db/migrations/YYYYMMDDHHMMSS_create_punches.cr

Whitespace-only changes.

shard.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors:
44
- Daniel Calixto [email protected]
55

66
description: |
7-
A Crystal shard for tracking and analyzing hit counts, trending items, and time-based analytics.
7+
A Crystal shard for tracking and analyzing hit counts, trending items, time and location analytics for PostgreSQL
88
scripts:
99
postinstall: crystal run scripts/install.cr
1010

0 commit comments

Comments
 (0)