bsw/jbe@0: #!/usr/bin/env lua bsw/jbe@0: bsw/jbe@0: member_count = 10000 bsw/jbe@0: area_count = 24 bsw/jbe@0: issue_count = 1000 bsw/jbe@0: policy_count = 3 -- do not change bsw/jbe@0: bsw/jbe@0: function write(...) bsw/jbe@0: io.stdout:write(...) bsw/jbe@0: end bsw/jbe@0: function writeln(...) bsw/jbe@0: write(...) bsw/jbe@0: write("\n") bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: math.randomseed(os.time()) bsw/jbe@0: bsw/jbe@0: writeln('BEGIN;') bsw/jbe@0: bsw/jbe@0: for i = 2, member_count do bsw/jbe@0: writeln('INSERT INTO "member" ("login", "name", "ident_number") VALUES (', "'testuser", i, "', 'Benutzer #", i, "', 'TEST", i, "');") bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: for i = 1, member_count do bsw/jbe@0: local is_linked = {} bsw/jbe@0: while math.random(4) > 1 do bsw/jbe@0: local k = math.random(member_count) bsw/jbe@0: if not is_linked[k] then bsw/jbe@0: local public = math.random(2) == 1 and "TRUE" or "FALSE" bsw/jbe@0: writeln('INSERT INTO "contact" ("member_id", "other_member_id", "public") VALUES (', i, ", ", k, ", ", public, ");") bsw/jbe@0: is_linked[k] = true bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: for i = 2, area_count do bsw/jbe@0: writeln('INSERT INTO "area" ("name") VALUES (', "'Area #", i, "');") bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: local memberships = {} bsw/jbe@0: bsw/jbe@0: for i = 1, area_count do bsw/jbe@0: memberships[i] = {} bsw/jbe@0: for j = 1, member_count do bsw/jbe@0: if math.random(4) == 1 then bsw/jbe@0: memberships[i][j] = true bsw/jbe@0: local autoreject = math.random(2) == 1 and "TRUE" or "FALSE" bsw/jbe@0: writeln('INSERT INTO "membership" ("member_id", "area_id", "autoreject") VALUES (', j, ", ", i, ", ", autoreject, ");") bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: do bsw/jbe@0: local issue_initiative_count = {} bsw/jbe@0: local initiative_draft_count = {} bsw/jbe@0: local initiative_idx = 1 bsw/jbe@0: local draft_count = 0 bsw/jbe@0: for i = 1, issue_count do bsw/jbe@0: local area = math.random(area_count) bsw/jbe@0: writeln('INSERT INTO "issue" ("area_id", "policy_id") VALUES (', area, ", ", math.random(policy_count), ");") bsw/jbe@0: issue_initiative_count[i] = 1 bsw/jbe@0: while math.random(3) > 1 do bsw/jbe@0: issue_initiative_count[i] = issue_initiative_count[i] + 1 bsw/jbe@0: end bsw/jbe@0: for j = 1, issue_initiative_count[i] do bsw/jbe@0: writeln('INSERT INTO "initiative" ("issue_id", "name") VALUES (', i, ", 'Initiative #", initiative_idx, "');") bsw/jbe@0: initiative_draft_count[i] = 1 bsw/jbe@0: while math.random(4) > 1 do bsw/jbe@0: initiative_draft_count[i] = initiative_draft_count[i] + 1 bsw/jbe@0: end bsw/jbe@0: local initiators = {} bsw/jbe@0: local is_used = {} bsw/jbe@0: repeat bsw/jbe@0: local member = math.random(member_count) bsw/jbe@0: if not is_used[member] then bsw/jbe@0: initiators[#initiators+1] = member bsw/jbe@0: is_used[member] = true bsw/jbe@0: end bsw/jbe@0: until math.random(2) == 1 bsw/jbe@0: for k = 1, initiative_draft_count[i] do bsw/jbe@0: draft_count = draft_count + 1 bsw/jbe@0: writeln('INSERT INTO "draft" ("initiative_id", "author_id", "content") VALUES (', initiative_idx, ", ", initiators[math.random(#initiators)], ", 'Lorem ipsum... (#", draft_count, ")');") bsw/jbe@0: end bsw/jbe@0: for k = 1, #initiators do bsw/jbe@0: local member = math.random(member_count) bsw/jbe@0: writeln('INSERT INTO "initiator" ("member_id", "initiative_id") VALUES (', initiators[k], ", ", initiative_idx, ");") bsw/jbe@0: if math.random(50) > 1 then bsw/jbe@0: writeln('INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES (', initiators[k], ", ", initiative_idx, ", ", draft_count - math.random(initiative_draft_count[i]) + 1, ");") bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: local probability = math.random(99) + 1 bsw/jbe@0: for k = 1, member_count do bsw/jbe@0: if not is_used[k] and (memberships[area][k] and math.random(probability) <= 4 or math.random(probability) == 1) then bsw/jbe@0: writeln('INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES (', k, ", ", initiative_idx, ", ", draft_count - math.random(initiative_draft_count[i]) + 1, ");") bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: initiative_idx = initiative_idx + 1 bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: writeln('END;')