Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Productization and Cloud Johan Mazorra Pull Request #170

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Sprint Challenge
Johan Mazorra authored and Johan Mazorra committed Apr 24, 2020
commit 306ba85478e39857ab1740d18c129e21ecce9c30
Binary file added .DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions sc/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
flask = "*"
flask-sqlalchemy = "*"
requests = "*"

[requires]
python_version = "3.7"
158 changes: 158 additions & 0 deletions sc/Pipfile.lock

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

56 changes: 56 additions & 0 deletions sc/aq_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import openaq
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy

APP = Flask(__name__)
APP.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3'
DB = SQLAlchemy(APP)

class Record(DB.Model):
id = DB.Column(DB.Integer, primary_key = True)
datetime = DB.Column(DB.String(25))
value = DB.Column(DB.Float, nullable = False)

def __repr__(self):
return '<Record date {}>'.format(self.datetime) + '<value {}>'.format(self.value)
api = openaq.OpenAQ()
status, body = api.measurements(city = 'Los Angeles', parameter = 'pm25')

date_and_value = []

for result in body['results']:
value = result['value']
keys, values = zip( * result['date'].items())
utc_datetime, _local = values
date_and_value.append((str(utc_datetime), value))

@APP.route('/')
def root():
my_list = date_and_value

return render_template('base.html', title = 'Home', list = my_list)

@APP.route('/main')
def main():
risky = Record.query.filter(Record.value >= 10).all()

return render_template('base.html', title = 'Potentially risky days', list = risky)

@APP.route('/refresh')
def refresh():
""
"Pull fresh data from Open AQ and replace existing data."
""
DB.drop_all()
DB.create_all()

status, body = api.measurements(city = 'Los Angeles', parameter = 'pm25')

for result in body['results']:
value = result['value']
keys, values = zip( * result['date'].items())
utc_datetime, _local = values
new_record = Record(datetime = str(utc_datetime), value = value)
DB.session.add(new_record)
DB.session.commit()
return 'Data refreshed!'
538 changes: 538 additions & 0 deletions sc/openaq.py

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions sc/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<head>
<title>Air Quality in the Cloud</title>
<link rel='stylesheet' href='https://unpkg.com/picnic'/>
</head>

<body>
<nav>
<a href="/" class="brand"><span>Air Quality</span></a>

<!-- responsive-->
<input id="bmenub" type="checkbox" class="show">
<label for="bmenub" class="burger pseudo button">Menu</label>

<div class="menu">
<a href="/refresh" class="button warning">Refresh Measurements</a>
</div>
</nav>
<article class='flex two' style='padding: 3em 1em;'>
{% block content %}
<div>
<h2>Cases of poor air quality in the Greater LA Area</h2>
{% for i in instance %}
<p>At {{ i.datetime }} Los Angeles had a particulate matter concentration of {{ i.value }}.</p>
{% endfor %}
</div>
{% endblock %}
</article>

</body>
</html>