Data360 Analyze

 View Only
  • 1.  How to only show rows that pass an If else statement

    Employee
    Posted 11-13-2019 09:39

    I am currently trying to determine if a particular field's date falls within the previous week, and if it does I want the whole record to be shown in the Transform pin.  I am new to data3sixty, so I am not sure what the command should be after the if else statement.

    I have attached my code below.

    ## import data package
    import datetime

    ## assign date variables
    today = datetime.date.today()

    six_day = datetime.timedelta(days = 6)

    week = today - six_day

    ## Statement to extract recent job movements
    if fields.JOBCODE_ENDDATE < week and fields.JOBCODE_ENDDATE > today:

    ???

     



  • 2.  RE: How to only show rows that pass an If else statement

    Employee
    Posted 11-14-2019 03:41

    Hi Jerome, welcome to Data3Sixty Analyze and Infogix.

    The Python code at the end of this post should output the records where the tested date is within the last week.

    The ConfigureFields script is executed once when the node initially executes and this occurs before any input records are processed. The ProcessRecords script is executed for each input record. Python module import statements should be included in the ConfigureFields script as the module only needs to be imported once. Similarly, as the first few statements in your code are creating constants it's usually better to define them in the ConfigureFields script too. You can also initialize values for variables here too and the variables are then available to the ProcessRecords script. If required you can alternatively use an if statement with the condition set to test the in-built 'node.fistExec' variable e.g.

    if node.firstExec:

      <Do something>

    However initializing variables and constants in the ConfigureFields statement is slightly more performant as the if statement does not have to be evaluated for each record.

     

    #########################

    #### ConfigureFields script ####

    ## import data package
    import datetime

    #Configure all fields from input 'in1' to be mapped
    #to the corresponding fields on the output 'out1'
    out1 += in1

    ## assign date variables
    today = datetime.date.today()

    ## define the offset period
    six_day = datetime.timedelta(days = 6)

    ## calculate the cut-off date for one week ago
    week = today - six_day

    #########################

    #### ProcessRecords Script ####

    if fields.JOBCODE_ENDDATE >= week and fields.JOBCODE_ENDDATE <= today:

      out1 += in1

    #########################

     

    Note that I modified the criteria for the if statement to match dates from today to today - 6 days, inclusive. 

     



  • 3.  RE: How to only show rows that pass an If else statement

    Employee
    Posted 11-19-2019 08:43

    Thank you, Adrian.