diff --git a/db/postgres_types.go b/db/postgres_types.go index 75e5722..1dd5893 100644 --- a/db/postgres_types.go +++ b/db/postgres_types.go @@ -706,14 +706,15 @@ func (v postgresAnswer) Value() (driver.Value, error) { } type postgresFlipsState struct { - flipCid string - answer byte - status byte - grade byte + flipCid string + answer byte + status byte + grade byte + gradeScore float32 } func (v postgresFlipsState) Value() (driver.Value, error) { - return fmt.Sprintf("(%v,%v,%v,%v)", v.flipCid, v.answer, v.status, v.grade), nil + return fmt.Sprintf("(%v,%v,%v,%v,%v)", v.flipCid, v.answer, v.status, v.grade, v.gradeScore), nil } func getFlipStatsArrays(stats []*FlipStats) (answersArray, statesArray interface { @@ -745,11 +746,13 @@ func getFlipStatsArrays(stats []*FlipStats) (answersArray, statesArray interface convertAndAddAnswer(false, s.Cid, answer) longAnswerCountsByAddr[answer.Address]++ } + gradeScore, _ := s.GradeScore.Float64() convertedStates = append(convertedStates, postgresFlipsState{ - flipCid: s.Cid, - answer: s.Answer, - status: s.Status, - grade: s.Grade, + flipCid: s.Cid, + answer: s.Answer, + status: s.Status, + grade: s.Grade, + gradeScore: float32(gradeScore), }) const gradeReported = 1 if s.Grade == byte(gradeReported) { diff --git a/db/types.go b/db/types.go index 91286cb..b56086f 100644 --- a/db/types.go +++ b/db/types.go @@ -338,6 +338,7 @@ type FlipStats struct { Status byte Answer byte Grade byte + GradeScore decimal.Decimal } type Answer struct { diff --git a/indexer/indexer.go b/indexer/indexer.go index 2bea2f9..496bf88 100644 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -968,6 +968,7 @@ func (indexer *Indexer) detectEpochResult(block *types.Block, ctx *conversionCon Status: convertFlipStatus(ceremony.FlipStatus(flipStats.Status)), Answer: convertAnswer(flipStats.Answer), Grade: byte(flipStats.Grade), + GradeScore: flipStats.GradeScore, } flipsStatsByCid[flipStats.Cid] = flipStats flipsStats = append(flipsStats, flipStats) diff --git a/resources/scripts/indexer/init.sql b/resources/scripts/indexer/init.sql index 11079ed..9913f28 100644 --- a/resources/scripts/indexer/init.sql +++ b/resources/scripts/indexer/init.sql @@ -723,6 +723,7 @@ CREATE TABLE IF NOT EXISTS flips status smallint, delete_tx_id bigint, grade smallint, + grade_score real, CONSTRAINT flips_pkey PRIMARY KEY (tx_id), CONSTRAINT flips_status_block_height_fkey FOREIGN KEY (status_block_height) REFERENCES blocks (height) MATCH SIMPLE @@ -1792,10 +1793,11 @@ $$ BEGIN CREATE TYPE tp_flip_state AS ( - flip_cid character varying(100), - answer smallint, - status smallint, - grade smallint + flip_cid character varying(100), + answer smallint, + status smallint, + grade smallint, + grade_score real ); EXCEPTION WHEN duplicate_object THEN null; @@ -3684,7 +3686,8 @@ BEGIN set status_block_height=null, status=null, answer=null, - grade=null + grade=null, + grade_score=null where status_block_height > p_block_height; update flips set delete_tx_id=null diff --git a/resources/scripts/indexer/init/procedures/saveEpochResult.sql b/resources/scripts/indexer/init/procedures/saveEpochResult.sql index 2c62562..fa42b00 100644 --- a/resources/scripts/indexer/init/procedures/saveEpochResult.sql +++ b/resources/scripts/indexer/init/procedures/saveEpochResult.sql @@ -319,6 +319,7 @@ BEGIN SET STATUS=state.status, ANSWER=state.answer, GRADE=state.grade, + GRADE_SCORE=state.grade_score, STATUS_BLOCK_HEIGHT=block_height WHERE lower(CID) = lower(state.flip_cid); end loop; diff --git a/resources/scripts/migration/20230228-grade-score.sql b/resources/scripts/migration/20230228-grade-score.sql new file mode 100644 index 0000000..4e3a3d7 --- /dev/null +++ b/resources/scripts/migration/20230228-grade-score.sql @@ -0,0 +1,4 @@ +DROP TYPE tp_flip_state CASCADE; + +ALTER TABLE flips + ADD COLUMN grade_score real;