Weekly Challenge

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

We're actively looking for ideas on how to improve Weekly Challenges and would love to hear what you think!

Submit Feedback
We've recently made an accessibility improvement to the community and therefore posts without any content are no longer allowed. Please use the spoiler feature or add a short message in the message body in order to submit your weekly challenge.

Challenge #192: Crane Leasing

Highlighted
5 - Atom

My solution:

 

 

Highlighted
8 - Asteroid
Spoiler

Kale_Malcom_0-1575562849787.png

 

Highlighted
Alteryx Partner
 
Highlighted
8 - Asteroid
Spoiler
LiD_0-1575573049498.png
Highlighted
7 - Meteor
Spoiler
Weekly Challenge 192.PNG
Highlighted
11 - Bolide

Having done this type of thing for years in SAS, I wanted to try this one in pandas/python in the Python tool.

 

 

Spoiler
#################################
# List all non-standard packages to be imported by your 
# script here (only missing packages will be installed)
# from ayx import Package
# #Package.installPackages(['pandas','numpy'])


#################################
from ayx import Alteryx
from datetime import datetime
from dateutil import parser
import pandas as pd


#################################
dfInput = Alteryx.read("#Input")
dfOutput = Alteryx.read("#Output")

expected_result = dfOutput.values.tolist()[0][0]


#################################
dfTinyTim = dfInput[(dfInput['Crane Name'] == "Tiny Tim") & (dfInput['Crane Status'] == "Leased")][['Start Date', 'End Date']]


#################################
dfMaximus = dfInput[(dfInput['Crane Name'] == "Maximus") & (dfInput['Crane Status'] == "Leased")][['Start Date', 'End Date']]


#################################
def start_end_list(s, e, mindt=datetime(2016,1,1), maxdt=datetime(2018,12,31)):

    sdt = parser.parse(s)
    edt = parser.parse(e)
    
    # Limit dates to the 2016-2018 years
    if edt >= mindt and sdt <= maxdt:
        
        if sdt < mindt:
            sdt = mindt
        if edt > maxdt:
            edt = maxdt
        
        epoch = datetime(1970,1,1)

        isdt = (sdt-epoch).days
        iedt = (edt-epoch).days

        return list(range(isdt,iedt+1))
    else:
        return []


#################################
tinyTimList = []

for r in dfTinyTim.values:
    tinyTimList.extend(start_end_list(r[0], r[1]))


#################################
maximusList = []

for r in dfMaximus.values:
    maximusList.extend(start_end_list(r[0], r[1]))


#################################
calculated_result = len(set(tinyTimList) & set(maximusList))


#################################
if expected_result == calculated_result:
    print("SUCCESS!!! Found the correct number of days")
else:
    print("ERROR!!! Try again")


#################################
dfOutput = pd.DataFrame({'Expected Result': [expected_result], 'Calculated Result': [calculated_result]})


#################################
Alteryx.write(dfOutput, 1)

 

 

Highlighted
Alteryx
Alteryx

My Solution.

 

Highlighted
11 - Bolide

My solution :

Spoiler
solution.png

Highlighted
6 - Meteoroid
 
Highlighted
5 - Atom
Spoiler
Spoiler
Here is my solution:
Spoiler
 

EwanHarris_0-1575642362065.png