Skip to content

Commit 05253ca

Browse files
authored
Merge pull request #10 from codingpot/refactor-6-paper-result-list
feat: implement PaperResultList
2 parents f238108 + facb339 commit 05253ca

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

dummy/paper_result_list.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"count": 2,
3+
"next": null,
4+
"previous": null,
5+
"results": [
6+
{
7+
"id": "657bb1c5-de55-4afc-ba54-0af74eaab5e2",
8+
"best_rank": 1,
9+
"metrics": {
10+
"mean iou (class)": "85.1%"
11+
},
12+
"methodology": "hrnet-ocr (hierarchical multi-scale attention)",
13+
"uses_additional_data": false,
14+
"paper": "hierarchical-multi-scale-attention-for",
15+
"best_metric": "mean iou (class)",
16+
"evaluated_on": "2020-05-21"
17+
},
18+
{
19+
"id": "a0db982b-68a8-4685-921d-a8a557304c85",
20+
"best_rank": null,
21+
"metrics": {
22+
"pq": "17.6"
23+
},
24+
"methodology": "hrnet-ocr (hierarchical multi-scale attention)",
25+
"uses_additional_data": false,
26+
"paper": "hierarchical-multi-scale-attention-for",
27+
"best_metric": null,
28+
"evaluated_on": "2020-05-21"
29+
}
30+
]
31+
}

models/results.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package models
2+
3+
type Result struct {
4+
ID string `json:"id"`
5+
BestRank *int `json:"best_rank"`
6+
Metrics map[string]string `json:"metrics"`
7+
Methodology string `json:"methodology"`
8+
UsesAdditionalData bool `json:"uses_additional_data"`
9+
Paper *string `json:"paper"`
10+
BestMetric *string `json:"best_metric"`
11+
EvaluatedOn YyyyMmDdDashed `json:"evaluated_on"`
12+
ExternalSourceUrl *string `json:"external_source_url"`
13+
}
14+
15+
// ResultList contains results produced in a paper.
16+
type ResultList struct {
17+
Count int `json:"count"`
18+
Next *string `json:"next"`
19+
Previous *string `json:"previous"`
20+
Results []*Result
21+
}

models/yyyymmdd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ func (y *YyyyMmDdDashed) UnmarshalJSON(bytes []byte) error {
2121
func (y YyyyMmDdDashed) MarshalJSON() ([]byte, error) {
2222
return json.Marshal(y)
2323
}
24+
25+
func NewYyyyMmDdDashed(year int, month time.Month, day int) YyyyMmDdDashed {
26+
return YyyyMmDdDashed(time.Date(year, month, day, 0, 0, 0, 0, time.UTC))
27+
}

paper_result_list.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package paperswithcode_go
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/codingpot/paperswithcode-go/models"
7+
"net/url"
8+
)
9+
10+
func (c *Client) PaperResultList(paperID string) (*models.ResultList, error) {
11+
pURL := fmt.Sprintf("%s/papers/%s/results", c.BaseURL, url.QueryEscape(paperID))
12+
13+
resp, err := c.HTTPClient.Get(pURL)
14+
if err != nil {
15+
return nil, err
16+
}
17+
18+
var paperResultList models.ResultList
19+
err = json.NewDecoder(resp.Body).Decode(&paperResultList)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
return &paperResultList, nil
25+
}

paper_result_list_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package paperswithcode_go
2+
3+
import (
4+
"github.com/codingpot/paperswithcode-go/models"
5+
"github.com/stretchr/testify/assert"
6+
"testing"
7+
)
8+
9+
var one int = 1
10+
11+
func TestClient_PaperResultList(t *testing.T) {
12+
paperID := "hierarchical-multi-scale-attention-for"
13+
bestMetric := "Mean IoU (class)"
14+
15+
c := NewClient()
16+
got, err := c.PaperResultList(paperID)
17+
assert.NoError(t, err)
18+
19+
expected := &models.ResultList{
20+
Count: 2,
21+
Next: nil,
22+
Previous: nil,
23+
Results: []*models.Result{
24+
{
25+
ID: "657bb1c5-de55-4afc-ba54-0af74eaab5e2",
26+
BestRank: &one,
27+
Metrics: map[string]string{
28+
bestMetric: "84.2",
29+
},
30+
Methodology: "HRNet-OCR (Hierarchical Multi-Scale Attention)",
31+
UsesAdditionalData: false,
32+
Paper: &paperID,
33+
BestMetric: &bestMetric,
34+
EvaluatedOn: models.NewYyyyMmDdDashed(2020, 5, 21),
35+
},
36+
{
37+
ID: "a0db982b-68a8-4685-921d-a8a557304c85",
38+
BestRank: nil,
39+
Metrics: map[string]string{
40+
"PQ": "17.6",
41+
},
42+
Methodology: "HRNet-OCR (Hierarchical Multi-Scale Attention)",
43+
UsesAdditionalData: false,
44+
Paper: &paperID,
45+
BestMetric: nil,
46+
EvaluatedOn: models.NewYyyyMmDdDashed(2020, 5, 21),
47+
},
48+
},
49+
}
50+
51+
assert.Equal(t, expected, got)
52+
}

0 commit comments

Comments
 (0)