# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


import sys
import time
from os import rename
from shutil import copy as filecopy
from copy import deepcopy
from ast import literal_eval
from configparser import SafeConfigParser
from config import config,loadconfig
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


numcells = config['battery']['numcells']
voltages = []
avv = []


summaryfile = SafeConfigParser()

def tail(file, n=1, bs=1024):
    f = open(file,'rb')
    f.seek(-1,2)
    l = 1-f.read(1).decode('utf-8').count('\n') # If file doesn't end in \n, count it anyway.
    B = f.tell()
    while n >= l and B > 0:
            block = min(bs, B)
            B -= block
            f.seek(B, 0)
            x = f.read(block).decode('utf-8')
            l += x.count('\n')
    f.seek(B, 0)
    l = min(l,n) # discard first (incomplete) line if l > n
    lines = f.readlines()[-l:]
    f.close()
    return lines

def avv():
  vstr=""
  v=[0.0 for i in range(numcells+1)]

# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


# Path: calvcourse.py
import sys
import time
from os import rename
from shutil import copy as filecopy
from copy import deepcopy
from ast import literal_eval
from configparser import SafeConfigParser
from config import config,loadconfig

# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


numcells = config['battery']['numcells']
voltages = []
avv = []


summaryfile = SafeConfigParser()

def tail(file, n=1, bs=1024):
    f = open(file,'rb')
    f.seek(-1,2)
    l = 1-f.read(1).decode('utf-8').count('\n') # If file doesn't end in \n, count it anyway.
    B = f.tell()
    while n >= l and B > 0:
            block = min(bs, B)
            B -= block
            f.seek(B, 0)
            x = f.read(block).decode('utf-8')
            l += x.count('\n')
    f.seek(B, 0)
    l = min(l,n) # discard first (incomplete) line if l > n
    lines = f.readlines()[-l:]
    f.close()
    return lines

def avv():
  vstr=""
  v=[0.0 for i in range(numcells+1)]

  endlog=tail(config['files']['logfile'],11)