Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/owainkenwayucl/stats-plus-plus
My latest attempt to have some useful stats tools for our services.
https://github.com/owainkenwayucl/stats-plus-plus
hy python3 r sql
Last synced: 22 days ago
JSON representation
My latest attempt to have some useful stats tools for our services.
- Host: GitHub
- URL: https://github.com/owainkenwayucl/stats-plus-plus
- Owner: owainkenwayucl
- License: mit
- Created: 2017-08-04T12:11:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-25T15:47:52.000Z (6 months ago)
- Last Synced: 2024-04-25T16:58:24.773Z (6 months ago)
- Topics: hy, python3, r, sql
- Language: Python
- Size: 121 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stats-plus-plus
My latest attempt to have some useful stats tools for our services.This is a set of tools that can hopefully be used to write useful just in time stats programs to fulfil the arbitrary requirements we sometimes get. I'm basing it on the stuff I did in the tailoredrcstats (https://github.com/UCL-RITS/tailoredrcstats) package with the aim of having a more generic set of stuff.
## Requirements
### Python
* Python 3
* The official mysql connector package### R
* R
* RMySQL## Examples
Here's an example of the kind of thing you can do now in R:
```R
source("r/simpletemplate.r")
source("r/dbtools.r")keys <- genkeys(c("%DB%", "%PERIOD%"), c("thomas_sgelogs", "2017-08"))
query <- templatefile("sql/mean-slowdown-by-user.sql", keys)
data <- dbquery(keys["%DB%"], query)
```What's happening here is we are setting some parameters for the `mean-slowdown-by-user` SQL query, namely which service and the time period (August 2017), using my templating library to put them into the query, passing that query to the database and getting back an R data object which we can do the usual R tricks on.
The equivalent in Python3 looks like this:
```Python
import simpletemplate as st
import dbtools as dbtkeys = {'%DB%':'thomas_sgelogs', '%PERIOD%':'2017-08'}
query = st.templatefile(filename='sql/mean-slowdown-by-user.sql', keys=keys)
data = dbt.dbquery(db=keys['%DB%'], query=query)
```Or even better, in [hy](http://docs.hylang.org/en/stable/):
```Clojure
(import simpletemplate)
(import dbtools)(setv keys {"%DB%" "thomas_sgelogs" "%PERIOD%" "2017-08"})
(setv query (simpletemplate.templatefile
:filename "sql/mean-slowdown-by-user.sql"
:keys keys))
(setv data (dbtools.dbquery :db (get keys "%DB%")
:query query))
```