Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Angle between hour and minute documentation.docx
Binary file not shown.
28 changes: 28 additions & 0 deletions Angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Angle:

def __init__(self, hr, mi):
self.hr = hr
self.mi = mi

def calculateAngle(self):
#calculate per minute degree
self.perMinDegree = int(360/60)
#degree for min input
self.minAngle= int(self.perMinDegree * self.mi)
#calculate per hour degree
self.perHourDegree = int(360/12)
#degree for hour input
self.hourAngle = int(self.perHourDegree * self.hr)
#convert mins to hour
self.minsToHr = self.mi/60
#degree for mins coverted to hr
self.minsToHrAngle = self.minsToHr * self.perHourDegree
#total hour min angle
self.hrMinAngleTotal = self.hourAngle + self.minsToHrAngle
#differnece of hour and min angle
self.angleBetweenHrMin = self.hrMinAngleTotal - self.minAngle
return self.angleBetweenHrMin

#angle = Angle(3, 00)
#print(angle.calculateAngle())
#print(angle.angleBetweenHrMin)
22 changes: 22 additions & 0 deletions AngleService.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
"""
Created on Thu May 7 19:20:50 2020

@author: prem
"""

from flask import Flask, request
import Angle
app = Flask(__name__)


@app.route("/")
def home():
hr = int(request.args.get("hr"))
mi = int(request.args.get("mi"))
angle = Angle.Angle(hr, mi)
response = "Angle between hour hand %d and minute hand %d is %.1f degrees" % (hr, mi, angle.calculateAngle())
return response

if __name__ == "__main__":
app.run(debug=True)
66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
# Clock Exercise
# clocks
An interview exercise for a devops position

This exercise is not meant to take an excessive amount of time. It is an opportunity for you to demonstrate your skills without the stress of an interview. If you start to run out of time, it’s ok to leave an imaginary team member a TODO list that details all the things you didn’t quite have time to do in order for your solution to go to prod.
# Brief description of how and where application will run
This is web based application designed in python and deployed as flask web service on python.

## Scenario
This application will be accessed using browser URL (given example below) with request parameters as hour and minute value and hit enter. Angle between hour and minute hand will be displayed on browser.

You have just joined a DevOps team. This team lives by DevOps principles and you want to let them know you mean business! This particular team is developing a product that is deployed in a Google Cloud Project.
**Below are instructions to setup this application**

This sprint, the team has been asked to work on a new feature that depends on being able to calculate the angle between the hands on a clock face. They’ve asked you to write some code to help out with that. This is an IOT project, and they have sensors emitting times at a pretty low frequency (about 10 a minute), and for some reason they need to be processed and stored as angles.
Install flask package in python environment: pip install Flask

You may need to make some assupmtions, that's OK, just document what they are and move on.
Run program – python AngleService.py

The team loves innovation, so you can use whatever languages and technologies you like to complete this. Approach this problem as if your code will go to production. Whilst we don’t expect the code to be perfect, we are not looking for a hacked together script.
Request url with parameters –

Your solution should offer the rest of the team a way to submit a time and receive an angle in return or store it somewhere. They are little fuzzy on the best way to get this low frequency data to your service, so if you can offer them any hints on that, they’d be really happy.
Hr – hour hand value

## How to proceed
Mi – minute hand value

Fork this repo, then start working in a feature branch, based on develop. Remember that this is a DevOps team, so make sure your repo reflects that. Spend however much time you feel is reasonable. It doesn’t matter if the project is ‘done’, nothing ever is. When you’re ready push your changes back to Github and put in a pull request.
http://localhost:5000/?hr=3&mi=15

Be sure to add in instructions for how to deploy your solution, and document things in a way that the rest of the team can pick this up and run with it. Remember you have all the tools in the GCP arsenal at your disposal.
This application runs on python server as webservice.

We are looking for you to demonstrate your abilities in software practices and DevOps, including reusability, portability, reliability, ease of maintenance etc.
AngleService.py – this file needs to be run. It will host application as webservice on localhost. Use this url to request angle value - http://localhost:5000/?hr=3&mi=15

Think about how this will actually be deployed and maintained in the future as you build on it and expand it. You don’t have to implement deployment practices if you don’t have the time or resources, its ok to just document those.
# Code files
[Angle.py](Angle.py) – This file contains python code which contains mathematical logic for calculating time value to angle value in degrees.

[AngleService.py](AngleService.py) – This file contains python code which deploys Angle.py code to as webservice using flask api.

# Output
**Request url with parameters**

Hr – hour hand value

Mi – minute hand value

http://localhost:5000/?hr=3&mi=15

![Image of output](output.png)

**Spyder Editor for python code**

![Image of code](code.png)

# How will you manage any infrastructure needed?
We can use some cloud services like AWS like elastic beanstalk to deploy python application as web app.

# Bonus points for a working deployed solution in GCP that you can demo at the "sprint review" (ie interview)
Not familiar with GCP however after some google I found some of the steps I can follow:

Deploying your service

To deploy your web service, you run the gcloud app deploy command from the root directory of your project, where your app.yaml file is located:

gcloud app deploy

Viewing your service

To quickly launch your browser and access your web service at https://PROJECT_ID.REGION_ID.r.appspot.com, enter the following command:
gcloud app browse

# Any DevOps/Cicd components that would support this feature in a production setting
Yaml file for libraries dependencies.
Binary file added code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.