如何在 Heroku 上的 Rails 应用程序中计算箱线图(四分位数、中位数)的数据? (Heroku 使用 Postgresql)
我正在尝试计算生成箱线图所需的数据,这意味着我需要计算出第一和第三四分位数以及中位数。我已经找到了一些在 Postgresql 中执行此操作的解决方案,但是它们似乎依赖于 PL/Python 或 PL/R,而 Heroku 似乎没有为其 postgresql 数据库启用这两者。事实上,我运行了“select lanname from pg_language;”只返回“internal”、“c”和“sql”。
我还发现了一些代码可以在纯 ruby 中执行此操作,但这对我来说似乎有些低效。
我对箱线图、Postgresql 和 Ruby on Rails 相当陌生,所以我愿意接受关于如何处理这个问题的建议。有可能拥有大量数据,这就是为什么我关心性能,但是如果解决方案最终过于复杂,我可能只是在 ruby 中完成,如果我的应用程序变得足够大以保证它得到我自己的 Postgresql 我可以在其他地方托管。
*注意:由于我只能发布一个链接,因为我是新人,所以我决定分享一个 pastie 一些相关信息
I'm trying to calculate the data needed to generate a box plot which means I need to figure out the 1st and 3rd Quartiles along with the median. I have found some solutions for doing it in Postgresql however they seem to depend on either PL/Python or PL/R which it seems like Heroku does not have either enabled for their postgresql databases. In fact I ran "select lanname from pg_language;" and only got back "internal", "c", and "sql".
I also found some code to do it in pure ruby but that seems somewhat inefficient to me.
I'm rather new to Box Plots, Postgresql, and Ruby on Rails so I'm open to suggestions on how I should handle this. There is a possibility to have a lot of data which is why I'm concerned with performance however if the solution ends up being too complex I may just do it in ruby and if my application gets big enough to warrant it get my own Postgresql I can host somewhere else.
*note: since I was only able to post one link, cause I'm new, I decided to share a pastie with some relevant information
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Heroku 不向您提供 PostgreSQL 集群的超级用户访问权限,这是安装任何其他语言所必需的。
如果可能,出于性能原因,最好在服务器端(在数据库中)执行聚合。有不需要其他语言的中值聚合实现。通过查看 PL/Python boxplot 实现,人们应该能够编写一个PL/pgSQL 或 PL/SQL 等效项。
Heroku does not give you superuser access on the PostgreSQL cluster, which is required to install any additional languages.
If possible, it's best to perform aggregation server side (in the database) for performance reasons. There are median aggregate implementations which don't need additional languages. By looking at PL/Python boxplot implementations, one should be able to write a PL/pgSQL or PL/SQL equivilant.