Skip to content

Commit

Permalink
some bugfixes, autorefresh job and service table, improved polygon se…
Browse files Browse the repository at this point in the history
…lection
  • Loading branch information
bgoesswe committed Jun 24, 2020
1 parent 031e445 commit be3b97b
Show file tree
Hide file tree
Showing 12 changed files with 631 additions and 89 deletions.
2 changes: 1 addition & 1 deletion drawPoly.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def canvasPressEvent(self, e):
if self.rb.numberOfVertices() > 2:
self.status = 0
self.selectionDone.emit()
geometry = self.rb.asGeometry().orientedMinimumBoundingBox()
geometry = self.rb.asGeometry()
self.parent.draw_poly(geometry)
else:
self.reset()
Expand Down
19 changes: 19 additions & 0 deletions job_adapt_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ def __init__(self, parent=None, iface=None, job=None, backend=None, subgraph=Non
self.rawgraph_window = None
self.raw_pg_box = None

def hide(self):
super(JobAdaptDialog, self).hide()

if self.main_dia:
self.main_dia.hide()

def show(self):
if self.main_dia:
self.main_dia.show()
super(JobAdaptDialog, self).show()

def process_selected(self):
"""
Gets called if a process in the "add process" combobox is selected.
Expand Down Expand Up @@ -493,6 +504,12 @@ def clear_process_add_fields(self):
self.processesComboBox.setCurrentText("Select a process")
self.processIdText.setText("")

def clear_process_table(self):
self.clear_process_add_fields()
self.processTableWidget.clear()
self.init_process_table()
self.processTableWidget.setRowCount(0)

def process_to_table(self, node_id, row):
"""
Loads a process from the process graph table to the process table.
Expand Down Expand Up @@ -703,6 +720,8 @@ def delete_node(self, node_id):
self.processgraph_buffer.pop(node_id)
self.process_graph_to_table()

self.clear_process_table()

def process_graph_to_table(self):
"""
Loads the current process graph to the process graph table.
Expand Down
26 changes: 17 additions & 9 deletions job_detail_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,26 @@ def __init__(self, parent=None, iface=None, job=None, backend=None):
self.setupUi(self)

self.backend = backend

self.log_info = self.backend.job_log(job.id)

self.job = job
self.init_table()
self.fill_table()

self.dlg = None

self.cancelButton.clicked.connect(self.close)
self.adaptButton.clicked.connect(self.adapt_job)
# self.adaptButton.clicked.connect(self.adapt_job)

def adapt_job(self):
"""
Starts an adaption dialog to adapt the current job.
"""
self.dlg = JobAdaptDialog(iface=self.iface, job=self.job, backend=self.backend)
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
self.dlg.show()
self.close()
# def adapt_job(self):
# """
# Starts an adaption dialog to adapt the current job.
# """
# self.dlg = JobAdaptDialog(iface=self.iface, job=self.job, backend=self.backend)
# self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
# self.dlg.show()
# self.close()

def init_table(self):
"""
Expand Down Expand Up @@ -141,6 +144,11 @@ def fill_table(self):
if self.job.budget:
property_list.append(("Budget", self.job.budget))

if self.log_info:
property_list.append(("Log Entries:", "see below"))
for log in self.log_info.get("logs"):
property_list.append((log.get("code"), log.get("message")))

self.jobInfoTableWidget.setRowCount(len(property_list))
row = 0
for prop in property_list:
Expand Down
13 changes: 0 additions & 13 deletions job_detail_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton" name="adaptButton">
<property name="geometry">
<rect>
<x>190</x>
<y>320</y>
<width>84</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Adapt</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name=OpenEO
qgisMinimumVersion=3.0
description=Plugin to access openEO compliant backends.
version=0.9
version=0.9.1
author=Bernhard Goesswein, Nina Gnann
email=bernhard.goesswein@geo.tuwien.ac.at

Expand Down
10 changes: 8 additions & 2 deletions models/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ def get_process(self, id):
else:
return None

def service_create(self, process):
return self.connection.service_create(process_graph=process)
def service_create(self, process, s_type, title="", description=""):
return self.connection.service_create(process_graph=process, s_type=s_type, title=title, description=description)

def service_info(self, service_id):
service = self.get_service(service_id)
Expand Down Expand Up @@ -258,6 +258,9 @@ def service_info(self, service_id):
def service_delete(self, service_id):
return self.connection.delete_service(service_id=service_id)

def get_service_types(self):
return self.connection.get_service_types()

def service_pg_info(self, service_id):
return self.connection.pg_info_service(service_id=service_id)

Expand Down Expand Up @@ -358,6 +361,9 @@ def job_pg_info(self, job_id):
.replace("'", "").replace("[", "").replace("]", "").replace("{", "").replace("}", "")
return job_info_id

def job_log(self, job_id):
return self.connection.job_log(job_id=job_id)

def job_result_download(self, job_id):
req = self.connection.job_result(job_id=job_id)

Expand Down
38 changes: 29 additions & 9 deletions models/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ def get_file_formats(self):
get_info = self.get(requested_info, stream=True)
return get_info.json()

def get_service_types(self):
requested_info = "/service_types"
get_info = self.get(requested_info, stream=True)
return get_info.json()

def service_info(self, service_id):
"""
Returns information about a created service.
Expand Down Expand Up @@ -272,6 +277,20 @@ def job_result_url(self, job_id):
return download_url
return None

def job_log(self, job_id):
"""
Downloads the log info of the job and returns it
:param: job_id: Identifier of the job
:return: path: String, log info
"""
log_url = "/jobs/{}/logs".format(job_id)
r = self.get(log_url, stream=True)

if r.status_code == 200:
return self.parse_json_response(r)

return None

def job_result(self, job_id):
"""
Downloads the result of the job into the temporary folder.
Expand Down Expand Up @@ -339,23 +358,24 @@ def job_create(self, process_graph, title=None, desc=None):

return self.parse_json_response(job_status)

def service_create(self, process_graph):
def service_create(self, process_graph, s_type, title="", description=""):
"""
Sends the process graph to the backend and creates a new job.
:param: process_graph: Dict, Process Graph of the new job
:return: status: String, Status of the job creation
"""
pg = {
"process_graph": process_graph
}
#print(process_graph)
pg = {"process": {"process_graph": process_graph}, "type": s_type}

service_status = self.post("/jobs", postdata=pg)
if title:
pg["title"] = title
if description:
pg["description"] = description

#if job_status.status_code == 201:
# return job_status
service_data = json.dumps(pg)

service_status = self.post("/services", postdata=service_data)

return service_status
return self.parse_json_response(service_status)

def post(self, path, postdata):
"""
Expand Down
66 changes: 55 additions & 11 deletions openeo_connector_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,31 @@
import json
import webbrowser
import copy
import time, threading
from hashlib import md5

from qgis.PyQt import uic, QtGui, QtWidgets
from qgis.PyQt.QtWidgets import QTreeWidgetItem, QTableWidgetItem, QMessageBox
import qgis.PyQt.QtCore as QtCore
from qgis.core import QgsRasterLayer, QgsProject
from qgis.core import QgsRasterLayer, QgsProject, QgsTask, QgsApplication, QgsMessageLog
from qgis.utils import iface

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QPushButton, QHBoxLayout, QTextEdit, QListWidget, QListWidgetItem, QApplication, \
QLabel, QGridLayout, QVBoxLayout, QDialog, QLineEdit

from PyQt5.QtCore import Qt, QSize, QSettings
from PyQt5.QtCore import Qt, QSize, QSettings, QTimer
from PyQt5.QtGui import QColor, QIcon, QPixmap

from .models.result import Result
from .models.processgraph import Processgraph
from .models.openeohub import get_hub_jobs
from .utils.logging import info, warning, error
from .models.models import Job, Process
from .models.models import Job, Process, Service

from .job_detail_dialog import JobDetailDialog
from .job_adapt_dialog import JobAdaptDialog
from .service_create_dialog import ServiceCreateDialog

os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) # enable highdpi scaling
Expand Down Expand Up @@ -76,6 +79,7 @@ def __init__(self, parent=None, interface=None, backend=None):

