MonthlyExportResult GET endpoint is not returning a full month by month record

When pulling the MonthlyExportResults, there are gaps in the month by month record by well. See screenshot for example. Is anyone else experiencing this issue? Please advise!

Hey Sterling, could I take a look at the body you’re sending in the request?

We can take a further look into it tomorrow if the body looks correct.

private void LoadMonthlyExportResults(string projectId, string scenarioId, EconRunEx econRun, Action log, out DataMergeResult mergeResult)
{
var crudOp = CrudOperation.Insert | CrudOperation.Update;
if (Delete)
crudOp |= CrudOperation.Delete;

mergeResult = null;

log($"Loading Monthly Export Results - Run Date: {econRun.RunDate}");

var econRunId = econRun.EconRunId;

mergeResult = null;

MonthlyExportJob monthlyExportJob = null;
// create monthly export job
monthlyExportJob = ExecuteApiCall(() => ccApi.PostMonthlyExports(projectId, scenarioId, econRunId), log);

var exportTimer = new Stopwatch();
exportTimer.Start();
MonthlyExport monthlyExportResult = null;

while (true && exportTimer.Elapsed.TotalSeconds < 900)
{

monthlyExportResult = ExecuteApiCall(() => ccApi.GetMonthlyExportById(projectId, scenarioId, econRunId, monthlyExportJob.Id), log);

    if (monthlyExportResult.Status.EqualsCI("Completed"))
    {
        break;
    }

    // wait for 5 seconds and try again
    Thread.Sleep(5000);
}

if (monthlyExportResult != null)
{
    var mapper = new ClassMapper<MonthlyExportOutput, MonthlyExportResultEx>();

    IEnumerable<MonthlyExportResultEx> GetRecords(int skip, int take)
    {
        IEnumerable<MonthlyExportResults> records = null;

records = ExecuteApiCall(() => ccApi.GetMonthlyExportById(projectId, scenarioId, econRunId, monthlyExportJob.Id, skip, take)?.Results, log);

        if (records != null)
        {
            foreach (var item in records)
            {
                var newItem = mapper.Map(item.Output);
                //newItem.ProjectId = projectId;
                //newItem.ScenarioId = scenarioId;
                if (item.Date.HasValue && !string.IsNullOrWhiteSpace(item.Well))
                {
                    newItem.EconRunId = econRunId;
                    newItem.Date = item.Date.Value;
                    newItem.ComboName = item.ComboName;
                    newItem.WellId = item.Well;

                    yield return newItem;
                }
            }
        }

    }

    mergeResult = LoadToDatabase(
        GetAllEntities(GetRecords, 1000),
        "dbo.MonthlyExportResult",
        crudOp,
        new Dictionary<string, string>
        {
            //{"ProjectId", projectId },
            //{"ScenarioId", scenarioId },
            {"EconRunId", econRunId }
        },
        log
    );

    log($"Processed: {mergeResult.RecordsProcessed:n0}, Added: {mergeResult.RecordsAdded:n0}, Updated: {mergeResult.RecordsUpdated:n0}, Deleted: {mergeResult.RecordsDeleted:n0}");
}

}

IEnumerable GetAllEntities(Func<int, int, IEnumerable> getRecords, int batchSize = 200)
{
var skip = 0;
var more = true;

_apiTimer.Start();

while (more)
{
    IEnumerable<T> items = getRecords(skip, batchSize);

    if (items == null)
    {
        more = false;
    }
    else
    {
        int cnt = 0;

        foreach (var i in items)
        {
            yield return i;
            cnt++;
        }

        if (cnt == batchSize)
        {
            skip += batchSize;
            more = true;
        }
        else
            more = false;
    }
}

_apiTimer.Stop();

Looks like it might be a hard problem to figure out. Could you reach out to your customer success representative and we can schedule a call to troubleshoot in the near future?

1 Like

Will do. In the meantime, is it possible to run an export of the data in the source table so we can verify that isn’t the issue?

To check whether this is an econ run issue or an api endpoint issue, you can run a csv report export from the scenario econ run. That’ll be done on the econ run result screen, and you’ll be able to verify the timeseries on the CSV to see if there are any missing months.