USACE / instrumentation

Instrumentation project issue tracking and project planning
MIT License
4 stars 1 forks source link

[BUG REPORT]: Empty Timeseries Not Displaying In Collection Groups #120

Closed lucasb16-exe closed 2 years ago

lucasb16-exe commented 3 years ago

Describe the bug

Empty timeseries can be added to created collection groups, but only begin to display after data is added via some other means.

Steps To Reproduce

  1. Create an instrument=
  2. Add a timeseries to the instrument
  3. Create a collection group in the same project as the instrument
  4. Attempt to add the timeseries to the created collection group

Expected behavior

Empty timeseries successfully added to collection group

Actual behavior

Timeseries adds, but UI does not display added timeseries until data is inputted into the timeseries via another method

Screenshots

bug1 bug2 bug3 bug4

After adding data via .csv uploader

bug

Desktop (please complete the following information):

Additional context

UI issue, will investigate collection group code

lucasb16-exe commented 3 years ago

API successfully returns all timeseries in collection group, but UI selector 'selectCollectionGroupDetailByRoute' only returns timeseries with data

KevinJJackson commented 3 years ago

@brettpalmberg | @adamscarberry | @dliang864 - When someone gets a chance, can you take a look into the collection group details here https://github.com/USACE/instrumentation-api/blob/stable/models/collection_group.go#L59

Looks to me like it can't return the required timeseries info unless there has been a measurement with the same timeseries_id. The api should be able to return the timeseries data in the response as normal and leave the latest_value and latest_time as null.

lucasb16-exe commented 2 years ago

In https://github.com/USACE/instrumentation-api/blob/stable/models/collection_group.go#L59 -

// GetCollectionGroupDetails returns details for a single CollectionGroup
func GetCollectionGroupDetails(db *sqlx.DB, projectID *uuid.UUID, collectionGroupID *uuid.UUID) (*CollectionGroupDetails, error) {
    var d CollectionGroupDetails
    // Query 1
    if err := db.Get(&d, listCollectionGroupsSQL+" WHERE project_id=$1 AND id=$2", projectID, collectionGroupID); err != nil {
        return nil, err
    }
    // Query 2
    d.Timeseries = make([]cgdTsItem, 0)
    if err := db.Select(
        &d.Timeseries,
        `SELECT t.*, tm.time as latest_time, tm.value as latest_value 
        FROM collection_group_timeseries cgt 
        INNER JOIN collection_group cg on cg.id = cgt.collection_group_id 
        INNER JOIN v_timeseries t on t.id = cgt.timeseries_id 
        INNER JOIN timeseries_measurement tm on tm.timeseries_id = t.id and tm.time = (
            select time from timeseries_measurement 
            where timeseries_id = t.id 
            order by time desc limit 1) 
        WHERE cgt.collection_group_id = $2 and t.project_id = $1
         `, projectID, collectionGroupID,
    ); err != nil {
        return nil, err
    } else if len(d.Timeseries) == 0 { //  if query isn't an error but doesn't return anything, execute second query disregarding latest measurement
        if err := db.Select(
            &d.Timeseries,
            `SELECT t.*
            FROM collection_group_timeseries cgt 
            INNER JOIN collection_group cg on cg.id = cgt.collection_group_id 
            INNER JOIN v_timeseries t on t.id = cgt.timeseries_id 
            WHERE cgt.collection_group_id = $2 and t.project_id = $1
             `, projectID, collectionGroupID,
        ); err != nil {
            return nil, err
        }
    }

    return &d, nil
}

Probably best to restructure original SQL query to allow for also returning null date/time values rather than having 3 queries in a single model func (with a redundant query if the collection group is actually empty) but this works on local environment

lucasb16-exe commented 2 years ago

addressed in USACE/instrumentation-api/pull/128

will resolve issue after review and merge

lucasb16-exe commented 2 years ago

fix merged to dev, resolved issue, closing