Skip to content

Commit cb61b5d

Browse files
committed
Basic types refactoring
1 parent 11b893f commit cb61b5d

64 files changed

Lines changed: 1102 additions & 1549 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

admodels/ad_asset.go

Lines changed: 0 additions & 119 deletions
This file was deleted.

admodels/ad_file_asset.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// @project GeniusRabbit corelib 2018 - 2019
3+
// @author Dmitry Ponomarev <demdxx@gmail.com> 2018 - 2019
4+
//
5+
6+
package admodels
7+
8+
import (
9+
"github.com/geniusrabbit/adcorelib/admodels/types"
10+
)
11+
12+
// AdFileAssetThumb of the file
13+
type AdFileAssetThumb struct {
14+
URL string `json:"url"`
15+
Width int `json:"w"`
16+
Height int `json:"h"`
17+
Type types.AdFileAssetType `json:"type,omitempty"`
18+
}
19+
20+
// IsSuits thumb by size
21+
func (th AdFileAssetThumb) IsSuits(w, h, wmin, hmin int) bool {
22+
return th.Width <= w && th.Width >= wmin && th.Height <= h && th.Height >= hmin
23+
}
24+
25+
// IsImage file type
26+
func (th *AdFileAssetThumb) IsImage() bool {
27+
return th.Type.IsImage()
28+
}
29+
30+
// IsVideo file type
31+
func (th *AdFileAssetThumb) IsVideo() bool {
32+
return th.Type.IsVideo()
33+
}
34+
35+
// AdFileAsset information
36+
type AdFileAsset struct {
37+
ID uint64 `json:"id,omitempty"`
38+
Name string `json:"name,omitempty"` // Name of the asset, like "main", "banner", "icon", etc.
39+
URL string `json:"url,omitempty"` // In case of HTML5, hare must be the path to directory on CDN
40+
Type types.AdFileAssetType `json:"type,omitempty"`
41+
ContentType string `json:"content_type,omitempty"`
42+
Width int `json:"width,omitempty"`
43+
Height int `json:"height,omitempty"`
44+
Thumbs []AdFileAssetThumb
45+
}
46+
47+
// ThumbBy size borders and specific type
48+
func (f *AdFileAsset) ThumbBy(w, h, wmin, hmin int) (th *AdFileAssetThumb) {
49+
if w <= 0 {
50+
w = 0x0fffffff
51+
}
52+
if h <= 0 {
53+
h = 0x0fffffff
54+
}
55+
for i := 0; i < len(f.Thumbs); i++ {
56+
if f.Thumbs[i].IsSuits(w, h, wmin, hmin) {
57+
if th == nil || th.Width > f.Thumbs[i].Width {
58+
th = &f.Thumbs[i]
59+
}
60+
}
61+
}
62+
return th
63+
}
64+
65+
// IsImage file type
66+
func (f *AdFileAsset) IsImage() bool {
67+
return f.Type.IsImage()
68+
}
69+
70+
// IsVideo file type
71+
func (f *AdFileAsset) IsVideo() bool {
72+
return f.Type.IsVideo()
73+
}
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"github.com/geniusrabbit/adcorelib/admodels/types"
55
)
66

7-
// AdAssets contains the list of file assets
8-
type AdAssets []*AdAsset
7+
// AdFileAssets contains the list of file assets
8+
type AdFileAssets []*AdFileAsset
99

1010
// Main asset of the list
11-
func (assets AdAssets) Main() *AdAsset {
11+
func (assets AdFileAssets) Main() *AdFileAsset {
1212
return assets.Asset(types.FormatAssetMain)
1313
}
1414

1515
// Asset by name
16-
func (assets AdAssets) Asset(name string) *AdAsset {
16+
func (assets AdFileAssets) Asset(name string) *AdFileAsset {
1717
isMain := name == types.FormatAssetMain
1818
for _, it := range assets {
1919
if (isMain && (it.Name == "" || it.Name == types.FormatAssetMain)) || it.Name == name {
@@ -23,18 +23,8 @@ func (assets AdAssets) Asset(name string) *AdAsset {
2323
return nil
2424
}
2525

26-
// AssetByID returns asset with specific ID
27-
func (assets AdAssets) AssetByID(id uint64) *AdAsset {
28-
for _, it := range assets {
29-
if it.ID == id {
30-
return it
31-
}
32-
}
33-
return nil
34-
}
35-
36-
// AssetBaner by fixed size
37-
func (assets AdAssets) AssetBanner(w, h int) *AdAsset {
26+
// AssetBanner by fixed size
27+
func (assets AdFileAssets) AssetBanner(w, h int) *AdFileAsset {
3828
for i, it := range assets {
3929
if it.Name == types.FormatAssetBanner && it.Width == w && it.Height == h {
4030
return assets[i]
@@ -44,6 +34,6 @@ func (assets AdAssets) AssetBanner(w, h int) *AdAsset {
4434
}
4535

4636
// Len of the assets list
47-
func (assets AdAssets) Len() int {
37+
func (assets AdFileAssets) Len() int {
4838
return len(assets)
4939
}

admodels/rtb_source.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func RTBSourceFromModel(cl *models.RTBSource, acc *Account) (src *RTBSource) {
7272

7373
filter := types.BaseFilter{
7474
Secure: int8(cl.Secure),
75-
Adblock: int8(cl.AdBlock),
75+
AdBlock: int8(cl.AdBlock),
7676
PrivateBrowsing: int8(cl.PrivateBrowsing),
7777
IP: int8(cl.IP),
7878
}
@@ -130,3 +130,8 @@ func (s *RTBSource) TestFormat(f *types.Format) bool {
130130
func (s *RTBSource) PriceCorrectionReduceFactor() float64 {
131131
return s.PriceCorrectionReduce
132132
}
133+
134+
// Weight of the source for ad selection
135+
func (s *RTBSource) Weight() float64 {
136+
return s.MinimalWeight
137+
}

admodels/types/ad_asset_type.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)