-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilise Strava's Best Effort Estimates (#4)
Strava calculates athlete's best 400m, 1/2 mile, 1K, ... stats from running activities. It only gives limited how those best efforts rank between different activities on the website, but you can fetch all that data in small chunks via Strava API and do the processing on your own. While we can fetch summary of athlete's activities with decent number of API calls, best effort estimates have to be requested separately for each activity and this quickly becomes problem with Strava's rate limits ( https://developers.strava.com/docs/rate-limits/ ). For this reason, we once again store data as JSON in local files before we start making any sqlite database entries out of it. On database end, this forced us to create second table into database and so I ended up renaming former `mystats` table into `summary` and introduce new Best Effort table. On CLI, the best efforts information is available via `mystats best` command. Web UI got new 'Best Running Efforts' tab for web presentation of data.
- Loading branch information
Showing
21 changed files
with
671 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
_ "github.com/mattn/go-sqlite3" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/jylitalo/mystats/pkg/stats" | ||
) | ||
|
||
// topCmd turns sqlite db into table or csv by week/month/... | ||
func bestCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "best", | ||
Short: "Best Run Efforts based on Strava", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
flags := cmd.Flags() | ||
format, _ := flags.GetString("format") | ||
limit, _ := flags.GetInt("limit") | ||
distance, _ := flags.GetString("distance") | ||
update, _ := flags.GetBool("update") | ||
formatFn := map[string]func(headers []string, results [][]string){ | ||
"csv": printTopCSV, | ||
"table": printTopTable, | ||
} | ||
if _, ok := formatFn[format]; !ok { | ||
return fmt.Errorf("unknown format: %s", format) | ||
} | ||
db, err := makeDB(update) | ||
if err != nil { | ||
return err | ||
} | ||
defer db.Close() | ||
headers, results, err := stats.Best(db, distance, limit) | ||
if err != nil { | ||
return err | ||
} | ||
formatFn[format](headers, results) | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().String("format", "csv", "output format (csv, table)") | ||
cmd.Flags().String("distance", "Marathon", "Best Efforts distance") | ||
cmd.Flags().Int("limit", 10, "number of entries") | ||
cmd.Flags().Bool("update", true, "update database") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.