Example #1
0
def merge_forecast(forecast_id, iterations, connection):
    ''' Computes the bucket-wise statistics after all iterations of the
        simulation have completed. Subsequently deleting the iteration specific
        data stored previously.
        This assumes that the previous rows are stored with
            ITERATION < iterations
        and stores the new rows with ITERATION=iterations
    '''
    connection.execute('INSERT INTO FORECAST SELECT FORECAST_ID, YEAR, GENDER, \
            AGE, LOCATION, SPECIALTY, sum(HeadcountSigma), \
            sum(HeadcountSigmaSquare), sum(FTESigma), sum(FTESigmaSquare), \
            {0} FROM FORECAST WHERE FORECAST_ID={1} \
            GROUP BY YEAR, GENDER, AGE, LOCATION, SPECIALTY' \
            .format(iterations, forecast_id))
    connection.execute(FORECAST.delete(
        (FORECAST.c.FORECAST_ID==forecast_id) &
        (FORECAST.c.ITERATION < iterations)))
Example #2
0
def write_forecast(rows, connection):
    connection.execute(FORECAST.insert(rows))
Example #3
0
def clear_forecast_id(forecast_id, connection):
    connection.execute(FORECAST.delete().where(
        FORECAST.c.FORECAST_ID==forecast_id))