Git Product home page Git Product logo

ceo-reporting's Introduction

Super quick prototype

The voice assistant that your CEO will love

Screenshot Screenshot Screenshot

1. Generate Dummy dataset

import pandas as pd
from datetime import datetime
import numpy as np

# create DatetimeIndex
date_rng = pd.date_range(start='1/1/2018', end='9/5/2019', freq='D') # m/d/yyyy

# create dataframe
df = pd.DataFrame(date_rng, columns=['date'])

# create column 'revenue' with random values
df['revenue'] = np.random.randint(3000000,6000000,size=(len(date_rng)))

# create column 'bookings' with random values
df['bookings'] = np.random.randint(10000,20000,size=(len(date_rng)))

# export csv file (you can create the table in BigQuery from pandas dataframe as well)
df.to_csv(<path>)

2. Create Dataset and Table in BigQuery

3. Set up dialogflow

First, make sure you understand the basics of Dialogflow: you can start here.

Screenshot

4. Create Cloud Function

// import BigQuery module
const {BigQuery} = require('@google-cloud/bigquery');

// you can deploy this directly from your machine using gcloud functions deploy ceo --runtime nodejs8 --trigger-http

exports.ceo = functions.https.onRequest((request,response) =>{

        async function datarequest(agent) { // async -> so we can use await later

        const bigquery = new BigQuery();

        // declare variables
        let metric
        let dimension
        let date = agent.parameters.date // from Dialogflow
        
        let dateString = date.substr(0, 10)

        // this could be done better
        if (agent.parameters.querymetric === 'revenue') { // user asked for Revenue
            metric    = 'revenue'
            dimension = 'pounds'
        } else if (agent.parameters.querymetric === 'bookings') { // user asked for Revenue
            metric    = 'bookings'
            dimension = 'bookings'
        }

        console.log(`Reading ${metric} ${dimension}`) // testing
        
        // SQL Query
        const query = `SELECT ${metric} FROM testceo.ceo WHERE date = '${dateString}'`;

        const options = {
            query: query,
            // Location must match that of the dataset(s) referenced in the query.
            location: 'US',
        };

        // Run the query as a job
        const [job] = await bigquery.createQueryJob(options);
        console.log(`Job ${job.id} started.`);

        // Wait for the query to finish
        const [rows] = await job.getQueryResults();

        // Print the results
        console.log('Rows:');

        const revenue = rows[0][metric]
        agent.add(`${revenue.toString()} ${dimension}`);
        // add vlY
        // add error handler
        //rows.forEach(row => console.log(row));


    }
    
 
}

ceo-reporting's People

Contributors

pabloferg avatar

Stargazers

Dharam avatar

Watchers

 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.