{"id":18296548,"url":"https://github.com/fiedsch/data_util","last_synced_at":"2025-06-14T04:34:27.541Z","repository":{"id":62504498,"uuid":"55849118","full_name":"fiedsch/data_util","owner":"fiedsch","description":"misc. Utilities for data files like variable name lists","archived":false,"fork":false,"pushed_at":"2023-05-04T11:29:23.000Z","size":40,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T10:08:54.345Z","etag":null,"topics":["data","helper","management","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fiedsch.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-09T14:36:12.000Z","updated_at":"2023-02-03T12:37:34.000Z","dependencies_parsed_at":"2024-11-05T14:46:51.598Z","dependency_job_id":"b8ec37bb-9bed-4799-ba22-66d44815f9b5","html_url":"https://github.com/fiedsch/data_util","commit_stats":{"total_commits":45,"total_committers":1,"mean_commits":45.0,"dds":0.0,"last_synced_commit":"e6730bc26a2b04b0cbfb72123e5263ace4771de2"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fdata_util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fdata_util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fdata_util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fdata_util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fiedsch","download_url":"https://codeload.github.com/fiedsch/data_util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008555,"owners_count":21032553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","helper","management","php"],"created_at":"2024-11-05T14:41:37.227Z","updated_at":"2025-04-09T08:43:47.152Z","avatar_url":"https://github.com/fiedsch.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Utilities\n\nPHP classes and helpers that might be helpful when working with data files, variable name lists, etc.\n\n * `Data\\Helper` provides some static helper functions\n\n\n## Usage\n\n```php\n\u003c?php\nrequire '/path/to/vendor/autoload.php';\n\nuse Fiedsch\\Data\\Helper;\nuse Fiedsch\\Data\\Listmanager;\nuse Fiedsch\\Data\\ArrayRecordCreator;\n\n// use Helper::expandExpression() et al.\n// use Listmanager to perform operations on lists (arrays)\n// use ArrayRecordCreator to create data records\n// use Helper::columnIndex() and Helper::columnName() for column name to numerical index mappings\n```\n\n\n## Examples\n\n\n### Create a list of variable names  \n\nCreate a list of variable names that might make it easier to write code in your favourite software for\nstatistical analysis.\n\n```php\nprint Helper::getExpression('a001', 'a111');\n// 'a{001,111}'\n\nHelper::expandExpression('a{001,111}');\n// array('a001', 'a002', 'a003', ..., 'a099', 'a100', ..., 'a111')\n\nprint \"someFunction(\" . join(',', Helper::expandExpression('a{001,101}')) . \");\";\n```\n\n\n### Create a list of file names\n\n```php\nHelper::expandExpression('image{00001,00099}.jpg');\n// array('image00001.jpg', ..., 'image00099.jpg')\n```\n### Comparing Lists\n\nNotice: result are a lists, not sets (see e.g. union()!)\n\n```php\n$listA = ['a','b','c'];\n$listB = ['c','d','e'];\n$manager = new Listmanager($listA);\n$result = $manager-\u003ewithout($listB);   // ['a', 'b']\n$result = $manager-\u003eintersect($listB); // ['c']\n$result = $manager-\u003eunion($listB);     // ['a','b','c','c','d','e']\n\n$manager = new Listmanager(['a','b','c','c','b']);\n$result = $manager-\u003eunique(); // ['a','b','c']\n\n// find duplicates in a list\n$list = ['a','b','a','a','c'];\n$manager = new Listmanager($list);\n$result = $manager-\u003eduplicates(); // ['a','a']\n// $list[0] is considered unique, $list[2] and $list[3] are in the result\n```\n\n### Creating data records\n\n```php\n$creator = new ArrayRecordCreator(['foo','bar','baz']);\n // add values in arbitrary order\n $creator-\u003efoo = '1';\n $creator-\u003ebaz = '2';\n $creator-\u003ebar = '3';\n $record = $creator-\u003egetRecord(); // [1, 3, 2]\n\n $creator-\u003ereset();\n $creator-\u003efoo = 'FOO';\n $record = $creator-\u003egetRecord(); // ['FOO', null, null]\n```\n\n Combined usage with `Helper`\n\n```php\n // create target columns 'col001' to 'col100'\n $creator = new ArrayRecordCreator(Helper::expandExpression('col{001,100}'));\n $creator-\u003ecol042 = 'fourtytwo';\n // ...\n```\n\n ### Working with data arrays read from a (CSV) file\n\n If you are working with data records stored in PHP arrays--e.g. when reading lines from\n a CSV file--you might find it useful to access the entries by their \"column name\" rather\n than their numerical index. This is especially useful if the data originally \"lives\" in\n an Excel Spreadsheet where you have column names \"A\", \"B\", ...\n\n To map  \"A\", \"B\", ... to the respective array indices 0, 1, ... you can use\n\n```php\nHelper::columnIndex(\"A\"); // 0\nHelper::columnIndex(\"B\"); // 1\n// ...\nHelper::columnIndex(\"AQ\"); // 42\n```\n\nThe inverse funtion to `columnIndex()` is `columnName()` which might also be useful when\ndealing with column name to array index mappings.\n\n```php\nHelper::columnName(0); // \"A\"\nHelper::columnName(1); // \"B\"\n// ...\nHelper::columnName(42); // \"AQ\"\n```\n\n### Working with column name mappings\n\nAssume, you have an array that maps (some) variable names to column names:\n```php\n['one'=\u003e'A', 'two'=\u003e'C', 'three'=\u003e'X']\n```\n(with \"some\" meaning that the mapping does not have to be continous).\n\nNow, if you prepend new columns in a data management step you need to adapt\nthe mapping for the next step to match the new data:\n```php\nHelper::prependAndRemap(['one'=\u003e'A', 'two'=\u003e'C', 'three'=\u003e'X'], ['four', 'five'])\n// ['four'=\u003e'A', 'five'=\u003e'B', 'one'=\u003e'C', 'two'=\u003e'E', 'three'=\u003e'Z']\n```\n\n\n### Working with wave specifications\n\nExperimental: might change in future versions!\n\nConsider a survey that is conducted 12 times a year. We call \"these waves\" something like `'01-2023'`, `'02-2023'`, ..., `'12-2023'`.\n\nWhen we want to access the name of a wave \"tree waves back\", we want to move from `'08-2023'` to `'05-2023'` for example, \nbut '02-2023'` to `'11-2022'` should also be computed correctly.\n\n```php\nHelper::moveWave('08-2023', -3); // '05-2023'\nHelper::moveWave('02-2023', -3); // '11-2023'\nHelper::moveWave('10-2023', +3); // '01-2024'\n```\n\nUse a different pattern like so:\n```php\nHelper::moveWave('09/2023', -3, '(\\d{2})(\\/)(\\d{4})', Helper::ORDER_WAVE_FIRST); // '06/2023'\nHelper::moveWave('2023/09', -3, '(\\d{4})(\\/)(\\d{2})', Helper::ORDER_WAVE_LAST);  // '2023/06' \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiedsch%2Fdata_util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiedsch%2Fdata_util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiedsch%2Fdata_util/lists"}