Example #1
0
def idleFunc():
    global frame
    global starttime
    global basetime
    global time
    global fps

    global startcycle
    global stop

    if not stop:
        # Draw current frame
        glutPostRedisplay()

        elapsed_time = glutGet(GLUT_ELAPSED_TIME)

        startcycle = time
        if frame == 0:
            starttime = elapsed_time
            basetime = elapsed_time
            time = starttime
            fps = 0
        else:
            if not paused:
                time = elapsed_time - starttime
            else:
                starttime = elapsed_time - time
            if (elapsed_time - basetime > 1000):
                fps = int(round(frame * 1000 / (elapsed_time - basetime)))
                basetime = elapsed_time
                frame = 0
            if time >= totaltime:
                time = totaltime
                stop = True
            if not paused:
                cyclesuccess, crashedarms = cycle.run(arms, strikers,
                                                      strikercommands,
                                                      startcycle, time,
                                                      numberofnotes, notelist,
                                                      offset, midifilename)
                # Play hit notes
                for notehit in cycle.notehits:
                    if not notehit[2]:
                        # Hitvel is yet to be implemented, assign a static 127
                        sound.play(notehit[0], 127)
                        notehit[2] = True
                if not cyclesuccess:
                    gui.arm.crashedarms = crashedarms
                    stop = True
                    glutPostRedisplay()
                    log.close()
                else:
                    if time == totaltime:
                        log.info('Simulation successful')
                        log.close()
    frame += 1
def checkinstructionlist(instructionlist,
                         startpositions=[
                             shimon.arm.positiontable[0],
                             shimon.arm.positiontable[2],
                             shimon.arm.positiontable[-4],
                             shimon.arm.positiontable[-2]
                         ],
                         strikercommands=None,
                         midifilename=None,
                         infofilename='info.log',
                         warningfilename='warning.log'):
    # Open log output
    log.open(infofilename, warningfilename)

    # Arm initialization
    instructionlist = sorted(instructionlist, key=lambda x: x[0])
    totaltime = instructionlist[-1][0] + 2000
    arms = [
        shimon.arm.Arm(1, startpositions[0]),
        shimon.arm.Arm(2, startpositions[1]),
        shimon.arm.Arm(3, startpositions[2]),
        shimon.arm.Arm(4, startpositions[3])
    ]
    for instruction in instructionlist:
        arms[instruction[1] - 1].instructionqueue.append(instruction)

    # Striker initialization
    strikers = []
    numberofnotes = 0
    notelist = []
    offset = 0
    if strikercommands is not None and len(strikercommands) > 0:
        strikercommands = sorted(strikercommands, key=lambda x: x[0])
        for i in range(8):
            strikers.append(shimon.striker.Striker(i + 1))
        strikermaxtime = int(strikercommands[-1][0]) + 2000
        if totaltime < strikermaxtime:
            totaltime = strikermaxtime
        for strikercommand in strikercommands:
            for i in range(8):
                if strikercommand[i + 1] == 1:
                    strikers[i].instructionqueue.append(strikercommand[0])
        if midifilename is not None:
            numberofnotes, notelist = checkmidi.readnotes(midifilename)
            offset = checkmidi.findstaticoffset(strikercommands[0][0] + 85,
                                                notelist)
            log.info(f'Static offset: {offset}')

    success, hitnotes = cycle.run(arms, strikers, strikercommands, 0,
                                  totaltime, numberofnotes, notelist, offset,
                                  midifilename)
    if success:
        log.info('Simulation successful')
    log.close()
Example #3
0
def clean_log():
        for file in NEW_PRODUCTS_FILES:
            with open(NEW_PRODUCTS_FILES[file],"r+") as log:
                logs = log.readlines()
                logs = logs[::-1]
                mod_logs = logs[:config.max_log_products]
                log.close()
                fmod = open(NEW_PRODUCTS_FILES[file],"w")
                fmod.write("")
                fmod.close()
                s = open(NEW_PRODUCTS_FILES[file],"r+")
                for p in mod_logs:
                    p+="\n"
                
                s.writelines(mod_logs[::-1])
Example #4
0
def xgboost_optimizer(trainInput, targetInput):

	log.init('xgboost_optimizer.log')
	log.msg('**************************************')
	log.msg('log file initialized')
	#----------------------------------------------------------
	global train
	global target
	train = trainInput
	target = targetInput
	#---------------------------------------------------------------

	n,v,s = optimize_param('max_delta_step', 0, 1)
	logmsg(n,v,s)
	n,v,s = optimize_param('scale_pos_weight', 1, 1)
	logmsg(n,v,s)
	#------------------------------------------------

	n,v,s = optimize_param('min_child_weight', 0, 1)
	logmsg(n,v,s)

	n,v,s = optimize_param('max_depth', 0, 1)
	logmsg(n,v,s)
	#--------------------------------------------------

	n,v,s = optimize_param('gamma', 0, .1, 2)
	logmsg(n,v,s)
	#---------------------------------------------------

	n,v,s = optimize_param('subsample', 0, .05, 1)
	logmsg(n,v,s)

	n,v,s = optimize_param('colsample_bylevel', 0.1, .05, 1)
	logmsg(n,v,s)
	#----------------------------------------------------------

	n,v,s = optimize_param('reg_alpha',0, 0.1, 1)
	logmsg(n,v,s)

	n,v,s = optimize_param('reg_lambda',1, 1, 10)
	logmsg(n,v,s)

#----------------------------------------------------------------------------------------
	log.msg("saving parameters to file")
	with open('../data/parameters.pkl', 'wb') as f:
		pickle.dump(file=f, obj=params)
	log.msg("Done.")
	log.close()
Example #5
0
 def init_log(self, index):
     if index == 0: index = "test"
     log.LOG_PATH = './logs/'
     try:
         _ = log.close()
     except:
         pass
     log.init('tuning_params-' + str(index) + '.log')
Example #6
0
def handle_package(package):
	global inserted

	if package is None:
		return

	try:
		kill = package['killmail']

		# get ids and names
		munge(kill)
		# move items off of victim
		kill['items'] = kill['victim']['items']
		del kill['victim']['items']
		for item in kill['items']:
			item['typeID'] = item.pop('itemTypeID')
			item['qtyDropped'] = item.pop('quantityDropped', 0)
			item['qtyDestroyed'] = item.pop('quantityDestroyed', 0)
		# make sure entities are present
		# (alliance and faction can be missing for players; character and corporation can be missing for NPCs)
		for char in kill['attackers'] + [kill['victim']]:
			for entity in db.queries.entity_types + ['faction']:
				if entity + 'ID' not in char:
					char[entity + 'ID'] = 0
					char[entity + 'Name'] = ''
		# make sure weapon and ship are present
		for char in kill['attackers']:
			char.setdefault('weaponTypeID', 0)
			char.setdefault('shipTypeID', 0)

		with db.cursor() as c:
			db.queries.insert_kill(c, kill)
		inserted += 1
		if inserted % 500 == 0:
			log.write('redisq inserted %s kills' % inserted)
	except:
		log.write('redisq error: %s\n%s' % (package, traceback.format_exc()))
		log.close()
		sys.exit()
Example #7
0
	def __onClose(self):
		self.statusTimer.stop()
		log.close()
		self.session.nav.playService(self.oldref)
Example #8
0
def quit(signum, frame):
	for bot in bots:
		bot.disconnect()
	log.close()
	sys.exit()
Example #9
0
	def exit():
		conn.close()
		log.close()
Example #10
0
	def __onClose(self):
		self.statusTimer.stop()
		log.close()
		self.session.nav.playService(self.oldref)
Example #11
0
File: pbot.py Project: jmw327/pbot
	fd = bot.connect()
	fds[fd] = bot
	epoll.register(fd, EPOLLFLAGS)

try:
	while keep_going:
		try:
			results = epoll.poll(config.EPOLL_TIMEOUT)
		except IOError as e:
			if e.errno == errno.EINTR and not keep_going:
				break
			raise
		flags = dict(results)
		ts = time.time()
		for fd, bot in fds.items():
			if flags.get(fd, 0) & select.EPOLLIN == select.EPOLLIN:
				bot.handle()
			else:
				if bot.check_disconnect(ts):
					del fds[fd]
					epoll.unregister(fd)
					fd = bot.connect()
					fds[fd] = bot
					epoll.register(fd, EPOLLFLAGS)
		log.flush()
	for b in fds.values():
		b.disconnect()
finally:
	epoll.close()
	log.close()
Example #12
0
        for c in cur.fetchall():
            respond.processSelftext(c[0], c[1], c[2])
        
        #Process comments
        cur.execute("select id, body, author from t1")
        for c in cur.fetchall():
            respond.processComment(c[0], c[1], c[2])

    else:
        log.write("Error: could not log in, responses skipped", "error")

stats.printStats()

if len(argv) == 1:
    print "No arguments found, try 'python hollowbot.py runall' or check the README"

# Remove all data from database and logfile
if 'wipe' in argv:
    log.wipe()
    cur.execute("drop table if exists session")
    cur.execute("drop table if exists crawl_locations")
    cur.execute("drop table if exists t3")
    cur.execute("drop table if exists t1")
    cur.execute("drop table if exists responses")
    db.commit()
    print "Data Wiped!!"

db.close()

if _['logging']: log.close()
Example #13
0
File: stomp.py Project: raylu/ykill
def exit():
	if conn.is_connected():
		conn.disconnect()
	log.close()
Example #14
0
def closeLog():
	log.close()
Example #15
0
File: stomp.py Project: mgway/ykill
def exit():
	conn.disconnect()
	log.close()
Example #16
0
File: pbot.py Project: raylu/pbot
def quit(signum, frame):
    for bot in bots:
        bot.disconnect()
    log.close()
    sys.exit()