0% found this document useful (0 votes)
10 views7 pages

Python Code

The document discusses code to read data from an electrical load list Excel sheet, process the data, and write outputs to other Excel sheets. It defines classes and functions to extract tag, voltage, current and other details for various equipment from the load list. Calculations are performed to determine the total demand, proposed transformer rating, and rating of the largest motor starting kVA.

Uploaded by

Quantum Realm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Python Code

The document discusses code to read data from an electrical load list Excel sheet, process the data, and write outputs to other Excel sheets. It defines classes and functions to extract tag, voltage, current and other details for various equipment from the load list. Calculations are performed to determine the total demand, proposed transformer rating, and rating of the largest motor starting kVA.

Uploaded by

Quantum Realm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

# To read from Electrical Load list

from openpyxl import load_workbook


from openpyxl.styles import Font
import math

# Assigning Path for Electrical Load list


Read_path="D:\\Productivity\\Workspace\\Load_list_tf_sizing\\Electrical Load
list.XLSX"
#Loading the excel file to workbook_obj
workbook_obj=load_workbook(Read_path, data_only=True) # data_only = True els else
get formula used in that cell
sheet_name='6.6kV MV SWGR'
#Accessing particular Sheet in Load list
sheet=workbook_obj[sheet_name]

#Largest motor dictionary with tag,V,I


largest_motor = {}

class database:
def
__init__(self,row_no,eqpt_area,eqpt_name,eqpt_tag,voltage,eqpt_rating,bkW_rating,cu
rrent,

feeder_rating,starting_method,duty_type,switchgear,duty_factor,load_factor,power_fa
ctor,efficiency,starting_sequence,LM_starting_method,net_demand):
self.row_no = row_no
self.eqpt_area = eqpt_area
self.eqpt_name = eqpt_name
self.eqpt_tag = eqpt_tag
self.voltage = voltage
self.eqpt_rating = eqpt_rating
self.bkW_rating = bkW_rating
self.current = current
self.feeder_rating = feeder_rating
self.starting_method = starting_method
self.duty_type = duty_type
self.switchgear = switchgear
self.duty_factor = duty_factor
self.load_factor = load_factor
self.power_factor = power_factor
self.efficiency = efficiency
self.starting_sequence = starting_sequence
self.LM_starting_method = LM_starting_method

self.net_demand = net_demand
if self.starting_sequence == 1:
largest_motor[self.eqpt_tag] =
[self.LM_starting_method,self.voltage,self.current]
print("\n Largest Motor List:" , largest_motor)

def display(self):
print(self.row_no)
print(self.eqpt_area)
print(self.eqpt_name)
print(self.eqpt_tag)
print(self.voltage)
print(self.eqpt_rating)
print(self.bkW_rating)
print(self.current)
print(self.feeder_rating)
print(self.starting_method)
print(self.duty_type)
print(self.switchgear)
print(self.duty_factor)
print(self.load_factor)
print(self.power_factor)
print(self.efficiency)
print(self.net_demand)
print(self.starting_sequence)
print(self.LM_starting_method)
print("\n")

#Here element is the TO EQUIPMENT AREA LIST


element=[]

#row to tag dictionary


row_to_tag={}
#counting number of active rows

#class for storing data


for x in range(9,50):
row_no = x
eqpt_area = sheet['G'+str(x)].value
## eqpt_name = sheet['F'+str(x)].value
eqpt_tag = sheet['E'+str(x)].value

#print(temp)
if eqpt_area == None:
break
element.append(eqpt_area)
row_to_tag[row_no]=eqpt_tag

print('\n')
print("Row to Tag dic:",row_to_tag)
print("\n")
print(f"Element:{element}")
print("\n Type of Element:",type(element))
print("Length of element:",len(element))
title=list(sorted(set(element))) #Title Value
print("Title list :",title)
print(type(title))

#DATA PROCESSING

#Count dulicate
sort_element=sorted(element) #element sort
print("Sorted ELEMENT:",sort_element)
##title=list(set(sort_element))
##print("Title element:",title)
len_title=len(title) #length of title
len_sort_element=len(sort_element) #Length of sort element

print("Length of title:",len_title)
print("Length of sort_element:",len_sort_element)
#print("Title list:",title[0])

#Dictionary for duplicate entry

title_duplicate_count={}
eqpt_mapper_wrto_area={}

#print(title_duplicate_count)
for x in range(0,len_title):
count=0
temp_list=[]
for c in range(0,len_sort_element):
if title[x] == sort_element[c]:
count += 1
temp_list.insert(count-1,sheet['F'+str(c+9)].value)

title_duplicate_count[title[x]]=count
eqpt_mapper_wrto_area[title[x]]=temp_list