QApplication.setStyle("cleanlooks")

self.jobs_hash = ""
self.iface = interface
self.processgraph = Processgraph()
self.called = False
Expand All @@ -87,7 +91,6 @@ def __init__(self, parent=None, interface=None, backend=None):
self.setupUi(self)

self.operationManualBtn.clicked.connect(self.user_manual)
#TODO
self.operationManualBtn.hide()

self.collectionBox.currentTextChanged.connect(self.col_info)
Expand Down Expand Up @@ -125,6 +128,8 @@ def __init__(self, parent=None, interface=None, backend=None):

# Create Job
self.createjobBtn.clicked.connect(self.create_job)
self.createserviceBtn.clicked.connect(self.create_service)
self.servicewebBtn.clicked.connect(self.web_view)

# Jobs Tab
self.init_jobs()
Expand Down Expand Up @@ -178,6 +183,22 @@ def __init__(self, parent=None, interface=None, backend=None):

self.infoWindow5 = None

# Start autorefreshing thread
# self.task1 = TestTask('Scheduled Task', self.iface)
self.timer = QTimer()
self.timer.timeout.connect(self.refresh_task)
self.timer.start(3000)
# QgsMessageLog.logMessage("Start Timer!", "name")

def closeEvent(self, event):
self.timer.stop()

