Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/nursix/eden
Browse files Browse the repository at this point in the history
Conflicts:
	static/scripts/S3/s3.vulnerability.js
	views/vulnerability/map.html
  • Loading branch information
flavour committed Oct 10, 2012
2 parents aa5a879 + c48043b commit e42f471
Show file tree
Hide file tree
Showing 18 changed files with 689 additions and 274 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
b9af092 (2012-10-10 13:21:30)
aa5a879 (2012-10-10 13:51:35)
126 changes: 124 additions & 2 deletions controllers/vulnerability.py
Expand Up @@ -32,9 +32,14 @@ def index():
append("/%s/static/scripts/S3/s3.dataTables.js" % appname)
append("/%s/static/scripts/jquery.dataTables.js" % appname)
append("/%s/static/scripts/jquery.dataTables.fnSetFilteringDelay.js" % appname)
append("/%s/static/scripts/flot/jquery.flot.js" % appname)
append("/%s/static/scripts/flot/jquery.flot.fillbetween.js" % appname)
append("/%s/static/scripts/flot/jquery.flot.crosshair.js" % appname)
else:
append("/%s/static/scripts/S3/s3.vulnerability.min.js" % appname)
append("/%s/static/scripts/S3/s3.dataTables.min.js" % appname)
append("/%s/static/scripts/flot/jquery.flot.min.js" % appname)
append("/%s/static/scripts/flot/jquery.flot.crosshair.min.js" % appname)

js_global = []
append = js_global.append
Expand Down Expand Up @@ -524,6 +529,123 @@ def vdata():
response.headers["Content-Type"] = "application/json"
return script

# -----------------------------------------------------------------------------
def rdata():
"""
Controller to extract data for resilience analysis line graph
returns a JavaScript like:
r={"location_id":
{"year":
{"indicator_index": [value, deviation]}
}
}
where indicator_index is 0 for the overall resilience (mean), or
1-10 for the individual indicators (=index in the list + 1).
Any data which are not available from the db will be omitted (to
save bandwidth) - the client-side script must detect any missing
keys itself.
@todo: this controller must make sure that there is always a mean
(overall resilience) in each set => calculate if not present.
"""

response.headers["Content-Type"] = "application/json"

if not len(request.args):
return '''n={}'''
else:
locations = list(set([a for a in request.args if a.isdigit()]))

vars = request.get_vars
fyear = None
lyear = None
if "after" in vars:
try:
fyear = int(vars["after"])
except ValueError:
pass
if "before" in vars:
try:
lyear = int(vars["before"])
except ValueError:
pass

if lyear and fyear and lyear > fyear:
lyear, fyear = fyear, lyear
if fyear:
fdate = datetime.datetime(fyear, 1, 1)
else:
fdate = None
if lyear:
ldate = datetime.datetime(lyear+1, 1, 1)
else:
ldate = request.utcnow

resilience_id = s3db.vulnerability_resilience_id()
indicator_pids = s3db.vulnerability_ids()
pos = Storage([(indicator_pids[i], i+1)
for i in xrange(len(indicator_pids))])
pos[resilience_id] = 0

stable = s3db.stats_aggregate
query = (stable.deleted != True) & \
(((stable.parameter_id == resilience_id) & \
(stable.agg_type == 4)) |
(stable.parameter_id.belongs(indicator_pids)))

if len(locations) == 1:
query &= (stable.location_id == locations[0])
else:
query &= (stable.location_id.belongs(locations))
if fyear:
query &= (stable.date >= fdate)
if lyear is None or lyear == request.utcnow.year:
query &= ((stable.end_date < ldate) | (stable.end_date == None))
else:
query &= (stable.end_date < ldate)

rows = db(query).select(stable.location_id,
stable.parameter_id,
stable.date,
stable.mean,
stable.median,
stable.mad,
orderby=~stable.date)

keys = []
seen = keys.append
data = dict()
for row in rows:
l = row.location_id
y = row.date.year
p = pos[row.parameter_id]
if (l, y, p) in keys:
continue
seen((l, y, p))

if p == pos[resilience_id]:
val = int(round(row.mean, 0))
else:
val = row.median
dev = row.mad

if l not in data:
ldata = data[l] = dict()
else:
ldata = data[l]
if y not in ldata:
ydata = ldata[y] = dict()
else:
ydata = ldata[y]
ydata[p] = (val, dev)

script = '''r=%s\n''' % json.dumps(data)
return script

# -----------------------------------------------------------------------------
def reportFilter(filter_request):
"""
Expand Down Expand Up @@ -1301,7 +1423,7 @@ def import_image(action):

# -----------------------------------------------------------------------------
def import_demo_create():
"""
"""
Controller to import demographic data
"""

