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
01d732f1
Unverified
Commit
01d732f1
authored
6 years ago
by
Simon Belak
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #8741 from metabase/insights-add-nil-guards2
Insights: add nil guards
parents
6ce8a480
dfb293b8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/sync/analyze/fingerprint/insights.clj
+21
-9
21 additions, 9 deletions
src/metabase/sync/analyze/fingerprint/insights.clj
test/metabase/sync/analyze/fingerprint/insights_test.clj
+35
-0
35 additions, 0 deletions
test/metabase/sync/analyze/fingerprint/insights_test.clj
with
56 additions
and
9 deletions
src/metabase/sync/analyze/fingerprint/insights.clj
+
21
−
9
View file @
01d732f1
...
...
@@ -11,7 +11,8 @@
[
n
]
(
fn
([]
[])
([
acc
]
acc
)
([
acc
]
(
concat
(
repeat
(
-
n
(
count
acc
))
nil
)
acc
))
([
acc
x
]
(
if
(
<
(
count
acc
)
n
)
(
conj
acc
x
)
...
...
@@ -99,19 +100,30 @@
(
redux/fuse
{
:fits
(
->>
(
for
[{
:keys
[
x-link-fn
y-link-fn
formula
model
]}
trendline-function-families
]
(
redux/post-complete
(
stats/simple-linear-regression
(
comp
x-link-fn
fx
)
(
comp
y-link-fn
fy
))
(
stats/simple-linear-regression
(
comp
(
stats/somef
x-link-fn
)
fx
)
(
comp
(
stats/somef
y-link-fn
)
fy
))
(
fn
[[
offset
slope
]]
(
when-not
(
or
(
Double/isNaN
offset
)
(
when-not
(
or
(
nil?
offset
)
(
nil?
slope
)
(
Double/isNaN
offset
)
(
Double/isNaN
slope
))
{
:model
(
model
offset
slope
)
:formula
(
formula
offset
slope
)}))))
(
apply
redux/juxt
))
:validation-set
((
map
(
juxt
fx
fy
))
(
reservoir-sample
validation-set-size
))})
:validation-set
((
keep
(
fn
[
row
]
(
let
[
x
(
fx
row
)
y
(
fy
row
)]
(
when
(
and
x
y
)
[
x
y
]))))
(
reservoir-sample
validation-set-size
))})
(
fn
[{
:keys
[
validation-set
fits
]}]
(
->>
fits
(
remove
nil?
)
(
apply
min-key
#
(
transduce
identity
(
mae
(
comp
(
:model
%
)
first
)
second
)
validation-set
))
:formula
))))
(
some->>
fits
(
remove
nil?
)
not-empty
(
apply
min-key
#
(
transduce
identity
(
mae
(
comp
(
:model
%
)
first
)
second
)
validation-set
))
:formula
))))
(
defn-
timeseries?
[{
:keys
[
numbers
datetimes
others
]}]
...
...
@@ -138,7 +150,7 @@
;; unit=year workaround. While the field is in this case marked as :type/Text,
;; at this stage in the pipeline the value is still an int, so we can use it
;; directly.
(
comp
ms->day
#
(
nth
%
x-position
)))]
(
comp
(
stats/somef
ms->day
)
#
(
nth
%
x-position
)))]
(
apply
redux/juxt
(
for
[
number-col
numbers
]
(
redux/post-complete
(
let
[
y-position
(
:position
number-col
)
...
...
This diff is collapsed.
Click to expand it.
test/metabase/sync/analyze/fingerprint/insights_test.clj
0 → 100644
+
35
−
0
View file @
01d732f1
(
ns
metabase.sync.analyze.fingerprint.insights-test
(
:require
[
expectations
:refer
:all
]
[
metabase.sync.analyze.fingerprint.insights
:refer
:all
]))
(
def
^
:private
cols
[{
:base_type
:type/DateTime
}
{
:base_type
:type/Number
}])
(
expect
700
(
->
(
transduce
identity
(
insights
cols
)
[[
"2014"
100
]
[
"2015"
200
]
[
"2016"
nil
]
[
nil
300
]
[
nil
nil
]
[
"2017"
700
]])
first
:last-value
))
(
expect
700
(
->
(
transduce
identity
(
insights
cols
)
[[
"2017"
700
]])
first
:last-value
))
;; Here we just make sure we don't blow up on empty input
(
expect
nil
(
->
(
transduce
identity
(
insights
cols
)
[])
first
:last-value
))
(
expect
nil
(
->
(
transduce
identity
(
insights
cols
)
[[
nil
nil
]])
first
:last-value
))
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