# 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
  v=[0.0 for i in range(numcells+1)]
  endlog=tail(config['files']['logfile'],11)
  for j in range(1,numcells+1):
    for i in range(10):
      x=float(endlog[i][(j-1)*6+15:(j-1)*6+20])+config['calibrate']['delta'][j-1]
      v[j]=v[j]+x
  for i in range(1,len(v)):
    v[i]=v[i]/10+v[i-1]
    vstr=vstr+str(i) + "=" +str(round(v[i],3)).ljust(5,'0') + ", "
  print(vstr)
  print(config['calibrate']['measured'])
  print(config['calibrate']['displayed'])
  return v

def main():
  print('Usage: Pressing just the [Enter] key will display the latest voltage readings, type ^C to exit')
  print('       Type in the cell # that you want to calibrate followed by [Enter]')
  print('       Then type in the mesured voltage for that cell followed by [Enter]')
  print()
  print('       Make sure the Battery Monitoring software is running otherwise the summary file will not be current')
  print('       This program uses the data from the log file generated by the Battery Monitoring software')
  print('       Make sure that the Battery Monitoring software is logging to a real file and not /dev/null')
  print('       This program averages the data from the log file for the last 100 seconds.')
  print('       To make sure that the calibration is accurate make sure the input voltages are not varying')
  avvolts=[]
  while True:
    try:
      loadconfig()
      avvolts=avv()
#      time.sleep(60.0)

# 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

  v=[0.0 for i in range(numcells+1)]
  endlog=tail(config['files']['logfile'],11)
  for j in range(1,numcells+1):
    for i in range(10):
      x=float(endlog[i][(j-1)*6+15:(j-1)*6+20])+config['calibrate']['delta'][j-1]
      v[j]=v[j]+x
  for i in range(1,len(v)):
    v[i]=v[i]/10+v[i-1]
    vstr=vstr+str(i) + "=" +str(round(v[i],3)).ljust(5,'0') + ", "
  print(vstr)
  print(config['calibrate']['measured'])
  print(config['calibrate']['displayed'])
  return v

def main():
  print('Usage: Pressing just the [Enter] key will display the latest voltage readings, type ^C to exit')
  print('       Type in the cell # that you want to calibrate followed by [Enter]')
  print('       Then type in the mesured voltage for that cell followed by [Enter]')
  print()
  print('       Make sure the Battery Monitoring software is running otherwise the summary file will not be current')
  print('       This program uses the data from the log file generated by the Battery Monitoring software')
  print('       Make sure that the Battery Monitoring software is logging to a real file and not /dev/null')
  print('       This program averages the data from the log file for the last 100 seconds.')
  print('       To make sure that the calibration is accurate make sure the input voltages are not varying')
  avvolts=[]
  while True:
    try:
      loadconfig()
      avvolts=avv()
#      time.sleep(60.0)

      what = input(">")