def load_from_db(self) -> bool: self.reset() tmp_list = DatabaseEntry.DatabaseEntry().get_utility_db().ListFromDB( AliasTable.TABLE, AliasTable.FIELD) if tmp_list is None or len(tmp_list) == 0: return False for alias, standard, comments in tmp_list: self.add_alias(alias, standard) self.__has_update = False return True
def dump_to_db(self) -> bool: tmp_list = [] for alias in self.__alias_standard_table.keys(): standard = self.__alias_standard_table[alias] tmp_list.append(alias) tmp_list.append(standard) tmp_list.append('') DatabaseEntry.DatabaseEntry().get_utility_db().ListToDB( AliasTable.TABLE, tmp_list, -1, 3, AliasTable.FIELD) return True
def __update_date_field(self, tags: [str], date: datetime or str, field: int, compare): joined_tags = self.join_tags(tags) sql_update = ("UPDATE %s SET %s = '%s' WHERE tags = '%s';" % (UpdateTableEx.TABLE, UpdateTableEx.FIELD[field], text_auto_time(date), joined_tags)) sql_insert = ("INSERT INTO %s (tags, %s) VALUES ('%s', '%s');" % (UpdateTableEx.TABLE, UpdateTableEx.FIELD[field], joined_tags, text_auto_time(date))) record = self.get_update_record(tags) if record is None or len(record) == 0: return De.DatabaseEntry().get_utility_db().QuickExecuteDML( sql_insert, True) elif record[0][field] is None or compare( text_auto_time(date), text_auto_time(record[0][field])): return De.DatabaseEntry().get_utility_db().QuickExecuteDML( sql_update, True) else: return True
def check_initialize(self) -> bool: if self.__inited: return True import DataHub.DataHubEntry as DataHubEntry import Database.DatabaseEntry as DatabaseEntry import Utiltity.plugin_manager as plugin_manager self.__collector_plugin = plugin_manager.PluginManager('./Collector') self.__strategy_plugin = plugin_manager.PluginManager('./Strategy') self.__collector_plugin.refresh() self.__strategy_plugin.refresh() root_path = path.dirname(path.abspath(__file__)) self.__database_entry = DatabaseEntry.DatabaseEntry(root_path + '/Data/') self.__data_hub_entry = DataHubEntry.DataHubEntry( self.__database_entry, self.__collector_plugin) self.__inited = True return True
def check_initialize(self) -> bool: if self.__inited: return True print('Initializing Stock Analysis System ...') clock = Clock() self.__log_errors = [] root_path = path.dirname(path.abspath(__file__)) import DataHub.DataHubEntry as DataHubEntry import Strategy.StrategyEntry as StrategyEntry import Database.DatabaseEntry as DatabaseEntry import Utiltity.plugin_manager as plugin_manager if not self.__config.load_config(path.join(root_path, 'config.json')): self.__log_errors.append('Load config fail.') return False ok, reason = self.__config.check_config() if not ok: self.__log_errors.append(reason) return False proxy_protocol = self.__config.get('PROXY_PROTOCOL') proxy_host = self.__config.get('PROXY_HOST') if str_available(proxy_protocol): import os if str_available(proxy_host): os.environ[proxy_protocol] = proxy_host print('Set proxy: %s = %s' % (proxy_protocol, proxy_host)) else: os.environ[proxy_protocol] = '' print('Clear proxy: %s' % proxy_protocol) self.__database_entry = DatabaseEntry.DatabaseEntry() if not self.__database_entry.config_sql_db(path.join( root_path, 'Data')): self.__log_errors.append('Config SQL database fail.') return False if not self.__database_entry.config_nosql_db( self.__config.get('NOSQL_DB_HOST'), self.__config.get('NOSQL_DB_PORT'), self.__config.get('NOSQL_DB_USER'), self.__config.get('NOSQL_DB_PASS')): self.__log_errors.append('Config NoSql database fail.') return False self.__factor_plugin = plugin_manager.PluginManager( path.join(root_path, 'Factor')) self.__strategy_plugin = plugin_manager.PluginManager( path.join(root_path, 'Analyzer')) self.__collector_plugin = plugin_manager.PluginManager( path.join(root_path, 'Collector')) self.__extension_plugin = plugin_manager.PluginManager( path.join(root_path, 'Extension')) self.__factor_plugin.refresh() self.__strategy_plugin.refresh() self.__collector_plugin.refresh() # self.__extension_plugin.refresh() self.__data_hub_entry = DataHubEntry.DataHubEntry( self.__database_entry, self.__collector_plugin) self.__strategy_entry = StrategyEntry.StrategyEntry( self.__strategy_plugin, self.__data_hub_entry, self.__database_entry) from DataHub.FactorCenter import FactorCenter self.__factor_center = FactorCenter(self.__data_hub_entry, self.__database_entry, self.__factor_plugin) self.__factor_center.reload_plugin() # TODO: Refactor self.__data_hub_entry.get_data_center().set_factor_center( self.__factor_center) from extension import ExtensionManager self.__extension_manager = ExtensionManager(self, self.__extension_plugin) self.__extension_manager.init() self.__task_queue.start() print('Stock Analysis System Initialization Done, Time spending: ' + str(clock.elapsed_ms()) + ' ms') self.__inited = True return True
def delete_update_record(self, tags: [str]): joined_tags = self.join_tags(tags) sql_delete = ("DELETE FROM %s WHERE tags = '%s';" % (UpdateTableEx.TABLE, joined_tags)) return De.DatabaseEntry().get_utility_db().QuickExecuteDML( sql_delete, True)
def get_update_record(self, tags: [str]) -> []: joined_tags = self.join_tags(tags) return De.DatabaseEntry().get_utility_db().ListFromDB( UpdateTableEx.TABLE, UpdateTableEx.FIELD, "tags = '%s'" % joined_tags)
def main(): app = QApplication(sys.argv) dlg = WrapperQDialog( XListTableUi(DatabaseEntry().get_black_table(), '黑名单'), False) dlg.exec()