Skip to content

Commit

Permalink
fixed foreign
Browse files Browse the repository at this point in the history
  • Loading branch information
jirhiker committed Sep 14, 2018
1 parent 324295d commit 28bbb40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
27 changes: 11 additions & 16 deletions wellpy/database_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_connection(h, u, p, n, *args, **kw):

class SessionCTX:
def __init__(self, h, u, p, n, *args, **kw):
conn = get_connection(h,u,p,n,*args,**kw)
conn = get_connection(h, u, p, n, *args, **kw)
self._conn = conn

def __enter__(self):
Expand Down Expand Up @@ -152,22 +152,15 @@ def get_point_ids(self):

def get_point_ids_simple(self):
with self._get_cursor() as cursor:
cmd='''SELECT DISTINCT PointID FROM dbo.Equipment
WHERE PointID
IS
NOT
NULL
AND(EquipmentType
LIKE
'pressure%') ORDER
BY[PointID]'''
cmd = '''SELECT DISTINCT PointID FROM dbo.Equipment
WHERE PointID IS NOT NULL
AND(EquipmentType LIKE 'pressure%')
ORDER BY[PointID]'''

cursor.execute(cmd)

return [PointIDRecord(*r) for r in cursor.fetchall()]

# return sorted([PointIDRecord(*r) for r in cursor.fetchall()], key=lambda x: x.name)

def get_qc_point_ids(self, qced=False):
with self._get_cursor() as cursor:
cursor.execute('GetPointIDsQCdPython %d', (int(qced),))
Expand Down Expand Up @@ -245,19 +238,19 @@ def insert_continuous_water_levels(self, pointid, rows, with_update=False):
chunk_len = 300
ntries = 2
cursor = conn.cursor()
cn = n/chunk_len+1
cn = n / chunk_len + 1
for i in xrange(0, n, chunk_len):
print 'Insert chunk: {}/{}'.format(i, cn)
#pd.change_message('Insert chunk: {}/{}'.format(i, cn))
# pd.change_message('Insert chunk: {}/{}'.format(i, cn))
# pd.update(i)
chunk = rows[i:i+chunk_len]
chunk = rows[i:i + chunk_len]
values = [(pointid, datetime.fromtimestamp(x).strftime('%m/%d/%Y %I:%M:%S %p'), temp, a, ah, bgs, note)
for x, a, ah, bgs, temp in chunk]
for j in xrange(ntries):
try:
cursor.executemany(cmd, values)
except:
print 'need to retry', j+1
print 'need to retry', j + 1
time.sleep(2)
continue

Expand Down Expand Up @@ -345,9 +338,11 @@ def get_continuous_water_levels(self, point_id, low=None, high=None, qced=None):

def _get_cursor(self):
return SessionCTX(self._host, self._user, self._password, self._dbname)

def _get_connection(self):
return get_connection(self._host, self._user, self._password, self._dbname)


if __name__ == '__main__':
d = DatabaseConnector(bind=False)
import os
Expand Down
32 changes: 15 additions & 17 deletions wellpy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,12 @@ def load_viewer_data(self):
marker='circle', marker_size=2.5,
type='scatter', color='yellow')

foreign_plot = create_line_plot((ocxs, ohs), color='blue')
left, bottom = add_default_axes(foreign_plot)
left.orientation = "right"
bottom.orientation = "top"
plot.add(foreign_plot)

self._broadcast_zoom(plot, foreign_plot)
self._add_head(plot, ocxs, ohs)

self._calculate_deviations(xs, ys, cxs, ds)
self.refresh_plot()

def load_qc_data(self, as_viewer=False):
def load_qc_data(self):
pid = self.selected_qc_point_id
if pid is None:
return
Expand Down Expand Up @@ -291,20 +285,24 @@ def load_qc_data(self, as_viewer=False):
type='scatter', color='yellow')

# plot.plot((DEPTH_X, HEAD_Y), color='blue')

foreign_plot = create_line_plot((cxs, hs), color='blue')
left, bottom = add_default_axes(foreign_plot)
left.orientation = "right"
bottom.orientation = "top"
plot.add(foreign_plot)

self._broadcast_zoom(plot, foreign_plot)

self._add_head()
self._calculate_deviations(xs, ys, cxs, ds)
self.refresh_plot()
else:
information(None, 'No records required QC for this point id: "{}"'.format(self.selected_qc_point_id.name))

def _add_head(self, plot, cxs, hs):
foreign_plot = create_line_plot((cxs, hs), color='blue')
left, bottom = add_default_axes(foreign_plot)
left.orientation = "right"
bottom.orientation = "top"

foreign_plot.index_mapper = plot.index_mapper

plot.add(foreign_plot)

self._broadcast_zoom(plot, foreign_plot)

def _broadcast_zoom(self, plot, foreign_plot):
zoom = plot.plots['plot0'][0].overlays.pop(1)
fz = ZoomTool(component=foreign_plot,
Expand Down

0 comments on commit 28bbb40

Please sign in to comment.