misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
cb09648ba1
commit
9d19fb8e7a
@ -57,7 +57,7 @@ if __name__ == '__main__':
|
||||
elif args.do_manual:
|
||||
logging.info("entering manual mode ...")
|
||||
|
||||
agent.last_session.parse(args.skip_session)
|
||||
agent.last_session.parse(agent.view(), args.skip_session)
|
||||
if not args.skip_session:
|
||||
logging.info(
|
||||
"the last session lasted %s (%d completed epochs, trained for %d), average reward:%s (min:%s max:%s)" % (
|
||||
|
@ -167,12 +167,14 @@ class LastSession(object):
|
||||
self.duration_human = ', '.join(self.duration_human)
|
||||
self.avg_reward /= (self.epochs if self.epochs else 1)
|
||||
|
||||
def parse(self, skip=False):
|
||||
def parse(self, ui, skip=False):
|
||||
if skip:
|
||||
logging.debug("skipping parsing of the last session logs ...")
|
||||
else:
|
||||
logging.debug("reading last session logs ...")
|
||||
|
||||
ui.on_reading_logs()
|
||||
|
||||
lines = []
|
||||
|
||||
if os.path.exists(self.path):
|
||||
@ -184,11 +186,18 @@ class LastSession(object):
|
||||
lines.append(line)
|
||||
if LastSession.START_TOKEN in line:
|
||||
break
|
||||
|
||||
lines_so_far = len(lines)
|
||||
if lines_so_far % 100 == 0:
|
||||
ui.on_reading_logs(lines_so_far)
|
||||
|
||||
lines.reverse()
|
||||
|
||||
if len(lines) == 0:
|
||||
lines.append("Initial Session");
|
||||
|
||||
ui.on_reading_logs()
|
||||
|
||||
self.last_session = lines
|
||||
self.last_session_id = hashlib.md5(lines[0].encode()).hexdigest()
|
||||
self.last_saved_session_id = self._get_last_saved_session_id()
|
||||
|
@ -233,6 +233,11 @@ class View(object):
|
||||
self.set('status', self._voice.on_free_channel(channel))
|
||||
self.update()
|
||||
|
||||
def on_reading_logs(self, lines_so_far=0):
|
||||
self.set('face', faces.SMART)
|
||||
self.set('status', self._voice.on_reading_logs(lines_so_far))
|
||||
self.update()
|
||||
|
||||
def wait(self, secs, sleeping=True):
|
||||
was_normal = self.is_normal()
|
||||
part = secs / 10.0
|
||||
|
@ -43,6 +43,12 @@ class Voice:
|
||||
def on_free_channel(self, channel):
|
||||
return self._('Hey, channel {channel} is free! Your AP will say thanks.').format(channel=channel)
|
||||
|
||||
def on_reading_logs(self, lines_so_far=0):
|
||||
if lines_so_far == 0:
|
||||
return self._('Reading last session logs ...')
|
||||
else:
|
||||
return self._('Read {lines_so_far} log lines so far ...').format(lines_so_far=lines_so_far)
|
||||
|
||||
def on_bored(self):
|
||||
return random.choice([
|
||||
self._('I\'m bored ...'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user