Add visits info
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/all-checks-complete Pipeline was successful

This commit is contained in:
Smaug123
2023-11-01 16:43:33 +00:00
parent 989a4a7a33
commit 77ceafde0b
7 changed files with 174 additions and 4 deletions

View File

@@ -260,6 +260,74 @@ type MemberActivityDto =
LastRefreshed = this.LastRefreshed
}
type SessionsAggregate =
{
/// Number of gym "activities" within some query-defined time period; presumably this is like classes?
/// It's always 0 for me.
Activities : int
/// Number of visits to the gym within some query-defined time period.
Visits : int
/// In minutes: total time spent in gym during the query-defined time period.
Duration : int
}
/// The DTO for gym info returned from the Sessions endpoint.
type VisitGym =
{
// Omitting Location, GymAccess, ContactInfo, TimeZone because these were all null for me
/// The PureGym ID of this gym, e.g. 19
Id : int
/// E.g. "London Oval", the canonical name of this gym
Name : string
/// For some reason this always seems to be "Blocked"
Status : string
}
/// Summary of a single visit to a gym.
type Visit =
{
// Omitted Name because it always was null for me
/// Whether the Duration field is estimated.
IsDurationEstimated : bool
/// When the visit began.
StartTime : DateTime
/// In minutes.
Duration : int
/// Which gym was visited
Gym : VisitGym
}
/// Human-readable non-round-trip representation.
override this.ToString () =
let startTime = this.StartTime.ToString "yyyy-MM-dd HH:mm"
$"%s{this.Gym.Name}: %s{startTime} (%i{this.Duration} minutes)"
/// Aggregate statistics for gym visits across a time period.
type SessionsSummary =
{
/// Aggregate stats for gym visits within the query-dependent time period.
Total : SessionsAggregate
/// Aggregate stats for gym visits "this week", whatever that means to PureGym.
ThisWeek : SessionsAggregate
}
/// Human-readable non-round-trip representation.
override this.ToString () =
$"%i{this.Total.Visits} visits, totalling %i{this.Total.Duration} minutes"
type Sessions =
{
Summary : SessionsSummary
Visits : Visit list
}
/// Human-readable non-round-trip representation.
override this.ToString () =
let summary = string<SessionsSummary> this.Summary
let visits = this.Visits |> Seq.map string<Visit> |> String.concat "\n"
$"%s{summary}\n%s{visits}"
/// The PureGym REST API. You probably want to instantiate one of these with `Api.make`.
[<Header("User-Agent", "PureGym/1523 CFNetwork/1312 Darwin/21.0.0")>]
type IPureGymApi =
@@ -283,6 +351,10 @@ type IPureGymApi =
[<Get "v1/member/activity">]
abstract GetMemberActivity : unit -> Task<MemberActivityDto>
/// Get information about the individual visits to all PureGyms the currently-authenticated PureGym human has made.
[<Get "v2/gymSessions/member">]
abstract GetSessions : [<Query>] fromDate : DateTime -> [<Query>] toDate : DateTime -> Task<Sessions>
// [<Get "v1/member/activity/history">]
// abstract GetMemberActivityAll : unit -> Task<string>