Chi2fit.Times (Chi-SquaredFit v3.1.0)

Copy Markdown View Source

Summary

Functions

Adjusts the times to working hours and/or work days.

Returns a Stream that generates a stream of dates.

Maps the date to weekdays such that weekends are eliminated; it does so with respect to a given Saturday

Maps the time of a day into the working hour period

Counts the number of dates (datelist) that is between consecutive dates in intervals and returns the result as a list of numbers. The intervals are allowed to be in reversed order. The start of the interval is considered inside the interval, while the end of the interval is excluded.

Returns a list of time differences (assumes an ordered list as input)

Functions

adjust_times(data, options)

@spec adjust_times(Enumerable.t(), options :: Keyword.t()) :: Enumerable.t()

Adjusts the times to working hours and/or work days.

Options

`workhours` - a 2-tuple containing the starting and ending hours of the work day (defaults
    to {8.0, 18.0})
`epoch` - the epoch to which all data elements are relative (defaults to 1970-01-01)
`saturday` - number of days since the epoch that corresponds to a Saturday (defaults
    to 9)
`correct` - whether to correct the times for working hours and weekdays; possible values
    `:worktime`, `:weekday`, `:"weekday+worktime"` (defaults to `false`)

intervals(options \\ [])

@spec intervals(options :: Keyword.t()) :: Enumerable.t()

Returns a Stream that generates a stream of dates.

Examples

iex> intervals(end: ~D[2019-06-01]) |> Enum.take(4)
[~D[2019-06-01], ~D[2019-05-16], ~D[2019-05-01], ~D[2019-04-16]]

iex> intervals(end: ~D[2019-06-01], type: :weekly) |> Enum.take(4)
[~D[2019-06-01], ~D[2019-05-18], ~D[2019-05-04], ~D[2019-04-20]]

iex> intervals(end: ~D[2019-06-01], type: :weekly, weeks: 1) |> Enum.take(4)
[~D[2019-06-01], ~D[2019-05-25], ~D[2019-05-18], ~D[2019-05-11]]

iex> intervals(end: ~D[2019-06-01], type: :weekly, weeks: [3,2]) |> Enum.take(4)
[~D[2019-06-01], ~D[2019-05-11], ~D[2019-04-27], ~D[2019-04-13]]

map2weekdays(t, sat)

@spec map2weekdays(t :: number(), sat :: pos_integer()) :: number()

Maps the date to weekdays such that weekends are eliminated; it does so with respect to a given Saturday

Example

iex> map2weekdays(43568.123,43566)
43566.123

iex> map2weekdays(43574.123,43566)
43571.123

map2workhours(t, startofday, endofday)

@spec map2workhours(t :: number(), startofday :: number(), endofday :: number()) ::
  number()

Maps the time of a day into the working hour period

Scales the resulting part of the day between 0..1.

Arguments

`t` - date and time of day as a float; the integer part specifies the day and the fractional part the hour of the day
`startofday` - start of the work day in hours
`endofday` - end of the working day in hours

Example

iex> map2workhours(43568.1, 8, 18)
43568.0

iex> map2workhours(43568.5, 8, 18)
43568.4

throughput(intervals, datelist)

@spec throughput(intervals :: Enumerable.t(), datelist :: [NaiveDateTime.t()]) :: [
  number()
]

Counts the number of dates (datelist) that is between consecutive dates in intervals and returns the result as a list of numbers. The intervals are allowed to be in reversed order. The start of the interval is considered inside the interval, while the end of the interval is excluded.

Examples:

iex> throughput([~D[2019-06-01], ~D[2019-05-25]], [~N[2019-05-28 23:00:00]])
[1]

iex> throughput([~D[2019-05-25], ~D[2019-06-01]], [~N[2019-05-28 23:00:00]])
[1]

iex> throughput([~D[2019-06-01], ~D[2019-05-25]], [~N[2019-05-25 23:00:00]])
[1]

iex> throughput([~D[2019-06-01], ~D[2019-05-25]], [~N[2019-06-01 23:00:00]])
[0]

time_diff(data, options)

@spec time_diff(data :: Enumrable.t(), options :: Keyword.t()) :: Enumerable.t()

Returns a list of time differences (assumes an ordered list as input)

Options

`cutoff` - time differences below the cutoff are changed to the cutoff value (defaults to `0.01`)
`drop?` - whether to drop time differences below the cutoff (defaults to `false`)