lib_score.js: refactor. add two functions for score correction. remove unneeded arbitrary hard-coded multipliers.

[?]
Apr 29, 2020, 2:30 PM
G7YVCY6HM6W46JYZWU6HY4VO4SQCHBP73LW2RTI2LPNRQD2TNKCAC

Dependencies

  • [2] 2WOLGB42 README.md: update. kill.js: fix argument parser. lshw.js: add `-p` option. increase information given. main.js: fix error message. set saner defaults. hacker.js: split some functions into "lib_time.js" and "lib_score.js". ram.js: fix.
  • [3] IVSW4A6P lib_score.js: normalised scores against average instead of using arbitrary values.
  • [4] BKG7YVUV main.js, hacker.js, servers.js, ram.js: refactor.
  • [5] 2BKHJI2S init
  • [6] DJDWBCCQ add missing "nop.js". killall.js: rename to kill.js. add `--script` and `--server` options.
  • [7] NQ22FUSW add more options to `main.js`. update `README.md`.
  • [8] MKHG4OQB make worker scripts and worker script executor time-aware.

Change contents

  • replacement in lib/lib_score.js at line 32
    [4.3716661][4.3716661:3716740]()
    const array_get_servers_trait = function (ns, array_servers, void_get_trait) {
    [4.3716661]
    [4.3716740]
    // score correction methods
    const float_get_standard_score = function (float_original, array_numbers) {
    const
    float_get_variance = function (array_numbers) {
    const float_mean = float_get_mean(array_numbers);
    let float_sum_squared_differences = 0;
    for (
    let integer_indices_0 = 0;
    integer_indices_0 < array_numbers.length;
    ++integer_indices_0
    )
    float_sum_squared_differences += Math.pow(
    array_numbers[integer_indices_0] - float_mean,
    2
    );
    return float_sum_squared_differences / array_numbers.length;
    },
    float_get_standard_deviation = function (array_numbers) {
    return Math.sqrt(float_get_variance(array_numbers));
    };
    return (
    (float_original - float_get_mean(array_numbers)) /
    float_get_standard_deviation(array_numbers)
    );
    };
    const float_get_mean_normalised_score = function (
    float_original,
    array_numbers
    ) {
    return (
    (float_original - float_get_mean(array_numbers)) /
    (Math.max(...array_numbers) - Math.min(...array_numbers))
    );
    };
    // returns a corrected score using a chosen correction method
    const float_get_corrected_score = function (float_original, array_numbers, float_method_score_correction) {
    return float_method_score_correction(float_original, array_numbers);
    };
    const array_get_servers_trait = function (ns, array_servers, float_get_trait_score) {
  • replacement in lib/lib_score.js at line 80
    [4.3716885][4.3716885:3716969]()
    array_servers_trait.push(void_get_trait(ns, array_servers[integer_indices_0]));
    [4.3716885]
    [4.3716969]
    array_servers_trait.push(float_get_trait_score(ns, array_servers[integer_indices_0]));
  • edit in lib/lib_score.js at line 82
    [4.3716999][4.3716999:3717183]()
    };
    const float_get_servers_hackable_mean_trait = function (ns, void_get_trait) {
    return float_get_mean(array_get_servers_trait(ns, array_get_servers_hackable(ns), void_get_trait));
  • replacement in lib/lib_score.js at line 84
    [4.3717187][4.3717187:3717421]()
    // gives a score for how well you will be able to hack a server (how much cash you can take per hack and how long it takes) given your current hacking level and its required hacking level. adapted from various functions in Hacking.js
    [4.3717187]
    [4.3717421]
    // gives a score for how well you will be able to hack a server (how much cash you can take per hack, how long it takes and your chances of hacking it successfully) given your current hacking level and its required hacking level. adapted from various functions in Hacking.js
  • replacement in lib/lib_score.js at line 98
    [4.3717891][4.3717891:3718051]()
    // returns the score of a server which is calculated by taking into account the deviation from mean of its max cash, its growth rate and your skill against it.
    [4.3717891]
    [4.3718051]
    // returns the score of a server which is calculated by taking into account its max cash, its growth rate and your skill against it as factors which are corrected and summed.
  • replacement in lib/lib_score.js at line 101
    [4.3718128][3.1567:1637]()
    float_mean_skill_against = float_get_servers_hackable_mean_trait(
    [4.3718128]
    [3.1637]
    // can change this to try different correction methods
    float_method_score_correction = float_get_standard_score,
    float_get_score_factor = function (
    ns,
    string_server,
    float_method_score_correction,
    float_get_trait_score
    ) {
    return float_get_corrected_score(
    float_get_trait_score(ns, string_server),
    array_get_servers_trait(
    ns,
    array_get_servers_hackable(ns),
    float_get_trait_score
    ),
    float_method_score_correction
    );
    },
    float_factor_skill = float_get_score_factor(
  • edit in lib/lib_score.js at line 123
    [3.1647]
    [3.1647]
    string_server,
    float_method_score_correction,
  • replacement in lib/lib_score.js at line 127
    [3.1684][3.1684:1756]()
    float_mean_server_cash_max = float_get_servers_hackable_mean_trait(
    [3.1684]
    [3.1756]
    float_factor_max_cash = float_get_score_factor(
  • edit in lib/lib_score.js at line 129
    [3.1766]
    [3.1766]
    string_server,
    float_method_score_correction,
  • replacement in lib/lib_score.js at line 133
    [3.1805][3.1805:1875]()
    float_mean_server_growth = float_get_servers_hackable_mean_trait(
    [3.1805]
    [3.1875]
    float_factor_growth = float_get_score_factor(
  • edit in lib/lib_score.js at line 135
    [3.1885]
    [3.1885]
    string_server,
    float_method_score_correction,
  • replacement in lib/lib_score.js at line 138
    [3.1915][3.1915:1922](),[3.1922][4.3718128:3718153](),[4.3718128][4.3718128:3718153](),[4.3718153][3.1923:2035](),[3.2035][4.3718278:3718306](),[4.3718278][4.3718278:3718306](),[4.3718306][3.2036:2145](),[3.2145][4.3718426:3718452](),[4.3718426][4.3718426:3718452](),[4.3718452][3.2146:2249]()
    ),
    float_factor_skill =
    (float_get_skill_against(ns, string_server) - float_mean_skill_against) /
    float_mean_skill_against,
    float_factor_max_cash =
    (ns.getServerMaxMoney(string_server) - float_mean_server_cash_max) /
    float_mean_server_cash_max,
    float_factor_growth =
    (ns.getServerGrowth(string_server) - float_mean_server_growth) /
    float_mean_server_growth;
    [3.1915]
    [4.3718568]
    );
  • replacement in lib/lib_score.js at line 140
    [4.3718569][3.2250:2402]()
    // Can adjust the weights of the variables. 1 = normal importance, > 1 = more importance, < 1 = less importance, 0 = not used, < 0 = negative effect.
    [4.3718569]
    [4.3718732]
    // can adjust the weights of the factors. 1 = factor has normal importance, > 1 = factor has more importance, < 1 = factor has less importance, 0 = factor is not used, < 0 = factor has negative effect.
  • replacement in bin/main.js at line 43
    [4.1917][4.3080:3111](),[2.2181][4.3080:3111](),[4.3080][4.3080:3111](),[4.3111][2.2182:2215]()
    // duration between each job
    let float_padding_seconds = 1;
    [2.2181]
    [4.3144]
    // duration between each job used to prevent collisions between them to keep them in sequence
    let float_padding_seconds = 0.5;
  • replacement in README.md at line 35
    [4.3600][2.5488:5608]()
    * SECONDS = The duration of delay between each job, in seconds. Should be a floating-point number > 0. Defaults to 1.
    [4.3600]
    [4.3722]
    * SECONDS = The duration of delay between each job, in seconds. Should be a floating-point number > 0. Defaults to 0.5.