...
 
Commits (2)
......@@ -82,11 +82,6 @@ def process_csv():
os.remove(file_name)
message+=T("The file was imported successfully into the database")
session.status=True
# except psycopg2.IntegrityError as e:
# db.rollback()
# message+=T("There was an integrity integrity error when importing the file")
# session.message=message+" "+str(e)
# session.status=False
except Exception as e:
db.rollback()
message+=T("There was an error when importing the file")
......
......@@ -4,13 +4,9 @@ def index():
return dict(grid=SQLFORM.smartgrid(db.languages, linked_tables=[], user_signature=False))
def set_language():
# language=request.vars.language
# print( request.vars.language)
# return
if(session.active_method=='UP'):
session.active_language=request.vars.language
redirect(URL(session.active_controller,session.active_method,args=(session.active_city)))
else:
session.active_language=request.vars.language
#T.force(language)
redirect(URL(session.active_controller,session.active_method))
\ No newline at end of file
......@@ -73,7 +73,6 @@ def process_csv():
message += T("The file was uploaded successfully ")
data = pd.read_csv(file_name, sep=",", encoding='utf-8', quotechar='"')
#data['user_id'] = auth.user_id
data['country_code'] = request.vars.country_code
data['city_code'] = request.vars.city_code
data['language'] = request.post_vars.language
......@@ -103,14 +102,7 @@ def getPolicyLevers():
result = {}
for category in categories:
result[category["category"]+"_level"]=db((db.policy_levers.city_code == city)& (db.policy_levers.country_code == country) &( db.policy_levers.category == category["category"]) & (db.policy_levers.language==session.active_language)).select(
db.policy_levers.level_name, db.policy_levers.level, db.policy_levers.level_title, orderby=db.policy_levers.level)
# query = """
# select distinct level_name, level,level_title from(
# select distinct category,level_name,level_title,level from where urbper_data.assumptions.city_code = {city} and urbper_data.assumptions.country_code = {country}
# and "category"='infill'
# )c1 order by level asc
# """.format(city=city, country=country)
# result = db.executesql(query, as_dict=True)
db.policy_levers.level_name, db.policy_levers.level, db.policy_levers.lever_title, orderby=db.policy_levers.level)
return dict(result=result)
@auth.requires(lambda: (auth.has_membership('Administrator_back')) or (auth.has_membership('Specialist')) or (auth.has_membership('Manager')) or (auth.has_membership('General Manager')))
......
......@@ -16,43 +16,110 @@ def getResults():
def getResultsCSV():
response.generic_patterns = ['csv']
results = db((db.results.scenario_id == db.scenario.scenario_id) & (db.scenario.country_code==session.cur_country_code )
&(db.scenario.city_code==session.cur_city_code )).select(
&(db.scenario.city_code==session.cur_city_code)).select(
db.scenario.scenario_id,
db.scenario.scenario_name,
db.scenario.scenario_definition,
db.results.country_code,
db.results.city_code,
db.results.pop_total,
db.results.pop_density,
db.results.footprint_km2,
db.results.land_consumption_km,
db.results.land_consumption_pct,
db.results.agric_consumption,
db.results.biodiversity_consumption,
db.results.greenland_consumption,
db.results.other_land_consumption,
db.results.infill_area_km2,
db.results.pop_density,
db.results.ghg_emissions,
db.results.energy_consumption,
db.results.tot_water,
db.results.wwt_pct,
db.results.ww,
db.results.energy_consumption,
db.results.energy_security,
db.results.ren_energy,
db.results.localren_energy,
db.results.local_energy,
db.results.energy_lighting,
db.results.energy_water,
db.results.energy_transport,
db.results.energy_swaste,
db.results.energy_buildings,
db.results.municipal_service_costs,
db.results.energy_wwt,
db.results.energy_transport,
db.results.energy_gasoline,
db.results.energy_diesel,
db.results.ghg_emissions,
db.results.emissions_transport,
db.results.infrastructure_costs,
db.results.infrastructure_new_costs,
db.results.infrastructure_infill_costs,
db.results.job_prox,
db.results.transit_prox,
db.results.inv_cost,
db.results.hu_cost,
db.results.municipal_service_costs,
db.results.plrunning_cost,
db.results.cwrunning_cost,
db.results.wwtrunning_cost,
db.results.solidw_coverage,
db.results.transport_energy,
db.results.collection_energy,
db.results.cw_coverage,
db.results.hu_tot,
db.results.vhu_tot,
db.results.vhu_rate,
db.results.pop_infill,
db.results.pop_expan,
db.results.school_proximity,
db.results.public_space_proximity,
db.results.sports_proximity,
db.results.worship_proximity,
db.results.pop_prox_school,
db.results.elementary_school_proximity,
db.results.pop_prox_elementary_school,
db.results.secondary_school_proximity,
db.results.pop_prox_secondary_school,
db.results.high_school_proximity,
db.results.pop_prox_high_school,
db.results.university_proximity,
db.results.pop_prox_university,
db.results.health_proximity,
db.results.pop_prox_health,
db.results.nursery_proximity,
db.results.public_service_proximity,
db.results.pop_prox_nursery,
db.results.cultural_facility_proximity,
db.results.pop_prox_cultural_facility,
db.results.public_space_proximity,
db.results.pop_prox_public_space,
db.results.sports_proximity,
db.results.pop_prox_sports,
db.results.job_prox,
db.results.pop_prox_jobs,
db.results.market_proximity,
db.results.pop_prox_market,
db.results.worship_proximity,
db.results.pop_prox_worship,
db.results.public_service_proximity,
db.results.pop_prox_public_service,
db.results.transit_prox,
db.results.pop_prox_transit,
db.results.cycle_prox,
db.results.pop_prox_cycle,
db.results.tot_cycle,
db.results.cycle_cover,
db.results.avge_cycle_track,
db.results.roads_density,
db.results.intersections_density,
db.results.percapita_ps,
db.results.tree_cover,
db.results.carbon_sequestration,
db.results.hazard_exp,
db.results.hu_tot,
db.results.vhu_tot,
db.results.vhu_rate)
db.results.pop_prox_hazards,
db.results.prim_road_km,
db.results.prim_road_km2,
db.results.sec_road_km,
db.results.sec_road_km2,
db.results.ter_road_km,
db.results.ter_road_km2,
db.results.street_coef,
db.results.city_data,
db.results.indirect_data,
db.results.borrowed_data)
return results.as_csv()
@auth.requires(lambda: auth.has_membership('Administrator_back') or auth.has_membership('Specialist') or auth.has_membership('Manager') or auth.has_membership('General Manger'))
......
......@@ -75,11 +75,6 @@ def process_csv():
os.remove(file_name)
message += T("The file was imported successfully into the database")
session.status = True
# except psycopg2.IntegrityError as e:
# db.rollback()
# message+=T("There was an integrity integrity error when importing the file")
# session.message=message+" "+str(e)
# session.status=False
except Exception as e:
db.rollback()
message += T("There was an error when importing the file")
......
@request.restful()
def api():
response.view = 'generic.json'
#if request.env.http_origin:
# response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers["Access-Control-Allow-Origin"] = '*'
response.headers['Access-Control-Max-Age'] = 86400
response.headers['Access-Control-Allow-Headers'] = '*'
response.headers['Access-Control-Allow-Methods'] = '*'
response.headers['Access-Control-Allow-Credentials'] = 'true'
def GET(table,country,language):
patterns = 'auto'
parser=()
if not table == 'city_maps':
raise HTTP(400)
parser = dict(tile = db((db.city_maps.language==language)&(db.city_maps.country_code==country)).select(db.city_maps.base_map,db.city_maps.base_map_label,db.city_maps.url))
return parser
return dict(GET=GET)
@auth.requires(lambda: (auth.has_membership('Administrator_back')) or (auth.has_membership('Specialist')) or (auth.has_membership('Manager')) or (auth.has_membership('General Manager')))
def index():
session.active_method="index"
session.active_controller="city_maps"
return dict(grid=SQLFORM.smartgrid(db.city_maps, linked_tables=[], user_signature=False))
@auth.requires(lambda: auth.has_membership('Administrator_back') or auth.has_membership('Specialist') or auth.has_membership('Manager') or auth.has_membership('General Manger'))
def import_csv():
countries = db(db.countries).select(
db.countries.country_code, db.countries.country)
languages = db(db.languages).select(
db.languages.id, db.languages.name)
form = FORM(
_action=URL("tiles", "/process_csv"),
_method="post",
*[DIV(_class='form-group',
*[
LABEL(
"Select a country:", _class='col-xs-12', _for="country_code"
),
SELECT(
_name='country_code', _id="country_code", *[OPTION(countries[i].country, _value=str(countries[i].country_code)) for i in range(len(countries))], _class="form-control")
]
),
DIV(_class='form-group',
*[
LABEL(
"Select language:", _class='col-xs-12', _for="language"
), SELECT(
_name='language', _id="language", *[OPTION(languages[i].name, _value=str(languages[i].id)) for i in range(len(languages))], _class="form-control"
)
]
),
DIV(_class='form-group',
*[
LABEL(
"Select a file:", _class='col-xs-12', _for="csv_file"
), INPUT(
_type='file',
_name='csv_file', _id="csv_file", _class="", _accept=".csv")
]
),
DIV(_class='form-group',
*[
INPUT(_type='submit',
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
]
)
return dict(form=form)
@auth.requires(lambda: auth.has_membership('Administrator_back') or auth.has_membership('Specialist') or auth.has_membership('Manager') or auth.has_membership('General Manger'))
def process_csv():
response.generic_patterns = ['*']
message = ''
import csv
import shutil
import pandas as pd
import os
try:
filename = request.vars.csv_file.filename
file = request.vars.csv_file.file
file_name = request.env.web2py_path + \
'/applications/'+request.application+'/uploads/'+filename
shutil.copyfileobj(file, open(file_name, "wb"))
message += T("The file was uploaded successfully ")
data = pd.read_csv(file_name, sep=",", encoding='utf-8', quotechar='"')
data['country_code'] = request.post_vars.country_code
data['language'] = request.post_vars.language
data['created_by'] = auth.user_id
#csv.field_size_limit(data.location.map(lambda x: len(x)).max())
data.to_csv(file_name, sep=',', encoding='utf-8', index=False,
doublequote=True, quotechar='"', quoting=csv.QUOTE_MINIMAL)
db.city_maps.import_from_csv_file(open(file_name))
os.remove(file_name)
message += T("The file was imported successfully into the database")
session.status = True
except Exception as e:
db.rollback()
message += T("There was an error when importing the file")
message = message+" "+str(e)
session.status = False
else:
db.commit()
session.message = message
redirect(URL("tiles", "index"))
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -58,7 +58,7 @@ def insert_permission():
try:
db.admin_permission.bulk_insert([
{"group_id": 1, "name": "UP_GENERAL", "table_name": "UP_GENERAL", "module_order": 0, "module_hierarchy": 100},
{"group_id": 1, "name": "UP_JR", "table_name": "UP_PS", "module_order": 1, "module_hierarchy": 100},
{"group_id": 1, "name": "UP_PS", "table_name": "UP_PS", "module_order": 1, "module_hierarchy": 100},
{"group_id": 1, "name": "UP_ADMIN", "table_name": "UP_ADMIN", "module_order": 0, "module_hierarchy": 99}
])
......@@ -66,8 +66,10 @@ def insert_permission():
print(str(e))
else:
db.commit()
def create_schemas():
db.executesql("create schema if not exists visualizer;")
db.executesql("create extension if not exists postgis")
db.executesql("create extension if not exists dblink")
create_schemas()
populate()
This diff is collapsed.
......@@ -14,9 +14,9 @@ names = localhost:*, 127.0.0.1:*, *:*, *
; db configuration
[db]
uri = postgres://dbuser:dbpassword@dbhost:dbport/dbname
uri = postgres://dbuser:dbpassword@dbhost:dbport/up_visualizer_db_name
migrate = true
fake_migrate_all = true
fake_migrate_all = false
pool_size = 0
check_reserved = None
#schema = 'visualizer'
......
......@@ -16,6 +16,7 @@ routers = dict(
'results',
'scenario_levers_control',
'scenarios',
'tiles',
'transit',
'visualizer_general',
'voronoi'
......@@ -59,7 +60,8 @@ routers = dict(
'get_transit_origin',
'get_footprint',
'get_footprint_0',
'getActivePolicies'
'getActivePolicies',
'get_indicators_to_show',
],
cities=['index',
'getCities',
......@@ -104,7 +106,7 @@ routers = dict(
'delete'],
policy_levers=['index',
'import_csv',
'getPolicylevels',
'getPolicyLevels',
'process_csv',
'delete',
'massive_delete_policy_levers'],
......@@ -130,6 +132,12 @@ routers = dict(
'import_csv',
'process_csv',
'delete'],
tiles=[
'api',
'index',
'import_csv',
'process_csv'
],
scenario_levers_control=['index',
'getScenarioleversControl',
'import_csv',
......
This diff is collapsed.
This diff is collapsed.
......@@ -62,14 +62,14 @@ function create_sliders(levels){
$.each(levels, function (label, level) {
var rangos = [];
if ($(level).length > 1) {
console.log('level',level)
//console.log('level',level)
var titulo = null;
$.each(level, function (i, val) {
// console.log(i,val)
rangos.push(parseInt(val["level"]));
if (typeof val["level_title"] != "undefined") {
titulo = val["level_title"];
// console.log('titulo',titulo);
if (typeof val["lever_title"] != "undefined") {
titulo = val["lever_title"];
//console.log('titulo',titulo);
}
});
var marcadores = [];
......@@ -137,9 +137,7 @@ function set_slider_label(selector) {
}
function restart_visualizer() {
delete ordenInds;
if(!$('#incDer').is(':visible')){
$('#incDer').show();
......
......@@ -17,24 +17,8 @@ function load_cities_a() {
var interval = setInterval(function () {
if (cities_loaded) {
clearInterval(interval);
$("body").append("<div id='step_2' class='hidden'></div>");
//$("#Cities>option[value=" + parseInt(string_city[0]["city_code"]) + "]").attr("selected", "selected");
$("#Cities").val(string_city[0]["city_code"].toString());
$("#Cities").change()
//$("#Cities>option[value=" + parseInt(string_city[0]["city_code"]) + "]").change()
//$("#step_2").click();
}
}, 100);
}
// $(document).on("click", "#step_2", function () {
// $("#Scenarios1").val(parseInt(string_city[0]["scenario"]));
// $("#Scenarios2").val(parseInt(string_city[0]["scenario"]));
// $("#Scenarios1>option[value=" + parseInt(string_city[0]["scenario"]) + "]").attr("selected", "selected");
// $("#Scenarios2>option[value=" + parseInt(string_city[0]["scenario"]) + "]").attr("selected", "selected");
// //$("#Scenarios1").change();
// setTimeout(function () {
// //$("#Scenarios1>option[value="+parseInt(string_city[0]["scenario"])+"]").attr("selected", "selected");
// $("#Scenarios1>option[value=" + parseInt(string_city[0]["scenario"]) + "]").change()
// //$("#Scenarios1>option[value="+parseInt(string_city[0]["scenario"])+"]").attr("selected", "selected");
// }, 1000);
// })
\ No newline at end of file
}
\ No newline at end of file
{{extend 'sb-admin-2/index.html'}}
<h1>{{=T('Delete policy levels')}}</h1>
<h1>{{=T('Delete policy levers')}}</h1>
{{=form}}
......
{{extend 'sb-admin-2/index.html'}}
<h1>{{=T('Import policy levels')}}</h1>
<h1>{{=T('Import policy levers')}}</h1>
{{=form}}
......
......@@ -7,7 +7,7 @@
</div>
<div class="w2p_delete_menu" style="margin: 5px 0;">{{=T("Delete")}}:
<a class="btn btn-default" href="{{=URL('policy_levers','delete')}}" title="Delete all policy levels. This may take a while for many rows">
{{=T('Delete policy levels')}}
{{=T('Delete policy levers')}}
</a>
</div>
<script>
......
......@@ -125,7 +125,7 @@
<a href="{{=URL('countries','country_visualizer_texts')}}">{{=T('Country visualizer texts')}}</a>
</li>
<li>
<a href="{{=URL('policy_levers','index')}}">{{=T('Country Policy levels')}}</a>
<a href="{{=URL('policy_levers','index')}}">{{=T('Country Policy levers')}}</a>
</li>
</ul>
</li>
......@@ -197,6 +197,9 @@
<li>
<a href="{{=URL('admin','create_tables')}}">{{=T('Admin Spatial')}}</a>
</li>
<li>
<a href="{{=URL('tiles','index')}}">{{=T('Tiles')}}</a>
</li>
{{pass}}
<li>
<a href="{{=URL('admin','users')}}">{{=T('Manage users')}}</a>
......
{{extend 'sb-admin-2/index.html'}}
<h1>{{=T('Import Tiles')}}</h1>
{{=form}}
{{extend 'sb-admin-2/index.html'}}
<h1>{{=T('Tiles')}}</h1>
{{=grid}}
<div class="w2p_import_menu" style="margin: 5px 0;">{{=T("Import")}}:
<a class="btn btn-default" href="{{=URL("tiles","/import_csv ")}}" title="Comma-separated import. This may take a while for many rows">CSV</a>
</div>
\ No newline at end of file
......@@ -71,34 +71,36 @@
</script>
<style>
/*Layers icons*/
.circle_off {
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') -0 0;
.circle_on {
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') 0 0;
background-size: 675% 337.50%;
/*background-position: */
width: 14px;
height: 14px;
}
.circle_on {
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') 19.2% 0;
.circle_off {
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') 19.6% 0;
background-size: 675% 337.50%;
width: 14px;
height: 14px;
}
.square_off {
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') 58.5% 0;
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') 59% 0;
background-size: 675% 337.50%;
width: 14px;
height: 14px;
}
.square_on {
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') 38.4% 0%;
background-size: 675% 337.50%;
width: 14px;
height: 14px;
}
.square_buff{
padding: 0rem 0rem .5rem 1.6rem;
}
.triangle_off {
background:url('{{="/"+request.application}}/static/images/visualizador/layer_icons.png') 97% 49%;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -94,7 +94,8 @@ function dibujaBaseMaps(){
$.ajax({
type: 'GET',
dataType: 'json',
url: "https://tiles.urbanperformance.in/map/tiles_country/api/city_maps/"+__country_code+"/"+idiomaSesion,
//url: "https://tiles.urbanperformance.in/map/tiles_country/api/city_maps/"+__country_code+"/"+idiomaSesion,
url: url_config+"/tiles/api/city_maps/"+__country_code+"/"+idiomaSesion,
success: function (datos) {
console.log("basemaps", datos)
$.each(datos["tile"], function(i, tile) {
......