Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Code issue to claim distribution stat #1675

Merged
merged 9 commits into from
Jan 27, 2021

Conversation

whaught
Copy link
Contributor

@whaught whaught commented Jan 25, 2021

Issue #1231

Proposed Changes

  • Adds new DB array for issue-claim age distribution stat
  • Adds running average issue-claim age stat
  • Marshal to CSV and json
  • Record bucket when updating code-claim stats
  • Record running avarage

Release Note

Add code issue to claim age average and distribution stat

@googlebot googlebot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Jan 25, 2021
@whaught
Copy link
Contributor Author

whaught commented Jan 25, 2021

/retest

@whaught whaught changed the title [WIP] Issue to claim distribution stat Issue to claim distribution stat Jan 27, 2021
@whaught
Copy link
Contributor Author

whaught commented Jan 27, 2021

/hold

@@ -447,7 +447,7 @@ func TestStatDates(t *testing.T) {
db, _ := testDatabaseInstance.NewDatabase(t, nil)
realm := NewRealmWithDefaults("Test Realm")

now := time.Now()
now := time.Now().UTC()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug. This test fails in the evening.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I've hit a few of those when I run tests late at night too.

@whaught whaught changed the title Issue to claim distribution stat Code issue to claim distribution stat Jan 27, 2021
pkg/database/token.go Outdated Show resolved Hide resolved
pkg/database/token.go Outdated Show resolved Hide resolved
pkg/controller/issueapi/validate_code.go Outdated Show resolved Hide resolved
pkg/database/realm_stats.go Outdated Show resolved Hide resolved
}
}

// updateStatsCodeClaimed updates the statistics, increasing the number of codes
// claimed.
func (db *Database) updateStatsCodeClaimed(t time.Time, authApp *AuthorizedApp) {
t = timeutils.UTCMidnight(t)
func (db *Database) updateStatsCodeClaimed(t time.Time, authApp *AuthorizedApp, vc *VerificationCode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function could be simplified by updating the two stats independently, potentially even updating CodeClaimDistribution in another function.

Similarly, this will be faster and less error-prone to do it in straight SQL:

WITH arr AS (
  -- this is the fun part. you could build this with case statements or use a 
  -- range function: https://www.postgresql.org/docs/9.3/rangetypes.html
)
INSERT INTO realm_stats(date, realm_id, code_claim_distribution
  VALUES ($1, $2, arr)
ON CONFLICT (date, realm_id) DO UPDATE
  SET code_claim_distribution = array_agg(UNNEST(arr) + UNNEST(realm_stats.code_claim_distribution))

@whaught
Copy link
Contributor Author

whaught commented Jan 27, 2021

/hold cancel

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sethvargo, whaught

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-robot google-oss-robot merged commit 680ec09 into google:main Jan 27, 2021
@whaught whaught deleted the claim_age_stat branch January 27, 2021 21:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Auto: added by CLA bot when all committers have signed a CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants