|
Occupation Generator 3.0.1
Employment status and occupation by country, age, sex and education for C++23
|
Occupation Generator: draws a person's employment status, education and job. More...
#include <occupationgen.hpp>
Public Types | |
| enum class | table : std::uint8_t { status , inactivity , education , isco , shares , factors , occupations } |
| The data tables. More... | |
Public Member Functions | |
| ocg () | |
| Default constructor — creates an empty generator with no data. | |
| ocg (const ocg &)=delete | |
| Not copyable. | |
| ocg & | operator= (const ocg &)=delete |
| Not copyable. | |
| ocg (ocg &&) noexcept=default | |
| Movable. | |
| ocg & | operator= (ocg &&) noexcept=default |
| Movable. | |
| ~ocg ()=default | |
| Destructor. | |
| occupation | get_occupation (const occupation_request &request) |
| Generate a random occupation for a request. | |
| occupation | get_occupation (const occupation_request &request, std::uint64_t call_seed) const |
| Generate a deterministic occupation for a request. | |
| std::vector< occupation > | get_occupation_batch (const occupation_request &request, const core::batch_options &options) |
| Generate a batch of occupation results from a seed drawn like get_occupation() draws its own. | |
| std::vector< occupation > | get_occupation_batch (const occupation_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| Generate a batch of occupation results, deterministically. | |
| template<typename Sink > | |
| void | for_each_occupation (const occupation_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| Stream a batch of occupation results to a sink without holding the whole batch. | |
| template<typename Sink > | |
| void | for_each_occupation (const occupation_request &request, const core::batch_options &options, Sink &&sink) |
| Stream a batch of occupation results with a batch seed drawn like get_occupation() draws its own. | |
| bool | has_data () const |
| Check whether status data has been loaded. | |
| std::size_t | country_count () const |
| Return the number of countries that can be drawn from. | |
| std::size_t | job_count () const |
| Return the number of jobs in the catalogue. | |
| const std::vector< std::string > & | unresolved () const |
| Rows that name something that is not loaded: a share for an unknown ISCO group, a job for an unknown ISCO group. They are ignored, so removing a group needs no other change; this lists them to catch misspelt codes. | |
| void | load (const std::filesystem::path &dir) |
| Load a resource directory, replacing all data and layers loaded before. | |
| bool | load (dataset tier) |
| Load a dataset tier, replacing all data and layers loaded before. | |
| void | extend (const std::filesystem::path &path, core::layer_mode mode=core::layer_mode::override) |
| Add data layers from a directory or a file. | |
| const core::layer_info & | extend (table which, core::tsv_document doc, core::layer_mode mode=core::layer_mode::override) |
| Add a data layer to one table. | |
| const core::layer_info & | extend_from_string (table which, std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override) |
| Add a data layer to one table from TSV text (for example from a WebAssembly host). | |
| const std::vector< core::layer_info > & | layers (table which) const |
| The layers in effect for one table, in order. | |
| std::uint64_t | data_hash () const |
| Hash of the loaded data (all tables), recorded in each result's signature(). | |
Static Public Member Functions | |
| static ocg & | instance () |
| Access the global singleton instance. | |
Occupation Generator: draws a person's employment status, education and job.
The country (when not given) comes from the "country" stream of the call seed, the sex from "sex", the status from "status", the education from "education", the ISCO-08 group from "isco" and the job within it from "job", so fields added later leave these unchanged. Output is identical on every compiler and platform (dasmig-core).
The status comes from the country's employment and unemployment rates for the person's sex and age band; the inactive are split into students, retired and others by age. From 6 to 14 a person is a student, and under 6 inactive with no job. The job is an ISCO-08 level-2 group drawn by the country's employment share for the person's sex, multiplied by factors for the person's age class and education (how much more or less common the group is at that age or education than in employment as a whole), then a job of the catalogue within the group. Groups with no job open to the person's age are skipped.
The education comes from the country's shares for the sex and age band. A level the person is too young to have completed (basic under 14, intermediate under 17, advanced under 21) counts as the level below.
A country chosen at random is uniform over the countries loaded; the data has no population column. Pass a country chosen by country-generator for a population-weighted world.
Every call takes an occupation_request; generation choices are never stored as instance defaults. Data loading and layers belong to the instance. Can be used as a singleton via instance() or constructed independently.
Definition at line 260 of file occupationgen.hpp.
|
strong |
The data tables.
Definition at line 264 of file occupationgen.hpp.
|
inline |
Default constructor — creates an empty generator with no data.
Definition at line 277 of file occupationgen.hpp.
|
inline |
Return the number of countries that can be drawn from.
Definition at line 408 of file occupationgen.hpp.
|
inline |
Hash of the loaded data (all tables), recorded in each result's signature().
Definition at line 549 of file occupationgen.hpp.
|
inline |
Add data layers from a directory or a file.
A directory may hold any of the table files (status.tsv, inactivity.tsv, education.tsv, isco.tsv, shares.tsv, factors.tsv, occupations.tsv); all are applied together or, if any fails, none. A file must have one of those names.
| path | Directory or file. |
| mode | How the layers combine with the data loaded before. |
| core::tsv_error | If a file cannot be read or a row is invalid; the data is then unchanged. |
| std::invalid_argument | If path is a file with another name. |
Definition at line 484 of file occupationgen.hpp.
|
inline |
Add a data layer to one table.
Rows are keyed by the table's key columns (see table). In the default override mode a row replaces the loaded row with the same key and new keys are added; a row with disabled set to 1 removes its key.
| which | The table. |
| doc | TSV with that table's columns. |
| mode | How the layer combines with the data loaded before. |
| core::tsv_error | If a row is invalid; the data is unchanged. |
Definition at line 515 of file occupationgen.hpp.
|
inline |
Add a data layer to one table from TSV text (for example from a WebAssembly host).
| which | The table. |
| text | TSV with that table's columns. |
| source | Name used in errors. |
| mode | How the layer combines with the data loaded before. |
| core::tsv_error | If a row is invalid; the data is unchanged. |
Definition at line 532 of file occupationgen.hpp.
|
inline |
Stream a batch of occupation results with a batch seed drawn like get_occupation() draws its own.
| Sink | Callable taking (std::uint64_t, occupation&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 393 of file occupationgen.hpp.
|
inline |
Stream a batch of occupation results to a sink without holding the whole batch.
Generates the same items as get_occupation_batch() and calls sink(index, item) in index order on the calling thread; index includes options.first.
| Sink | Callable taking (std::uint64_t, occupation&); for example core::jsonl_writer or core::csv_writer. |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items. |
Definition at line 378 of file occupationgen.hpp.
|
inline |
Generate a random occupation for a request.
| request | Country, age, sex, education and status; any may be omitted. Pass {} to use the request defaults. |
Draws a call seed from the instance's entropy-seeded engine.
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | If the country has no data for the person (or, with no country, no country has any), or no occupation is open to the person. |
Definition at line 307 of file occupationgen.hpp.
|
inline |
Generate a deterministic occupation for a request.
| request | Country, age, sex, education and status; any may be omitted. |
| call_seed | Seed; the same seed, request and data give the same occupation. |
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | As for the unseeded overload. |
Definition at line 319 of file occupationgen.hpp.
|
inline |
Generate a batch of occupation results from a seed drawn like get_occupation() draws its own.
Item i is get_occupation(request, core::item_seed(batch_seed, options.first + i)) for the drawn batch seed; see the seeded overload.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 335 of file occupationgen.hpp.
|
inline |
Generate a batch of occupation results, deterministically.
Item i is exactly get_occupation(request, core::item_seed(batch_seed, options.first + i)), so an item replays on its own, a range can be generated directly, two batches that follow each other equal one, and the output does not depend on options.threads.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for occupation). |
| batch_seed | Seed of the whole batch. |
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 356 of file occupationgen.hpp.
|
inline |
Check whether status data has been loaded.
Definition at line 404 of file occupationgen.hpp.
|
inlinestatic |
Access the global singleton instance.
Loads the lite tier (or full if lite is missing) on first access, from compiled-in data or an auto-probed resources/.
Definition at line 290 of file occupationgen.hpp.
|
inline |
Return the number of jobs in the catalogue.
Definition at line 412 of file occupationgen.hpp.
|
inline |
The layers in effect for one table, in order.
| which | The table. |
Definition at line 541 of file occupationgen.hpp.
|
inline |
Load a resource directory, replacing all data and layers loaded before.
The directory must contain status.tsv; the other tables are read when present (a missing one leaves its table empty). A path without status.tsv is ignored.
| dir | Directory such as resources/lite. |
| core::tsv_error | If a file is malformed; the data is then unchanged. |
Definition at line 434 of file occupationgen.hpp.
|
inline |
Load a dataset tier, replacing all data and layers loaded before.
Uses the compiled-in copy when the library is built with DASMIG_OCCUPATION_EMBED, otherwise searches resources/, ../resources, occupation-generator/resources and ../occupation-generator/resources.
| tier | The tier. |
| core::tsv_error | If a file is malformed. |
Definition at line 456 of file occupationgen.hpp.
|
inline |
Rows that name something that is not loaded: a share for an unknown ISCO group, a job for an unknown ISCO group. They are ignored, so removing a group needs no other change; this lists them to catch misspelt codes.
Definition at line 420 of file occupationgen.hpp.