annotate mod_report_affiliations/traits.lib.lua @ 6083:ffd0184cd478

mod_compliance_latest: New module that depends on and therefore loads the latest compliance tester mod. diff --git a/mod_compliance_latest/README.md b/mod_compliance_latest/README.md new file mode 100644 --- /dev/null +++ b/mod_compliance_latest/README.md @@ -0,0 +1,25 @@ +--- +summary: XMPP Compliance Suites self-test +labels: +- Stage-Beta +rockspec: + dependencies: + - mod_compliance_2023 +... + +# Introduction + +This module will always require and load to the lastest compliance tester we have in the community modules. +Currently this is [mod_compliance_2023]. + +# Configuration + +Just load this module as any other module and it will automatically install [mod_compliance_2023] if you use the Prosody plugin installer. +See the linked module for further details. + +# Compatibility + + Prosody-Version Status + --------------- ---------------------- + trunk Works as of 2024-12-22 + 0.12 Works diff --git a/mod_compliance_latest/mod_compliance_latest.lua b/mod_compliance_latest/mod_compliance_latest.lua new file mode 100644 --- /dev/null +++ b/mod_compliance_latest/mod_compliance_latest.lua @@ -0,0 +1,1 @@ +module:depends("compliance_2023");
author Menel <menel@snikket.de>
date Sun, 22 Dec 2024 18:12:42 +0100
parents e905ef16efb7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6030
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local known_traits = {};
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local function trait_added(event)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local trait = event.item;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local name = trait.name;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 if known_traits[name] then return; end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 known_traits[name] = trait.probabilities;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local function trait_removed(event)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local trait = event.item;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 known_traits[trait.name] = nil;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 module:handle_items("account-trait", trait_added, trait_removed);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local function bayes_probability(prior, prob_given_true, prob_given_false)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local numerator = prob_given_true * prior;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local denominator = numerator + prob_given_false * (1 - prior);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 return numerator / denominator;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local function prob_is_bad(traits, prior)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 prior = prior or 0.50;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 for trait, state in pairs(traits) do
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 local probabilities = known_traits[trait];
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 if probabilities then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 if state then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 prior = bayes_probability(
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 prior,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 probabilities.prob_bad_true,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 probabilities.prob_bad_false
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 );
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 else
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 prior = bayes_probability(
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 prior,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 1 - probabilities.prob_bad_true,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 1 - probabilities.prob_bad_false
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 );
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 return prior;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local function get_probability_bad(username, prior)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 local user_traits = {};
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 module:fire_event("get-account-traits", { username = username, host = module.host, traits = user_traits });
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 local result = prob_is_bad(user_traits, prior);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 return result;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 return {
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 get_probability_bad = get_probability_bad;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 };