Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkuhn committed Oct 10, 2024
1 parent 8f9e134 commit 092e2f7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
41 changes: 24 additions & 17 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,32 @@ According to the article, OS X has a timer called *HIDIdleTime* that tracks the

*billy-idle* simply queries this value periodically using the `ioreg` utility that ships with macOS, and matches it against a pre-defined threshold. If exceeded, it will create a record for the busy time period in database. This data can later be used as input for time tracking tools or statistics.

== Example Report
== Example Time Tracking Report

----
------------------------------------ DAILY BILLY IDLE REPORT ------------------------------
Tuesday 13:10:03: Spent 2m30s Drinking a Bock Celebrator Doppelbock
Tuesday 13:54:12: Spent 40m52s Building app Horsehad in Cayenne
Tuesday 14:07:48: Spent 2s Driving a Highlander Hybrid 2wd Passenger car compact to Austin
Tuesday 14:10:23: Spent 1s Drinking a Bock HopSlam Ale
Tuesday 14:10:35: Spent 2s Driving a Sl600 Passenger car light to Winston-Salem
Tuesday 14:11:21: Spent 5s Drinking a Porter Racer 5 India Pale Ale, Bear Republic Bre
Tuesday 14:11:32: Spent 3s Drinking a Belgian And French Ale Pliny The Elder
Tuesday 14:12:48: Spent 1s Drinking a Dark Lager Founders Breakfast Stout
Tuesday 14:35:04: Spent 1m6s Building app Thingdoes in SASL
Tuesday 14:36:10: Spent 23s Drinking a Porter Orval Trappist Ale
Tuesday 14:36:33: Spent 1h51m16s Eating a Viskos praline sauce with Blueberry
Tuesday 16:28:49: Spent 44m40s Driving a Charger Sport utility vehicle to St. Petersburg
------------------------------------------------------------------------------------
Total time spent: 3h21m0s (net) / 3h51m0s (with 30m0s kitKat break)
------------------------------------------------------------------------------------
2024-10-08 Tue 08:46:55 #131 Spent 1h24m21s Building App Beetlecan 3.7.17 in Prolog until 10:11AM
2024-10-08 Tue 11:09:36 #132 Spent 32m12s Eating a Islands bananas foster topped with Gooseberry until 11:41AM
2024-10-08 Tue 11:41:49 #133 Spent 1h11m45s Driving a Sport utility vehicle Grand Marquis to Virginia Beach until 12:53PM
2024-10-08 Tue 12:59:47 #134 Spent 11m21s Building App Cigarettebe 4.13.19 in JOSS until 1:11PM
2024-10-08 Tue 13:32:02 #135 Spent 1h46m51s Driving a Passenger car medium C1500 Yukon 2wd to Glendale until 3:18PM
2024-10-08 Tue 15:30:33 #136 Spent 1h56m28s Eating a Chocolate almond roca bar topped with Cherry until 5:27PM
2024-10-08 Tue 17:30:30 #137 Spent 11m41s Driving a Passenger car compact Bentley Arnage to Hialeah until 5:42PM
2024-10-08 Tue 18:39:54 #138 Spent 1h19m44s Driving a Passenger car heavy Escalade Esv Awd to Louisville/Jefferson until 7:59PM
2024-10-08 Tue 19:59:58 #139 Spent 43m43s Driving a Van M3 Convertible to Reno until 8:43PM
----------------------------------------------------------------------------------------------------
total: 20h46m0s busy: 9h18m0s busy+break: 10h3m0s skipped(<5m0s): 12 belowMax(10h0m0s): true
Simple Entry for Tuesday: 09:00 → 19:03 (inc. 45m break) overtime: 1h30m0s
====================================================================================================
----
----
2024-10-10 Thu 03:05:53 #157 Spent 48m27s Drinking a Fruit Beer Péché Mortel with 6.6% until 3:54AM
2024-10-10 Thu 08:54:09 #158 Spent 4h2m30s Building App Dollarjump 2.11.6 in Napier88 until 12:56PM
2024-10-10 Thu 13:17:21 #159 Spent 3h59m22s Eating a Sonic strawberry cheesecake shake topped with Huckleberry until 5:16PM
2024-10-10 Thu 17:17:44 #160 🕰️ Still busy with Building App SkyBlueline 5.14.18 in Elixir since 49m50s
----------------------------------------------------------------------------------------------------
total: 17h48m0s busy: 9h40m0s busy+break: 10h25m0s skipped(<5m0s): 3 belowMax(10h0m0s): true
Simple Entry for Thursday: 09:00 → 19:25 (inc. 45m break) overtime: 1h52m0s
====================================================================================================
----
== Run form source
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func main() {
trackCmd.DurationVar(&opts.CheckInterval, "interval", 2*time.Second, "Interval to check for idle time")
trackCmd.DurationVar(&opts.IdleTolerance, "idle", 10*time.Second, "Max tolerated idle time before client enters idle state")
trackCmd.DurationVar(&opts.MinBusy, "min-busy", 5*time.Minute, "Minimum time for a busy record to count for the report")
trackCmd.DurationVar(&opts.MaxBusy, "max-busy", 10*time.Hour, "Max allowed time busy period per day (w/o breaks), report only")
trackCmd.DurationVar(&opts.RegBusy, "reg-busy", 7*time.Hour+48*time.Minute, "Regular busy period per day (w/o breaks), report only")
if len(os.Args) < 2 {
os.Args = append(os.Args, "help")
}
Expand Down
25 changes: 16 additions & 9 deletions pkg/tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,26 @@ func (t *Tracker) Report(ctx context.Context, w io.Writer) error {
_, _ = fmt.Fprintln(w, strings.Repeat("-", 100))

kitKat := mandatoryBreak(spentBusy)
spentBusy = spentBusy.Round(time.Minute)
spentTotal = spentTotal.Round(time.Minute)
// todo: raise warning if totalBusy is > 10h (or busyPlus > 10:45), since more than 10h are not allowed
_, _ = fmt.Fprintf(w, "%s total=%v busy=%v busy+=%v (inc. %.0fm break) skipped=%d (<%v)\n",
first.BusyStart.Format("2006-01-02 Mon"),
spentTotal.Round(time.Minute),
spentBusy.Round(time.Minute),
_, _ = fmt.Fprintf(w, "total: %v busy: %v busy+break: %v skipped(<%v): %d belowMax(%v): %v\n",
//first.BusyStart.Format("2006-01-02 Mon"),
spentTotal,
spentBusy,
(spentBusy + kitKat).Round(time.Minute),
kitKat.Round(time.Minute).Minutes(),
skippedTooShort, t.opts.MinBusy,
t.opts.MinBusy, skippedTooShort,
t.opts.MaxBusy, spentBusy <= t.opts.MaxBusy,
)
sugStart, _ := time.Parse("15:04", "09:00")
_, _ = fmt.Fprintf(w, "%s Suggestion: %v until %v %s\n", strings.Repeat("=", 30),
sugStart.Format("15:04"), sugStart.Add((spentBusy + kitKat).Round(time.Minute)).Format("15:04"), strings.Repeat("=", 30))
// _, _ = fmt.Fprintln(w, strings.Repeat("=", 100))
_, _ = fmt.Fprintf(w, "Simple Entry for %s: %v → %v (inc. %.0fm break) overtime: %v\n",
first.BusyStart.Format("Monday"),
sugStart.Format("15:04"),
sugStart.Add((spentBusy + kitKat).Round(time.Minute)).Format("15:04"),
kitKat.Round(time.Minute).Minutes(),
spentBusy-t.opts.RegBusy,
)
_, _ = fmt.Fprintln(w, strings.Repeat("=", 100))
_, _ = fmt.Fprintln(w, "")
}
return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/tracker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Options struct {
Env string
IdleTolerance time.Duration
MinBusy time.Duration
MaxBusy time.Duration
RegBusy time.Duration
}

// TrackRecord representation of a database record
Expand Down

0 comments on commit 092e2f7

Please sign in to comment.