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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/clocks.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from alpine:latest

RUN apk add --no-cache python3-dev \
&& pip3 install --upgrade pip

WORKDIR /app
COPY . /app

RUN pip3 --no-cache-dir install -r requirements.txt

RUN pylint main.py

EXPOSE 5000

ENTRYPOINT ["python3"]
CMD ["main.py"]
73 changes: 24 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,33 @@
# Clock Exercise

We are interested in running code of course, but even more in your development process and understanding of Software Development Lifecycle Management.
Calculating angle between Clock handles Exercise-

**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.**
This codebase shows how to calculate angle between clock handles.

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.
For example - If user pass input as 03:00, it should yield an angle of 90 degree.

If you need clarification, or would like to request additional information, pease reach out to the interviewer by email.
Deployed URL: https://ca-cr-app-icbqkvt2oa-uc.a.run.app/

## Scenario
Technology Stack

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.
1. Python 3.7
2. Cloud Source Repository
3. Cloud Build
4. Docker
5. Cloud Run
6. HTML5
7. Ajax

Following is the approach steps:

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.
i) Using python language build Flask application that calculates the angle between clock handles.
ii) Using python3 packages like Flask, Request,Render_Template, Jsonify etc and HTML5, AJAX to build interactive front end/web page for accepting user parameters .
iii) Using GIT create local repository.
iv) Using Docker to convert Python Flask application into Docker Image

You may need to make some assupmtions, that's OK, just document what they are and move on.
Deployment using GCP developer tools-

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.

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.

## How to proceed

**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.**

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.

We are looking for you to demonstrate your abilities in software practices and DevOps, including reusability, portability, reliability, ease of maintenance etc.

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.

---

## Product Backlog Item (Sprint Story)

Here is the story that is in the backlog.

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:-

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

### Detail:-

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

### Acceptance Criteria:-

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)
1) Any DevOps/Cicd components that would support this feature in a production setting
1. Cloud Build to create a CI/CD pipeline for building, deploying.
2. Cloud Run that is a server-less compute platform that enables above hosted app URL.
3. Cloud Source Repositories, a private Git repositories hosted on Google Cloud.
Author : Dheeraj Tingloo
Created date : 29-April-2020
Empty file added __main__.py
Empty file.
30 changes: 30 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
steps:
# build the container image
-
name: gcr.io/cloud-builders/docker
args:
- build
- '-t'
- 'gcr.io/ind-coe/github-repo:$COMMIT_SHA'
- .
# push the container image to Container Registry
-
name: gcr.io/cloud-builders/docker
args:
- push
- 'gcr.io/ind-coe/github-repo:$COMMIT_SHA'

# Deploy container image to Cloud Run
-
name: 'gcr.io/cloud-builders/gcloud'
args:
- 'run'
- 'deploy'
- 'ca-cr-app'
- '--image'
- 'gcr.io/ind-coe/github-repo:$COMMIT_SHA'
- '--region'
- 'us-central1'
- '--platform'
- 'managed'
- '--allow-unauthenticated'
39 changes: 39 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
###########
Author: Dheeraj Tingloo
Created Date: 27-April-2020
Use Case: Calculating angle between clock hands!
###########
"""
from flask import Flask, render_template, request, jsonify

APP = Flask(__name__)


@APP.route('/')
def index():
"""Calling default web page."""
return render_template('index.html')


@APP.route('/cal_clock_angle')
def cal_clock_angle():
"""
Getting arguments from user.
Using abs() to make generalised formula.
And return calculation back to web call in JSON format.
"""
hrs = request.args.get('hrs', 0, type=str)
mins = request.args.get('min', 0, type=str)

# Input validation for hours and minutes.
if 1 <= int(hrs) <= 12 and 0 <= int(mins) < 60:
angle = float(abs(11 / 2 * int(mins) - 30 * int(hrs)))
else:
return jsonify(result="Error in input hours or minutes.")

return jsonify(result=" {}:{} This makes the following angle {}°".format(hrs, mins, angle))


if __name__ == "__main__":
APP.run(host='0.0.0.0', debug=True)
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Flask==1.1.1
gunicorn==20.0.4
pytest==5.2.2
pylint==2.4.3
42 changes: 42 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script type=text/javascript>
$(function() {
$('#calculate').click(function(){
$.ajax({
url: '/cal_clock_angle',
data:{
hrs: $('#hrs').val(),
min: $('#min').val()
},
dataType: 'JSON',
type: 'GET',
success: function(data){
$("#result").html(data.result);
}
});
});
});
</script>
</head>
<body>
<div class="container">
<div class="header">
<h3 class="text-muted">Calculate angle between clock handles.</h3>
</div>
<hr/>
<div>
<p>
<input type="number" id='hrs' size="2" name="hrs" maxlength = "2"> :
<input type="number" id='min' size="2" name="min" maxlength = "2"> =
<span id="result">?</span>
<p><button class="btn btn-success" id="calculate">Calculate angle</button></p>
</form></p>
</div>
</div>
</body>
</html>