diff options
author | Tom Smeding <tom@tomsmeding.com> | 2022-03-09 00:08:00 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2022-03-09 00:08:00 +0100 |
commit | 78eedbb2aba66695cacac8d832a44512379e4a22 (patch) | |
tree | 6492fdd56ab6fe5b9cb953c349654518fef641cb /timetrack-migrate.js | |
parent | 1e082de1d574ab0cf3404e63d65798210590e5f3 (diff) |
Timetrack 2
Diffstat (limited to 'timetrack-migrate.js')
-rw-r--r-- | timetrack-migrate.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/timetrack-migrate.js b/timetrack-migrate.js new file mode 100644 index 0000000..c94b1b5 --- /dev/null +++ b/timetrack-migrate.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +const fs = require("fs"); + +// accounts: {"user": hash (String)} +const origaccounts_obj = JSON.parse(fs.readFileSync("persist/timetrack/7a90e38a211ece1c346928e7d1f3e968")); +const origaccounts = origaccounts_obj.value; + +// events: {"user": [{id: Int,sheet: String,text: String,date: Date,type: String}]} +// type: "in" / "out" +const origevents_obj = JSON.parse(fs.readFileSync("persist/timetrack/16908b0605f2645dfcb4c3a8d248cef3")); +const origevents = origevents_obj.value; + +const destfname = "persist/timetrack2/7a90e38a211ece1c346928e7d1f3e968"; + +const accounts = {}; +for (let user in origaccounts) { + accounts[user] = { + list: [], + current: null, + pwhash: origaccounts[user], + }; + + let current = null; + for (let ev of origevents[user]) { + if (ev.type == "in" && current == null) { + current = ev; + } else if (ev.type == "out" && current != null) { + if (current.sheet != ev.sheet) { + console.error("Inconsistent in/out pairs (sheet for id " + ev.id + ")"); + process.exit(1); + } + + const text = current.text.length > ev.text.length ? current.text : ev.text; + + accounts[user].list.push({ + id: current.id, // arbitrarily choose check-in id + sheet: current.sheet, + text: text, + indate: current.date, + outdate: ev.date, + }); + + current = null; + } else { + console.error("Inconsistent in/out pairs at id=" + ev.id); + process.exit(1); + } + } +} + +fs.writeFileSync(destfname, JSON.stringify({key:"accounts",value:accounts})); |