Skip to content

Knvgpt/tcsAssignments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

My Assignments This repository contains my solutions for take home assignments. It's organized into separate directories.

Folder Structure The repository has the following top-level structure:

. ├── asn1/ └── asn2/ asn1/: Contains the code and related files for Assignment 1. asn2/: Contains the code and related files for Assignment 2.

Assignment 1 (asn1/)

This folder holds the solution for Assignment 1. You'll find specific details, instructions on how to run it, and its purpose within the README.md file located inside the asn1/ directory.

Features

checks for server availabity and gives the best one to the client.

Node Module with findServer() function: This function should return a Promise. Resolution: It resolves with the online server that has the lowest priority number. Rejection: It rejects with an error if no servers are online. HTTP GET Requests for Availability: HTTP GET requests should be used to determine if a server is online or offline. Simultaneous Requests: All GET requests should be done simultaneously. Timeout: A GET request should timeout after 5 seconds. Online Criteria: A server should be considered online if its response status code is between 200 and 299. Server Prioritization: Online servers are sorted based on priority. Setup and Running

To set up and run this assignment:

Navigate to the folder: Open your terminal or command prompt and go to the asn1/ directory. Bash cd asn1 Install Dependencies: Install any required Node.js packages. Bash npm install Run the Demo: A working demo of the module, that meets the above requirements, is expected. Bash node demo.js

Run Unit Tests: A working unit test suite for the module, that meets the above requirements, is expected. All server interaction in unit tests should be mocked. Bash npm test

Assignment 2 (asn2/) This folder contains the application developed for Assignment 2, which is a Weather Information Service that retrieves current weather conditions for a given city, utilizes caching, and handles various API interactions.

Features

City Geocoding: Uses the Google Geocoding API to convert city names into geographical coordinates (latitude and longitude). Weather Data Fetching: Retrieves current weather conditions from the Google Climate and Weather API using the obtained coordinates. Intelligent Caching: Implements a caching mechanism using SQLite to store weather data. It serves cached data if it's recent and fetches new data from the API only when the cache is stale or empty. Robust Error Handling: Gracefully handles API errors (e.g., city not found, network issues, API timeouts) and propagates them effectively. Unit Tests: Includes comprehensive unit tests using Jest and Nock to ensure the reliability and correctness of the service by mocking external API calls and database interactions. Setup and Running

To get Assignment 2 up and running, follow these steps:

Navigate: Open your terminal or command prompt and go to the asn2/ directory: Bash cd asn2 Install Dependencies: Install all required Node.js packages: Bash npm install Configuration: Create a .env file in the asn2/ directory and add your Google API Key and Google Cloud Project ID. Alternatively, you can directly update config.js with your credentials.

.env example

GOOGLE_API_KEY="YOUR_ACTUAL_GOOGLE_API_KEY_HERE" GOOGLE_WEATHER_API_BASE_URL="YOUR_ACTUAL_API_URL_HERE"

Optional: You can also specify other configs if not using defaults

DB_PATH="./weather.db"

API_TIMEOUT="5000"

WEATHER_CACHE_DURATION_MS="20000"

Important: Remember to replace YOUR_ACTUAL_GOOGLE_API_KEY_HERE and YOUR_GOOGLE_CLOUD_PROJECT_ID with your actual values. Run the Demo: Execute the demo script to see the weather service in action, including caching and error handling: Bash node demo.js Run Tests: To run the unit tests and verify the code's functionality: Bash npm test How to Contribute If you're looking to contribute or suggest improvements (perhaps for future assignments!), feel free to fork this repository and submit pull requests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published