Skip to content

A Z Score calculator endpoint. Implemented with an API Gateway + Lambda + Dynamo DB table by way of CDK.

Notifications You must be signed in to change notification settings

yethon/cdk-zCalc-serverless

Repository files navigation

Z Score Calculator

This repo is the foundation for a technical interview/project.

Given a data set, calculate a Z-Score. This repo uses the following formula:

Z=(((X/M)^L) – 1)/LS

* This formula assumes L is > 0. You could expand this logic to handle L = 0 with a different forumla.

Implementation Details

This is a fully functioning API Gateway + Lambda Function + DynamoDB project.

  • The endpoint expects 3 query parametersagemos, sex, head_circumference
  • Once the endpoint is hit, it will retrieve the values for M, L and S from the DynamoDB
  • L, M, S and the head_circumference value will be used to calculate the Z-Score
  • The response will look like:
Z Score calculation was successful!

 Data retrieved from DB for Z Score: {
    "Sex": {
        "S": "1"
    },
    "L": {
        "N": "1.424084853"
    },
    "M": {
        "N": "48.72064621"
    },
    "S": {
        "N": "0.029242207"
    },
    "P25": {
        "N": "47.75563267"
    },
    "Agemos": {
        "S": "24.5"
    }
} 

Your query params were {
    "agemos": "24.5",
    "sex": "1",
    "head_circumference": "50"
} 

 The Z Score is 0.0007721242974448446

This started out as a standard TypeScript repo with a function and tests (like this one)...but I pivoted and decided to focus on the logistics of creating a project with AWS tools. I've created lambdas based projects before, but handed them off to a DevOps team and focused exclusively on the logic of the lambda.

Getting an understanding of the "Infrastructure as Code" in the CdkZCalcServerlessStack.ts class made the concept very approachable.

The cdk watch command (which hotswaps your lamda function changes as you make them) is amazing.

What this implementation is missing / should change

  1. A fully functioning test suite
  2. I'd focus much more on error handling (The pre-generated code that AWS tutorials provide have extensive examples of error messaging logic.)
  3. I'd remove anything that reveals implementation details from the response objects
  4. I'd create a security policy for the endpoint
  5. Decide to use a DB is one option, another option would be to load your CSV Data into an AWS bucket and parse it
  6. Creating the DB Schema in this repo so that it's a 100% functioning project

Extending

  • You could iterate on the lambda to calculate other Z Scores.
  • You could iterate on the lambda to calculate Z Scores with the alternate formula.
  • You could create an additional call type to retrieve a data set from the DB for plotting.

Part II

Creating a graphing app for this data.

  • You could use a new API call that would return the data, based on gender.
  • You'd use that response to plot your ranges.
  • You'd need an array of measurements to plot over those ranges.
  • You could use the Z Score call to show the Z Score on hover. (Assuming that's something people would want to see)

Tooling

  • This project was created with AWS's CDK
  • Marcia Villalba's videos can get you started with CDK
  • I created DynamoDB table using the AWS NoSQL Workbench, therefore you can't use this project "as is" without creating an identical table
  • This project has been successfully deployed

Auto generated by CDK

Welcome to your CDK TypeScript project

This is a project for CDK development with TypeScript.

The cdk.json file tells the CDK Toolkit how to execute your app.

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

About

A Z Score calculator endpoint. Implemented with an API Gateway + Lambda + Dynamo DB table by way of CDK.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published