normalize_json.lua

changeset 0
8e1675826e46
child 5
e28748388509
equal deleted inserted replaced
-1:000000000000 0:8e1675826e46
1 local json = require "cjson";
2
3 local data_base_path = "data/";
4
5 local function read_json_file(fn)
6 local data = assert(io.open(data_base_path .. fn)):read("*a");
7 return assert(json.decode(data));
8 end
9
10 local software_list = read_json_file("software_list_doap.json");
11 local software_table = {};
12 local known_software = {};
13
14 local software_categories_table = {};
15 local software_platforms_table = {};
16
17 local software_counter = -1;
18 for software_name, entry in pairs(software_list) do
19 software_counter = software_counter + 1;
20 known_software[entry.name_slug] = software_counter;
21 local new_entry = {
22 id = software_counter;
23 short_name = entry.name_slug;
24 name = software_name;
25 };
26 table.insert(software_table, new_entry);
27 for _, platform in ipairs(entry.platforms) do
28 table.insert(software_platforms_table, {
29 software_id = software_counter;
30 platform = platform;
31 });
32 end
33 for _, category in ipairs(entry.categories) do
34 table.insert(software_categories_table, {
35 software_id = software_counter;
36 category = category;
37 });
38 end
39 end
40
41
42 local xep_list = read_json_file("xeplist.json");
43 local xep_table, xeps_by_url = {}, {};
44 local implementations_table = {
45 --[[{
46 xep = <XEP id>
47 software = <software id>
48 version =
49 status =
50 }]]
51 };
52
53 table.sort(xep_list, function (a, b)
54 if a.number ~= json.null and b.number ~= json.null then
55 return a.number < b.number;
56 end
57 return a.last_updated < b.last_updated;
58 end);
59
60 local xep_counter = -1;
61 for _, entry in ipairs(xep_list) do
62 xep_counter = xep_counter + 1;
63 if entry.status == "Proto" then
64 entry.status = "ProtoXEP";
65 end
66 local xep = {
67 id = xep_counter;
68 number = entry.number;
69 title = entry.title;
70 status = entry.status;
71 last_updated = entry.last_updated;
72 type = entry.type;
73 version = entry.version;
74 approver = entry.approver;
75 accepted = entry.accepted;
76 short_name = entry.short_name;
77 url = entry.url;
78 };
79
80 if entry.url ~= json.null then
81 xeps_by_url[entry.url] = xep_counter;
82 end
83
84 for _, implementation in ipairs(entry.implementations) do
85 local software_id = known_software[implementation.package_name_slug];
86 if software_id then
87 table.insert(implementations_table, {
88 software_id = software_id;
89 xep_id = xep_counter;
90 xep_version = implementation.implemented_version;
91 status = implementation.status;
92 });
93 end
94 end
95 table.insert(xep_table, xep);
96 end
97
98 local function write_json(fn, data)
99 local f = assert(io.open(fn, "w+"));
100 f:write(json.encode(data));
101 f:close();
102 end
103
104 local compliance_table = {};
105
106 for category, level_data in pairs(read_json_file("compliance_suite.json")) do
107 for level, software_data in pairs(level_data) do
108 for software_type, spec_list in pairs(software_data) do
109 for _, spec_url in ipairs(spec_list) do
110 local xep_id = xeps_by_url[spec_url];
111 if xep_id then
112 table.insert(compliance_table, {
113 xep_id = xep_id;
114 category = category;
115 level = level;
116 software_type = software_type;
117 });
118 end
119 end
120 end
121 end
122 end
123
124 write_json("db_xeps.json", xep_table);
125 write_json("db_software.json", software_table);
126 write_json("db_software_platforms.json", software_platforms_table);
127 write_json("db_software_categories.json", software_categories_table);
128 write_json("db_implementations.json", implementations_table);
129 write_json("db_compliance.json", compliance_table);

mercurial