DAG: SierraGorda_BrightBoard Functions that clean data in files related to SierraGorda

schedule: 30,30 12,0 * * *


Task Instance: BrighBoard_GenerarCruceAutonomas


Task Instance Details

Dependencies Blocking Task From Getting Scheduled
Dependency Reason
Dagrun Running Task instance's dagrun was not in the 'running' state but in the state 'failed'.
Task Instance State Task is in the 'success' state which is not a valid state for execution. The task must be cleared in order to be run.
Attribute: python_callable
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def generar_dataset_autonomas(origin_drilled_hole_container, origin_drilled_hole_blob, origin_mwd_hole_sm_container, origin_mwd_hole_sm_blob, origin_mwd_hole_container, origin_mwd_hole_blob, origin_rig_container, origin_rig_blob, final_container, final_blob, rango_dias): 
    """
    Función que permite generar un archivo final con los datos de DrilledHoleTransaction, MwdHoleSM, MwdHole y Rig

    Parámetros
    ----------
    origin_drilled_hole_container: str
        Nombre del contenedor donde se encuentra el archivo DrilledHoleTransaction.
    origin_drilled_hole_blob: str
        Nombre del archivo DrilledHoleTransaction.
    origin_mwd_hole_sm_container: str
        Nombre del contenedor donde se encuentra el archivo MwdHoleSM.
    origin_mwd_hole_sm_blob: str
        Nombre del archivo MwdHoleSM.
    origin_mwd_hole_container: str
        Nombre del contenedor donde se encuentra el archivo MwdHole.
    origin_mwd_hole_blob: str
        Nombre del archivo MwdHole.
    origin_rig_container: str
        Nombre del contenedor donde se encuentra el archivo Rig.
    origin_rig_blob: str
        Nombre del archivo Rig.
    final_container: str
        Nombre del contenedor donde se guardará el archivo final.
    final_blob: str
        Nombre del archivo final.

    Returns
    -------
    None
    """

    # Archivo DrilledHoleTransaction
    conn_origin_drilled_hole = BlobClient.from_connection_string(conn_str=BLOB_CONNECT_STRING, container_name=origin_drilled_hole_container, blob_name=origin_drilled_hole_blob)
   
    try: 
        download_drilled_hole = conn_origin_drilled_hole.download_blob().readall()
        data_drilled_hole = json.loads(download_drilled_hole)
        df_drilled_hole = pd.DataFrame(data_drilled_hole['values'], columns=data_drilled_hole['headers'])
    except:
        download_drilled_hole = conn_origin_drilled_hole.download_blob()
        df_drilled_hole = pd.read_json(download_drilled_hole, orient='table')

    # Archivo MwdHoleSM
    conn_origin_mwd_hole_sm = BlobClient.from_connection_string(conn_str=BLOB_CONNECT_STRING, container_name=origin_mwd_hole_sm_container, blob_name=origin_mwd_hole_sm_blob)
   
    try: 
        download_mwd_hole_sm = conn_origin_mwd_hole_sm.download_blob().readall()
        data_mwd_hole_sm = json.loads(download_mwd_hole_sm)
        df_mwd_hole_sm = pd.DataFrame(data_mwd_hole_sm['values'], columns=data_mwd_hole_sm['headers'])
    except:
        download_mwd_hole_sm = conn_origin_mwd_hole_sm.download_blob()
        df_mwd_hole_sm = pd.read_json(download_mwd_hole_sm, orient='table')
    
    # Archivo MwdHole
    conn_origin_mwd_hole = BlobClient.from_connection_string(conn_str=BLOB_CONNECT_STRING, container_name=origin_mwd_hole_container, blob_name=origin_mwd_hole_blob)
   
    try: 
        download_mwd_hole = conn_origin_mwd_hole.download_blob().readall()
        data_mwd_hole = json.loads(download_mwd_hole)
        df_mwd_hole = pd.DataFrame(data_mwd_hole['values'], columns=data_mwd_hole['headers'])
    except:
        download_mwd_hole = conn_origin_mwd_hole.download_blob()
        df_mwd_hole = pd.read_json(download_mwd_hole, orient='table')

    # Archivo Rig
    conn_origin_rig = BlobClient.from_connection_string(conn_str=BLOB_CONNECT_STRING, container_name=origin_rig_container, blob_name=origin_rig_blob)
   
    try: 
        download_rig = conn_origin_rig.download_blob().readall()
        data_rig = json.loads(download_rig)
        df_rig = pd.DataFrame(data_rig['values'], columns=data_rig['headers'])
    except:
        download_rig = conn_origin_rig.download_blob()
        df_rig = pd.read_json(download_rig, orient='table')

    """
        Procesamiento de archivos
    """

    """ Calculando campos """
    df_mwd_hole_sm['Time'] = df_mwd_hole_sm['Time'].astype('datetime64[ns]')
    df_mwd_hole_sm['DrillTime'] = (df_mwd_hole_sm.groupby('MwdHoleId')['Time'].transform('max') -
    df_mwd_hole_sm.groupby('MwdHoleId')['Time'].transform('min')).dt.total_seconds()/60

    df_mwd_hole_sm = df_mwd_hole_sm.groupby(['MwdHoleId','DrillTime'])['Depth'].max().reset_index()

    """ Primer cruce """
    df_mwd_hole = df_mwd_hole.rename(columns={'Id': 'MwdHoleId'})
    df_mwd_hole_full = df_mwd_hole_sm.merge(df_mwd_hole, how='left', left_on=['MwdHoleId'], right_on=['MwdHoleId'], indicator=True)
    df_mwd_hole_full = df_mwd_hole_full.drop(columns=['_merge'])

    """ Segundo cruce """
    df = df_mwd_hole_full.merge(df_rig, how='left', left_on=['RigSerialNumber'], right_on=['SerialNumber'], indicator=True)
    df = df.drop(columns=['_merge'])

    """ Tercer cruce """
    df['RigSerialNumber'] = df['RigSerialNumber'].astype(str)
    df_drilled_hole['RigSerialNumber'] = df_drilled_hole['RigSerialNumber'].astype(str)

    df_full = df_drilled_hole.merge(df, how='left', left_on=['HoleId', 'RigSerialNumber', 'PreviousStartTime', 'PreviousEndTime'], right_on=['HoleId', 'RigSerialNumber', 'StartLogTime', 'EndLogTime'], indicator=True)

    if len(df_full.index) == 0: 
        columnas = ['Id_x', 'TransactionType', 'TransactionTime', 'UserLogin', 'Comment',
                    'DrillPlanName', 'HoleId', 'RigSerialNumber', 'PreviousStartTime',
                    'PreviousEndTime', 'HoleName_x', 'StartHoleTime', 'EndHoleTime',
                    'EndPointX', 'EndPointY', 'EndPointZ', 'StartPointX', 'StartPointY',
                    'StartPointZ', 'DrillBitDiameter', 'Status', 'MwdHoleId', 'DrillTime',
                    'Depth', 'DrillPlanId', 'StartLogTime', 'EndLogTime', 'SampleDistance',
                    'DrillMethodId', 'HoleName_y', 'Id_y', 'Name', 'SerialNumber',
                    'RigInformationDate', 'ExportPath', 'RRAStatusId', 'HasGps',
                    'EquipmentType', 'IsArchived', '_merge']

        df = pd.DataFrame(columns=columnas)
        blob = BlobClient.from_connection_string(conn_str=BLOB_CONNECT_STRING, container_name=final_container, blob_name=final_blob)

        json_data = df.to_json(index=False, orient='table')
        blob.upload_blob(json_data, overwrite=True)  

        return None    

    blob = BlobClient.from_connection_string(conn_str=BLOB_CONNECT_STRING, container_name=final_container, blob_name=final_blob)
    json_data = df_full.to_json(index=False, orient='table')
    blob.upload_blob(json_data, overwrite=True)