def refresh_task(self):
if self.tabWidget.currentIndex() == 1:
self.refresh_jobs()
elif self.tabWidget.currentIndex() == 2:
self.refresh_services()

def web_view(self):
"""
Opens the web browser and the openEO web editor with the currently connected backend.
Expand Down Expand Up @@ -232,7 +253,7 @@ def pick_job_from_hub(self):

job = self.example_hub_jobs[selected_row].to_job()

self.dlg = JobAdaptDialog(iface=self.iface, job=job, backend=self.backend)
self.dlg = JobAdaptDialog(iface=self.iface, job=job, backend=self.backend, main_dia=self)
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
self.dlg.show()

Expand All @@ -246,7 +267,15 @@ def create_job(self):

job.process = process

self.dlg = JobAdaptDialog(iface=self.iface, job=job, backend=self.backend)
self.dlg = JobAdaptDialog(iface=self.iface, job=job, backend=self.backend, main_dia=self)
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
self.dlg.show()

def create_service(self):
"""
Creates a new service from job by a new dialog window.
"""
self.dlg = ServiceCreateDialog(iface=self.iface, backend=self.backend)
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
self.dlg.show()

Expand Down Expand Up @@ -409,6 +438,18 @@ def init_services(self):
header.setSectionResizeMode(4, QtWidgets.QHeaderView.Interactive)
header.setSectionResizeMode(5, QtWidgets.QHeaderView.Interactive)

def jobs_changed(self, jobs):
jobs_str = str([str(item) for item in jobs])
# QgsMessageLog.logMessage(json.dumps(jobs_str), "something")

new_jobs_hash = md5(jobs_str.encode()).hexdigest()

if new_jobs_hash == self.jobs_hash:
return False
else:
self.jobs_hash = new_jobs_hash
return True

def refresh_jobs(self):
"""
Refreshes the job table, so fetches all jobs of the user from the backend and lists them in the table.
Expand All @@ -420,6 +461,9 @@ def refresh_jobs(self):
if not isinstance(jobs, list):
jobs = []

if not self.jobs_changed(jobs):
return

self.init_jobs()
self.jobsTableWidget.setSortingEnabled(False)
self.jobsTableWidget.setRowCount(len(jobs))
Expand Down Expand Up @@ -576,7 +620,7 @@ def job_execute(self, job_id):
"""
Executes the job of the given row of the job table.
This method is called after the "Execute" button is clicked at the job table.
:param row: Integer number of the row the button is clicked.
:param job_id: Integer number of the job id the button is clicked.
"""
resp = self.backend.job_start(job_id)

Expand All @@ -589,20 +633,20 @@ def adapt_job(self, job_id):
"""
Opens an adaption dialog of the job on the given row of the job table.
This method is called after the "Adapt" button is clicked at the job table.
:param row: Integer number of the row the button is clicked.
:param job_id: Integer number of the job id the button is clicked.
"""
job_id

job = self.backend.detailed_job(job_id)

self.dlg = JobAdaptDialog(iface=self.iface, job=job, backend=self.backend)
self.dlg = JobAdaptDialog(iface=self.iface, job=job, backend=self.backend, main_dia=self)
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
self.dlg.show()

def job_display(self, job_id):
"""
Displays the job of the given row of the job table on a new QGis Layer.
This method is called after the "Display" button is clicked at the job table.
:param row: Integer number of the row the button is clicked.
:param job_id: Integer number of the job id the button is clicked.
"""
job = self.backend.get_job(job_id)
process_graph_job = self.backend.job_pg_info(job_id)
Expand Down
Loading

0 comments on commit be3b97b

Please sign in to comment.