Permalink
Browse files

Population Report & prepop

  • Loading branch information...
1 parent 0d2b8cd commit d364aa65684a3834f797c5d00598dd8d883a61bc @flavour committed Apr 17, 2012
View
@@ -1 +1 @@
-a66413d (2012-04-16 18:54:49)
+0d2b8cd (2012-04-17 14:28:42)
View
@@ -116,22 +116,28 @@ def location():
table = s3db[tablename]
# Location Search Method
- gis_location_search = s3base.S3LocationSearch(
- simple = (s3base.S3SearchSimpleWidget(
- name="location_search_text_simple",
- label = T("Search"),
- #comment = T("Search for a Location by name, including local names."), # How? These aren't fields in this table or in a table that we link to.
- comment = T("To search for a location, enter the name. You may use % as wildcard. Press 'Search' without input to list all locations."),
- field = ["name"]
- )
- ),
- advanced = (s3base.S3SearchSimpleWidget(
+ gis_location_adv_search = (s3base.S3SearchSimpleWidget(
name = "location_search_text_advanced",
label = T("Search"),
#comment = T("Search for a Location by name, including local names."),
comment = T("To search for a location, enter the name. You may use % as wildcard. Press 'Search' without input to list all locations."),
field = ["name"]
),
+ s3base.S3SearchLocationHierarchyWidget(
+ name="location_search_L0",
+ field="L0",
+ cols = 3,
+ ),
+ s3base.S3SearchLocationHierarchyWidget(
+ name="location_search_L1",
+ field="L1",
+ cols = 3,
+ ),
+ s3base.S3SearchLocationHierarchyWidget(
+ name="location_search_L2",
+ field="L2",
+ cols = 3,
+ ),
s3base.S3SearchOptionsWidget(
name = "location_search_level",
label = T("Level"),
@@ -146,13 +152,31 @@ def location():
# cols = 2
#),
)
+ gis_location_search = s3base.S3LocationSearch(
+ simple = (s3base.S3SearchSimpleWidget(
+ name="location_search_text_simple",
+ label = T("Search"),
+ #comment = T("Search for a Location by name, including local names."), # How? These aren't fields in this table or in a table that we link to.
+ comment = T("To search for a location, enter the name. You may use % as wildcard. Press 'Search' without input to list all locations."),
+ field = ["name"]
+ )
+ ),
+ advanced = (
+ gis_location_adv_search
+ )
)
s3mgr.configure(tablename,
# Don't include Bulky Location Selector in List Views
listadd=False,
# Custom Search Method
- search_method=gis_location_search)
+ search_method=gis_location_search,
+ report_filter=gis_location_adv_search,
+ report_rows = ["name"],
+ report_cols = [],
+ report_fact = ["population"],
+ report_method=["sum"],
+ )
# Custom Method
s3mgr.model.set_method("gis", "location", method="parents",
@@ -389,7 +413,9 @@ def get_location_info():
output = s3_rest_controller(csv_extra_fields = [
dict(label="Country",
field=country())
- ])
+ ],
+ interactive_report = True
+ )
_map = vars.get("_map", None)
if _map and isinstance(output, dict):
View
@@ -107,9 +107,9 @@ def model(self):
if current.deployment_settings.get_gis_spatialdb():
# Add a spatial field
# Should we do a test to confirm this? Ideally that would be done only in eden_update_check
- meta_spatial_fields = (meta_fields() + (Field("the_geom", "geometry()"),))
+ meta_spatial_fields = (s3.lx_fields() + meta_fields() + (Field("the_geom", "geometry()"),))
else:
- meta_spatial_fields = meta_fields()
+ meta_spatial_fields = (s3.lx_fields() + meta_fields())
tablename = "gis_location"
table = define_table(tablename,
@@ -194,7 +194,9 @@ def model(self):
#Field("ce", "integer", writable=False, readable=False), # Circular 'Error' around Lat/Lon (in m). Needed for CoT.
#Field("le", "integer", writable=False, readable=False), # Linear 'Error' for the Elevation (in m). Needed for CoT.
Field("area", "double", writable=False, readable=False), # Area of the Polygon (in km2).
- Field("population", "integer", writable=False, readable=False, represent = lambda v, row=None: IS_INT_AMOUNT.represent(v),), # Population of the Location
+ Field("population", "integer",
+ label = T("Population"),
+ represent = lambda v, row=None: IS_INT_AMOUNT.represent(v)),
Field("source", length=32,
requires=IS_NULL_OR(IS_IN_SET(gis_source_opts))),
s3.comments(),
@@ -319,7 +321,8 @@ def model(self):
"gis_feature_type",
"lat",
"lon"
- ])
+ ]
+ )
# Names as component of Locations
self.add_component("gis_location_name", gis_location="location_id")
@@ -635,6 +638,25 @@ def get_location_info():
# Add the bounds (& Centroid for Polygons)
gis.wkt_centroid(form)
+ # Add the Lx
+ if level == "L0":
+ vars.L0 = vars.name
+ elif level == "L1":
+ vars.L1 = vars.name
+ if parent:
+ query = (table.id == parent)
+ country = db(query).select(table.name,
+ limitby=(0, 1)).first()
+ if country:
+ vars.L0 = country.name
+ else:
+ # Get Names of ancestors at each level
+ vars = gis.get_parent_per_level(vars,
+ vars.id,
+ feature=vars,
+ ids=False,
+ names=True)
+
return
# -------------------------------------------------------------------------
View
@@ -273,6 +273,11 @@ def model(self):
ondelete = self.hrm_human_resource_ondelete,
deduplicate=self.hrm_human_resource_deduplicate,
report_filter=[
+ #S3SearchLocationHierarchyWidget(
+ # name="location_search_L0",
+ # field="L0",
+ # cols = 3,
+ #),
S3SearchLocationHierarchyWidget(
name="human_resource_search_L1",
field="L1",
View
@@ -734,6 +734,10 @@ def config_args():
M("Import", m="import"),
#M("Geocode", f="geocode_manual"),
),
+ M("Population Report", f="location", m="report",
+ vars=dict(rows="name",
+ fact="population",
+ aggregate="sum")),
M("Configuration", f="config", args=config_args(),
_id="gis_menu_config",
check=config_menu),
View
@@ -433,7 +433,7 @@ def _select_field(self, list_fields, **attr):
_selected= value == f.selector and "selected" or None)
for f in lfields
if (f.field is None or f.field.name != table._id.name) and f.show]
- if len(options) < 2:
+ if len(options) and len(options) < 2:
options[0].update(_selected="selected")
else:
options.insert(0, OPTION("", _value=None))
@@ -1137,7 +1137,8 @@ def __init__(self, report, show_totals=True, **attributes):
if cols and col_titles and col_totals:
dcols = top(zip(col_titles, col_totals))
row_label = "%s %s" % (BY, str(row_label))
- col_label = "%s %s" % (BY, str(col_label))
+ if col_label:
+ col_label = "%s %s" % (BY, str(col_label))
layer_label=str(layer_label)
json_data = json.dumps(dict(rows=drows,
cols=dcols,
@@ -1,16 +1,14 @@
-"ADM0_NAME","ADM1_NAME"
-"Timor-Leste","Ainaro"
-"Timor-Leste","Aileu"
-"Timor-Leste","Baucau"
-"Timor-Leste","Bobonaro"
-"Timor-Leste","Ermera"
-"Timor-Leste","Covalima"
-"Timor-Leste","Dili"
-"Timor-Leste","Ermera"
-"Timor-Leste","Manufahi"
-"Timor-Leste","Liquiçá"
-"Timor-Leste","Lautem"
-"Timor-Leste","Manufahi"
-"Timor-Leste","Manatuto"
-"Timor-Leste","Oecusse"
-"Timor-Leste","Viqueque"
+"ADM0_NAME","ADM1_NAME","Population"
+"Timor-Leste","Ainaro",52476
+"Timor-Leste","Aileu",37926
+"Timor-Leste","Baucau",100326
+"Timor-Leste","Bobonaro",83034
+"Timor-Leste","Covalima",52818
+"Timor-Leste","Dili",173541
+"Timor-Leste","Ermera",103199
+"Timor-Leste","Lautem",55921
+"Timor-Leste","Liquiçá",54834
+"Timor-Leste","Manatuto",36719
+"Timor-Leste","Manufahi",44950
+"Timor-Leste","Oecusse",57469
+"Timor-Leste","Viqueque",65245
@@ -1,66 +1,66 @@
-"ADM1_NAME","ADM2_NAME","ADM2_CODE"
-"Aileu","Aileu Vila",201
-"Aileu","Laulara",204
-"Aileu","Liquidoe",802
-"Aileu","Remexio",203
-"Ainaro","Ainaro",101
-"Ainaro","Hatu-Builico",102
-"Ainaro","Hatu-Udo",104
-"Ainaro","Maubisse",103
-"Baucau","Baguia",304
-"Baucau","Baucau",301
-"Baucau","Laga",302
-"Baucau","Quelicai",303
-"Baucau","Vemase",305
-"Baucau","Venilale",306
-"Bobonaro","Atabae",404
-"Bobonaro","Balibo",403
-"Bobonaro","Bobonaro",406
-"Bobonaro","Cailaco",402
-"Bobonaro","Lolotoe",405
-"Bobonaro","Maliana",401
-"Covalima","Fatululic",501
-"Covalima","Fatumean",502
-"Covalima","Fohorem",503
-"Covalima","Maucatar",504
-"Covalima","Suai",505
-"Covalima","Tilomar",506
-"Covalima","Zumalai",507
-"Dili","Atauro",604
-"Dili","Cristo Rei",606
-"Dili","Dom Aleixo",605
-"Dili","Metinaro",603
-"Dili","Nain Feto",602
-"Dili","Vera Cruz",601
-"Ermera","Atsabe",704
-"Ermera","Ermera",702
-"Ermera","Hatolia",705
-"Ermera","Letefoho",703
-"Ermera","Railaco",701
-"Lautem","Iliomar",903
-"Lautem","Lautem",902
-"Lautem","Lospalos",901
-"Lautem","Luro",904
-"Lautem","Tutuala",905
-"Liquiçá","Bazartete",801
-"Liquiçá","Liquiçá",202
-"Liquiçá","Maubara",803
-"Manatuto","Barique/Natarbora",1105
-"Manatuto","Laclo",1103
-"Manatuto","Laclubar",1106
-"Manatuto","Laleia",1102
-"Manatuto","Manatuto",1101
-"Manatuto","Soibada",1104
-"Manufahi","Alas",1002
-"Manufahi","Fatuberliu",1003
-"Manufahi","Same",1001
-"Manufahi","Turiscai",1004
-"Oecusse","Nitibe",1202
-"Oecusse","Oesilo",1203
-"Oecusse","Pante Macasar",1201
-"Oecusse","Passabe",1204
-"Viqueque","Lacluta",1305
-"Viqueque","Ossu",1302
-"Viqueque","Uatucarbau",1301
-"Viqueque","Viqueque",1304
-"Viqueque","Watulari",1301
+"ADM1_NAME","ADM2_NAME","ADM2_CODE","Population"
+"Aileu","Aileu Vila",201,17166
+"Aileu","Laulara",204,5448
+"Aileu","Liquidoe",802,5819
+"Aileu","Remexio",203,9493
+"Ainaro","Ainaro",101,12640
+"Ainaro","Hatu-Builico",102,10807
+"Ainaro","Hatu-Udo",104,8817
+"Ainaro","Maubisse",103,20212
+"Baucau","Baguia",304,8943
+"Baucau","Baucau",301,37112
+"Baucau","Laga",302,15133
+"Baucau","Quelicai",303,15915
+"Baucau","Vemase",305,8886
+"Baucau","Venilale",306,14337
+"Bobonaro","Atabae",404,9609
+"Bobonaro","Balibo",403,13540
+"Bobonaro","Bobonaro",406,22756
+"Bobonaro","Cailaco",402,8374
+"Bobonaro","Lolotoe",405,6992
+"Bobonaro","Maliana",401,21763
+"Covalima","Fatululic",501,1814
+"Covalima","Fatumean",502,3346
+"Covalima","Fohorem",503,4116
+"Covalima","Maucatar",504,5876
+"Covalima","Suai",505,21539
+"Covalima","Tilomar",506,6135
+"Covalima","Zumalai",507,9992
+"Dili","Atauro",604,7863
+"Dili","Cristo Rei",606,43909
+"Dili","Dom Aleixo",605,71489
+"Dili","Metinaro",603,3409
+"Dili","Nain Feto",602,18693
+"Dili","Vera Cruz",601,28178
+"Ermera","Atsabe",704,16037
+"Ermera","Ermera",702,27293
+"Ermera","Hatolia",705,30659
+"Ermera","Letefoho",703,19917
+"Ermera","Railaco",701,9293
+"Lautem","Iliomar",903,6726
+"Lautem","Lautem",902,13866
+"Lautem","Lospalos",901,25417
+"Lautem","Luro",904,6205
+"Lautem","Tutuala",905,3707
+"Liquiçá","Bazartete",801,20190
+"Liquiçá","Liquiçá",202,18304
+"Liquiçá","Maubara",803,16340
+"Manatuto","Barique/Natarbora",1105,4781
+"Manatuto","Laclo",1103,7558
+"Manatuto","Laclubar",1106,8034
+"Manatuto","Laleia",1102,3205
+"Manatuto","Manatuto",1101,10449
+"Manatuto","Soibada",1104,2692
+"Manufahi","Alas",1002,6485
+"Manufahi","Fatuberliu",1003,6326
+"Manufahi","Same",1001,26066
+"Manufahi","Turiscai",1004,6073
+"Oecusse","Nitibe",1202,11052
+"Oecusse","Oesilo",1203,10220
+"Oecusse","Pante Macasar",1201,29058
+"Oecusse","Passabe",1204,7139
+"Viqueque","Lacluta",1305,5187
+"Viqueque","Ossu",1302,15610
+"Viqueque","Uatucarbau",1301,6725
+"Viqueque","Viqueque",1304,20640
+"Viqueque","Watulari",1301,17083
Oops, something went wrong.

0 comments on commit d364aa6

Please sign in to comment.