Expand Down Expand Up @@ -1341,7 +1463,7 @@ def import_demo_create():
limitby=(0, 1)
).first()
if record == None:
# Save the source details & SE
# Save the source details & SE
doc_id = dd_table.insert(name = source)
update_super(dd_table, dict(id=doc_id))
source_id = dd_table[doc_id].source_id
Expand Down
25 changes: 25 additions & 0 deletions languages/en-gb.py
@@ -1,5 +1,6 @@
# coding: utf8
{
'%Y-%m-%d %H:%M:%S': '%Y-%m-%d %H:%M:%S',
'Ability to customize the list of details tracked at a Shelter': 'Ability to customise the list of details tracked at a Shelter',
'Ability to customize the list of human resource tracked at a Shelter': 'Ability to customise the list of human resource tracked at a Shelter',
'Ability to customize the list of important facilities needed at a Shelter': 'Ability to customise the list of important facilities needed at a Shelter',
Expand All @@ -13,6 +14,7 @@
'Add Organization Domain': 'Add Organisation Domain',
'Add Organization to Project': 'Add Organisation to Project',
'Add Organization Type': 'Add Organisation Type',
'Cannot be empty': 'Cannot be empty',
'Capturing the projects each organization is providing and where': 'Capturing the projects each organisation is providing and where',
'Catalog': 'Catalogue',
'Catalog added': 'Catalogue added',
Expand All @@ -25,13 +27,17 @@
'Catalog updated': 'Catalogue updated',
'Catalogs': 'Catalogues',
'Certifying Organization': 'Certifying Organisation',
'Client IP': 'Client IP',
'Comments': 'Comments',
'Competency Rating Catalog': 'Competency Rating Catalogue',
'Configure resources to synchronize, update methods and policies': 'Configure resources to synchronise, update methods and policies',
'Confirming Organization': 'Confirming Organization',
'Course Catalog': 'Course Catalogue',
'Create New Catalog': 'Create New Catalogue',
'Create New Catalog Item': 'Create New Catalogue Item',
'Create new Organization': 'Create new Organisation',
'Created By': 'Created By',
'Created On': 'Created On',
'Credentialling Organization': 'Credentialling Organisation',
'Current owning Organization': 'Current owning Organization',
'Delete Catalog': 'Delete Catalogue',
Expand All @@ -40,17 +46,22 @@
'Delete Organization Domain': 'Delete Organisation Domain',
'Delete Organization Type': 'Delete Organisation Type',
'Department Catalog': 'Department Catalogue',
'Description': 'Description',
'E-mail': 'E-mail',
'Edit Catalog': 'Edit Catalogue',
'Edit Catalog Item': 'Edit Catalogue Item',
'Edit Organization': 'Edit Organisation',
'Edit Organization Domain': 'Edit Organisation Domain',
'Edit Organization Type': 'Edit Organisation Type',
'Edit Project Organization': 'Edit Project Organisation',
'Edit Synchronization Settings': 'Edit Synchronisation Settings',
'enter an integer between %(min)g and %(max)g': 'enter an integer between %(min)g and %(max)g',
'Enter your organization': 'Enter your organisation',
'First name': 'First name',
'From Organization': 'From Organisation',
'Funding Organization': 'Funding Organisation',
'Funds Contributed by this Organization': 'Funds Contributed by this Organisation',
'Group ID': 'Group ID',
'Hair Color': 'Hair Colour',
'Identifier which the repository identifies itself with when sending synchronization requests.': 'Identifier which the repository identifies itself with when sending synchronisation requests.',
"If this field is populated then a user who specifies this Organization when signing up will be assigned as a Staff of this Organization unless their domain doesn't match the domain field.": "If this field is populated then a user who specifies this Organisation when signing up will be assigned as a Staff of this Organisation unless their domain doesn't match the domain field.",
Expand All @@ -61,10 +72,12 @@
'In Catalogs': 'In Catalogues',
'Intergovernmental Organization': 'Intergovernmental Organisation',
'International Organization': 'International Organisation',
'Is Active': 'Is Active',
'Item Catalog Details': 'Item Catalogue Details',
'Item Catalogs': 'Item Catalogues',
'Item Catalogues': 'Item Catalogues',
'Job Role Catalog': 'Job Role Catalogue',
'Last name': 'Last name',
'Last Synchronization': 'Last Synchronisation',
'Last synchronized on': 'Last synchronised on',
'List All Organization Approvers & Whitelists': 'List All Organisation Approvers & Whitelists',
Expand All @@ -75,6 +88,8 @@
'Logo of the organization. This should be a png or jpeg file and it should be no larger than 400x400': 'Logo of the organisation. This should be a png or jpeg file and it should be no larger than 400x400',
'Manual Synchronization': 'Manual Synchronisation',
'Matching Catalog Items': 'Matching Catalogue Items',
'Modified By': 'Modified By',
'Modified On': 'Modified On',
'Monetization': 'Monetisation',
'Monetization Report': 'Monetisation Report',
'No Catalog Items currently registered': 'No Catalogue Items currently registered',
Expand All @@ -84,6 +99,7 @@
'No Organization Types currently registered': 'No Organisation Types currently registered',
'No Organizations currently registered': 'No Organisations currently registered',
'No Organizations for this Project': 'No Organisations for this Project',
'Office/Warehouse/Facility': 'Office/Warehouse/Facility',
'Organization': 'Organisation',
'Organization added': 'Organisation added',
'Organization added to Project': 'Organisation added to Project',
Expand All @@ -108,13 +124,19 @@
'Organization/Supplier': 'Organisation/Supplier',
'Organizational Development': 'Organisational Development',
'Organizations': 'Organisations',
'Origin': 'Origin',
'Password': 'Password',
"Phone number to donate to this organization's relief efforts.": "Phone number to donate to this organisation's relief efforts.",
'Please use this field to record any additional information, including a history of the record if it is updated.': 'Please use this field to record any additional information, including a history of the record if it is updated.',
'Position Catalog': 'Position Catalogue',
'Project Details including organizations': 'Project Details including organisations',
'Project Details including organizations and communities': 'Project Details including organisations and communities',
'Project Organization Details': 'Project Organisation Details',
'Project Organization updated': 'Project Organisation updated',
'Project Organizations': 'Project Organisations',
'Registration key': 'Registration key',
'Resource Management System': 'Resource Management System',
'Role': 'Role',
'Schedule synchronization jobs': 'Schedule synchronisation jobs',
'Search by organization.': 'Search by organisation.',
'Search for an Organization by name or acronym': 'Search for an Organisation by name or acronym',
Expand All @@ -139,11 +161,14 @@
'The default Organization for whom you are acting.': 'The default Organisation for whom you are acting.',
'The Organization Registry keeps track of all the relief organizations working in the area.': 'The Organisation Registry keeps track of all the relief organisations working in the area.',
'The synchronization module allows the synchronization of data resources between Sahana Eden instances.': 'The synchronisation module allows the synchronisation of data resources between Sahana Eden instances.',
'Timestamp': 'Timestamp',
'Transfer ownership to Organization': 'Transfer ownership to Organisation',
"Type the name of an existing catalog item OR Click 'Add New Item' to add an item which is not in the catalog.": "Type the name of an existing catalogue item OR Click 'Add New Item' to add an item which is not in the catalogue.",
'Under which condition a local record shall be updated if it also has been modified locally since the last synchronization': 'Under which condition a local record shall be updated if it also has been modified locally since the last synchronisation',
'Unique identifier which THIS repository identifies itself with when sending synchronization requests.': 'Unique identifier which THIS repository identifies itself with when sending synchronisation requests.',
'User Guidelines Synchronization': 'User Guidelines Synchronisation',
'User ID': 'User ID',
'UTC Offset': 'UTC Offset',
'Utilization Report': 'Utilisation Report',
'Year that the organization was founded': 'Year that the organisation was founded',
}
16 changes: 8 additions & 8 deletions modules/eden/project.py
Expand Up @@ -240,7 +240,7 @@ def model(self):
fields=["sector_id"],
),
)

