This repository was archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsanity.py
56 lines (48 loc) · 1.46 KB
/
sanity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import orm
def getcountrylist():
for value in orm.session.query(orm.Value).filter(orm.Value.indID == "CG060").all():
yield value.region
dsIDs = """
acled
echo
emdat
esa-unpd-*
fao-foodsec
faostat3
hdi-disaster
HDRStats
m49
mdgs
reliefweb-api
unicef-infobycountry
unterm
accuweather
who-athena-other
who-athena
wikipedia
worldaerodata
worldbank-lending-groups
World Bank""".strip().split('\n')
orm.session.execute("create temporary table dsIDs (dsID);")
for dsID in dsIDs:
orm.session.execute("insert into dsIDs values ('%s')" % dsID)
def sql(s):
return orm.session.execute(s).fetchmany(11)
should_be_empty = """
select distinct dsID from value where source is null; -- Blank source
select distinct dsID from value where source is ''; -- Blank source
select distinct dsID from value where period like "%P%" and period not like "%/%"; -- Bad recurring
select distinct dsID from value where period like "%T%"; -- Bad time
select dsID from dataset where dsID not in (select dsID from value); -- Not minimal list of dsID
select indID from indicator where indID not in (select indID from value); -- Not minimal list of indID
select dsID from dsIDs where dsID not in (select dsID from dataset); -- completeness
""".strip().split('\n')
for line in should_be_empty:
values = sql(line)
number = len(values)
if number > 10:
number = "many"
if values:
print "FAIL: %s occurrences of %r" % (number, line)
print values
print "------\n"