-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Total_type World total trade special case management related to #1
- Loading branch information
Paul Girard
committed
Feb 19, 2015
1 parent
07a9dc7
commit 39ab51b
Showing
3 changed files
with
96 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import codecs | ||
import os | ||
|
||
import json | ||
import sqlite3 | ||
|
||
|
||
def test(cursor): | ||
cursor.execute("""SELECT count(*) | ||
FROM flow_joined | ||
WHERE partner="World_undefined" | ||
""") | ||
print "%s undefined type of Total Trade to World"%cursor.fetchone() | ||
|
||
cursor.execute("""SELECT count(*),sum(nb) FROM (SELECT count(*) as nb | ||
FROM flow_joined | ||
group by reporting,Yr,expimp) | ||
""") | ||
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 | ||
FROM flow_joined | ||
WHERE partner IN ("World_undefined","World_estimated","World_as_reported","World_as_reported2") | ||
group by reporting,Yr,expimp ) | ||
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 | ||
|
||
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 :" | ||
|
||
cursor.execute("""SELECT reporting,count(*),group_concat(Yr,"|") | ||
FROM (SELECT reporting,Yr,group_concat(partner) as partners_group | ||
FROM flow_joined | ||
WHERE partner IN ("World_undefined","World_estimated","World_as_reported","World_as_reported2") | ||
group by reporting,Yr,expimp ) | ||
WHERE partners_group="World_undefined" | ||
group by reporting | ||
""") | ||
for f in cursor: | ||
print "Reporting: %s, %s cases, years: %s"%f | ||
return True |