active_median 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +10 -2
- data/lib/active_median/model.rb +8 -5
- data/lib/active_median/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 629f5530448797da4aca90cd7d89f1b37550caeeacb64a7ce5f56c761dbad09a
|
4
|
+
data.tar.gz: 5d9b666c75a1c3ac976f968df91422e9cbc5d2c89f3f41a6cd58a7a409ef8c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f45451ab6d041058e087a88e56c0faaccfb066a96f3c9f48fae7abc4edbca67dcbf3841bdd142133b5b272847e54e783591046ef8f77589305fb412bdc213c94
|
7
|
+
data.tar.gz: ed76ff4622fbc943d3190c060193a55fb2d74f16541ccf8965b32313019e22a4bbd45eeb120d8aa8eb3f6866a1601e975123bc1276367c9a8128c2d796e04860
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -81,7 +81,15 @@ mysql <options> < load.sql
|
|
81
81
|
|
82
82
|
### SQLite
|
83
83
|
|
84
|
-
SQLite requires an extension. Download [percentile.c](https://www.sqlite.org/src/file?name=ext/misc/percentile.c&ci=d49c32e6e7cc341b) and follow the [instructions for compiling loadable extensions](https://www.sqlite.org/loadext.html#compiling_a_loadable_extension) for your platform.
|
84
|
+
SQLite requires an extension. Download [percentile.c](https://www.sqlite.org/src/file?name=ext/misc/percentile.c&ci=d49c32e6e7cc341b) and follow the [instructions for compiling loadable extensions](https://www.sqlite.org/loadext.html#compiling_a_loadable_extension) for your platform.
|
85
|
+
|
86
|
+
On Linux, use:
|
87
|
+
|
88
|
+
```sh
|
89
|
+
gcc -g -fPIC -shared -lsqlite3 percentile.c -o percentile.so
|
90
|
+
```
|
91
|
+
|
92
|
+
On Mac, use:
|
85
93
|
|
86
94
|
```sh
|
87
95
|
gcc -g -fPIC -dynamiclib -L/usr/local/opt/sqlite/lib -lsqlite3 percentile.c -o percentile.dylib
|
@@ -92,7 +100,7 @@ To load it in Rails, create an initializer with:
|
|
92
100
|
```ruby
|
93
101
|
db = ActiveRecord::Base.connection.raw_connection
|
94
102
|
db.enable_load_extension(1)
|
95
|
-
db.load_extension("percentile.
|
103
|
+
db.load_extension("percentile.so") # or percentile.dylib
|
96
104
|
db.enable_load_extension(0)
|
97
105
|
```
|
98
106
|
|
data/lib/active_median/model.rb
CHANGED
@@ -39,6 +39,9 @@ module ActiveMedian
|
|
39
39
|
|
40
40
|
group_values = all.group_values
|
41
41
|
|
42
|
+
# replace select to match behavior of average
|
43
|
+
relation = unscope(:select)
|
44
|
+
|
42
45
|
relation =
|
43
46
|
case connection.adapter_name
|
44
47
|
when /mysql/i
|
@@ -51,21 +54,21 @@ module ActiveMedian
|
|
51
54
|
over = "PARTITION BY #{group_values.join(", ")}"
|
52
55
|
end
|
53
56
|
|
54
|
-
select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
|
57
|
+
relation.select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
|
55
58
|
else
|
56
59
|
# if mysql gets native function, check (and memoize) version first
|
57
|
-
select(*group_values, "PERCENTILE_CONT(#{column}, #{percentile}) AS #{column_alias}")
|
60
|
+
relation.select(*group_values, "PERCENTILE_CONT(#{column}, #{percentile}) AS #{column_alias}")
|
58
61
|
end
|
59
62
|
when /sqlserver/i
|
60
63
|
if group_values.any?
|
61
64
|
over = "PARTITION BY #{group_values.join(", ")}"
|
62
65
|
end
|
63
66
|
|
64
|
-
select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
|
67
|
+
relation.select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) OVER (#{over}) AS #{column_alias}").unscope(:group)
|
65
68
|
when /sqlite/i
|
66
|
-
select(*group_values, "PERCENTILE(#{column}, #{percentile} * 100) AS #{column_alias}")
|
69
|
+
relation.select(*group_values, "PERCENTILE(#{column}, #{percentile} * 100) AS #{column_alias}")
|
67
70
|
when /postg/i, /redshift/i # postgis too
|
68
|
-
select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) AS #{column_alias}")
|
71
|
+
relation.select(*group_values, "PERCENTILE_CONT(#{percentile}) WITHIN GROUP (ORDER BY #{column}) AS #{column_alias}")
|
69
72
|
else
|
70
73
|
raise "Connection adapter not supported: #{connection.adapter_name}"
|
71
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_median
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|