Skip to content

Commit

Permalink
added viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
jirhiker committed Sep 14, 2018
1 parent 6160989 commit 4ab6278
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 6 deletions.
16 changes: 15 additions & 1 deletion wellpy/database_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,22 @@ def __init__(self, bind=True, *args, **kw):

def get_point_ids(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]'''

cursor.execute('GetPointIDsPython')
return sorted([PointIDRecord(*r) for r in cursor.fetchall()], key=lambda x: x.name)
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:
Expand Down
69 changes: 67 additions & 2 deletions wellpy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from datetime import datetime

from chaco.plot_factory import add_default_axes, create_line_plot
from chaco.tools.broadcaster import BroadcasterTool
from numpy import array, diff, where, ones, logical_and, hstack, zeros_like, vstack, column_stack, asarray, savetxt, \
ones_like, zeros, delete

Expand Down Expand Up @@ -79,8 +80,8 @@
EXISTING_DEPTH_Y = 'existing_depth_y'
EXISTING_DEPTH_X = 'exisiting_depth_x'

QC_DEPTH_Y = 'depth_y'
QC_DEPTH_X = 'depth_x'
QC_DEPTH_Y = 'qc_depth_y'
QC_DEPTH_X = 'qc_depth_x'

WATER_HEAD = 'water_head'
ADJ_WATER_HEAD = 'adjusted_water_head'
Expand Down Expand Up @@ -141,6 +142,9 @@ class WellpyModel(HasTraits):

qc_point_ids = List
selected_qc_point_id = Instance(PointIDRecord)
selected_viewer_point_id = Instance(PointIDRecord)
viewer_point_ids = List

dclick_qc_point_id = Any

path = Str
Expand Down Expand Up @@ -186,6 +190,7 @@ def activated(self):
self.point_id_entry = os.environ.get('POINTID_DEBUG', 'SO-0227')

self.load_qc()
self.load_viewer()

def apply_qc(self):
self._apply_qc()
Expand All @@ -209,6 +214,46 @@ def get_continuous(self, name, qced=0):
ds[i] = float(ri[5])
return xs, wts, hs, ahs, ds

def load_viewer_data(self):
pid = self.selected_viewer_point_id
if pid is None:
return

nqc_args = self.get_continuous(pid.name, qced=0)
args = self.get_continuous(pid.name, qced=1)
if args or nqc_args:
self.initialize_plot(qc=True)
"""
PointID, Timestamp, 'temp', 'head', 'adjusted_head', 'depth_to_water'', note
"""
plot = self._plots[DEPTH_TO_WATER]
if args:
cxs, wts, hs, ahs, ds = args
plot.data.set_data(QC_DEPTH_X, cxs)
plot.data.set_data(QC_DEPTH_Y, ds)

if nqc_args:
cxs, wts, hs, ahs, ds = nqc_args
plot.data.set_data(DEPTH_X, cxs)
plot.data.set_data(DEPTH_Y, ds)

xs, ys, ss = self.get_manual_measurements(pid.name)

plot.data.set_data(QC_MANUAL_X, xs)
plot.data.set_data(QC_MANUAL_Y, ys)
plot.plot((QC_MANUAL_X, QC_MANUAL_Y),
marker='circle', marker_size=2.5,
type='scatter', color='yellow')

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._calculate_deviations(xs, ys, cxs, ds)
self.refresh_plot()

def load_qc_data(self):
pid = self.selected_qc_point_id
if pid is None:
Expand Down Expand Up @@ -242,6 +287,9 @@ def load_qc_data(self):
plot = self._plots[DEPTH_TO_WATER]
plot.data.set_data(DEPTH_X, cxs)
plot.data.set_data(DEPTH_Y, ds)

zoom = plot.plots['plot0'][0].overlays.pop(1)

# plot.data.set_data(HEAD_Y, hs)

xs, ys, ss = self.get_manual_measurements(pid.name)
Expand All @@ -260,6 +308,20 @@ def load_qc_data(self):
bottom.orientation = "top"
plot.add(foreign_plot)

fz = ZoomTool(component=foreign_plot,
enable_wheel=True,
alpha=0.3,
axis='index',
always_on=False, tool_mode='range',
max_zoom_out_factor=1,
max_zoom_in_factor=10000)

broadcaster = BroadcasterTool()
broadcaster.tools.append(zoom)
broadcaster.tools.append(fz)

plot.tools.append(broadcaster)

self._calculate_deviations(xs, ys, cxs, ds)
self.refresh_plot()
else:
Expand All @@ -278,6 +340,9 @@ def _calculate_deviations(self, mxs, mys, cxs, cys):

self.deviations = devs

def load_viewer(self):
self.viewer_point_ids = self.db.get_point_ids()

def load_qc(self):
self.qc_point_ids = self.db.get_qc_point_ids()

Expand Down
22 changes: 22 additions & 0 deletions wellpy/tasks/panes.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ def traits_view(self):
return v


class ViewerPane(TraitsDockPane):
id = 'wellpy.viewer.pane'
name = 'Viewer'
dclicked = Event

def _dclicked_fired(self):
self.model.load_viewer_data()

def traits_view(self):
pa = PointIDAdapter()
pa.columns = pa.columns[:1]
dg = UItem('deviations', editor=TabularEditor(adapter=DeviationAdapter()))
pg = UItem('viewer_point_ids',
editor=TabularEditor(selected='selected_viewer_point_id',
dclicked='pane.dclicked',
editable=False,
adapter=pa))

v = View(VGroup(pg, dg))
return v


class WellPane(TraitsDockPane):
id = 'wellpy.well.pane'
name = 'Well'
Expand Down
8 changes: 5 additions & 3 deletions wellpy/tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from wellpy.database_connector import DatabaseConnector
from wellpy.model import WellpyModel
from wellpy.tasks.actions import ResetLayoutAction
from wellpy.tasks.panes import WellPane, WellCentralPane, ToolboxPane, AutoResultsPane, QCPane
from wellpy.tasks.panes import WellPane, WellCentralPane, ToolboxPane, AutoResultsPane, QCPane, ViewerPane


class WellpyTask(Task):
Expand All @@ -50,12 +50,14 @@ def create_dock_panes(self):
return [WellPane(model=self.model),
ToolboxPane(model=self.model),
AutoResultsPane(model=self.model),
QCPane(model=self.model)]
QCPane(model=self.model),
ViewerPane(model=self.model)]

def _default_layout_default(self):
return TaskLayout(left=VSplitter(PaneItem('wellpy.well.pane'),
Tabbed(PaneItem('wellpy.toolbox.pane'),
PaneItem('wellpy.qc.pane'))),
PaneItem('wellpy.qc.pane'),
PaneItem('wellpy.viewer.pane'))),
bottom=PaneItem('wellpy.autoresults.pane'))

def _menu_bar_factory(self, menus=None):
Expand Down

0 comments on commit 4ab6278

Please sign in to comment.