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 #192: Crane Leasing

salima
5 - Atom

My solution:

 

 

Kale_Malcom
8 - Asteroid
Spoiler

Kale_Malcom_0-1575562849787.png

 

prozanini
8 - Asteroid
 
LiD
8 - Asteroid
Spoiler
LiD_0-1575573049498.png
jacrae
7 - Meteor
Spoiler
Weekly Challenge 192.PNG
cam_w
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)

 

 

c-lopez
Alteryx
Alteryx

My Solution.

 

markcurry
12 - Quasar

My solution :

Spoiler
solution.png

LParker97
6 - Meteoroid
 
EwanHarris
5 - Atom
Spoiler
Spoiler
Here is my solution:
Spoiler
 

EwanHarris_0-1575642362065.png