Skip to content
Liam Fruzyna edited this page Jan 27, 2024 · 1 revision

Utils

There are a few miscellaneous functions that are used across the app. These are contained in utils.js.

Provided Functions

window_open(url, option)

Opens a url with the provided option. Will open in the same tab if the option is _self or a new tab if it is _blank.

  • url
    • String url to open.
  • option
    • String open option.

build_url(page, query)

Builds a new URL string for a given HTML file and a object representation of query parameters.

  • page
    • String type of page to open (index/selection).
  • query
    • JS object of query parameters.

build_query(query)

Builds a query string from a given object.

  • query
    • JS object of query parameters.

get_parameter(key, dvalue)

Attempt to get a parameter first as a URLSearchParam, then as a cookie if the parameter doesn't exist.

  • key
    • String name of the parameter/cookie.
  • dvalue
    • Default value to return if the parameter/cookie does not exist.

set_cookie(cname, cvalue)

Creates a cookie with a given name and value, set to expire in 1 week.

  • cname
    • String name of the cookie.
  • cvalue
    • Value to store in the cookie.

get_cookie(cname, dvalue)

Returns the value of the requested cookie or the default.

  • cname
    • String name of the cookie.
  • dvalue
    • Default value to return if the cookie does not exist. Also stored as the value if the cookie didn't exist.

mean(values)

Calculates the mean of a given array of values.

  • values
    • Array of values to calculate from.

std_dev(values)

Calculates the standard deviation of a given array of values.

  • values
    • Array of values to calculate from.

median(values)

Calculates the median of a given array of values.

  • values
    • Array of values to calculate from.

mode(values)

Calculates the mode of a given array of values.

  • values
    • Array of values to calculate from.

random_bool(low_odds)

Generates a random boolean.

  • low_odds
    • Numeric value between 0 and 1 representing the odds of false being selected.

random_int(min, max)

Generates a random integer between two given bounds.

  • min
    • Lowest value to generate.
  • max
    • Highest value to generate.

distance(x1, y1, x2, y2)

Calculates the distance between 2 x, y coordinates.

  • x1
    • x value of first point.
  • y1
    • y value of first point.
  • x2
    • x value of second point.
  • y2
    • y value of second point.

contained(vertices, x, y)

Determines if a given point is contained in a shape. Used primarily for doing analysis of Zebra data.

  • vertices
    • Array of vertices containing x and y properties.
  • x
    • x value to compare to vertices.
  • y
    • y value to compare to verticies.

scroll_to(container, goal)

Scrolls a given element on page until a contained element can be seen. Useful for options lists.

  • container
    • String scrollable element ID.
  • goal
    • String contained element ID.

ws(team_num)

Colors the header based on the given team number.

  • team_num
    • String containing a team number.

unix_to_match_time(unix_time)

Converts a given unix timestamp to Day Hour:Minute.

  • unix_time
    • Numeric unix timestamp in ms.

parse_server_addr(addr)

Removes the path from the end of a URL resulting in the root.

  • addr
    • String URL of a page.

check_server(server, notify)

Determines if the given server URL is available and is a WildRank POST server.

  • server
    • String URL of the server, does not have to be root.
  • notify
    • Boolean representing if the user should be notified of a failure.

include(name)

Includes a script from /scripts by name.

  • name
    • String name of a file without the .js.

apply_theme()

Applys the current theme to the application. Chooses theme from cookie.

to_hex(value)

Converts a given value to a 2 byte hex string.

  • value
    • Numeric value to convert.

find_team_placeholders(text)

Finds placeholder text in a string for a opponent or partner team.

  • text
    • String to find placeholder text in.