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
58 changes: 3 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,6 @@
# Clock Exercise
Calculating angle between Clock handles Exercise-

We are interested in running code of course, but even more in your development process and understanding of Software Development Lifecycle Management.
Hosted in App Engine for easy intraction UI web based application to get the angle from given inputs.

**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.**
App Engine URL: https://hallowed-key-273608.uc.r.appspot.com/

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.

If you need clarification, or would like to request additional information, pease reach out to the interviewer by email.

## Scenario

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.

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.

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

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
2 changes: 2 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runtime: python37

11 changes: 11 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- name: "python"
id: Test
entrypoint: /bin/sh
args:
- -c
- 'pip install --upgrade google-api-python-client && pip install google-cloud-bigquery && pip install flask && pip install pytest && python -m pytest'

- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
timeout: "1600s"
60 changes: 60 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
from flask import Flask, render_template, request
from google.cloud import bigquery
from google.cloud.bigquery.client import Client
import datetime

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'keyfile.json'

app = Flask(__name__)

@app.route('/')
def student():
return render_template('form.html')

@app.route('/result',methods = ['POST','GET'])
def result():
if request.method == 'POST':
#get the inputs from the form
h = int(request.form['hour'])
m = int(request.form['minute'])

if (h < 0 or m < 0 or h > 12 or m > 60):
print('Wrong input')

if (h == 12):
h = 0

if (m == 60):
m = 0
#calculate the hour and minute
hour_angle = 0.5 * (h * 60 + m)
minute_angle = 6 * m

#calculate the angle
angle = abs(hour_angle - minute_angle)


angle = min(360 - angle, angle)

# bigquery insert
client = bigquery.Client()
dataset_ref = client.dataset('clocks')
table_ref = dataset_ref.table('angles_details')
table = client.get_table(table_ref) # API call

#insert data
rows_to_insert = [
{u'hours': h,
u'minutes': m,
u'angle': angle,
u'updated_on': datetime.datetime.now()
}
]
client.insert_rows(table, rows_to_insert) # API request

#print the angle in result page
return render_template("result.html",result = str(angle))

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 @@
google-api-python-client
google-cloud
37 changes: 37 additions & 0 deletions templates/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<html>

<script>
function validateForm() {
var h = document.forms["angle"]["hour"].value;
var m = document.forms["angle"]["minute"].value;
if (h == "" ) {
alert("Hour must be filled out");
return false;
}
if (m == "") {
alert("Minute must be filled out");
return false;
}

if (h < 0 || h > 12 ) {
alert("Invlaid Input in Hour");
return false;
}

if (m < 0 || m > 60 ) {
alert("Invlaid Input in Minute");
return false;
}
}
</script>


<body>
<h1> Demo - Angle between the hands on a clock face</h1>
<form name="angle" action = "result" onsubmit="return validateForm()" method = "POST">
<p>Hours <input type = "text" name = "hour" /></p>
<p>Minute <input type = "text" name = "minute" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
</body>
</html>
15 changes: 15 additions & 0 deletions templates/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>
<body>
<table border = 1>

<tr>
<th> The Angle is </th>
<td> {{ result }} </td>
</tr>

</table>
</br>
<button onclick="window.history.back();">Home</button>
</body>
</html>
20 changes: 20 additions & 0 deletions test_angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from main import app as main_app


def test_root_page():
response = main_app.test_client().get('/')
assert response.status_code == 200

def test_result_data_success():
data = {
'hour': 3,
'minute': 0
}
response = main_app.test_client().post('/result', data=data)
assert '90.0' in str(response.data)