rapidpro / expressions

Expression parsing and evaluation support
BSD 3-Clause "New" or "Revised" License
4 stars 4 forks source link

Add WEEKNUM function #5

Open rowanseymour opened 8 years ago

rowanseymour commented 8 years ago

See https://support.office.com/en-us/article/WEEKNUM-function-e5c43a03-b4ab-426c-b411-b18c13c75340

Vandeabdou commented 8 years ago

In which Files of rapidPro can i add the function WEEKNUM??

rowanseymour commented 8 years ago

Java implementation goes in https://github.com/rapidpro/expressions/blob/master/java/src/main/java/io/rapidpro/expressions/functions/ExcelFunctions.java Java tests go in https://github.com/rapidpro/expressions/blob/master/java/src/test/java/io/rapidpro/expressions/functions/ExcelFunctionsTest.java Python implementation goes in https://github.com/rapidpro/expressions/blob/master/python/temba_expressions/functions/excel.py Python tests go in https://github.com/rapidpro/expressions/blob/master/python/temba_expressions/tests.py Cross-language tests go in https://github.com/rapidpro/expressions/blob/master/common/template_tests.json

Vandeabdou commented 8 years ago

@rowanseymour thank you very much. I will add it with java implementation

Vandeabdou commented 8 years ago

@rowanseymour I don't find these files on rapidPro. I must install them with command ?

rowanseymour commented 8 years ago

This is separate library which we import into RapidPro.

Remember you need to implement it in both Java and Python - then add tests to show that they are consistent with each other, and consistent with Excel itself.

Vandeabdou commented 8 years ago

OK. I install openjdk and now di i put ExcelFunctions.java in rapidpro/expressions/functions/ folder? Also if i add new function i can just call it with @(NEW_FUNCTION()) ?

rowanseymour commented 8 years ago

Look at the existing functions in ExcelFunctions.java and follow the same pattern. If you create a method called new_function you will be able to call it like @(NEW_FUNCTION())

Vandeabdou commented 8 years ago

I don't find ExcelFunctions.java in my RapidPro. I just find excels.py in /env/lib/python2.7/site-packages/expressions/functions folder. Do i import in that folder or in another folder?

rowanseymour commented 8 years ago

It's not in RapidPro - it's in this repo that this issue belongs to. This is a project which contains the Java implementation of the RapidPro expression engine (used by Surveyor) and the Python implementation (used by the RapidPro Django app)

Vandeabdou commented 8 years ago

Thank you. I finally add WEEKNUM function but in python. This is the function and it works fine

def weeknum(ctx, date): """ Returns the num of the week of a date (Between 1 and 52) """ return (conversions.to_date_or_datetime(date, ctx).isocalendar()[1])

Vandeabdou commented 8 years ago

Hello @rowanseymour. The function run in the simulator without error but if i test the flow with a phone i get @(WEEKNUM(TODAY())) instead of 4 for example

Vandeabdou commented 8 years ago

How can i test my need function just added in my copy of expressions lib ?