Made purge command reset the locale of the saved data, and added files for 0.44 release.
[QuestHelper.git] / Development / graph
blob653a9125f9d65c701427a564110be56111db24e9
1 #!/usr/bin/env lua
3 -- This script creates a graph of the known quests for the various locales from static.lua using gnuplot.
5 loadfile("../static.lua")()
7 plotdata = {}
9 for locale, data in pairs(QuestHelper_StaticData or {}) do
10   plotdata[locale] = {}
11   
12   for faction in pairs({1, 2}) do
13     levels = data.quest and data.quest[faction] or {}
14     
15     plotdata[locale][faction] = {}
16     
17     for level = 1,70 do
18       local list = levels[level] or {}
19       local count = 0
20       
21       for name, data in pairs(list) do
22         count = count + 1
23         if data.alt then
24           for hash in pairs(data.alt) do
25             count = count + 1
26           end
27         end
28       end
29       
30       plotdata[locale][faction][math.ceil(level/5)] = (plotdata[locale][faction][math.ceil(level/5)] or 0) + count
31     end
32   end
33 end
35 file = io.open("plot.dat", "w")
37 local use_locale = {}
39 for level = 1,14 do
40   local line = ""
41   for locale, data in pairs(plotdata) do
42     if data[1][level] > 0 or data[2][level] > 0 then use_locale[locale] = true end
43     line = line .. data[1][level].." "..data[2][level].." "
44   end
45   file:write(line.."\n")
46 end
48 use_locale["zhCN"] = false
50 local title = {enUS="English", frFR="Français", esES="Español (España)", deDE="Deutsch", koKR="한국어", esMX="Español (Mexico)"}
52 io.close(file)
54 local locale_count = 0
55 for locale in pairs(plotdata) do
56   if use_locale[locale] then
57     locale_count = locale_count + 1
58   end
59 end
61 local locale_colour_alliance = {enUS="#ff0000", frFR="#0000aa", deDE="#666666", esES="#ffaa00", koKR="#00aaff", zhCN="#ff00ff", esMX="#dddddd"}
62 local locale_colour_horde = {enUS="#dd0000", frFR="#000088", deDE="#44444444", esES="#dd8800", koKR="#0088dd", zhCN="#dd00dd", esMX="#bfbfbf"}
64 local command = nil
65 local i, j = 1, 1
66 for locale in pairs(plotdata) do
67   if use_locale[locale] then
68     local a = (j-0.5)/(locale_count+1)+0.5
69     local b = a + 1/(locale_count+1)
70     
71     command = (command and command..", " or "") .. "\"plot.dat\" using ($0+1):"..i..":($0+"..a.."):($0+"..b..") title \""..title[locale].."\" lc rgb '"..locale_colour_alliance[locale].."' with boxes"
72     command = (command and command..", " or "") .. "\"plot.dat\" using ($0+1):(-$"..(i+1).."):($0+"..a.."):($0+"..b..") notitle lc rgb '"..locale_colour_horde[locale].."' with boxes"
73     j = j + 1
74   end
75   i = i + 2
76 end
78 local stream = io.popen("gnuplot", "w")
80 if stream then
81   stream:write("set terminal svg size 800,600\n")
82   stream:write("set output 'locale.svg'\n")
83   --stream:write("set terminal png notransparent size 1024,786\n")
84   --stream:write("set output 'locale.png'\n")
85   --stream:write("set terminal pdf colour\n")
86   --stream:write("set output 'locale.pdf'\n")
87   stream:write("set key title 'Quests'\n")
88   stream:write("set key top left Left reverse samplen 1\n")
89   stream:write("set style fill solid 1 border -1\n")
90   stream:write("set xlabel 'Level'\n")
91   local line = "set xtics ("
92   for i = 0,13 do
93     line = line .. "'" .. i*5+1 .. "-" .. i*5+5 .. "' "..i+1 .. (i==13 and ")\n" or ",")
94   end
95   stream:write(line)
96   stream:write("set ytics out scale 0 ('Alliance' 250, 'Horde' -250)\n")
97   if command then stream:write("plot [0:15]"..command..";\n") end
98   stream:flush()
99   io.close(stream)
102 os.remove("plot.dat")