Skip to content

Commit

Permalink
Some static methods and other renames to help make quantified code ha…
Browse files Browse the repository at this point in the history
…ppy which will make other python users happy
  • Loading branch information
abkfenris committed Sep 7, 2015
1 parent 6488351 commit baab392
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion app/remote/cawateroffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class WaterOffice(RemoteGage):
"""
BC_07EA004
"""
def get_from_wateroffice(self, remote_id):
@staticmethod
def get_from_wateroffice(remote_id):
province = remote_id.split('_')[0]
url = 'http://dd.weather.gc.ca/hydrometric/csv/{}/hourly/{}_hourly_hydrometric.csv'.format(province, remote_id)
response = requests.get(url)
Expand Down
6 changes: 4 additions & 2 deletions app/remote/h2oline.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@


class H2Oline(RemoteGage):
def soup(self, remote_id):
@staticmethod
def soup(remote_id):
"""
Return a beautiful soup object from h2oline
"""
Expand All @@ -42,7 +43,8 @@ def value_strings(self, remote_id, parameter='CFS', soup=None):
p = re.compile('([\d.]+)+(?= {})'.format(parameter))
return soup.body.findAll(text=p)

def start_end(self, string, parameter):
@staticmethod
def start_end(string, parameter):
"""
Return the start and end of the parameter in the string
"""
Expand Down
6 changes: 4 additions & 2 deletions app/remote/usgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
class USGS(RemoteGage):
URLBASE = 'http://waterservices.usgs.gov/nwis/iv/?format=json,1.1'

def site_code(selt, site_json):
@staticmethod
def site_code(site_json):
"""
From a USGS array item within ['value']['timeSeries']
get the code back for the site
"""
return str(site_json['sourceInfo']['siteCode'][0]['value'])

def dt_value(self, site_json):
@staticmethod
def dt_value(site_json):
"""
From a USGS array item within ['value']['timeSeries']
return datetime, float value of sample
Expand Down
4 changes: 2 additions & 2 deletions app/tasks/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
USGS = usgs.USGS()
CEHQ = cehq.CEHQ()
CAWaterOffice = cawateroffice.WaterOffice()
Corps = corps.Corps()
CORPS = corps.Corps()
Failure = base.RemoteGage()


Expand All @@ -29,7 +29,7 @@
'usgs': USGS.get_multiple_samples,
'cehq': CEHQ.get_multiple_samples,
'cawater': CAWaterOffice.get_multiple_samples,
'corps': Corps.get_multiple_samples
'corps': CORPS.get_multiple_samples
}


Expand Down
4 changes: 2 additions & 2 deletions tests/test_remote_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class TestRemoteBase(BasicTestCase):
RemoteGage = base.RemoteGage()
remote_gage = base.RemoteGage()

def test_get_sample(self):
with pytest.raises(NotImplementedError):
self.RemoteGage.get_sample(1)
self.remote_gage.get_sample(1)
6 changes: 3 additions & 3 deletions tests/test_remote_corps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@

class TestCorps(BasicTestCase):
SITES = ['DSVN6', 'SCNM5', 'SMW']
Corps = corps.Corps()
corps = corps.Corps()

@my_vcr.use_cassette('tests/fixtures/corps_soup_dt_value')
def test_soup_dt_value(self):
for site_num in self.SITES:
dt, value = self.Corps.dt_value(site_num)
dt, value = self.corps.dt_value(site_num)
assert type(value) == float
assert type(dt) == datetime.datetime

@my_vcr.use_cassette('tests/fixtures/corps_get_sample')
def test_get_sample(self):
sensor = Sensor.query.filter(Sensor.remote_type == 'corps').first()
before = Sample.query.count()
self.Corps.get_sample(sensor.id)
self.corps.get_sample(sensor.id)
after = Sample.query.count()
assert after > before
18 changes: 9 additions & 9 deletions tests/test_remote_h2oline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@

class TestH2Oline(BasicTestCase):
SITE_NUM = 235127
h2 = h2oline.H2Oline()
h2oline = h2oline.H2Oline()

@my_vcr.use_cassette('tests/fixtures/h2oline_get_river', ignore_localhost=True)
def test_get_river(self):
assert self.h2.river(self.SITE_NUM) == 'RAPID RIVER MIDDLE DAM ON RICHARDSON LAKE, ME'
assert self.h2oline.river(self.SITE_NUM) == 'RAPID RIVER MIDDLE DAM ON RICHARDSON LAKE, ME'

@my_vcr.use_cassette('tests/fixtures/h2oline_get_cfs', ignore_localhost=True)
def test_get_cfs(self):
assert type(self.h2.value(self.SITE_NUM)) == float
assert type(self.h2oline.value(self.SITE_NUM)) == float

@my_vcr.use_cassette('tests/fixtures/h2oline_soup_get_river_cfs')
def test_soup_get_river_cfs(self):
soup = self.h2.soup(self.SITE_NUM)
assert self.h2.river(self.SITE_NUM, soup=soup) == 'RAPID RIVER MIDDLE DAM ON RICHARDSON LAKE, ME'
assert type(self.h2.value(self.SITE_NUM, soup=soup)) == float
soup = self.h2oline.soup(self.SITE_NUM)
assert self.h2oline.river(self.SITE_NUM, soup=soup) == 'RAPID RIVER MIDDLE DAM ON RICHARDSON LAKE, ME'
assert type(self.h2oline.value(self.SITE_NUM, soup=soup)) == float

@my_vcr.use_cassette('tests/fixtures/h2oline_get_dt_cfs')
def test_get_dt_cfs(self):
dt, value = self.h2.dt_value(self.SITE_NUM)
dt, value = self.h2oline.dt_value(self.SITE_NUM)
assert type(dt) == datetime.datetime
assert type(value) == float

@my_vcr.use_cassette('tests/fixture/h2oline_soup_get_dt_cfs')
def test_soup_get_dt_cfs(self):
soup = self.h2.soup(self.SITE_NUM)
dt, value = self.h2.dt_value(self.SITE_NUM, soup=soup)
soup = self.h2oline.soup(self.SITE_NUM)
dt, value = self.h2oline.dt_value(self.SITE_NUM, soup=soup)
assert type(dt) == datetime.datetime
assert type(value) == float

0 comments on commit baab392

Please sign in to comment.