Skip to content

Commit

Permalink
api/views: Use nullable for all breakdown fields
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed May 7, 2023
1 parent ceefa22 commit e5ccd6f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
24 changes: 12 additions & 12 deletions views/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ type ViewershipEventRow struct {

// breakdown fields

DeviceType string `bigquery:"device_type"`
Device string `bigquery:"device"`
CPU string `bigquery:"cpu"`

OS string `bigquery:"os"`
Browser string `bigquery:"browser"`
BrowserEngine string `bigquery:"browser_engine"`

Continent string `bigquery:"playback_continent_name"`
Country string `bigquery:"playback_country_name"`
Subdivision string `bigquery:"playback_subdivisions_name"`
TimeZone string `bigquery:"playback_timezone"`
DeviceType bigquery.NullString `bigquery:"device_type"`
Device bigquery.NullString `bigquery:"device"`
CPU bigquery.NullString `bigquery:"cpu"`

OS bigquery.NullString `bigquery:"os"`
Browser bigquery.NullString `bigquery:"browser"`
BrowserEngine bigquery.NullString `bigquery:"browser_engine"`

Continent bigquery.NullString `bigquery:"playback_continent_name"`
Country bigquery.NullString `bigquery:"playback_country_name"`
Subdivision bigquery.NullString `bigquery:"playback_subdivisions_name"`
TimeZone bigquery.NullString `bigquery:"playback_timezone"`

// metric data

Expand Down
42 changes: 25 additions & 17 deletions views/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ type Metric struct {

// breakdown fields

Device string `json:"device,omitempty"`
DeviceType string `json:"deviceType,omitempty"`
CPU string `json:"cpu,omitempty"`
Device *string `json:"device,omitempty"`
DeviceType *string `json:"deviceType,omitempty"`
CPU *string `json:"cpu,omitempty"`

OS string `json:"os,omitempty"`
Browser string `json:"browser,omitempty"`
BrowserEngine string `json:"browserEngine,omitempty"`
OS *string `json:"os,omitempty"`
Browser *string `json:"browser,omitempty"`
BrowserEngine *string `json:"browserEngine,omitempty"`

Continent string `json:"continent,omitempty"`
Country string `json:"country,omitempty"`
Subdivision string `json:"subdivision,omitempty"`
TimeZone string `json:"timezone,omitempty"`
Continent *string `json:"continent,omitempty"`
Country *string `json:"country,omitempty"`
Subdivision *string `json:"subdivision,omitempty"`
TimeZone *string `json:"timezone,omitempty"`

// metric data

Expand Down Expand Up @@ -141,13 +141,13 @@ func viewershipEventsToMetrics(rows []ViewershipEventRow) []Metric {
m := Metric{
PlaybackID: row.PlaybackID,
DStorageURL: row.DStorageURL,
Device: row.Device,
OS: row.OS,
Browser: row.Browser,
Continent: row.Continent,
Country: row.Country,
Subdivision: row.Subdivision,
TimeZone: row.TimeZone,
Device: toStringPtr(row.Device),
OS: toStringPtr(row.OS),
Browser: toStringPtr(row.Browser),
Continent: toStringPtr(row.Continent),
Country: toStringPtr(row.Country),
Subdivision: toStringPtr(row.Subdivision),
TimeZone: toStringPtr(row.TimeZone),
ViewCount: row.ViewCount,
PlaytimeMins: row.PlaytimeMins,
TtffMs: toFloat64Ptr(row.TtffMs),
Expand All @@ -174,6 +174,14 @@ func toFloat64Ptr(bqFloat bigquery.NullFloat64) *float64 {
return nil
}

func toStringPtr(bqFloat bigquery.NullString) *string {
if bqFloat.Valid {
f := bqFloat.StringVal
return &f
}
return nil
}

func viewershipSummaryToMetric(filter QueryFilter, summary *ViewSummaryRow) []Metric {
if summary == nil {
if dStorageURL := ToDStorageURL(filter.PlaybackID); dStorageURL != "" {
Expand Down

0 comments on commit e5ccd6f

Please sign in to comment.