## Production module

Control Module - Production - Common functions used to track production of items

### Usage

        -- import the module from the control modules
        local Production = require 'modules.control.production'

        -- This will return the less precise index from the one given
        -- this means that one_second will return one_minute or ten_hours will return fifty_hours
        -- the other precision work like wise
        Production.precision_up(defines.flow_precision_index.one_second)

        -- The get production function is used to get production, consumion and net
        -- it may be used for any item and with any precision level, use total for total
        Production.get_production(game.forces.player,'iron-plate',defines.flow_precision_index.one_minute)

        -- The fluctuations works by compearing recent production with the average over time
        -- again any precision may be used, apart from one_thousand_hours as there would be no valid average
        Production.get_fluctuations(game.forces.player,'iron-plate',defines.flow_precision_index.one_minute)

        -- ETA is calculated based on what function you use but all share a similar method
        -- for production eta it will take current production average given by the precision
        -- and work out how many ticks it will require to make the required amount (1000 by default)
        Production.get_production_eta(game.forces.player,'iron-plate',defines.flow_precision_index.one_minute,250000)

        -- Both get_color and format_number are helper functions to help format production stats
        -- get_color will return green,orange,red,or grey based on the active_value
        -- the passive_value is used when active_value is 0 and can only return orange,red,or grey
        Production.get_color(clamp,active_value,passive_value)

### Dependencies

resources.color_presets | Provides colors for Production.get_color
util | Provides format_number function to add surfixs

### Precision

precision_up (precision) | Gets the next lesser precision index value, eg 1 second -> 1 minute
precision_down (precision) | Gets the next greater precision index value, eg 1 minute -> 1 second
precision_ticks (precision) | Gets the number of tick that precision is given over, eg 1 minute -> 60 ticks

### Stats

get_production_total (force, item_name) | Returns the production data for the whole game time
get_production (force, item_name, precision) | Returns the production data for the given precision game time
get_fluctuations (force, item_name, precision) | Returns the current fluctuation from the average
get_production_eta (force, item_name, precision[, required=1000]) | Returns the amount of ticks required to produce a certain amount
get_consumsion_eta (force, item_name, precision[, required=1000]) | Returns the amount of ticks required to consume a certain amount
get_net_eta (force, item_name, precision[, required=1000]) | Returns the amount of ticks required to produce but not consume a certain amount

### Formating

get_color (clamp, active_value, passive_value) | Returns a color value bassed on the value that was given
format_number (value) | Returns three parts used to format a number

### Dependencies

# resources.color_presets

  Provides colors for Production.get_color

# util

  Provides format_number function to add surfixs

### Precision

# precision_up (precision)

  Gets the next lesser precision index value, eg 1 second -> 1 minute

  Parameters:
  - precision : (defines.flow_precision_index)
  Returns:
  - (defines.flow_precision_index) the next precision value
  - (number) the multiplicive difference between the values
# precision_down (precision)

  Gets the next greater precision index value, eg 1 minute -> 1 second

  Parameters:
  - precision : (defines.flow_precision_index)
  Returns:
  - (defines.flow_precision_index) the next precision value
  - (number) the multiplicive difference between the values
# precision_ticks (precision)

  Gets the number of tick that precision is given over, eg 1 minute -> 60 ticks

  Parameters:
  - precision : (defines.flow_precision_index)
  Returns:
  - (number) the number of ticks in this time

### Stats

# get_production_total (force, item_name)

  Returns the production data for the whole game time

  Parameters:
  - force : (LuaForce) the force to get the data for
  - item_name : (string) the name of the item that you want the data about
  Returns:
  - (table) contains total made, used and net
# get_production (force, item_name, precision)

  Returns the production data for the given precision game time

  Parameters:
  - force : (LuaForce) the force to get the data for
  - item_name : (string) the name of the item that you want the data about
  - precision : (defines.flow_precision_index) the precision that you want the data given to
  Returns:
  - (table) contains made, used and net
# get_fluctuations (force, item_name, precision)

  Returns the current fluctuation from the average

  Parameters:
  - force : (LuaForce) the force to get the data for
  - item_name : (string) the name of the item that you want the data about
  - precision : (defines.flow_precision_index) the precision that you want the data given to
  Returns:
  - (table) contains made, used and net
# get_production_eta (force, item_name, precision[, required=1000])

  Returns the amount of ticks required to produce a certain amount

  Parameters:
  - force : (LuaForce) the force to get the data for
  - item_name : (string) the name of the item that you want the data about
  - precision : (defines.flow_precision_index) the precision that you want the data given to
  - required : (number) the number of items that are required to be made (default: 1000)
  Returns:
  - (number) the number of ticks required to produce this ammount of items
# get_consumsion_eta (force, item_name, precision[, required=1000])

  Returns the amount of ticks required to consume a certain amount

  Parameters:
  - force : (LuaForce) the force to get the data for
  - item_name : (string) the name of the item that you want the data about
  - precision : (defines.flow_precision_index) the precision that you want the data given to
  - required : (number) the number of items that are required to be consumed (default: 1000)
  Returns:
  - (number) the number of ticks required to consume this ammount of items
# get_net_eta (force, item_name, precision[, required=1000])

  Returns the amount of ticks required to produce but not consume a certain amount

  Parameters:
  - force : (LuaForce) the force to get the data for
  - item_name : (string) the name of the item that you want the data about
  - precision : (defines.flow_precision_index) the precision that you want the data given to
  - required : (number) the number of items that are required to be made but not used (default: 1000)
  Returns:
  - (number) the number of ticks required to produce, but not use, this ammount of items

### Formating

# get_color (clamp, active_value, passive_value)

  Returns a color value bassed on the value that was given

  Parameters:
  - clamp : (number) value which seperates the different colours
  - active_value : (number) first value tested, tested against clamp
  - passive_value : (number) second value tested, tested against 0
  Returns:
  - (table) contains r,g,b keys
# format_number (value)

  Returns three parts used to format a number

  Parameters:
  - value : (number) the value to format
  Returns:
  - (string) the sign for the number
  - (string) the surfix for any unit used
  - (string) the number formated