Skip to content

Commit

Permalink
Add flip grade score
Browse files Browse the repository at this point in the history
  • Loading branch information
mbidenaio committed Feb 28, 2023
1 parent 3c7af00 commit f63ad04
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
21 changes: 12 additions & 9 deletions db/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ type FlipStats struct {
Status byte
Answer byte
Grade byte
GradeScore decimal.Decimal
}

type Answer struct {
Expand Down
1 change: 1 addition & 0 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions resources/scripts/indexer/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions resources/scripts/migration/20230228-grade-score.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP TYPE tp_flip_state CASCADE;

ALTER TABLE flips
ADD COLUMN grade_score real;

0 comments on commit f63ad04

Please sign in to comment.