associatedlocation finished
This commit is contained in:
@ -9,6 +9,7 @@ country_mapping = {
|
||||
read_df = pd.read_csv('../1_extract_data/results/SCInstalledBaseLocation__c.csv', header=0, keep_default_na=False, dtype=str)
|
||||
read_df_ib = pd.read_csv('../1_extract_data/results/SCInstalledBase__c.csv', header=0, keep_default_na=False, dtype=str)
|
||||
read_df_product2 = pd.read_csv('../1_extract_data/results/Product2.csv', header=0, keep_default_na=False, dtype=str)
|
||||
read_df_ibr = pd.read_csv('../1_extract_data/results/SCInstalledBaseRole__c.csv', header=0, keep_default_na=False, dtype=str)
|
||||
|
||||
for row in read_df.to_dict('records'):
|
||||
try:
|
||||
@ -28,11 +29,14 @@ reindex_columns_ib = ['Id','Name','CommissioningDate__c','InstallationDate__c','
|
||||
#"Id","Main_Product_Group__c","Family","MaterialType__c","Name","Product_Code__c","ProductCode","EAN_Product_Code__c"
|
||||
reindex_columns_product2 = ['Id','Main_Product_Group__c','Family','MaterialType__c','Name','Product_Code__c','ProductCode','EAN_Product_Code__c']
|
||||
#reindex_columns_product2 = ['EAN_Product_Code__c','Family','Id','Main_Product_Group__c','MaterialType__c','Name','Product_Code__c','ProductCode']
|
||||
#"Id","InstalledBaseLocation__c","Role__c","ValidFrom__c","ValidTo__c","Account__c"
|
||||
reindex_columns_ibr = ['Id', 'InstalledBaseLocation__c', 'Role__c', 'ValidFrom__c', 'ValidTo__c', 'Account__c']
|
||||
|
||||
# Reindex the columns to match the desired format
|
||||
df = read_df.reindex(reindex_columns, axis=1)
|
||||
df_ib = read_df_ib.reindex(reindex_columns_ib, axis=1)
|
||||
df_product2 = read_df_product2.reindex(reindex_columns_product2, axis=1)
|
||||
df_ibr = read_df_ibr.reindex(reindex_columns_ibr, axis=1)
|
||||
|
||||
df['Street'] = (
|
||||
df['Street__c'].astype(str) + ' ' +
|
||||
@ -117,7 +121,7 @@ parent_df['IsMobile'] = 'false'
|
||||
parent_df['LocationType'] = 'Site'
|
||||
|
||||
## 3. Child_Location.csv
|
||||
child_columns = ['Extension__c', 'FlatNo__c', 'Floor__c', 'City__c', 'Country__c',
|
||||
child_columns = ['Id', 'Extension__c', 'FlatNo__c', 'Floor__c', 'City__c', 'Country__c',
|
||||
'PostalCode__c', 'Street', 'PKey__c']
|
||||
# Modify child_df by explicitly creating a new DataFrame
|
||||
child_df = df[child_columns].copy() # Add .copy() to create an explicit copy
|
||||
@ -142,7 +146,7 @@ child_df['ExternalReference'] = (
|
||||
)
|
||||
|
||||
# Rename columns to match the desired format
|
||||
child_df.columns = ['Extension__c', 'Flat__c', 'Floor__c', 'City', 'Country',
|
||||
child_df.columns = ['Id', 'Extension__c', 'Flat__c', 'Floor__c', 'City', 'Country',
|
||||
'PostalCode', 'Street', 'PKey__c', 'Name', 'ExternalReference']
|
||||
|
||||
child_df = child_df.drop_duplicates(subset=['Extension__c', 'Flat__c', 'Floor__c','City', 'Country', 'PostalCode', 'Street'], keep='first')
|
||||
@ -180,11 +184,33 @@ merged_df_ib = merged_df_ib.drop('Product_Code__c', axis=1)
|
||||
|
||||
merged_df_ib = merged_df_ib.drop_duplicates(subset=['Name','SerialNumber'], keep='first')
|
||||
|
||||
# Merging LPG into one Value for Assets
|
||||
merged_df_ib = merged_df_ib.replace({'Kind_of_Energy__c': {'4': '3', '5': '3'}})
|
||||
|
||||
## 5. SCInstalledBaseRole__c.csv
|
||||
|
||||
df_ibr = pd.merge(df_ibr,
|
||||
child_df[['Id', 'ExternalReference']],
|
||||
left_on='InstalledBaseLocation__c',
|
||||
right_on='Id',
|
||||
how='left')
|
||||
|
||||
df_ibr = df_ibr.drop_duplicates(subset=['InstalledBaseLocation__c', 'Role__c', 'Account__c'], keep='first')
|
||||
|
||||
df_ibr = df_ibr.drop('Id_x', axis=1)
|
||||
df_ibr = df_ibr.drop('Id_y', axis=1)
|
||||
df_ibr = df_ibr.drop('InstalledBaseLocation__c', axis=1)
|
||||
|
||||
print(df_ibr.columns)
|
||||
|
||||
df_ibr.columns = ['Type', 'ActiveFrom', 'ActiveTo', 'ParentRecordId', 'Location.ExternalReference']
|
||||
|
||||
#remove kind_of_energy__c and kind_of_installation if field dependency to main product group is not correct
|
||||
# Create the mapping dictionary
|
||||
kind_of_energy_mapping = {
|
||||
'1': ['A2', 'A1', 'B2', 'B1', 'E1', '14', 'E3', '17'],
|
||||
'2': ['A2', 'A1', 'B2', 'B1', 'E1', '14', 'E3', '17'],
|
||||
'3': ['A2', 'A1', 'B2', 'B1', 'E1', '14', 'E3', '17'],
|
||||
'G': ['A2', 'A1', 'B2', 'B1', 'E1', 'E3', '17'],
|
||||
'6': ['B3', '11', '13', '14', '17'],
|
||||
'8': ['B4'],
|
||||
@ -227,6 +253,7 @@ address_df.to_csv('../3_upsert_address_and_parent_location/Address.csv', index=F
|
||||
parent_df.to_csv('../3_upsert_address_and_parent_location/Location.csv', index=False)
|
||||
child_df.to_csv('../5_upsert_child_location/Location.csv', index=False)
|
||||
merged_df_ib.to_csv('../7_upsert_assets/Asset.csv', index=False)
|
||||
df_ibr.to_csv('../9_upsert_associated_location/AssociatedLocation.csv', index=False)
|
||||
|
||||
## end mapping
|
||||
|
||||
|
Reference in New Issue
Block a user