Преглед на файлове

Add method used when calculating ihs values

ogert преди 4 години
родител
ревизия
0fbab3b325
променени са 1 файла, в които са добавени 35 реда и са изтрити 0 реда
  1. 35 0
      cdplib/db_migration/MigrationCleaning.py

+ 35 - 0
cdplib/db_migration/MigrationCleaning.py

@@ -638,6 +638,41 @@ class MigrationCleaning:
 
         return data
 
+
+    def label_is_level(
+                    self,
+                    data: pd.DataFrame, 
+                    column: str = "is", 
+                    include_schrott: bool = False, 
+                    drop_rows_with_no_is: bool = False) -> pd.DataFrame:
+        '''
+        '''
+
+        is_level_mapping = {0: None,
+                            1: ["IS1"],
+                            2: ["IS1L", "IL", "IS1 + IL"],
+                            3: ["IS2"],
+                            4: ["IS3"]}
+
+        for k, v in is_level_mapping.items():
+            if v is not None:
+                data.loc[data[column].isin(v), column] = k
+            else:
+                data.loc[data[column].isnull(), column] = k
+        
+        if include_schrott and ("operation_type_2" in data.columns):
+            schrott_mask = (data["operation_type_2"] == 2)
+            data.loc[schrott_mask, column] = 5
+        
+        data.loc[~data[column].isin([0,1,2,3,4,5]), column] = 0
+                    
+        if drop_rows_with_no_is:
+            data = data.loc[data[column] != 0].copy(deep=True)
+            
+        return data.reset_index(drop=True)
+
+
+
 if __name__ == "__main__":
 
     # testing