Skip to content

Commit

Permalink
better test for total_type related to #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Girard committed Feb 19, 2015
1 parent 39ab51b commit dfb81d2
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions database_creation/test/total_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,48 @@ def test(cursor):
nb_reporting_annual_flows, total_flows=cursor.fetchone()
print "%s number of reporting exp or imp total annual flows on %s total"%(nb_reporting_annual_flows,total_flows)

cursor.execute("""SELECT world_type_group, sum(nb) as sum FROM (SELECT count(*) as nb,group_concat(partner,"|") as world_type_group

print "\nrepartition of type of Total Trade to World as duplicates:"

cursor.execute("""SELECT count(*) FROM (SELECT count(*) as nb,group_concat(partner,"|") as world_type_group
FROM flow_joined
WHERE partner IN ("World_undefined","World_estimated","World_as_reported","World_as_reported2")
WHERE partner IN ("World_estimated","World_as_reported")
group by reporting,Yr,expimp )
""")
compatible_world_flows_worldview=cursor.fetchone()[0]
print "\n%s %.1f%% flows compatible with world view"%(compatible_world_flows_worldview,100*float(compatible_world_flows_worldview)/nb_reporting_annual_flows)

cursor.execute("""SELECT count(*) FROM (SELECT count(*) as nb,group_concat(partner,"|") as world_type_group
FROM flow_joined
WHERE partner IN ("World_as_reported","World_as_reported2")
group by reporting,Yr,expimp )
""")
compatible_world_flows_countryview=cursor.fetchone()[0]
print "%s %.1f%% flows compatible with world view"%(compatible_world_flows_countryview,100*float(compatible_world_flows_countryview)/nb_reporting_annual_flows)

cursor.execute("""SELECT count(*) FROM (SELECT count(*) as nb,group_concat(partner,"|") as world_type_group
FROM flow_joined
group by reporting,Yr,expimp )
WHERE world_type_group="World_undefined"
group by world_type_group
ORDER BY sum DESC
""")
print "\nrepartition of type of Total Trade to World as duplicates:"
missing_world_flows_worldview=0
missing_world_flows_countryview=0
undefined=0
undefined=cursor.fetchone()[0]
print "%s flows to World with only undefined Total"%(undefined)
# missing_world_flows_countryview=0
# undefined=0

for world_type_group,nb in cursor:
print world_type_group,nb
if "World_estimated" in world_type_group or "World_as_reported" in world_type_group:
missing_world_flows_worldview+=nb
if "World_as_reported2" in world_type_group or "World_as_reported" in world_type_group:
missing_world_flows_countryview+=nb
if world_type_group == "World_undefined":
undefined+=nb
print "\n%s %.1f%% flows compatible with world view"%(missing_world_flows_worldview,100*float(missing_world_flows_worldview)/nb_reporting_annual_flows)
print "%s %.1f%% flows compatible with country view"%(missing_world_flows_countryview,100*float(missing_world_flows_countryview)/nb_reporting_annual_flows)
print "%s Total trade to World flows with no type"%undefined
# for world_type_group,nb in cursor:
# print world_type_group,nb
# if "World_estimated" in world_type_group or "World_as_reported" in world_type_group:
# missing_world_flows_worldview+=nb
# if "World_as_reported2" in world_type_group or "World_as_reported" in world_type_group:
# missing_world_flows_countryview+=nb
# if world_type_group == "World_undefined":
# undefined+=nb
# print "\n%s %.1f%% flows compatible with world view"%(missing_world_flows_worldview,100*float(missing_world_flows_worldview)/nb_reporting_annual_flows)
# print "%s %.1f%% flows compatible with country view"%(missing_world_flows_countryview,100*float(missing_world_flows_countryview)/nb_reporting_annual_flows)
# print "%s Total trade to World flows with no type"%undefined

print "\nisolating World_undefined-only flows :"

Expand Down

0 comments on commit dfb81d2

Please sign in to comment.