AvyWeb.AvyController (avy v1.1.37)

Copy Markdown View Source

Manages a user request.

Summary

Functions

This function is called on a /extent request. It will fetch all the contents corresponding to the filters that were set up by AvyWeb.Plugs.Filters, in the assigns of the connection plug (conn.assigns.filters). For each filter, the database request is done asynchronously in parallel. Desactivate the timeout, as the DB pool has it's own already, and some requests can get quite long.

This controller exists to reformat the output suitable for a grafana state timeline

This function will convert a list of ordered datasources to
show gaps.

Functions

extent(conn, params)

extent_post(conn, params)

manage_request(conn, method)

@spec manage_request(Plug.Conn.t(), atom()) ::
  {:ok, list()} | {:too_much_data, String.t()}

This function is called on a /extent request. It will fetch all the contents corresponding to the filters that were set up by AvyWeb.Plugs.Filters, in the assigns of the connection plug (conn.assigns.filters). For each filter, the database request is done asynchronously in parallel. Desactivate the timeout, as the DB pool has it's own already, and some requests can get quite long.

For each entry, we call the post_process function in order to build a list of datasources and merge the contents of the same properties.

Finally, the datasources are put in the conn.assigns in order for ther renderer to access them in the :availabilities keyword.

open_api_operation(action)

@spec open_api_operation(atom()) :: OpenApiSpex.Operation.t()

query(conn, params)

shared_security()

shared_tags()

statetimeline(conn, opts)

This controller exists to reformat the output suitable for a grafana state timeline

All the formatting logic takes place in the render function AvyJson.statetimeline/1

to_gaps(datasources, bool)

@spec to_gaps(list(), boolean()) :: list()

This function will convert a list of ordered datasources to
show gaps.

First, group all datasources by the full keys. Then for each list:

  • keep the previous end date. (Start first iteration at second element)
  • on the current element:
    • set the start time at previous end date
    • set then end time at current start.
    • put the result at the head of the list we are building
  • we obtain a reversed list, so at the end we need to reverse it.

version(conn, params)