From 8af56040349092520b2905a4c0517b4e43e6f962 Mon Sep 17 00:00:00 2001
From: Simone Margaritelli <evilsocket@gmail.com>
Date: Wed, 9 Oct 2019 11:59:11 +0200
Subject: [PATCH] fix: fixed a LastSession bug which prevented the grid plugin
 from working when no previous session was available (fixes #228)

---
 pwnagotchi/log.py | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/pwnagotchi/log.py b/pwnagotchi/log.py
index 0f05789..fa3ddc1 100644
--- a/pwnagotchi/log.py
+++ b/pwnagotchi/log.py
@@ -22,6 +22,29 @@ class LastSession(object):
     HANDSHAKE_TOKEN = '!!! captured new handshake '
     PEER_TOKEN = 'detected unit '
 
+    def __init__(self, config):
+        self.config = config
+        self.voice = Voice(lang=config['main']['lang'])
+        self.path = config['main']['log']
+        self.last_session = []
+        self.last_session_id = ''
+        self.last_saved_session_id = ''
+        self.duration = ''
+        self.duration_human = ''
+        self.deauthed = 0
+        self.associated = 0
+        self.handshakes = 0
+        self.peers = 0
+        self.last_peer = None
+        self.epochs = 0
+        self.train_epochs = 0
+        self.min_reward = 1000
+        self.max_reward = -1000
+        self.avg_reward = 0
+        self._peer_parser = re.compile(
+            'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)\]')
+        self.parsed = False
+
     def _get_last_saved_session_id(self):
         saved = ''
         try:
@@ -158,26 +181,5 @@ class LastSession(object):
         self._parse_stats()
         self.parsed = True
 
-    def __init__(self, config):
-        self.config = config
-        self.voice = Voice(lang=config['main']['lang'])
-        self.path = config['main']['log']
-        self.last_session = None
-        self.last_session_id = ''
-        self.last_saved_session_id = ''
-        self.duration = ''
-        self.duration_human = ''
-        self.deauthed = 0
-        self.associated = 0
-        self.handshakes = 0
-        self.peers = 0
-        self.last_peer = None
-        self._peer_parser = re.compile(
-            'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)\]')
-        self.last_session = []
-        self.last_session_id = None
-        self.last_saved_session_id = None
-        self.parsed = False
-
     def is_new(self):
         return self.last_session_id != self.last_saved_session_id