Given a dataframe with the columns "id" and "desired_category", along with a separate tenant_id argument, bulk update the stations' categories to the desired values. If the station category does not exist, an error will be logged and stored as a return value and the script will continue to the next row.

TODO: add function to automatically create the desired category if it does not exist. see endpoint at /api/ContinuousStationCategory/List

set_monitoring_location_categories(master_df, tenant_id)

Arguments

master_df

Dataframe with columns of "id" and "desired_category". See below for more info.

station_id: id of the station's primary alias as shown in the Id column of the return dataframe of function get_wq_locations_list.

station_name: the name of the primary alias of the monitoring location to which you'd like to add change the category. See the Location column of get_wq_locations_list for list of existing primary station names.

desired_category: string name of the new category you want to set. The desired_category must exist for the given tenant in EnviroData. If not, you can create it in EnviroData administration tools --> Station Categories.

tenant_id

Integer number of tenant.

Value

The original dataframe with a new result column that contains the response from each HTTP request.

Examples

  # Example master_df
  master_df_example <- data.frame(
    station_id = c(101, 102),
    station_name = c("Station1", "Station2"),
    desired_category = c("Category1", "Category2")
  )

  # Example tenant_id
  tenant_id_example <- 12345

  # Call the set_monitoring_location_categories function
  updated_categories <- set_monitoring_location_categories(master_df = master_df_example, tenant_id = tenant_id_example)

  # View the results
  print(updated_categories)