0% found this document useful (0 votes)
3 views

Text Code File of Charging and Discharging

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Text Code File of Charging and Discharging

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

############## time code start

def convert_to_24_hour(time_str):
"""converts 12-hour time format to 24-hour format."""
#for fetching the am or pm from user input for both lower and upper case
period = time_str[-2:].upper() or time_str[-2:].lower() # Get AM/PM or am/pm
#converting the input time to string and splitting through ":"
time_parts = time_str[:-2].strip().split(":")
hours, minutes, seconds = map(int, time_parts)

if period == "PM" or "pm" and hours != 12:


hours += 12
#in case of midnight time
elif period == "AM" or "am" and hours == 12:
hours = 0

return f"{hours:02}:{minutes:02}:{seconds:02}"

def time_in_seconds(time_str):
"""converts time in 'HH:MM:SS' format to total seconds."""
hours, minutes, seconds = map(int, time_str.split(':'))
return hours * 3600 + minutes * 60 + seconds

#function to handle time input in either 12-hour or 24-hour format


def get_time_input(time_str):
if 'AM' in time_str.upper() or 'PM' in time_str.upper() or 'am' in
time_str.lower() or 'pm' in time_str.lower():
time_str = convert_to_24_hour(time_str)
return time_str

#function to process the arrays for start and end times


def process_time_array(start_times, end_times):
total_time_array = []

for i in range(len(start_times)):
#convert times to 24-hour format if needed
start_time = get_time_input(start_times[i])
end_time = get_time_input(end_times[i])

#calculate total seconds for start and end times


start_seconds = time_in_seconds(start_time)
end_seconds = time_in_seconds(end_time)

#handle the case where the end time is past midnight


if end_seconds < start_seconds:
end_seconds += 24 * 3600

total_seconds = end_seconds - start_seconds


total_time_array.append(total_seconds)

return total_time_array

#input arrays for start and end times


start_times = input("Enter start times separated by commas (e.g., 02:30:45 PM,
14:30:45): ").split(",")
end_times = input("Enter end times separated by commas (e.g., 05:30:45 PM,
17:30:45): ").split(",")
#ensure both arrays have the same length
if len(start_times) != len(end_times):
print("Error: The number of start times must match the number of end times.")
else:
#process the arrays and calculate total time in seconds for each pair
total_time_in_seconds = process_time_array(start_times, end_times)

#display results
for i, total_seconds in enumerate(total_time_in_seconds):
print(f"Total time in seconds from start time {start_times[i].strip()} to
end time {end_times[i].strip()}: {total_seconds} seconds")

time=total_seconds
print(time)
###########timr code end

######input for finding the soc

#code for find the battery %while charging and discharging and power delivered to
load and by load

#nominal capacity
un=int(input("enter (un) the nominal capacity in Ah = "))

#voltage supplied to/by the battery


Volt=int(input("enter the battery volt supplied = "))

#charging current
curf=int(input("enter the charging currentin amp = "))

#discharging current
curr=int(input("enter the discharging current = "))

###### when resistance is given

# when resistance is given for finding the current


ress=int(input("enter the resistive load in ohm "))

#resistance case code start


if(ress!=0):
#load current = battery current = charging or discharging currnet IA
IA=(Volt/ress)
print("load current or battery in A = ",IA," A")

# resistance case charging


if(IA>=0):
ut=((IA*time)/3600)
print("charge stored in battery(ut) in Ah = ",int(ut),"Ah")
#cal for % of Battery
SOCt=((ut/un)*100)
if(SOCt>=100):
print("soc of battery= ",100,"%")
else:
print("soc of battery= ",SOCt,"%")
#cal for power delivered to load
if ( Volt>=0 ) :
P=ut*Volt
print("power delivered to load",P,"watt-hour")

#resistance case discharging


if(IA<=0):
ut=((IA*time)/3600)
print("charge discharged from battery(ut) in Ah = ",int(ut),"Ah")
#cal for %of battery
SOCt=((ut/un)*100)
ASOCt=100-SOCt
print("Discharged State of Battery in % = ",ASOCt,"%")
#cal for power delivered by load
if ( Volt>=0 ) :
P=ut*Volt
print("power delivered by load",P,"watt-hour")

#####resistance case code end


#######when resistance is not given

if(curf!=0):
ut=((curf*time)/3600)##because time in sec and unit is coulamb so dividing by
3600 for Ah
print("charge stored in battery(ut) in Ah = ",int(ut),"Ah")

#cal for % of Battery


SOCt=((ut/un)*100)
if(SOCt>=100):
print("soc of battery= ",100,"%")
else:
print("soc of battery= ",SOCt,"%")

#cal for power delivered to load


if ( Volt>=0 ) :
P=ut*Volt
print("power delivered to load",P,"watt-hour")

if(curr!=0):
ut=((curr*time)/3600)##curr is dischrge current at time , this diaplay
discharge of battry
print("charge discharged from battery(ut) in Ah = ",int(ut),"Ah")

#cal for %of battery


SOCt=((ut/un)*100)
ASOCt=100-SOCt

print("Discharged State of Battery in % = ",ASOCt,"%")

#cal for power delivered by load


if ( Volt>=0 ) :
P=ut*Volt
print("power delivered by load = ",P,"watt-hour")

You might also like