0

I'm learning how to use Serverless Functions, I'm working trying to connect a Watson assistant through webhooks using a python action that is processing a small dataset, I'm still struggling to succeed on it.

I’ve done my coding on Jupyter environment calling raw csv dataset from Github and using pandas to handle it. The issue is when I’m invoking the action into IBM Functions works 10% of the times. I did debug on Jupyter and Visual Studio environments and the code seems to be ok, but once I move the code to the IBM Functions environment it doesn't perform.

import sys
import csv
import json
import pandas as pd

location = ('Germany') #Passing country parameter for testing purpose

data = pd.read_csv('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/03-24-2020.csv')

def main(args):
    location = args.get("location")

for index, row in data.iterrows():
    currentLoc = row['Country/Region']
    if currentLoc == location:
        covid_statistics = {
            "Province/State": row['Province/State'], 
            "Country/Region": row['Country/Region'], 
            "Confirmed":row['Confirmed'], 
            "Deaths":row['Deaths'], 
            "Recovered":row['Recovered']     
        }
        return {"message": covid_statistics}
    else:
        return {"message": "Data not available"}
Quantum Dreamer
  • 432
  • 1
  • 6
  • 17
  • 1
    Check your runtime of the code. you are iterating the entire dataframe. Event Driven functions are not designed for this kind of tasks. If you still need this, parallelize the iterating. Also cloud functions have timeout, try to increase the timeout – Quantum Dreamer Mar 25 '20 at 02:26
  • Looking at the code above, I would worry that your data load process could time out and thus fail. Not sure how else you could get around this. – timd Mar 25 '20 at 09:25

0 Answers0