Skip to content

Commit

Permalink
update description
Browse files Browse the repository at this point in the history
fixed data_cruncher to save year
  • Loading branch information
mosesmc52 committed Aug 12, 2022
1 parent 5e598c5 commit 42d20e9
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 33 deletions.
3 changes: 3 additions & 0 deletions frontend/src/components/PageNavHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class PageNavHeader extends React.Component {
<NavHashLink to="/#workshop" className="nav-items">
Workshop
</NavHashLink>
<NavHashLink to={{pathname: "https://github.com/codefordenver/waterbeacon"}} className="nav-items" target="_blank">
Github Repository
</NavHashLink>
</Nav>
</Navbar.Collapse>
</Navbar>
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/components/WhyWB.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ export default function WhyWB() {
</div>
<div className="center-all">
<p>
Imagine opening Google Maps and there there is a Water Quality layer as assessable as air quality. You could easily view which neighborhood has high water quality vs low water quality by an index rated by 0 - 100 or which river has bad water quality. You can use this index to easily understand how safe this water is to drink that is the vision of Water Beacon to make information about water quality easy to view and consume.
The vision of Water Beacon is to make drinking water quality data easy to understand.
</p>
<p>
Using EPA data, we created score to identify which counties have good versus bad drinking water.
Next, we use the score to rank each county. Counties ranked 1 have the best drinking water. The visualization is updated every quarter.
</p>
<p>
In addition, we use Twitter to identify counties that may report water quality alerts. If you subscribe and submit your zipcode, you will
recieve an notification if there are any water quality alerts within your county.
</p>
<p>
Water Beacon is completly open-source. Click Github-Repo to view the source code
</p>
</div>
</article>
Expand Down
148 changes: 116 additions & 32 deletions rawdata/management/commands/data_cruncher.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,169 @@
import os, json
import json
import os

import pandas as pd
from django.conf import settings
from django.core.management.base import BaseCommand
from utils.epa.sdw_data_cruncher import ( SDW_Data_Cruncher )
from django.utils import timezone
from django_pandas.io import read_frame

from app import models as app_models
from rawdata import models as raw_models
from utils.epa.sdw_data_cruncher import SDW_Data_Cruncher
from utils.log import log
from django_pandas.io import read_frame
import pandas as pd
from django.utils import timezone


class Command(BaseCommand):
def handle(self, *args, **options):

now = timezone.now()
year = now.year
if now.month >= 11:
quarter = 'q4'
quarter = "q4"
elif now.month >= 8:
quarter = 'q3'
quarter = "q3"
elif now.month >= 5:
quarter = 'q2'
quarter = "q2"
else:
quarter = 'q1'

quarter = "q1"

cruncher = SDW_Data_Cruncher()

states = [
"AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT",
"DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID",
"IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH",
"MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE",
"NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP",
"OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC",
"SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA",
"WV", "WI", "WY"
"AL",
"AK",
"AS",
"AZ",
"AR",
"CA",
"CO",
"CT",
"DE",
"DC",
"FM",
"FL",
"GA",
"GU",
"HI",
"ID",
"IL",
"IN",
"IA",
"KS",
"KY",
"LA",
"ME",
"MH",
"MD",
"MA",
"MI",
"MN",
"MS",
"MO",
"MT",
"NE",
"NV",
"NH",
"NJ",
"NM",
"NY",
"NC",
"ND",
"MP",
"OH",
"OK",
"OR",
"PW",
"PA",
"PR",
"RI",
"SC",
"SD",
"TN",
"TX",
"UT",
"VT",
"VI",
"VA",
"WA",
"WV",
"WI",
"WY",
]

for state in states:

areas = cruncher.calc_state_scores(state, print_test = True)
areas = cruncher.calc_state_scores(state, print_test=True)
for __, area in areas.iterrows():
# systems = raw_models.EpaFacilitySystem.objects.filter(FacFIPSCode = area['fips_county']).values()
# systems_df = read_frame(systems)
# if systems_df.shape[0] != 0:
# systems_df['in_violation'] = systems_df.apply(lambda x: x['CurrVioFlag']==1, axis=1)
# systems_df = systems_df[['PWSId', 'FacName', 'FacLong', 'FacLat', 'in_violation']]
if area['score'] == 0:
if not app_models.data.objects.filter(location = location, score = area['score'], quarter = quarter, year = year).exists():
if area["score"] == 0:
if not app_models.data.objects.filter(
location=location,
score=area["score"],
quarter=quarter,
year=year,
).exists():
data = app_models.data()
data.year = year
data.quarter = quarter
data.location = location
data.score = area['score']
data.score = area["score"]
try:
data.save()
log('%s, %s [%s]' % (location.major_city, location.state, area['score']), 'success')
log(
"%s, %s [%s]"
% (location.major_city, location.state, area["score"]),
"success",
)
except:
print(location)
else:
log('%s, %s [%s]' % (location.major_city, location.state, area['score']), 'info')
log(
"%s, %s [%s]"
% (location.major_city, location.state, area["score"]),
"info",
)
else:
location = app_models.location.objects.filter(fips_county = area['fips_county']).first()
location = app_models.location.objects.filter(
fips_county=area["fips_county"]
).first()
print(area.systems.head())
if area['score'] - 0.05 < 0:
if area["score"] - 0.05 < 0:
min_score = 0
else:
min_score = area['score'] - 0.05
max_score = area['score'] + 0.05
min_score = area["score"] - 0.05
max_score = area["score"] + 0.05

if not app_models.data.objects.filter(location = location, score__gte = min_score, score__lte = max_score, quarter = quarter, year = year).exists():
if not app_models.data.objects.filter(
location=location,
score__gte=min_score,
score__lte=max_score,
quarter=quarter,
year=year,
).exists():
data = app_models.data()
# todo: need to insert facilities here
data.location = location
data.quarter = quarter
data.year = year
data.location = location
data.score = area['score']
data.score = area["score"]
try:
data.save()
log('%s, %s [%s]' % (location.major_city, location.state, area['score']), 'success')
log(
"%s, %s [%s]"
% (location.major_city, location.state, area["score"]),
"success",
)
except:
print(location)
else:
log('%s, %s [%s]' % (location.major_city, location.state, area['score']), 'info')
log(
"%s, %s [%s]"
% (location.major_city, location.state, area["score"]),
"info",
)

0 comments on commit 42d20e9

Please sign in to comment.