Task Instance Attributes
Attribute Value
dag_id SierraGorda_BrightBoard
duration 0.510529
end_date 2025-12-21 00:31:02.202640+00:00
execution_date 2025-12-20T12:30:00+00:00
executor_config {}
generate_command <function TaskInstance.generate_command at 0x7783d3ac3040>
hostname 447b87b210b3
is_premature False
job_id 7346
key ('SierraGorda_BrightBoard', 'BrighBoard_GenerarCruceAutonomas', <Pendulum [2025-12-20T12:30:00+00:00]>, 2)
log <Logger airflow.task (INFO)>
log_filepath /usr/local/airflow/logs/SierraGorda_BrightBoard/BrighBoard_GenerarCruceAutonomas/2025-12-20T12:30:00+00:00.log
log_url http://localhost:8080/admin/airflow/log?execution_date=2025-12-20T12%3A30%3A00%2B00%3A00&task_id=BrighBoard_GenerarCruceAutonomas&dag_id=SierraGorda_BrightBoard
logger <Logger airflow.task (INFO)>
mark_success_url http://localhost:8080/success?task_id=BrighBoard_GenerarCruceAutonomas&dag_id=SierraGorda_BrightBoard&execution_date=2025-12-20T12%3A30%3A00%2B00%3A00&upstream=false&downstream=false
max_tries 0
metadata MetaData(bind=None)
next_try_number 2
operator PythonOperator
pid 1561586
pool default_pool
prev_attempted_tries 1
previous_execution_date_success None
previous_start_date_success None
previous_ti <TaskInstance: SierraGorda_BrightBoard.BrighBoard_GenerarCruceAutonomas 2025-12-20 00:30:00+00:00 [success]>
previous_ti_success None
priority_weight 1
queue default
queued_dttm 2025-12-21 00:30:32.716558+00:00
raw False
run_as_user None
start_date 2025-12-21 00:31:01.692111+00:00
state success
task <Task(PythonOperator): BrighBoard_GenerarCruceAutonomas>
task_id BrighBoard_GenerarCruceAutonomas
test_mode False
try_number 2
unixname airflow
Task Attributes
Attribute Value
dag <DAG: SierraGorda_BrightBoard>
dag_id SierraGorda_BrightBoard
depends_on_past False
deps {<TIDep(Not In Retry Period)>, <TIDep(Trigger Rule)>, <TIDep(Previous Dagrun State)>}
do_xcom_push True
downstream_list []
downstream_task_ids set()
email None
email_on_failure True
email_on_retry True
end_date None
execution_timeout None
executor_config {}
extra_links []
global_operator_extra_link_dict {}
inlets []
lineage_data None
log <Logger airflow.task.operators (INFO)>
logger <Logger airflow.task.operators (INFO)>
max_retry_delay None
on_failure_callback None
on_retry_callback None
on_success_callback None
op_args []
op_kwargs {'origin_drilled_hole_container': 'raw', 'origin_drilled_hole_blob': 'SierraGorda/2026-01-02/DrilledHoleTransaction.json', 'origin_mwd_hole_sm_container': 'raw', 'origin_mwd_hole_sm_blob': 'SierraGorda/2026-01-02/MwdSample_SM.json', 'origin_mwd_hole_container': 'raw', 'origin_mwd_hole_blob': 'SierraGorda/2026-01-02/MwdHole.json', 'origin_rig_container': 'raw', 'origin_rig_blob': 'SierraGorda/2026-01-02/Rig.json', 'final_container': 'processed', 'final_blob': 'SierraGorda/BrightBoard/Autonomas/2026-01-02/autonomas_2026-01-02.json', 'rango_dias': 5}
operator_extra_link_dict {}
operator_extra_links ()
outlets []
owner pedro
params {}
pool default_pool
priority_weight 1
priority_weight_total 1
provide_context False
queue default
resources None
retries 0
retry_delay 0:05:00
retry_exponential_backoff False
run_as_user None
schedule_interval 30,30 12,0 * * *
shallow_copy_attrs ('python_callable', 'op_kwargs')
sla None
start_date 2023-04-22T00:00:00+00:00
subdag None
task_concurrency None
task_id BrighBoard_GenerarCruceAutonomas
task_type PythonOperator
template_ext []
template_fields ('templates_dict', 'op_args', 'op_kwargs')
templates_dict None
trigger_rule all_success
ui_color #ffefeb
ui_fgcolor #000
upstream_list []
upstream_task_ids set()
wait_for_downstream False
weight_rule downstream