def convert_mash_to_zeromq_message(mash): try: logger.debug('mash: {0}'.format(mash)) obj = [{'id':mash.id, 'key':mash.key, 'song1':mash.song1, 'song2':mash.song2, 'status':mash.status}] return json.dumps(obj) except Exception, err: logger.exception('Something bad happened: convert_mash_to_zeromq_message, mash={0}'.format(mash))
def setup_weight_for_location(self, window, naz_bin, naz_bin_all): """ setup weight from location information, including distance, component and azimuth :param window: :param naz_bin: :param naz_bin_all: :return: """ idx_naz = self.get_azimuth_bin_number(window.azimuth) if self.config.normalize_category: tag = window.tag['obsd'] naz = naz_bin[tag][idx_naz] else: naz = naz_bin_all[idx_naz] logger.debug("%s.%s.%s, num_win, dist, naz: %d, %.2f, %d" % ( window.station, window.network, window.component, window.num_wins, window.dist_in_km, naz)) if self.config.normalize_window: mode = "uniform" else: # if the weight is not normalized by energy, # then use the old weighting method(exponential) mode = "exponential" # weighting on compoent, distance and azimuth window.weight = \ window.weight * self.config.weight_function( window.component, window.dist_in_km, naz, window.num_wins, dist_weight_mode=mode)
def setup_weight_for_location(self, window, naz_bin, naz_bin_all): """ setup weight from location information, including distance, component and azimuth :param window: :param naz_bin: :param naz_bin_all: :return: """ idx_naz = self.get_azimuth_bin_number(window.azimuth) if self.config.normalize_category: tag = window.tag['obsd'] naz = naz_bin[tag][idx_naz] else: naz = naz_bin_all[idx_naz] logger.debug("%s.%s.%s, num_win, dist, naz: %d, %.2f, %d", window.station, window.network, window.component, window.num_wins, window.dist_in_km, naz) mode = "uniform" #mode = "exponential" window.weight = window.weight * \ self.config.weight_function(window.component, window.dist_in_km, naz, window.num_wins, dist_weight_mode=mode)
def mash(key): try: logger.debug('/mash/{0}'.format(key)) mash = rdb_client.get('mashes', key) mash_model = MashMessage(mash['id'], mash['key'], mash['song1'], mash['song2'], mash['status']) return render_template('mash.html', mash=mash_model) except Exception, err: logger.exception('Something bad happened: mash, key={0}'.format(key))
def resubmit(key): try: mash = rdb_client.get('mashes', key) mash_model = MashMessage(mash['id'], mash['key'], mash['song1'], mash['song2'], mash['status']) logger.debug('resubmit mash:{0}'.format(mash_model)) socket.send_json(convert_mash_to_zeromq_message(mash_model)) return redirect(url_for('mash', key=mash_model.key)) except Exception, err: logger.exception('Something bad happened: resubmit, key={0}'.format(key))
def run(self): archivers = self.archivers extracts = self.extracts dirs = self.get_extracts() logger.debug('dirs: {}'.format(dirs)) chdir(archivers) for dir in dirs: globals()['zip'.capitalize()](archiver=dir + '.zip', path=join(extracts, dir)).make_archive()
def make_archive(self): with RarFile(self.archiver, 'w') as z: archiver_root = dirname(self.archiver) for root, dirs, files in walk(self.path): for f in files: filepath = join(root, f) arcname = join(archiver_root, relpath(filepath, self.path)) logger.debug( "write file to archiver file ,filepath: {}, arcname: {}" .format(filepath, arcname)) z.write(filepath, arcname)
def list(page = 1): try: logger.debug('/list/{0}'.format(page)) count = rdb_client.count('mashes', {}) mashes = rdb_client.filter_paging('mashes', {}, PER_PAGE, page) mash_list = [] for mash in mashes: mash_list.append(MashMessage(mash['id'], mash['key'], mash['song1'], mash['song2'], mash['status'])) logger.debug('mash:{0}'.format(mash)) if not mashes and page != 1: abort(404) pagination = Pagination(page, PER_PAGE, count) return render_template('list.html', pagination=pagination, mashes=mash_list) except Exception, err: logger.exception('Something bad happened: list')
def date_extract(df): date_loc = df.iloc[3:4, 1] date_loc1 = re.findall(pt.date_pat1, str(date_loc)) date_loc2 = re.findall(pt.date_pat2, str(date_loc)) if len(date_loc1) != 0: logger.debug("%s", date_loc1) date = datetime.datetime.strptime(date_loc1[0], "%d-%m-%y") return date elif len(date_loc2) != 0: logger.debug("%s", date_loc2) date = datetime.datetime.strptime(date_loc2[0], "%d/%m/%y") return date else: date = 'Null' return date
def run(self): extracts = self.extracts archives = self.get_archivers() logger.debug('archives: {}'.format(archives)) for file in archives: fileext = splitext(file)[1] # if fileext.lower() == 'zip': # Zip(path=file).un_archive() logger.debug('unzip file:{}, to dir: {}, pwd: {}'.format( file, self.extracts, self.pwd)) if fileext == '.7z': SevenZip(archiver=file, path=extracts, pwd=self.pwd).un_archive() else: globals()[fileext.replace('.', '').capitalize()]( archiver=file, path=extracts, pwd=self.pwd).un_archive()
def home(): if request.method == 'POST': try: key = uuid.uuid4().hex song1 = request.files['song1'] song1Filename = save_file(song1, key) song2 = request.files['song2'] song2Filename = save_file(song2, key) status = 'uploaded' mash = MashMessage(key, key, song1Filename, song2Filename, status) rdb_client.insert('mashes', {'id':key, 'key': key, 'song1': song1Filename, 'song2': song2Filename, 'status': status}) logger.debug('new mash:{0}'.format(mash)) socket.send_json(convert_mash_to_zeromq_message(mash)) return redirect(url_for('mash', key=mash.key)) except Exception, err: logger.exception('Something bad happened:')
def run_gui(): while True: event, values = window.read() if event in (None, 'Cancel'): break if event == 'Submit': logger.debug('values: {}'.format(values)) source = values['__SOURCE__'] target = values['__TARGET__'] pwd = values['__PWD__'] task = 'ExtractAll' if values['__ExtractAll__'] else 'MakeArchiver' if task == 'ExtractAll': task = Extractall(archivers=source, extracts=target, pwd=pwd) elif task == 'MakeArchiver': task = MakeArchiver(archivers=target, extracts=source, pwd=pwd) else: break logger.debug('{} gui command run: archivers: {}, extracts: {}, pwd: {}'.format(task, target, source, pwd)) task.run() sg.popup_ok("任务执行完成") window.close()
def normalize_weight(self): """ Normalize the weighting and make the maximum to 1 :return: """ max_weight = 0.0 for window in self.window: max_temp = np.max(window.weight) if max_temp > max_weight: max_weight = max_temp logger.debug("Global Max Weight: %f" % max_weight) for window in self.window: logger.debug("%s.%s.%s, weight: [%s]" % (window.network, window.station, window.component, ', '.join(map(self._float_to_str, window.weight)))) window.weight /= max_weight logger.debug("Updated, weight: [%s]" % (', '.join(map(self._float_to_str, window.weight))))
def uploads(key, filename): logger.debug('/uploads/{0}/{1}'.format(key, filename)) folder = os.path.join(app.root_path, cfg.UPLOAD_FOLDER, key) logger.debug('folder={0}, filename={1}'.format(folder, filename)) return send_from_directory(folder, filename)
def start(self): logger.debug("Start task, archiver in {}, extracts files in {}".format( self.archivers, self.extracts))
def about(): logger.debug('IN ABOUT') return render_template('about.html')
def end(self): logger.debug("*****End task*****")
#######FIRST_PHASE: (all the NPC inhabiting the world instead of those, generated inside quesut ly) #first let's define our world's population: this will include # all the NPC's of all types we have, except those which can be placed inside quesuts only #let's roll for number of NPC. let it lay from . NOTE that we will also add types denoted by ! later. mNPC_count = util.roll(*MNPC_ROLL) #now let's roll for number of quest-givers. we do want them to exist min_quest_fivers = util.roll(*QUEST_GIVER_ROLL) #now let's roll for immobile NPCs. we don't want many of them. let em be 0-3 at 50% chance for now immobile_npc = 0 if util.coinflip(): to_roll = util.roll(*IMMOBILE_NPC_ROLL) for i in range(0, to_roll): immobile_npc += util.coinflip() unique_npc = util.roll(*UNIQUES_ROLL) traders_npc = util.roll(*TRADERS_ROLL) logger.debug("Rolled for %d main NPCs (%d NPC able to issue quests), %d immobile NPCs, %d uniques, %d traders)", mNPC_count, min_quest_fivers, immobile_npc, unique_npc, traders_npc) logger.debug("Total of %d NPCs (%d with traders)", mNPC_count + immobile_npc + unique_npc, mNPC_count + immobile_npc + unique_npc + traders_npc) #now toss #generate_plot() class QuestNPC(object): #denotes if this NPC-type can be generate at first phase non_worldgen = False __metaclass__ = util.AutoAdd __meta_skip__ = '' def __init__(self): pass class GoodNPC(QuestNPC): pass