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
88 changes: 57 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,84 @@
# Clock Exercise

We are interested in running code of course, but even more in your development process and understanding of Software Development Lifecycle Management.

**Fork this repo, then get to work.** 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 back to the base repo.**
## Product Backlog Item (Sprint Story)

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.
Here is the story that is in the backlog.

If you need clarification, or would like to request additional information, pease reach out to the interviewer by email.
As with all stories, the team may have been optimistic with how much can be done in the time permitted. It's ok to meet some of the acceptance criteria by documenting what you would do in the next sprint! Prioritize your time and make sure you have some technical content to deliver.

## Scenario
### Description:-

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.
As a team<br>
We need a serivce that we can send a time value to and have it return or store an angle value<br>
So that we can use it in downstream processing

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.
URL :
Output JSON :

You may need to make some assupmtions, that's OK, just document what they are and move on.
### Detail:-

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.
We need to calculate the angle between the hands on a clock face. For example input 03:00 would yield 90 degrees.

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.
### Acceptance Criteria:-

## How to proceed
1) Code to perform the calculation

#### URL : http://127.0.0.1:5000//clock_angle/3:15
#### Output : {
"context": "Angle for time 3:15 is 7.5 degree."
}

**Fork this repo, then get to work.** 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 back to the base repo.**
1) How will you deploy this solution (in code or as a todo list if time is limited). i.e. how and where will this run?
---------------------------------
- Now Deploy the application on GCP
---------------------------------
File description
------------------------
app.yaml is used to deploy application on GCP

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.
- On google cloud
----------------
--create project

We are looking for you to demonstrate your abilities in software practices and DevOps, including reusability, portability, reliability, ease of maintenance etc.
- go to GC console generate ssh key
----------------------------------
---command to generate ssh key: ssh-keygen -t rsa -b 4096 -C "abhilash"
---cat .ssh/id_rsa.pub

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.
- Add pub key to git hub account
-------------------------------

---
- GC console: go into your project clone the repo
------------------------------------------------
--run : git clone https://github.com/githubabhilash/clocks.git

## Product Backlog Item (Sprint Story)

Here is the story that is in the backlog.
- GC console:Now go to project folder
------------------------------------
---run : gcloud app deploy
Note :It will ask region enter the numric value.

As with all stories, the team may have been optimistic with how much can be done in the time permitted. It's ok to meet some of the acceptance criteria by documenting what you would do in the next sprint! Prioritize your time and make sure you have some technical content to deliver.

### Description:-
2) How will you manage any infrastructure needed?

As a team<br>
We need a serivce that we can send a time value to and have it return or store an angle value<br>
So that we can use it in downstream processing
- Infrastructure needed
----------------------
- Technology Stack

### Detail:-
1. Python 3.7
2. Flask==1.1.2
3. GCP
- Implemented this service by using flask framework so we will be required to install flask.
-We will require GC resources based on the requirements
i. e.
- To run no of instances we will require no of CPU i. e. for now instances 1 , 1 cpu will be required.
- Memory will be required based on resource i.e memory_gb: 0.5
- disk_size_gb: 10

We need to calculate the angle between the hands on a clock face. For example input 03:00 would yield 90 degrees.

### Acceptance Criteria:-
3) Delivered as a feature branch in the repo fork
-- featureabhilash branch is created

1) Code to perform the calculation
1) How will you deploy this solution (in code or as a todo list if time is limited). i.e. how and where will this run?
1) How will you manage any infrastructure needed?
1) Delivered as a feature branch in the repo fork
1) Bonus points for a working deployed solution in GCP that you can demo at the "sprint review" (ie interview)
-- Deployed this service to on GCP and its running.
1) Any DevOps/Cicd components that would support this feature in a production setting
10 changes: 10 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
runtime: python37
env: flex
entrypoint: gunicorn -b :$PORT:app

#manual_scaling:
# instances: 1
#resources:
# cpu: 1
# memory_gb: 0.5
# disk_size_gb: 10
60 changes: 60 additions & 0 deletions find_angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from flask import Flask, jsonify
import time

app = Flask(__name__)


@app.route('/clock_angle/<string:data>', methods=['GET'])
def get_clock_angle(data):
if is_valid_time(data):
return jsonify(context="Angle for time {} is {} degree.".format(data, cal_culculate_angle(data)))

return jsonify(context="Please enter the valid format i.e. This time function will accept time b/w 00:00 To 23:59.")


def is_valid_time(value):
""" This time function will accept time b/w 00:00 to 23:59"""

try:
time.strptime(value, '%H:%M')
return True
except ValueError:
return False


def cal_culculate_angle(data):
"""Explanation:
Hour Calculation :
------------------
A analog clock is divided up into 12 sectors, based on the numbers 1–12. One sector represents
30 degrees (360/12 = 30).
so 1 hour = 30 degree
one minute = 0.5 degree

Min Calculation :
-----------------
a clock represent 360 degree so
1 min = 360 /60 = 6 degree
"""

CONST_PER_HOUR_DEGREE = 30
CONST_PER_MIN_DEGREE = 0.5
CONST_PER_MIN_DEG_FOR_MIN = 6

_hour, _min = data.split(":")
_hour = 12 if int(_hour) == 0 else int(_hour)
_min = int(_min)

if int(_hour) > 12:
_hour = int(_hour) - 12

# Position of Hour
h = _hour * CONST_PER_HOUR_DEGREE + _min * CONST_PER_MIN_DEGREE
# Position of Min
m = _min * CONST_PER_MIN_DEG_FOR_MIN

return abs(h - m)


if __name__ == '__main__':
app.run(debug=True)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==1.1.2
gunicorn==20.0.4
51 changes: 51 additions & 0 deletions test_find_angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import unittest

from find_angle import app, get_clock_angle


class testClock(unittest.TestCase):

def setUp(self):
# self.app = app.test_client()
self.app_context = app.app_context()
self.app_context.push()

def test_get_clock_angle_for_time_fail_testing(self):
"""Test case for fail testing """
data = get_clock_angle("as:aa")
expected_data = "Please enter the valid format i.e. This time function will accept time b/w 00:00 To 23:59."
self.assertEqual(expected_data, data.json['context'])

data = get_clock_angle("as:11")
expected_data = "Please enter the valid format i.e. This time function will accept time b/w 00:00 To 23:59."
self.assertEqual(expected_data, data.json['context'])

data = get_clock_angle("111:12")
expected_data = "Please enter the valid format i.e. This time function will accept time b/w 00:00 To 23:59."
self.assertEqual(expected_data, data.json['context'])

data = get_clock_angle("24:60")
expected_data = "Please enter the valid format i.e. This time function will accept time b/w 00:00 To 23:59."
self.assertEqual(expected_data, data.json['context'])

def test_get_clock_angle_for_time_pass_testing(self):
"""Test case for pass testing """
data = get_clock_angle("00:59")
expected_data = "Angle for time 00:59 is 35.5 degree."
self.assertEqual(expected_data, data.json['context'])

data = get_clock_angle("12:59")
expected_data = "Angle for time 12:59 is 35.5 degree."
self.assertEqual(expected_data, data.json['context'])

data = get_clock_angle("01:00")
expected_data = "Angle for time 01:00 is 30.0 degree."
self.assertEqual(expected_data, data.json['context'])

data = get_clock_angle("03:20")
expected_data = "Angle for time 03:20 is 20.0 degree."
self.assertEqual(expected_data, data.json['context'])


if __name__ == '__main__':
unittest.find_angle()