def get_data_from_file(self): """ This function loads data from file, which you choose. :return: nothing. """ i = 0 while True: i = self.user_input(lambda: input("1 - Load from *.pickle \n" "2 - Load from *.yaml \n" "3 - Load from *.json \n")) if i == 1: config.AppConfiguration().set_file_type("pickle") return storage.Storage().load_data( open("database." + config.AppConfiguration().get_file_type(), 'rb')) elif i == 2: config.AppConfiguration().set_file_type("yaml") return storage.Storage().load_data( open("database." + config.AppConfiguration().get_file_type(), 'rb')) elif i == 3: config.AppConfiguration().set_file_type("json") return storage.Storage().load_data( open("database." + config.AppConfiguration().get_file_type(), 'r'))
def getStorage(self, name, world=False): """ Return a storage object for storing configurations, player data, and any other data your plugin will need to remember across reboots. Setting world=True will store the data inside the current world folder, for world-specific data. """ if world == False: return storage.Storage(name, False, root=".wrapper-data/plugins/%s" % self.id) else: return storage.Storage(name, True, root="%s/plugins/%s" % (self.minecraft.getWorldName(), self.id))
def __init__(self, username, wrapper): self.wrapper = wrapper self.server = wrapper.server self.permissions = wrapper.permissions self.name = username self.username = self.name # just an alias - same variable self.loggedIn = time.time() self.abort = False self.uuid = self.wrapper.getUUID(username) self.client = None if not self.wrapper.proxy == False: for client in self.wrapper.proxy.clients: if client.username == username: self.client = client self.uuid = client.uuid break self.data = storage.Storage(self.uuid, root="wrapper-data/players") if not "firstLoggedIn" in self.data: self.data["firstLoggedIn"] = (time.time(), time.tzname) if not "logins" in self.data: self.data["logins"] = {} t = threading.Thread(target=self.__track__, args=()) t.daemon = True t.start()
def list(): database = storage.Storage() boards = database.fetch_boards() board_list = [] favorites_list = [] for board in boards: attributes = { 'board': board['board'], 'title': board['title'], #'pages': board['pages'], 'favorite': board['favorite'], 'default_board': board['default_board'], 'last_used': board['last_used'] } if board['favorite']: favorites_list.append(attributes) else: board_list.append(attributes) for board in reversed(favorites_list): board_list.insert(0, board) return board_list
def __init__(self): logging.info("Bot initialized.") self.text = '' self.storage = storage.Storage() self.translation = None self.translation_engine = YandexTranslate(yandex_api_key) self.last_sender = None
def callback_payments_month(call): args = parse_args(call.data) data = storage.Storage() token = data.get_token(call.message.chat.id, args[0]) t = datetime.now() t2 = t - timedelta(days=30) frm = t2.strftime(words.TIME_FMT) to = t.strftime(words.TIME_FMT) print(frm) try: info = api.subscribers.get_charges_list(args[0], token, frm, to) info = info.body['data'] for info_chunk in chunks(info, 30): msg = "" for i in info_chunk: msg += "*Тип*: " + i['type'] + '\n' + '*Дата*: ' + i[ 'date'] + '\n' + '*Стоимость*: ' + str(i['fee']) + '\n\n' bot.send_message(call.message.chat.id, msg, parse_mode='Markdown') except ClientError as e: bot.send_message( call.message.chat.id, 'Не удалось получить платежи: ' + e.response.body['meta']['message']) print(e) finally: data.close()
def test_find(self): environment = storage.Environment(True, storage.ProbeMode_NONE, storage.TargetMode_DIRECT) s = storage.Storage(environment) devicegraph = storage.Devicegraph(s) sda = storage.Disk.create(devicegraph, "/dev/sda") sda.set_region(storage.Region(0, 1000000, 512)) gpt = sda.create_partition_table(storage.PtType_GPT) sda1 = gpt.create_partition("/dev/sda1", storage.Region(0, 100, 512), storage.PartitionType_PRIMARY) self.assertEqual(sda.get_sid(), 42) self.assertEqual(gpt.get_sid(), 43) self.assertEqual(sda1.get_sid(), 44) self.assertTrue(storage.Disk.find_by_name(devicegraph, "/dev/sda")) self.assertRaises( storage.DeviceNotFound, lambda: storage.Disk.find_by_name(devicegraph, "/dev/not-here")) self.assertRaises( storage.DeviceHasWrongType, lambda: storage.Disk.find_by_name(devicegraph, "/dev/sda1"))
def test_polymorphism(self): environment = storage.Environment(True, storage.ProbeMode_NONE, storage.TargetMode_DIRECT) s = storage.Storage(environment) devicegraph = storage.Devicegraph(s) sda = storage.Disk.create(devicegraph, "/dev/sda") gpt = sda.create_partition_table(storage.PtType_GPT) self.assertEqual(sda.get_sid(), 42) self.assertEqual(gpt.get_sid(), 43) tmp1 = devicegraph.find_device(42) self.assertTrue(storage.is_disk(tmp1)) self.assertTrue(storage.to_disk(tmp1)) self.assertFalse(storage.is_partition_table(tmp1)) self.assertRaises(storage.DeviceHasWrongType, lambda: storage.to_partition_table(tmp1)) self.assertRaises(storage.Exception, lambda: storage.to_partition_table(tmp1)) self.assertEqual(storage.downcast(tmp1).__class__, storage.Disk) tmp2 = devicegraph.find_device(43) self.assertTrue(storage.is_partition_table(tmp2)) self.assertTrue(storage.to_partition_table(tmp2)) self.assertFalse(storage.is_disk(tmp2)) self.assertRaises(storage.DeviceHasWrongType, lambda: storage.to_disk(tmp2)) self.assertRaises(storage.Exception, lambda: storage.to_disk(tmp2)) self.assertEqual(storage.downcast(tmp2).__class__, storage.Gpt) tmp3 = devicegraph.find_holder(42, 43) self.assertTrue(storage.is_user(tmp3)) self.assertTrue(storage.to_user(tmp3)) self.assertFalse(storage.is_filesystem_user(tmp3)) self.assertRaises(storage.HolderHasWrongType, lambda: storage.to_filesystem_user(tmp3)) self.assertRaises(storage.Exception, lambda: storage.to_filesystem_user(tmp3)) self.assertEqual(storage.downcast(tmp3).__class__, storage.User)
def setUp(self): """Настройка базы перед тестом""" self.storage = storage.Storage(IOC.config.main) self.controller = processing.AirfieldsController(IOC) self.storage.airfields.update_airfields( self.controller.initialize_managed_airfields( IOC.config.mgen.airfields_data[MOSCOW]))
def __init__(self, token, command_prefix, modules): commands.Bot.__init__(self, command_prefix=command_prefix) self.modules = modules self.storage = storage.Storage() self.owner_id = config.bot_owner self.load() self.run(token, bot=True, reconnect=True)
def setUp(self): self.filename = '_test.db' try: os.remove(self.filename) except FileNotFoundError: pass self.storage = storage.Storage(self.filename)
def __init__(self, storageClass = None, robot = False): self.storageClass = storageClass if storageClass else storage.Storage() self.robot = robot self.msgList = self.storageClass.msgList self.loginInfo = {} self.s = requests.Session() self.uuid = None
def __init__(self, wrapper): self.wrapper = wrapper self.api = API(wrapper, "Web", internal=True) self.log = log.PluginLog(self.wrapper.log, "Web") self.config = wrapper.config self.socket = False self.data = storage.Storage("web", self.log) if "keys" not in self.data: self.data["keys"] = [] #if not self.config["Web"]["web-password"] == None: # self.log.info("Changing web-mode password because web-password was changed in wrapper.properties") # self.data["password"] = md5.md5(self.config["Web"]["web-password"]).hexdigest() # self.config["Web"]["web-password"] = None # self.wrapper.configManager.save() self.api.registerEvent("server.consoleMessage", self.onServerConsole) self.api.registerEvent("player.message", self.onPlayerMessage) self.api.registerEvent("player.join", self.onPlayerJoin) self.api.registerEvent("player.leave", self.onPlayerLeave) self.api.registerEvent("irc.message", self.onChannelMessage) self.consoleScrollback = [] self.chatScrollback = [] self.memoryGraph = [] self.loginAttempts = 0 self.lastAttempt = 0 self.disableLogins = 0
def reset(self): # Reset everything except: # # - The install language # - The keyboard self.instClass = None self.network = network.Network() self.firewall = firewall.Firewall() self.security = security.Security() self.timezone = timezone.Timezone() self.timezone.setTimezoneInfo( self.instLanguage.getDefaultTimeZone(self.anaconda.rootPath)) self.users = None self.rootPassword = {"isCrypted": False, "password": "", "lock": False} self.auth = "--enableshadow --passalgo=sha512" self.desktop = desktop.Desktop() self.upgrade = None if flags.cmdline.has_key("preupgrade"): self.upgrade = True self.storage = storage.Storage(self.anaconda) self.bootloader = booty.getBootloader(self) self.upgradeRoot = None self.rootParts = None self.upgradeSwapInfo = None self.escrowCertificates = {} if self.anaconda.isKickstart: self.firstboot = FIRSTBOOT_SKIP else: self.firstboot = FIRSTBOOT_DEFAULT # XXX I still expect this to die when kickstart is the data store. self.ksdata = None
def smarter_predict(x=300, y=1000, z=5000.0, n=5, runs=None): #finds the n closest runs to start off data = storage.Storage() if runs: data.setRuns(runs) closest = data.findNClosestRuns(z, n) #now reads in the actual data for these runs lists = [] for distance, name in closest: current_data = data.readRun(name)[1:] lists.append(current_data) #calculates the weights for these runs weights = [] for distance, name in closest: weights.append(weighting.weightDistance(z, distance)) #now calculates the average runs combined = average.averageN(lists, 1000, weights) #now gives a prediction prediction = predict.secant_prediction(combined, y, x, z) sec_pred = prediction["prediction"] multiple = prediction["multiple"] #un-normalizes the data rescaled = [(time * multiple, distance) for (time, distance) in combined] plotter = Plotter() #plotter.createGraph([rescaled,[(x,y)]],['r', 'bo']) return {"prediction": sec_pred}
def __init__(self): self.storageClass = storage.Storage() self.memberList = self.storageClass.memberList self.msgList = self.storageClass.msgList self.loginInfo = {} self.s = requests.Session() self.uuid = None
def test_getFile(self): file = uuid.uuid1() fileName = uuid.uuid1() a = storage.Storage() a.put(fileName, file) t = a.get(fileName) self.assertEqual(file, t)
def test(n=1): for i in range(n): data = storage.Storage() runs = [ "10minute1.csv", "10minute5.csv", "5minute4.csv", "fast10minute3.csv", "10minute2.csv", "5minute1.csv", "5minute5.csv", "fast10minute4.csv", "10minute3.csv", "5minute2.csv", "fast10minute1.csv", "fast10minute5.csv", "10minute4.csv", "5minute3.csv", "fast10minute2.csv" ] index = randint(0, len(runs) - 1) current = runs.pop(index) current_data = data.readRun(current)[1:] #get the last time and distance from the current run last_time = current_data[-1][0] last_distance = current_data[-1][1] #generate a random number in this range random_time = randint(1, last_time - 1) random_distance = current_data[random_time][1] prediction = smarter_predict(random_time, random_distance, last_distance, 5, runs) actual = smarter_predict(random_time, random_distance, last_distance, 1, [current]) #print current, random_time, random_distance, prediction, actual print current, random_distance, last_distance, actual[ "prediction"], prediction["prediction"]
def test_json_format(self): """ This function tests json file. :return: nothing """ import json # test load file = io.StringIO(json.dumps(self.test_data)) config.AppConfiguration().set_file_type("json") self.assertEqual(self.test_data, storage.Storage().load_data(file)) # test save config.AppConfiguration().set_file_type("json") self.assertEqual( self.test_data, storage.Storage().save_data(io.StringIO(), self.test_data))
def test_yaml_format(self): """ This function tests yaml file. :return: nothing. """ import yaml # test load file = io.StringIO(yaml.dump(self.test_data)) config.AppConfiguration().set_file_type("yaml") self.assertEqual(self.test_data, storage.Storage().load_data(file)) # test save config.AppConfiguration().set_file_type("yaml") self.assertEqual( self.test_data, storage.Storage().save_data(io.StringIO(), self.test_data))
def _storage(self, unique_id, unique_str): ''' Connect to NetApp Storage Create LUN and Map to VersaPLX ''' netapp = storage.Storage(unique_id, unique_str) netapp.lun_create() netapp.lun_map()
def __post_init__(self, refine): if refine: logger.info('Getting user information from database') user = storage.Storage().find_user(self.messenger, self.id) if user: self.key = user.key self.lang = user.lang or self.lang self.receiver = user.receiver logger.info('Done')
def save_data_into_file(data): """ This function save data into file, which format you choose. :param data: data. :return: nothing. """ if config.AppConfiguration().get_file_type() == "pickle": storage.Storage().save_data( open("database." + config.AppConfiguration().get_file_type(), 'wb'), data) elif config.AppConfiguration().get_file_type() == "yaml": storage.Storage().save_data( open("database." + config.AppConfiguration().get_file_type(), 'w'), data) elif config.AppConfiguration().get_file_type() == "json": storage.Storage().save_data( open("database." + config.AppConfiguration().get_file_type(), 'w'), data)
def run(self): #First let's read our config file, in this case a yaml file yaml = yamlFile.ReadYaml() #Initialization of storage class, passing the configuration storage = dbStorage.Storage(yaml) #Initialization of the Genetic algorithm for seeking the solution genetic = algorithm.GeneticAlgorithm(self.__queens) #Finally , print the solution myPrinter = printer.Printer(genetic, storage)
def get_session(request, other_application='admin'): """ checks that user is authorized to access other_application""" if request.application == other_application: raise KeyError try: session_id = request.cookies['session_id_' + other_application].value osession = storage.load_storage(os.path.join( up(request.folder), other_application, 'sessions', session_id)) except Exception, e: osession = storage.Storage()
def test_putFileExists(self): file = uuid.uuid1() fileName = uuid.uuid1() a = storage.Storage() a.put(fileName, file) self.assertIn(fileName, a.store) self.assertRaises( storage.ErrorFileExists, a.put, fileName)
def getEntropys(passengersTrain, features): entropyStorage = None dataStorage = [] # Array aus entropyStorages entropyArr = list(features) passengers = passengersTrain.copy() for i in range(0, len(features)): feature = features[i] passenger = passengers[feature] if feature == 'Survived': possibleValues = checkPossibleValues(passenger) entropyGesamt = callTotalEntropy(passenger, possibleValues) entropyArr[i] = entropyGesamt elif feature == 'Pclass': possibleValues = pclassValues(passenger) elif feature == 'Name': possibleValues, passenger = nameValues(passenger) elif feature == 'Sex': possibleValues = sexValues(passenger) elif feature == 'Age': possibleValues, passenger = ageValues(passenger) elif feature == 'SibSp': possibleValues = sibSpValues(passenger) elif feature == 'Parch': possibleValues, passenger = parchValues(passenger) elif feature == 'Cabin': possibleValues, passenger = cabinValues(passenger) elif feature == 'Fare': possibleValues, passenger = fareValues(passenger) elif feature == 'Embarked': possibleValues, passenger = embarkedValues(passenger) if feature != 'Survived': sumEntropy, entropyValues = calcFeatureEntropy( passenger, possibleValues, passengersTrain['Survived']) entropyStorage = store.Storage( feature, possibleValues, entropyValues, sumEntropy) # Datenhaltung fuer ein Feature else: entropyValues = [0, 0] entropyStorage = store.Storage(feature, possibleValues, entropyValues, entropyGesamt) dataStorage.append( entropyStorage) # Datenhaltung der daten fuer alle Features return dataStorage
def test_pickle_format(self): """ This function tests pickle file. :return: nothing. """ import pickle # test load config.AppConfiguration().set_file_type("pickle") self.assertEqual( self.test_data, storage.Storage().load_data( io.BytesIO(pickle.dumps(self.test_data)))) # test save config.AppConfiguration().set_file_type("pickle") self.assertEqual( self.test_data, storage.Storage().save_data(io.BytesIO(), self.test_data))
def __init__(self, resized_h = 1216, resized_w = 1936): super().__init__() s = storage.Storage() self.__dtc_path = s.dataset_path(os.path.join("edgeai", "dtc")) self.__seg_path = s.dataset_path(os.path.join("edgeai", "seg")) self.__rgb_path_dict = {} self.__json_path_dict = {} self.__seg_rgb_path_dict = {} self.__seg_lbl_path_dict = {} self.__resized_h = resized_h self.__resized_w = resized_w self.__org_w = 1936 self.__org_h = 1216 self.conv_dict = \ { "Car":"car", "Bicycle":"bicycle", "Pedestrian":"person", "Signal":"traffic light", "Signs":"traffic sign", "Truck":"truck", "Bus":"bus", "SVehicle":"special", "Motorbike":"motorcycle", "Train":"train", } for v in self.conv_dict.values(): assert(v in self.label_dict.keys()) self.seg_palette = \ { "car" : [0 , 0, 255], "bus" : [193, 214, 0], "truck" : [180, 0, 129], "special" : [255, 121, 166], "person" : [255, 0, 0], "motorcycle" : [208, 149, 1], "traffic light" : [255, 255, 0], "traffic sign" : [255, 134, 0], "sky" : [ 0, 152, 225], "building" : [ 0, 203, 151], "vegetation" : [ 85, 255, 50], "wall" : [ 92, 136, 125], "road" : [ 69, 47, 142], # definitionでは"lane"だが、普通の道路 "ground" : [136, 45, 66], "sidewalk" : [ 0, 255, 255], "road shoulder" : [215, 0, 255], "static" : [180, 131, 135], "out of eval" : [ 81, 99, 0], "ego vehicle" : [ 86, 62, 67], } for k in self.seg_palette.keys(): assert(k in self.label_dict.keys())
def __init__(self, resized_h=720, resized_w=1280): super().__init__() s = storage.Storage() self.__data_path = s.dataset_path("bdd100k") self.__rgb_path_dict = {} self.__json_path_dict = {} self.__seg_path_dict = {} self.__segimg_path_dict = {} self.__rgb_h, self.__rgb_w = 720, 1280 self.__resized_h = resized_h self.__resized_w = resized_w