configure(tablename,
crud_form=crud_form)

Expand Down Expand Up @@ -773,7 +773,7 @@ def model(self):
fields=["sector_id"],
),
)

configure(tablename,
crud_form=crud_form)

Expand Down Expand Up @@ -1596,7 +1596,7 @@ def model(self):
configure(tablename,
super_entity = "stats_parameter",
)


# Reusable Field
beneficiary_type_param_id = S3ReusableField("parameter_id", table,
Expand Down Expand Up @@ -1627,7 +1627,7 @@ def model(self):
project_id(readable=False,
writable=False),
project_location_id(comment=None),

# stats_data Fields
super_link("data_id", "stats_data"),
beneficiary_type_param_id(),
Expand Down Expand Up @@ -1978,7 +1978,7 @@ def project_beneficiary_represent(id, row=None):
@staticmethod
def project_beneficiary_onaccept(form):
"""
Update project_beneficiary project & location from project_location_id
Update project_beneficiary project & location from project_location_id
"""

db = current.db
Expand Down Expand Up @@ -4843,17 +4843,17 @@ def project_rheader(r, tabs=[]):
if r.representation != "html":
# RHeaders only used in interactive views
return None

# Need to use this as otherwise demographic_data?viewing=project_location.x
# doesn't have an rheader
tablename, record = s3_rheader_resource(r)
if not record:
return None
s3db = current.s3db
table = s3db.table(tablename)

resourcename = r.name

T = current.T
auth = current.auth
settings = current.deployment_settings
Expand Down

0 comments on commit e42f471

Please sign in to comment.