liquid_feedback_frontend
diff db/demodata.lua @ 0:3bfb2fcf7ab9
Version alpha1
author | bsw/jbe |
---|---|
date | Wed Nov 18 12:00:00 2009 +0100 (2009-11-18) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/db/demodata.lua Wed Nov 18 12:00:00 2009 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +#!/usr/bin/env lua 1.5 + 1.6 +member_count = 10000 1.7 +area_count = 24 1.8 +issue_count = 1000 1.9 +policy_count = 3 -- do not change 1.10 + 1.11 +function write(...) 1.12 + io.stdout:write(...) 1.13 +end 1.14 +function writeln(...) 1.15 + write(...) 1.16 + write("\n") 1.17 +end 1.18 + 1.19 +math.randomseed(os.time()) 1.20 + 1.21 +writeln('BEGIN;') 1.22 + 1.23 +for i = 2, member_count do 1.24 + writeln('INSERT INTO "member" ("login", "name", "ident_number") VALUES (', "'testuser", i, "', 'Benutzer #", i, "', 'TEST", i, "');") 1.25 +end 1.26 + 1.27 +for i = 1, member_count do 1.28 + local is_linked = {} 1.29 + while math.random(4) > 1 do 1.30 + local k = math.random(member_count) 1.31 + if not is_linked[k] then 1.32 + local public = math.random(2) == 1 and "TRUE" or "FALSE" 1.33 + writeln('INSERT INTO "contact" ("member_id", "other_member_id", "public") VALUES (', i, ", ", k, ", ", public, ");") 1.34 + is_linked[k] = true 1.35 + end 1.36 + end 1.37 +end 1.38 + 1.39 +for i = 2, area_count do 1.40 + writeln('INSERT INTO "area" ("name") VALUES (', "'Area #", i, "');") 1.41 +end 1.42 + 1.43 +local memberships = {} 1.44 + 1.45 +for i = 1, area_count do 1.46 + memberships[i] = {} 1.47 + for j = 1, member_count do 1.48 + if math.random(4) == 1 then 1.49 + memberships[i][j] = true 1.50 + local autoreject = math.random(2) == 1 and "TRUE" or "FALSE" 1.51 + writeln('INSERT INTO "membership" ("member_id", "area_id", "autoreject") VALUES (', j, ", ", i, ", ", autoreject, ");") 1.52 + end 1.53 + end 1.54 +end 1.55 + 1.56 +do 1.57 + local issue_initiative_count = {} 1.58 + local initiative_draft_count = {} 1.59 + local initiative_idx = 1 1.60 + local draft_count = 0 1.61 + for i = 1, issue_count do 1.62 + local area = math.random(area_count) 1.63 + writeln('INSERT INTO "issue" ("area_id", "policy_id") VALUES (', area, ", ", math.random(policy_count), ");") 1.64 + issue_initiative_count[i] = 1 1.65 + while math.random(3) > 1 do 1.66 + issue_initiative_count[i] = issue_initiative_count[i] + 1 1.67 + end 1.68 + for j = 1, issue_initiative_count[i] do 1.69 + writeln('INSERT INTO "initiative" ("issue_id", "name") VALUES (', i, ", 'Initiative #", initiative_idx, "');") 1.70 + initiative_draft_count[i] = 1 1.71 + while math.random(4) > 1 do 1.72 + initiative_draft_count[i] = initiative_draft_count[i] + 1 1.73 + end 1.74 + local initiators = {} 1.75 + local is_used = {} 1.76 + repeat 1.77 + local member = math.random(member_count) 1.78 + if not is_used[member] then 1.79 + initiators[#initiators+1] = member 1.80 + is_used[member] = true 1.81 + end 1.82 + until math.random(2) == 1 1.83 + for k = 1, initiative_draft_count[i] do 1.84 + draft_count = draft_count + 1 1.85 + writeln('INSERT INTO "draft" ("initiative_id", "author_id", "content") VALUES (', initiative_idx, ", ", initiators[math.random(#initiators)], ", 'Lorem ipsum... (#", draft_count, ")');") 1.86 + end 1.87 + for k = 1, #initiators do 1.88 + local member = math.random(member_count) 1.89 + writeln('INSERT INTO "initiator" ("member_id", "initiative_id") VALUES (', initiators[k], ", ", initiative_idx, ");") 1.90 + if math.random(50) > 1 then 1.91 + writeln('INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES (', initiators[k], ", ", initiative_idx, ", ", draft_count - math.random(initiative_draft_count[i]) + 1, ");") 1.92 + end 1.93 + end 1.94 + local probability = math.random(99) + 1 1.95 + for k = 1, member_count do 1.96 + if not is_used[k] and (memberships[area][k] and math.random(probability) <= 4 or math.random(probability) == 1) then 1.97 + writeln('INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES (', k, ", ", initiative_idx, ", ", draft_count - math.random(initiative_draft_count[i]) + 1, ");") 1.98 + end 1.99 + end 1.100 + initiative_idx = initiative_idx + 1 1.101 + end 1.102 + end 1.103 +end 1.104 + 1.105 +writeln('END;')