Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Weekly Challenges

Solve the challenge, share your solution and summit the ranks of our Community!

Also available in | Français | Português | Español | 日本語
IDEAS WANTED

Want to get involved? We're always looking for ideas and content for Weekly Challenges.

SUBMIT YOUR IDEA

Challenge #10: Date Time Calculations

NicoleJohnson
ACE Emeritus
ACE Emeritus

If I was to calculate the DateTimeDiff between the last time @SeanAdams and I raced to the finish on something, it would have been a while... until now 😉

 

#SnakingMyWayThruChallenges (and starting with the easier ones, because I don't really know what I'm doing yet...)

 

Spoiler
Solved previously (like a million years ago) using standard Alteryx tools... this time I have done the entire thing in the Python tool. 🙂

10_py1.JPG10_py2.JPG

  



PYTHON SCRIPT:

## INPUT DATA

# Read in various packages + Alteryx start data from input 1

from ayx import Package
import datetime
import re
import pandas

from ayx import Alteryx
dist_data = Alteryx.read("#1").values


## FORMAT DATA

# Define the datediff_list variable, which will become
# the list of our date differences.

# Also define the pattern that will be used in the RegEx
# expression to isolate datetime diff values.

datediff_list = list()
pattern = '(\d+)\sdays\s(\d+):(\d+):(\d+)'

# For loop to iterate through records & create a list
# for each of the desired date component values.

for i in range (len(dist_data)):

# Calculate datediff (from datetime module) using
# data in positions 1 & 2, which are datetime values.
testrecord1 = dist_data[i][1]
testrecord2 = dist_data[i][2]
diff = str(testrecord2 - testrecord1)

# Split the results of datetime diff calc from
# "n days nn:nn:nn" format into 4 columns.
diff = re.split(pattern,diff)

# Regex leaves some extra '' values in list,
# so this will remove them.
while '' in diff: diff.remove('')

# Convert the 4 list values into integers.
for n in range (0,4):
diff[n] = int(diff[n])

# Prepend original list values to the new diff list.
diff.insert(0,str(dist_data[i][2]))
diff.insert(0,str(dist_data[i][1]))
diff.insert(0,str(dist_data[i][0]))

#For each iteration, append new list to the existing list.
datediff_list.append(diff)

output = pandas.DataFrame(datediff_list)

## OUTPUT DATA

# Convert to dataframe using pandas module,
# and then rename columns.
output = pandas.DataFrame(datediff_list)
output = output.rename(columns={0: "Registrant ID", 1: "TIMESTAMP", 2: "Time_Now", 3: "Days", 4: "Hours", 5: "Minutes", 6: "Seconds"})

Alteryx.write(output,1)

Cheers! 

NJ

PeterH23
8 - Asteroid

My solution

Spoiler
Could have jammed them into one tool, but left them separate for clarity.

Challenge#10.png
dipin
6 - Meteoroid
 
alozano
8 - Asteroid

Here is my answer:

 

Spoiler
challenge_10_alozano.jpg
jaschirmer
7 - Meteor

Here's my solution, thanks!

Treyson
13 - Pulsar
13 - Pulsar

Revisiting in order do some #SnakingMyWayThruChallenges

 

I laughed

I cried

It took a long time

Treyson Marks
Senior Analytics Engineer
myouree
8 - Asteroid

Solution attached.

byagelski
8 - Asteroid

interesting problem, very cool problem solving.

atcodedog05
22 - Nova
22 - Nova

On a spree to binge complete weekly challenges

 

Spoiler
This is my solution

atcodedog05_0-1584876743033.png

 

AngelosPachis
16 - Nebula

Challenge #10 solved. That was my 50th Alteryx Challenge 👏👏