rewards-api

module
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2023 License: Apache-2.0

README

Background

Each Monday at 05:00 UTC, a new DIMO issuance week begins; week 0 started on 2022-01-31. At the end of each issuance week, this service runs a cron job that calculates how many points each vehicle earned that week. A simple REST API provides vehicle owners with a view of when and how their vehicles earned.

The formulas are available on the docs site, but it's worth summarizing the steps here with an emphasis on the implementation:

Activity. A vehicle's integration is considered active in a given week if during that time it has transmitted some non-trivial signal. Vehicles without active integrations do not earn points.

Integration. Better integrations earn more points, as shown in the table below. The only valid combination of two of these is Smartcar and AutoPi together, which earns the sim 7000.

Integration Points
Smartcar 1000
Tesla 4000
AutoPi 6000

Streak. The program maintains a "weeks connected" counter for each vehicle. Ideally, this starts at 0 and simply increments by 1 every week, with the vehicle staying continuously connected. Being disconnected for one or two weeks in a row merely pauses this counter.

Level. The connection streak at the end of a week determines a level for the vehicle. An active vehicle then earns points based on the level:

Level Min streak Points
1 0 0
2 4 1000
3 20 2000
4 36 3000

Being inactive for three weeks straight drops your connection streak to the minimum one for the previous level.

Contributing

Database modifications

Create a new Goose migration file:

goose -dir migrations create MIGRATION_TITLE sql

This will create a file in the migrations folder named something like $TIMESTAMP_MIGRATION_TITLE.sql. Edit this with your new innovations. To run the migrations:

go run ./cmd/rewards-api migrate

And then to generate the models:

sqlboiler psql --no-tests --wipe

Generate API documentation

swag init -g cmd/rewards-api/main.go --parseDependency --parseInternal --generatedTime true --parseDepth 2

Directories

Path Synopsis
cmd
Code generated by swaggo/swag at 2023-02-23 17:55:09.537271 -0500 EST m=+1.114415501.
Code generated by swaggo/swag at 2023-02-23 17:55:09.537271 -0500 EST m=+1.114415501.
internal
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL