Beispiel #1
0
 def insert_data(self, data):
     if isinstance(data, dict):
         col_number = 0
         for key, values in data.iteritems():
             for value in values:
                 pos = self.table.InsertStringItem(col_number, str(value))
                 col_number += 1
                 self.table.SetStringItem(pos, col_number, str(key))
                 col_number = 0
     else:
         elog.debug("PreRunCtrl.insert_data must be a dictionary")
     return
Beispiel #2
0
    def parseValues(self, sitecode, variable, start=None, end=None):
        data = self.getValuesObject(sitecode, variable, start.strftime("%Y-%m-%d"), end.strftime("%Y-%m-%d"))
        valuesList = []
        if data is not None:
            for values in data[0].values[0].value:
                # values_list = [[date1, value1], [date2, value2]]
                valuesList.append([values._dateTime, values.value])
        else:
            elog.debug("data is None")
            elog.error("Failed to retrieve data")

        return valuesList
Beispiel #3
0
 def get_geometries(self, exchange_item):  # This method should work for both input and output
     if isinstance(exchange_item, list):
         igeoms = {}
         for item in exchange_item:
             name = item['name']
             geoms = [ogr.CreateGeometryFromWkb(g) for g in item['geometry']['wkb']]
             igeoms[name] = geoms
         return igeoms
     else:
         elog.debug("Exchange item must be a list of dictionaries")
         elog.debug("Exchange item may be None")
         return {}
Beispiel #4
0
    def parseValues(self, sitecode, variable, start=None, end=None):
        data = self.getValuesObject(sitecode, variable,
                                    start.strftime("%Y-%m-%d"),
                                    end.strftime("%Y-%m-%d"))
        valuesList = []
        if data is not None:
            for values in data[0].values[0].value:
                # values_list = [[date1, value1], [date2, value2]]
                valuesList.append([values._dateTime, values.value])
        else:
            elog.debug("data is None")
            elog.error("Failed to retrieve data")

        return valuesList
Beispiel #5
0
def loadAccounts():
    import coordinator.users as users
    known_users = []
    userjson = os.environ['APP_USER_PATH']

    #  Create the file if it does not exist
    if os.path.isfile(userjson):
        with open(userjson, 'r') as file:
            content = file.read()
            file.close()
        if not (content.isspace() or len(content) < 1):  # check if file is empty
            # file does exist so proceed like normal and there is content in it
            elog.debug('userjson ' + userjson)
            with open(userjson, 'r') as f:
                known_users.extend(users.BuildAffiliationfromJSON(f.read()))
                f.close()
    else:
        # file does not exist so we'll create one.
        file = open(userjson, 'w')
        file.close()

    return known_users
Beispiel #6
0
    def on_swap(self, event):
        link_id = self.get_selected_link_id()
        if link_id == "":
            elog.debug("No link is selected")
            return

        selected = self.get_selected_link_id()
        engine.removeLinkById(selected)
        self.__links.pop(selected)

        #  Swapping components of models
        self.output_component, self.input_component = self.input_component, self.output_component

        self.__link_source_id = self.output_component["id"]
        self.__link_target_id = self.input_component["id"]

        self.input_combo.SetItems(self.get_exchange_item_from_engine(self.input_component, "INPUT"))
        self.output_combo.SetItems(self.get_exchange_item_from_engine(self.output_component, "OUTPUT"))
        self.input_combo.SetSelection(0)
        self.output_combo.SetSelection(0)

        self.on_new_button(1)
Beispiel #7
0
    def on_swap(self, event):
        link_id = self.get_selected_link_id()
        if link_id == "":
            elog.debug("No link is selected")
            return

        selected = self.get_selected_link_id()
        engine.removeLinkById(selected)
        self.__links.pop(selected)

        #  Swapping components of models
        self.output_component, self.input_component = self.input_component, self.output_component

        self.__link_source_id = self.output_component['id']
        self.__link_target_id = self.input_component['id']

        self.input_combo.SetItems(self.get_exchange_item_from_engine(self.input_component, "INPUT"))
        self.output_combo.SetItems(self.get_exchange_item_from_engine(self.output_component, "OUTPUT"))
        self.input_combo.SetSelection(0)
        self.output_combo.SetSelection(0)

        self.on_new_button(1)
Beispiel #8
0
def loadAccounts():
    import coordinator.users as users
    known_users = []
    userjson = os.environ['APP_USER_PATH']

    #  Create the file if it does not exist
    if os.path.isfile(userjson):
        with open(userjson, 'r') as file:
            content = file.read()
            file.close()
        if not (content.isspace()
                or len(content) < 1):  # check if file is empty
            # file does exist so proceed like normal and there is content in it
            elog.debug('userjson ' + userjson)
            with open(userjson, 'r') as f:
                known_users.extend(users.BuildAffiliationfromJSON(f.read()))
                f.close()
    else:
        # file does not exist so we'll create one.
        file = open(userjson, 'w')
        file.close()

    return known_users
Beispiel #9
0
    def on_close(self, event):
        dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question',
            wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

        dial.SetYesNoLabels(yes="Quit", no="Cancel")
        if event == None or dial.ShowModal() == wx.ID_YES:

            # kill multiprocessing
            e = Engine()
            msg = e.close()
            elog.debug('Closing Engine Processes: %s' % msg)


            # kill all threads

            threads = {t.name:t for t in threading.enumerate()}
            mainthread = threads.pop('MainThread')

            elog.debug('Closing EMIT Threads: %s' % msg)

            non_daemon = []
            for t in threads.itervalues():

                # check if the thread is a daemon, if so, it should not cause any problems
                if t.isDaemon():
                    elog.debug('%s daemon=%s' %(t.name, t.isDaemon()))
                else:
                    # add this thread to the non-daemon list
                    non_daemon.append(t)

            for t in non_daemon:
                elog.warning('%s is not a daemon thread and may cause problems while shutting down' % t.name)
                t.join(1)

            # determine if there are any non-daemon threads that are still alive
            non_daemon_and_alive = []
            for t in threads.itervalues():
                if not t.isDaemon() and t.isAlive():
                    non_daemon_and_alive.append(t)

            # attempt to stop non-daemon threads
            try:
                for t in non_daemon_and_alive:
                    t._Thread__stop()
            except Exception, e:
                elog.error('Error encountered closing thread %s: %s' % (t.name, e))

            # close the main thread
            self.Destroy()
            wx.App.ExitMainLoop
            wx.WakeUpMainThread