Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
135f8c7f
Unverified
Commit
135f8c7f
authored
1 year ago
by
Chris Truter
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Prevent NPE when formatting geographic coords (#40550)
parent
d52d4fe1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/formatter.clj
+8
-7
8 additions, 7 deletions
src/metabase/formatter.clj
test/metabase/formatter_test.clj
+4
-1
4 additions, 1 deletion
test/metabase/formatter_test.clj
test/metabase/pulse/render/body_test.clj
+12
-4
12 additions, 4 deletions
test/metabase/pulse/render/body_test.clj
with
24 additions
and
12 deletions
src/metabase/formatter.clj
+
8
−
7
View file @
135f8c7f
...
...
@@ -205,15 +205,16 @@
(
defn
format-geographic-coordinates
"Format longitude/latitude values as 0.00000000° N|S|E|W"
[
lon-or-lat
^
double
v
]
(
let
[
dir
(
case
lon-or-lat
[
lon-or-lat
v
]
(
str
(
when
(
number?
v
)
(
let
[
v
(
double
v
)
dir
(
case
lon-or-lat
:type/Latitude
(
if
(
neg?
v
)
"S"
"N"
)
:type/Longitude
(
if
(
neg?
v
)
"W"
"E"
)
nil
)
base-value
(
Math/abs
v
)]
(
if
dir
(
format
"%.8f° %s"
base-value
dir
)
(
str
v
))))
nil
)]
(
if
dir
(
format
"%.8f° %s"
(
Math/abs
v
)
dir
)
v
)))))
(
mu/defn
create-formatter
"Create a formatter for a column based on its timezone, column metadata, and visualization-settings"
...
...
This diff is collapsed.
Click to expand it.
test/metabase/formatter_test.clj
+
4
−
1
View file @
135f8c7f
...
...
@@ -159,4 +159,7 @@
(
formatter/format-geographic-coordinates
:type/Latitude
0
))))
(
testing
"A non-coordinate type just stringifies the value"
(
is
(
=
"0.0"
(
formatter/format-geographic-coordinates
:type/Froobitude
0
))))))
(
formatter/format-geographic-coordinates
:type/Froobitude
0
))))
(
testing
"We handle missing values"
(
is
(
=
""
(
formatter/format-geographic-coordinates
:type/Longitude
nil
))))))
This diff is collapsed.
Click to expand it.
test/metabase/pulse/render/body_test.clj
+
12
−
4
View file @
135f8c7f
...
...
@@ -47,7 +47,9 @@
(
def
^
:private
example-test-data
[[
1
34.0996
"2014-04-01T08:30:00.0000"
"Stout Burgers & Beers"
]
[
2
34.0406
"2014-12-05T15:15:00.0000"
"The Apple Pan"
]
[
3
34.0474
"2014-08-01T12:45:00.0000"
"The Gorbals"
]])
[
3
34.0474
"2014-08-01T12:45:00.0000"
"The Gorbals"
]
[
4
0
"2018-09-01T19:32:00.0000"
"The Tipsy Tardigrade"
]
[
5
nil
"2022-10-12T05:55:00.0000"
"The Bungalow"
]])
(
defn-
col-counts
[
results
]
(
set
(
map
(
comp
count
:row
)
results
)))
...
...
@@ -167,14 +169,18 @@
(
deftest
format-result-rows
(
is
(
=
[{
:bar-width
nil,
:row
[(
number
"1"
1
)
"34.09960000° N"
"April 1, 2014, 8:30 AM"
"Stout Burgers & Beers"
]}
{
:bar-width
nil,
:row
[(
number
"2"
2
)
"34.04060000° N"
"December 5, 2014, 3:15 PM"
"The Apple Pan"
]}
{
:bar-width
nil,
:row
[(
number
"3"
3
)
"34.04740000° N"
"August 1, 2014, 12:45 PM"
"The Gorbals"
]}]
{
:bar-width
nil,
:row
[(
number
"3"
3
)
"34.04740000° N"
"August 1, 2014, 12:45 PM"
"The Gorbals"
]}
{
:bar-width
nil,
:row
[(
number
"4"
4
)
"0.00000000° N"
"September 1, 2018, 7:32 PM"
"The Tipsy Tardigrade"
]}
{
:bar-width
nil,
:row
[(
number
"5"
5
)
""
"October 12, 2022, 5:55 AM"
"The Bungalow"
]}]
(
rest
(
#
'body/prep-for-html-rendering
pacific-tz
{}
{
:cols
test-columns
:rows
example-test-data
})))))
;; Testing the bar-column, which is the % of this row relative to the max of that column
(
deftest
bar-column
(
is
(
=
[{
:bar-width
(
float
85.249
)
,
:row
[(
number
"1"
1
)
"34.09960000° N"
"April 1, 2014, 8:30 AM"
"Stout Burgers & Beers"
]}
{
:bar-width
(
float
85.1015
)
,
:row
[(
number
"2"
2
)
"34.04060000° N"
"December 5, 2014, 3:15 PM"
"The Apple Pan"
]}
{
:bar-width
(
float
85.1185
)
,
:row
[(
number
"3"
3
)
"34.04740000° N"
"August 1, 2014, 12:45 PM"
"The Gorbals"
]}]
{
:bar-width
(
float
85.1185
)
,
:row
[(
number
"3"
3
)
"34.04740000° N"
"August 1, 2014, 12:45 PM"
"The Gorbals"
]}
{
:bar-width
(
float
0.0
)
,
:row
[(
number
"4"
4
)
"0.00000000° N"
"September 1, 2018, 7:32 PM"
"The Tipsy Tardigrade"
]}
{
:bar-width
nil,
:row
[(
number
"5"
5
)
""
"October 12, 2022, 5:55 AM"
"The Bungalow"
]}]
(
rest
(
#
'body/prep-for-html-rendering
pacific-tz
{}
{
:cols
test-columns
:rows
example-test-data
}
{
:bar-column
second,
:min-value
0
,
:max-value
40
})))))
...
...
@@ -241,7 +247,9 @@
(
deftest
cols-with-semantic-types
(
is
(
=
[{
:bar-width
nil,
:row
[(
number
"1"
1
)
"34.09960000° N"
"April 1, 2014, 8:30 AM"
"Stout Burgers & Beers"
]}
{
:bar-width
nil,
:row
[(
number
"2"
2
)
"34.04060000° N"
"December 5, 2014, 3:15 PM"
"The Apple Pan"
]}
{
:bar-width
nil,
:row
[(
number
"3"
3
)
"34.04740000° N"
"August 1, 2014, 12:45 PM"
"The Gorbals"
]}]
{
:bar-width
nil,
:row
[(
number
"3"
3
)
"34.04740000° N"
"August 1, 2014, 12:45 PM"
"The Gorbals"
]}
{
:bar-width
nil,
:row
[(
number
"4"
4
)
"0.00000000° N"
"September 1, 2018, 7:32 PM"
"The Tipsy Tardigrade"
]}
{
:bar-width
nil,
:row
[(
number
"5"
5
)
""
"October 12, 2022, 5:55 AM"
"The Bungalow"
]}]
(
rest
(
#
'body/prep-for-html-rendering
pacific-tz
{}
{
:cols
test-columns-with-date-semantic-type
:rows
example-test-data
})))))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment