<reponame>Azure-Samples/functions-python-time-series-forecasting<gh_stars>1-10
import logging
import os
import json
import azure.functions as func
from . import forecast
from pandas import Series
from io import StringIO

'''
This sample shows Azure Functions in Python doing some time series forecasting
using autoregression models with statsmodel libraries. This demonstrates
retraining of time series models with newer data using Azure Functions.
Statsmodel depends on pystan and this demonstrates ML library installation challenges
that are overcome through the Azure Functions deployment process
'''

def main(req: func.HttpRequest,
         input: func.InputStream,
         output: func.Out[bytes]) -> func.HttpResponse:
    
    logging.info('Python HTTP trigger function processed a request.')

    # If data has to be read from local csv file, you can mention the path this way
    # path = os.path.join(os.getcwd(),"ForecastAPI","daily-minimum-temperatures.csv")
    # Else, you can read it as a string from the blob and feed into from_csv this way,
    # This is more stateless and ready for operationalizing this ML flow.

    data = StringIO(input.read().decode('utf-8'))
    series = Series.from_csv(data, header=0)
    result = forecast.predict(series)
    output.set(result)

    return func.HttpResponse("Success")
import logging
import os
import json
import azure.functions as func
from . import forecast
from pandas import Series
from io import StringIO

'''
This sample shows Azure Functions in Python doing some time series forecasting
using autoregression models with statsmodel libraries. This demonstrates
retraining of time series models with newer data using Azure Functions.
Statsmodel depends on pystan and this demonstrates ML library installation challenges
that are overcome through the Azure Functions deployment process
'''

def main(req: func.HttpRequest,
         input: func.InputStream,
         output: func.Out[bytes]) -> func.HttpResponse:
    
    logging.info('Python HTTP trigger function processed a request.')

    # If data has to be read from local csv file, you can mention the path this way
    # path = os.path.join(os.getcwd(),"ForecastAPI","daily-minimum-temperatures.csv")
    # Else, you can read it as a string from the blob and feed into from_csv this way,
    # This is more stateless and ready for operationalizing this ML flow.

    data = StringIO(input.read().decode('utf-8'))
    series = Series.from_csv(data, header=0)
    result = forecast.predict(series)
    output.set(result)

    return func.HttpResponse("Success")
This sample shows Azure Functions in Python doing some time series forecasting
 using autoregression models with statsmodel libraries. This demonstrates
 retraining of time series models with newer data using Azure Functions.
 Statsmodel depends on pystan and this demonstrates ML library installation challenges
 that are overcome through the Azure Functions deployment process # If data has to be read from local csv file, you can mention the path this way # path = os.path.join(os.getcwd(),"ForecastAPI","daily-minimum-temperatures.csv") # Else, you can read it as a string from the blob and feed into from_csv this way, # This is more stateless and ready for operationalizing this ML flow.