print("Count Dictionary:",title_duplicate_count)
print("\n\n Mapper Dictionary:",eqpt_mapper_wrto_area)
for keys,value in eqpt_mapper_wrto_area.items():
print(f'\n{keys}:{value}')

#calculation function
def round_of(current):
rounded=math.ceil(current/10.0)*10
return rounded

def round_of_thousand(value):
r = math.ceil(value/1000)*1000
return r

# function for duty factor


def duty_fac(duty_type):
if duty_type == 'C':
return 1
elif duty_type == 'I':
return 0.2
elif duty_type == 'S':
return 0

total_demand = 0
for g in range(9,len_sort_element+9):
row_no = g
eqpt_area = sheet['G'+str(g)].value
eqpt_name = sheet['F'+str(g)].value
eqpt_tag = sheet['E'+str(g)].value
voltage = sheet['I'+str(g)].value
voltage=round(voltage)
eqpt_rating = sheet['J'+str(g)].value
eqpt_rating = round(eqpt_rating,2)
bkW_rating = sheet['J'+str(g)].value
bkW_rating = round(bkW_rating,2)
current = sheet['M'+str(g)].value
current=round(current,2)
starting_method = sheet['N'+str(g)].value
duty_type = sheet['O'+str(g)].value
switchgear = sheet['P'+str(g)].value
power_factor = sheet['Q'+str(g)].value
power_factor = round(power_factor,3)
efficiency = sheet['S'+str(g)].value
efficiency = round(efficiency,3)
feeder_rating = round_of(current)
duty_factor = duty_fac(duty_type)
load_factor = round(bkW_rating/eqpt_rating)
starting_sequence = sheet['T'+str(g)].value
LM_starting_method = sheet['U'+str(g)].value
net_demand = round((eqpt_rating * load_factor * duty_factor)/(power_factor))

row_to_tag[row_no] =
database(row_no,eqpt_area,eqpt_name,eqpt_tag,voltage,eqpt_rating,bkW_rating,

current,feeder_rating,starting_method,duty_type,switchgear,duty_factor,

load_factor,power_factor,efficiency,starting_sequence,LM_starting_method,net_demand
)

row_to_tag[row_no].display()
total_demand += row_to_tag[row_no].net_demand
print("\n Total_demand =", total_demand) # We get total demand
print("\n")

margin = round(total_demand * 1.1)


proposed_transformer = round_of_thousand(margin) #Transformer value with margin
print('Margin:',margin)
print('set_transformer:',proposed_transformer) # We get proposed transformer Rating

def starting_kVA(s_type,V,I):
if s_type == 'DOL':
x_time = 6.6
elif s_type == 'VFD':
x_time = 2.5
motor_starting_kVA = math.ceil(((math.sqrt(3)*V*I*x_time)/(1000)))
return motor_starting_kVA

#LARGEST MOTOR FINDING


tag_list_largest_motor = list(largest_motor.keys()) # we get first sequence tags as
list
print('tag list of largest motor :',tag_list_largest_motor)
largest_motor_tag={}

