Giter Club home page Giter Club logo

bbdn-blackboarddata-queries's Introduction

BBDN-BlackboardData-Queries

The format for contributions is as follows:

Example: Get User By User Id

/get-user-by-user-id

  • variables.json
  • query.sql
  • output.json
  • README.md

Example of SQL File with Variables

SQL files can have variables in the query. When retrieving query file, ensure that you check the variables.json file first for any variables to inject into the query.

An example of a variables.json file, is as follows:

{
    "variables": {
        "date": "2017-08-01"
    }
}

In this example, you would be looking for the variable {date} in your sql file, and it would be replaced with the variable in the variables.json file. So your sql would look like this:

select
    mcd.canon_desc as design_mode,
    ifnull(count(distinct lc.id),0) as course_count,
    ifnull(count(distinct case when course_role = 'I' then lpc.person_id else null end),0) as distinct_instructors,
    ifnull(count(distinct case when course_role = 'S' then lpc.person_id else null end),0) as distinct_students
from cdm_lms.course lc
left join cdm_lms.person_course lpc
    on lpc.course_id = lc.id
left join cdm_meta.canon_definition mcd
    on mcd.name = 'DESIGN_MODE'
    and mcd.source_domain = 'LMS'
    and mcd.canon_code = lc.design_mode
where lc.created_time > '{date}' 
group by 
    mcd.canon_desc
order by
    mcd.canon_desc

In order to call this programatically, you would use something similar to this example, written in Python:

def query_by_name(query_name):
    variables = requests.get(RAW_VARS_URL.replace('{query_name}', query_name)).json()['variables']
    query = requests.get(RAW_SQL_URL.replace('{query_name}', query_name)).text

    # ensure that if there are vars, then inject them into the query
    for key, value in variables.items():
        print(key, value)
        query = query.replace('{' + key + '}', str(value))

    return jsonify({
        'query': query
    })

For an example on how to use these queries with Python, check out BBDN-BlackboardData-Python.

bbdn-blackboarddata-queries's People

Contributors

cpintoval avatar elmiguel avatar smachaje avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.