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


from config import config
minmaxdemandpwr = [0,0]

def solaravailable(batdata):
  """Returns max amount of surpus solar energy available without using battery Power
     Calculates the difference between amount of power being consumed vesus
     power that could be consumed to get battery current=IBatZero"""

  global minmaxdemandpwr
  ibatminuteav=batdata.ibatminute/batdata.ibatnuminmin
  batdata.ibatminute = 0.0
  batdata.ibatnuminmin = 0

  minsoc = config['battery']['targetsoc'] -config['battery']['minsocdif']
  soc=1-batdata.socadj/config['battery']['capacity']

  """  iavailable=(IBatZero-ibatminuteav)
  #iavailable=iavailable+config['battery']['maxchargerate']* \
  #           (soc-config['battery']['targetsoc'])*20
  iavailable=(soc\
             -config['battery']['targetsoc'])*config['battery']['capacity']\
             *config['DemandManager']['socfeedback'] \
             -ibatminuteav*config['DemandManager']['currentfeedback']"""

  # calcualte power available as current I plus amount to get SOC to target in one minute
  iavailable=60*((1-config['battery']['targetsoc'])*config['battery']['capacity']-batdata.socadj)\
             -batdata.currentav[-3]
  pwravailable=iavailable*batdata.batvoltsav[config['battery']['numcells']+1]
  if soc<minsoc:
    minmaxdemandpwr[1]=0
  elif soc>=config['battery']['targetsoc']:

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


# Path: demandmanager.py
from config import config

minmaxdemandpwr = [0,0]

def solaravailable(batdata):
  """Returns max amount of surpus solar energy available without using battery Power
     Calculates the difference between amount of power being consumed vesus
     power that could be consumed to get battery current=IBatZero"""

  global minmaxdemandpwr
  ibatminuteav=batdata.ibatminute/batdata.ibatnuminmin
  batdata.ibatminute = 0.0
  batdata.ibatnuminmin = 0

  minsoc = config['battery']['targetsoc'] -config['battery']['minsocdif']
  soc=1-batdata.socadj/config['battery']['capacity']

  """  iavailable=(IBatZero-ibatminuteav)
  #iavailable=iavailable+config['battery']['maxchargerate']* \
  #           (soc-config['battery']['targetsoc'])*20
  iavailable=(soc\
             -config['battery']['targetsoc'])*config['battery']['capacity']\
             *config['DemandManager']['socfeedback'] \
             -ibatminuteav*config['DemandManager']['currentfeedback']"""

  # calcualte power available as current I plus amount to get SOC to target in one minute
  iavailable=60*((1-config['battery']['targetsoc'])*config['battery']['capacity']-batdata.socadj)\
             -batdata.currentav[-3]
  pwravailable=iavailable*batdata.batvoltsav[config['battery']['numcells']+1]
  if soc<minsoc:
    minmaxdemandpwr[1]=0
  elif soc>=config['battery']['targetsoc']:

    minmaxdemandpwr[1]=config['DemandManager']['maxdemandpwr']