for j in range(0,len(tag_list_largest_motor)):
Temp = largest_motor[tag_list_largest_motor[j]]
start_type = Temp[0]
Potential = Temp[1]
Ampere = Temp[2]
largest_kVA = starting_kVA(start_type,Potential,Ampere)
largest_motor_tag[tag_list_largest_motor[j]] = largest_kVA # we get
{tag:rating,'fds,:10390,'df':87238}
print("Largest_motor_tag_list :",largest_motor_tag)

def value_to_key(dics,value_of_dic):
for key,value in dics.items():
if value_of_dic == value:
return key

#L_Motor_tag = max(largest_motor_tag.keys()) #we get largest motor tag


lmotor_value = max(largest_motor_tag.values())

#The above line is set comprehension for more information


https://www.almabetter.com/bytes/tutorials/python/set-comprehension-in-python

L_Motor_tag = value_to_key(largest_motor_tag,lmotor_value)

print("Largest motor tag ",L_Motor_tag,"Largest Motor value:",lmotor_value)


print("Type of motor tag :",type(L_Motor_tag),'type of motor
value :',type(lmotor_value))

Largest_motor_starting_kVA_consumption = lmotor_value #we get largest starting


kva value

L_motor_row = value_to_key(row_to_tag,L_Motor_tag)

print('L motor Row number :',L_motor_row)

Required_Transformer_Rating = total_demand + Largest_motor_starting_kVA_consumption


- row_to_tag[L_motor_row].net_demand

cyclic_loading = proposed_transformer * 1.5

while cyclic_loading <= Required_Transformer_Rating:


proposed_transformer += 1000
cyclic_loading = proposed_transformer * 1.5
print("Proposed Transformer rating:",proposed_transformer)
print("cyclic loading value:",cyclic_loading)

# TO WRITE IN TRANSFORMER SIZING

#path for TF sizing excel


Write_path = "D:\\Productivity\\Workspace\\Load_list_tf_sizing\\UAT Transformer
sizing.xlsx"

wr_workbook=load_workbook(Write_path)
#select the required sheet from excel
wr_sheet_name='UAT'
wr_sheet=wr_workbook[wr_sheet_name]
# Writing the value in write file
print("Title 0 :",title[0])

initial_row=7

#The below function give the respective equipment Based on Area


def fetch(rows,title_index):
temp_list=eqpt_mapper_wrto_area[title[title_index]]
for x in range(1,len(temp_list)+1):
if rows == x:
return temp_list[x-1]

#Function for working and standby


def working_standby(row_num,read_row):
D_value = 0
E_value = 0
if(row_to_tag[read_row].duty_type == 'C'):
D_value = 1
wr_sheet['D'+str(row_num)]= 1
wr_sheet['E'+str(row_num)]= 0
if(row_to_tag[read_row].duty_type == 'S'):
E_value = 1
wr_sheet['D'+str(row_num)]= 0
wr_sheet['E'+str(row_num)]= 1

#Function for Bus entry


def bus(row_num,read_row):
if(row_to_tag[read_row].switchgear == 1):
wr_sheet['G'+str(row_num)]= 1
wr_sheet['H'+str(row_num)]= 0
if(row_to_tag[read_row].switchgear == 2):
wr_sheet['G'+str(row_num)]= 0
wr_sheet['H'+str(row_num)]= 1

#Function for kw,current,V,Load type,Duty_cycle,PF,Efficiency entry


def total_entry(row_num,read_row):
wr_sheet['J'+str(row_num)]= row_to_tag[read_row].eqpt_rating
wr_sheet['I'+str(row_num)]= row_to_tag[read_row].bkW_rating
wr_sheet['L'+str(row_num)]= row_to_tag[read_row].current
wr_sheet['M'+str(row_num)]= row_to_tag[read_row].feeder_rating
wr_sheet['N'+str(row_num)]= row_to_tag[read_row].voltage
wr_sheet['O'+str(row_num)]= row_to_tag[read_row].starting_method
wr_sheet['R'+str(row_num)]= row_to_tag[read_row].duty_type
wr_sheet['S'+str(row_num)]= row_to_tag[read_row].duty_factor
wr_sheet['T'+str(row_num)]= row_to_tag[read_row].load_factor
wr_sheet['U'+str(row_num)]= row_to_tag[read_row].power_factor
wr_sheet['V'+str(row_num)]= row_to_tag[read_row].efficiency
wr_sheet['C'+str(row_num)]= row_to_tag[read_row].eqpt_tag

def AB_bus(row_num,read_row):
if(row_to_tag[read_row].switchgear == 1):
wr_sheet['Q'+str(row_num)]= 'A'
wr_sheet['W'+str(row_num)] = row_to_tag[read_row].net_demand
wr_sheet['Y'+str(row_num)] = row_to_tag[read_row].net_demand
#return row_to_tag[read_row].net_demand
elif(row_to_tag[read_row].switchgear == 2):
wr_sheet['Q'+str(row_num)]= 'B'
wr_sheet['X'+str(row_num)] = row_to_tag[read_row].net_demand
wr_sheet['Y'+str(row_num)] = row_to_tag[read_row].net_demand
#return row_to_tag[read_row].net_demand

def write():
global current_row
current_row =7
global read_row
read_row =9
global total_demand
total_demand =0
S_no = 1
for total_iterate in range(1,len(title)+1):
if total_iterate != 1:
current_row +=1
wr_sheet['B'+str(current_row)]=title[total_iterate-1]
wr_sheet['B'+str(current_row)].font = Font(bold=True)
for rows in range(1,title_duplicate_count[title[total_iterate-1]]+1):
current_row +=1
if rows != 1:
read_row +=1
#wr_sheet.insert_rows(idx=current_row)
#two writing method
wr_sheet['A'+str(current_row)] = S_no
S_no += 1
wr_sheet['B'+str(current_row)]=fetch(rows,total_iterate-1)
##sheet['C10']=int(input("Enter the Value to feed:"))
working_standby(current_row,read_row)
##sheet.cell(row=11, column=3, value=3.14) # Assign 3.14 to cell C11
bus(current_row,read_row)
total_entry(current_row,read_row)
#total_demand += AB_bus(current_row,read_row)

#print('Total demand:',total_demand)
margin = round(total_demand * 1.1)
Req_transformer = round_of(margin)
print('Margin:',margin)
print('set_transformer:',Req_transformer)

write()
# We can only able to save the loaded workbook
wr_workbook.save(Write_path)

You might also like