def __init__(self, start_code, end_code): self.__logger = logger.createLogger(self.__class__.__name__) self.__configInfo = config.ConfigInfo('config.ini') repoPath = self.__configInfo.repo_path self.__rootPath = utils.appendEndSlash(repoPath) self.__start_commit_code = start_code self.__end_commit_code = end_code
def execute(proessor): __logger = logger.createLogger(__name__) try: proessor.process() except Exception as e: __logger.exception('Processing occur error.')
def __init__(self, queryServer=None): ##ugur self.rpclogger = createLogger('RPC') self.rpclogger.info('Starting JSONRPCServer') self.queryServer = queryServer self.queryManager = QueryManager( store=self.queryServer.createStore(), sources=self.queryServer.config.sources, plugins=self.queryServer.config.plugins)
def __init__(self, sources): self.qglogger = logger.createLogger('querygenerator') self.qglogger.debug('In %s' % sys._getframe().f_code.co_name) self.qglogger.info('Starting Query Generator') self.nfsen_filters = [ 'src_ip', 'src_port', 'dst_ip', 'dst_port', 'proto', 'protocol_version', 'packets', 'bytes', 'duration', 'flags', 'tos', 'pps', 'bps', 'bpp', 'AS', 'scale' ] self.store = db.get_store() self.sources = sources
from abc import ABCMeta, abstractmethod import random from event import SignalEvent, OrderEvent random.seed(10) import logger logger_s = logger.createLogger("strategy") class Strategy(object): """ Strategy is an abstract base class providing an interface for users to develop their own strategies. The goal of a (derived) Strategy object is to generate SignalEvent based on the inputs of bar, and generate OrderEvent based on the SignalEvent and the current portifolio. This is designed to work both with historic and live data as the Strategy object is agnostic to the data source. """ __metaclass__ = ABCMeta @abstractmethod def generate_signal(self, bar): """ Provides the mechanism to generate a SignalEvent based on the data bar, this method should return None if nothing needs
tester.timeout = kwargs["timeout"] tester.execute = generateJITScript(JIT="LLVMJIT", archTestScript=testOr1k) return tester elif index == 2: tester = pif.Or1kTester("Or1kTCCJITTester") tester.swDir = kwargs["Or1kSwDir"] tester.simDir = kwargs["Or1kSimDir"] tester.timeout = kwargs["timeout"] tester.execute = generateJITScript(JIT="TCCJIT", archTestScript=testOr1k) return tester elif index == 3: # TODO: Add VP tester return None else: return None # Unit test if __name__ == '__main__': logger = lg.createLogger("Or1kArchTesterLogger", debug=True) testers = [] for i in range(0, countPlugins()): testers.append(createPlugin(i)) for t in testers: if t: t.execute(t, logger)
from ib import Sharp from ib.ttypes import * from ib.constants import * from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol import logger import event import strategy import portfolio logger = logger.createLogger("trader") class AbstractTrader(object): """ the interface """ __metaclass__ = ABCMeta @abstractmethod def trade(self): """ monitor the data feed for watchlist and trade necessarily """ raise NotImplementedError("Should implement trade()") @abstractmethod
import time import logger import numpy as np from scipy.sparse import csr_matrix from sklearn import grid_search from sklearn import metrics from sklearn import linear_model from sklearn import svm logger = logger.createLogger("hw2_q3") class FeatureGenerator(object): """preparing features""" def __init__(self, data_file, label_file, groups = 20, docs = 11269, vocabulary = 61188): self.data_file = data_file self.label_file = label_file self.groups = groups self.docs = docs self.vocabulary = vocabulary self.binary_feature = None self.tf_feature = None self.tfidf_feature = None self.label = np.loadtxt(label_file, usecols = (0,)) def create_features(self): train_data = np.loadtxt(self.data_file, usecols = (0,1,2), dtype = np.int32) doc_ids = train_data[:,0] - 1 # make doc_id start from zero word_ids = train_data[:,1] - 1 # make word_id start from zero word_f = train_data[:,2] indptr = [0] dict_helper = {}
def initLoggerToUse(self, logger): self._log = logger.createLogger(G_NAME_MODULE_LOG, G_NAME_GROUP_LOG_GENERIC_INSTANCE, instance=self.loggerName) self.loggerManager.initLoggerToUse(self._log)
SIM_DIR = "../build_dir/installed/examples/bare_etiss_processor/" SW_DIR = "../build_dir/installed/examples/SW/" PLUGIN_DIR = "./plugins" # kwargs is the argument dict which will be passed to all createPlugins() function # and specific createPlugins() will pick up arguments in need. kwargs = {"Or1kSwDir": SW_DIR + "/or1k",\ "Or1kSimDir":SIM_DIR ,\ "RiscvSwDir": SW_DIR + "/riscv",\ "RiscvSimDir": SIM_DIR ,\ # timeout in seconds for simulator, 0 indicates timeout disabled "timeout": timeout }# add "Armv6MSwDir": SW_DIR + "/arm",\ "Armv6MSimDir": SIM_DIR ,\ for ARM logger = lg.createLogger("CITesterLogger") pl = PluginLoader(PLUGIN_DIR, logger) def loader(module): """This functions handles with plugin interface to create plugin""" plugins = [] # Return empty plugins list when do not have plugin # interface try: module.countPlugins() except Exception as e: logger.warning( "Module: {} in plugin directory is not a plugin".format( module.__name__)) return plugins
from ib import Sharp from ib.ttypes import * from ib.constants import * from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol import logger import event import strategy import portfolio logger = logger.createLogger("trader") class AbstractTrader(object): """ the interface """ __metaclass__ = ABCMeta @abstractmethod def trade(self): """ monitor the data feed for watchlist and trade necessarily """ raise NotImplementedError("Should implement trade()")
from abc import ABCMeta, abstractmethod import random from event import SignalEvent, OrderEvent random.seed(10) import logger logger_s = logger.createLogger("strategy") class Strategy(object): """ Strategy is an abstract base class providing an interface for users to develop their own strategies. The goal of a (derived) Strategy object is to generate SignalEvent based on the inputs of bar, and generate OrderEvent based on the SignalEvent and the current portifolio. This is designed to work both with historic and live data as the Strategy object is agnostic to the data source. """ __metaclass__ = ABCMeta @abstractmethod def generate_signal(self, bar): """ Provides the mechanism to generate a SignalEvent based on the data bar, this method should return None if nothing needs to be done for the data bar.
def logger(cls): if cls._logger is None: cls._logger = createLogger("datebase", level=cls.LOGLEVEL) return cls._logger
import logger # all prints from constants import * from model import Model from nn_util import num_parameters, layer_to_image_summary, weight_to_image_summary from util import accuracy, get_input, get_size from alexnet_small import AlexNetSmall from briannet import BrianNet from vggnet import VGGNet timestamp = time.strftime("%Y-%m-%d_%H:%M:%S") # print to save to full log and console full_log = logger.createLogger(LOGS_DIR + "full_output__" + timestamp + ".log", "all outputs", True) print = full_log.info # short git hash githashval = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode('UTF-8')[:7] # call log.info to save to proper log log = logger.createLogger(LOGS_DIR + "log__" + timestamp + ".log", "logs to keep", False) param_log_name = LOGS_DIR + "save__" + timestamp + "__" + githashval + ".log" # param_log = logger.createLogger(param_log_name, "parameters", True) import tensorflow as tf def run(target_categories,
class Weathers(object): _logger = createLogger("Weathers") #查询城市,keyword为模糊查询关键字,可为空 def cities(self, keyword=''): cities_tree = {} for r in DBInstance.records(Area, Area.namecn.ilike("%%" + keyword + "%%")): if r.nationcn not in cities_tree.keys(): cities_tree[r.nationcn] = {} if r.provcn not in cities_tree[r.nationcn].keys(): cities_tree[r.nationcn][r.provcn] = {} if r.districtcn not in cities_tree[r.nationcn][r.provcn].keys(): cities_tree[r.nationcn][r.provcn][r.districtcn] = [] cities_tree[r.nationcn][r.provcn][r.districtcn].append({ "areaid": r.areaid, "name": r.namecn }) return json.dumps(cities_tree, ensure_ascii=False) def request_network_api(self, location): print("++++++++++++++", location) headers = { "Authorization": "APPCODE 377ab35f6c624993b54e8c75345d23ba", "Content-Type": "application/json; charset=utf-8" } res = requests.get(SAWeatherURL + "?area=" + location + "&needMoreDay=1&needIndex=1", headers=headers) weather_data = json.loads(res.content, encoding="utf-8") #print(json.dumps(, ensure_ascii=False)) if weather_data["showapi_res_code"] != 0: Weathers._logger.warn("获取天气信息失败:" + weather_data["showapi_res_error"]) return print(json.dumps(weather_data, ensure_ascii=False)) data_body = weather_data["showapi_res_body"] days = ["f1", "f2", "f3", "f4", "f5", "f6", "f7"] for day in days: if day in data_body.keys(): day_info = data_body[day] if day_info is not None: w = {} w["areaid"] = data_body["cityInfo"]["c1"] w["day"] = data_body[day]["day"] w["day_weather"] = data_body[day]["day_weather"] w["night_weather"] = data_body[day]["night_weather"] w["day_air_temperature"] = data_body[day][ "day_air_temperature"] w["night_air_temperature"] = data_body[day][ "night_air_temperature"] w["day_wind_direction"] = data_body[day][ "day_wind_direction"] w["night_wind_direction"] = data_body[day][ "night_wind_direction"] w["day_wind_power"] = data_body[day]["day_wind_power"] w["night_wind_power"] = data_body[day]["night_wind_power"] w["sun_begin_end"] = data_body[day]["sun_begin_end"] w["weekday"] = data_body[day]["weekday"] w["day_weather_code"] = data_body[day]["day_weather_code"] w["night_weather_code"] = data_body[day][ "night_weather_code"] #w["air_press"] = data_body[day]["air_press"] w["jiangshui"] = data_body[day]["jiangshui"] if not DBInstance.isRecordExist( Weather, and_(Weather.areaid == w["areaid"], Weather.day == w["day"])): temp_w = Weather(**w) temp_size = DBInstance.addRecord(temp_w) if 1 == temp_size: #print("11111") indexs = data_body[day]["index"] temps = [] for key in indexs.keys(): ititle = indexs[key]["title"] idesc = indexs[key]["desc"] temps.append( Index( **{ "weather_id": temp_w.id, "title": ititle, "desc": idesc, "type": key })) if len(temps) > 0: s = DBInstance.addRecord(temps) print("===>", s) self.set_last_udpate_date(location) #获取天气情况 def weather_with_location(self, location): date_string = datetime.date.today().strftime("%Y-%m-%d") if date_string != self.last_update_date(location): #print("===", date_string, self.last_update_date(location), date_string == self.last_update_date(location)) #需要拉取远程API数据 self.request_network_api(location) #读取数据库数据 key_date_string = date_string.replace("-", "") #读取地区id area_rs = DBInstance.records(Area, Area.namecn == location) if len(area_rs) > 0: weather_rs = DBInstance.records( Weather, and_(Weather.day >= key_date_string, Weather.areaid == area_rs[0].areaid)) weathers = {} weathers["days"] = [] for temp_w in weather_rs: temp = {} temp["day"] = temp_w.day temp["day_weather"] = temp_w.day_weather temp["night_weather"] = temp_w.night_weather temp["day_air_temperature"] = temp_w.day_air_temperature temp["night_air_temperature"] = temp_w.night_air_temperature temp["day_wind_direction"] = temp_w.day_wind_direction temp["night_wind_direction"] = temp_w.night_wind_direction temp["day_wind_power"] = temp_w.day_wind_power temp["night_wind_power"] = temp_w.night_wind_power temp["sun_begin_end"] = temp_w.sun_begin_end temp["weekday"] = temp_w.weekday temp["day_weather_code"] = temp_w.day_weather_code temp["night_weather_code"] = temp_w.night_weather_code temp["jiangshui"] = temp_w.jiangshui #指数 indexs = DBInstance.records(Index, Index.weather_id == temp_w.id) for index in indexs: temp[index.type] = { "title": index.title, "desc": index.desc } weathers["days"].append(temp) return self.build_standard_response(0, "", data=weathers) return self.build_standard_response(-1, "获取天气预报异常") def build_standard_response(self, code, message, data=None): return json.dumps({ "code": code, "message": message, "data": data }, ensure_ascii=False) #获取最后更新日期 def last_update_date(self, location): if len(location) == 0: return rs = DBInstance.records(LastUpdateDate, LastUpdateDate.type == location) if len(rs) == 0: return datetime.date.fromtimestamp(0) return str(datetime.datetime.strptime(rs[0].date, '%Y-%m-%d').date()) #设置最后更新日期 def set_last_udpate_date(self, location): if len(location) == 0: return date_string = datetime.date.today().strftime("%Y-%m-%d") if DBInstance.isRecordExist(LastUpdateDate, LastUpdateDate.type == location): return DBInstance.updateRecords(LastUpdateDate, LastUpdateDate.type == location, {LastUpdateDate.date: date_string}) else: return DBInstance.addRecord( LastUpdateDate(type=location, date=date_string))
import time import logger import numpy as np from scipy.sparse import csr_matrix from sklearn import grid_search from sklearn import metrics from sklearn import linear_model from sklearn import svm logger = logger.createLogger("hw2_q3") class FeatureGenerator(object): """preparing features""" def __init__(self, data_file, label_file, groups=20, docs=11269, vocabulary=61188): self.data_file = data_file self.label_file = label_file self.groups = groups self.docs = docs self.vocabulary = vocabulary self.binary_feature = None self.tf_feature = None self.tfidf_feature = None self.label = np.loadtxt(label_file, usecols=(0, )) def create_features(self):
def __init__(self, queryServer = None): ##ugur self.rpclogger = createLogger('RPC') self.rpclogger.info('Starting JSONRPCServer') self.queryServer = queryServer self.queryManager = QueryManager(store=self.queryServer.createStore(), sources=self.queryServer.config.sources, plugins=self.queryServer.config.plugins)
def __init__(self, queryManager): self.rpclogger = createLogger('RPC') self.rpclogger.info('Starting JSONRPCServer') #self.queryGen = queryManager.queryGenerator self.queryManager = queryManager
for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit # Update the hall of fame with the generated individuals if halloffame is not None: halloffame.update(offspring) # Replace the current population by the offspring population[:] = offspring # Append the current generation statistics to the logbook record = mstats.compile(population) if mstats else {} logbook.record(gen=gen, nevals=len(invalid_ind), **record) if verbose: print logbook.stream if gen % FREQ == 0: cp = dict(population=population, generation=gen, halloffame=halloffame, logbook=logbook, rndstate=random.getstate()) with open("checkpoint_name.pkl", "wb") as cp_file: pickle.dump(cp, cp_file) return population, logbook if __name__ == "__main__": logger.createLogger() try: main() except Exception: logging.exception("KeyError")
def initLoggerToUse (self, logger): self._log = logger.createLogger(G_NAME_MODULE_LOG, G_NAME_GROUP_LOG_GENERIC_INSTANCE, instance=self.loggerName) self.loggerManager.initLoggerToUse(self._log)
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # # Author: Chair of Electronic Design Automation, TUM # # Version 0.1 # import os import re import imp import logger as lg logger = lg.createLogger("loaderLogger", debug=True) class PluginLoader: def __init__(self, pluginsDir, logger=logger): self.__filters = [] self.__loader = None self.__PLUGIN_DIR = pluginsDir self.__logger = logger self.__pluginModules = self.getPluginModules(self.__PLUGIN_DIR) def getPluginModules(self, pluginsDir): pluginModules = [] possiblePlugins = os.listdir(pluginsDir) for i in possiblePlugins: location = os.path.join(pluginsDir, i)
tester.timeout = kwargs["timeout"] tester.execute = generateJITScript(JIT="LLVMJIT", archTestScript=testRiscv) return tester elif index == 2: tester = pif.RiscvTester("RiscvTCCJITTester") tester.swDir = kwargs["RiscvSwDir"] tester.simDir = kwargs["RiscvSimDir"] tester.timeout = kwargs["timeout"] tester.execute = generateJITScript(JIT="TCCJIT", archTestScript=testRiscv) return tester elif index == 3: # TODO: Add VP tester return None else: return None # Unit test if __name__ == '__main__': logger = lg.createLogger("RiscvArchTesterLogger", debug=True) testers = [] for i in range(0, countPlugins()): testers.append(createPlugin(i)) for t in testers: if t: t.execute(t, logger)
# tester.swDir = kwargs["RiscvSwDir"] # tester.simDir = kwargs["RiscvSimDir"] tester.execute = testRiscvArchGDB return tester elif index == 2: # Add Armv6M GDB here return None else: return None def testOr1kArchGDB(self, logger): logger.info(Color.BOLD + Color.RED +"\n\nGDB tester for Or1k architecure not implemented yet\n"\ + Color.END) def testRiscvArchGDB(self, logger): logger.info(Color.BOLD + Color.RED +"\n\nGDB tester for RISCV architecure not implemented yet\n"\ + Color.END) # Unit test if __name__ == '__main__': logger = lg.createLogger("GDBTesterLogger", debug = True) testers = [] for i in range(0, countPlugins()): testers.append(createPlugin(i)) for t in testers: if t: print(t.namePlugin()) print (t.nameArch())
import unittest from word_net import * import logger as logging #from knowledgegraph import * #from read import * logger = logging.createLogger("test", "./", out=True) class TestWordNet(unittest.TestCase): def test_synonym_sets(self): print("\ntest_synonym_sets") out = synonym_sets('ball') logger.debug(out) self.assertTrue(out) def test_lemmas(self): print("\ntest_lemmas") out = lemmas('ball.n.01') logger.debug(out) self.assertTrue(out) def test_antonyms(self): print("\ntest_antonyms") out = antonyms('ball.n.01.ball') logger.debug(out) self.assertTrue(out) def test_hypernyms(self): print("\ntest_hypernyms") out = hypernyms('ball.n.01')