[web2py] web2py down after adding a table in db.py

2013-06-11 Thread Rocco
Dear all,

it's more than a year that I'm using web2py to develop scientific 
application for marine acoustic data analysis and stock assessment. 
For many years I used LAMP and moving to web2py has been very exciting. I 
saved a lot of developing time, and the products are better in look and 
usability.

But sometime I get some problem that leave me in big trouble.

I'm using web2py in a ubuntu i686 linux, with apache and wsgi module. The 
dbms is postgres/postgis

This time my big error has been to rename a field in a table. After that 
web2py frozed with no ticket, no warning, no messages.
I tried to restart apache, but web2py won't start. Also the welcome app 
gives me a connection timeout.

So I decided to edit manually via ssh the db.py resuming the previous 
version. Web2py restarted with no problem, but when I added a new table, i 
got again the trouble.

What shall I do?





-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: web2py down after adding a table in db.py

2013-06-11 Thread Rocco

Ok, I solved using 

fake_migrate_all=True

Thanks to Angelo, who helped me :)

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Bulk insert: how to improve performances?

2013-05-20 Thread Rocco
Dear all,

I've a loop to insert about 2K records into a postgres database (running on 
same host).

This is the used code:

for row in cnv.data_matrix:
   sensor_n=0
   for element in row:
  db.CTD_DATA.insert(CTD_STATION_ID=stationid,SENSOR=
sensor_n,VALUE=float(element))
  sensor_n+=1


It takes more than 20 seconds, sometimes... also more.
I could change the database structure to reduce the number of inserts, but 
there is a way to aggregate multiple insert o to improve the performances?
Thanks in advance for any suggestion.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Bulk insert: how to improve performances?

2013-05-20 Thread Rocco
Many thanks, Niphlod!

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] cpdb.py not working...

2013-04-24 Thread Rocco
Hi all,

I've some trouble trying to migrate an app db from mysql to postgres using 
the cpdb.py script

My appname is sviluppo and it has all the tables defined inside 
db_wizard.py.
Both the connection url (source and dest) are tested working

I used this command:
./web2py.py -S sviluppo -M  -R scripts/cpdb.py -A -f 
applications/sviluppo/databases 
\
-y 'mysql://sviluppo:password@localhost/sviluppo' -Y 
'postgres://web2py:password@192.168.0.23/sviluppo'

But I get this error:
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2013
Version 2.4.5-stable+timestamp.2013.03.18.22.46.22
Database drivers available: SQLite(sqlite3), MySQL(pymysql), 
MySQL(MySQLdb), PostgreSQL(pg8000), MSSQL(pyodbc), DB2(pyodbc), 
Teradata(pyodbc), Ingres(pyodbc), IMAP(imaplib)
creating tables...
EXCEPTION: could not make a copy of the database
'NoneType' object is not iterable


The folder application/sviluppo/databases exists and it is not empy

I also tryed to save to sqlite ( -Y 'sqlite://storage.sqlite') with same 
failure.

Any suggestions?

Thanks, Rocco


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] JSON and COUNT: avoid _extra field?

2013-03-28 Thread Rocco

Hello,

I'm doing some exciting test using jqplot and handsontable with web2py. The 
approach is almost linear: 
   controller with db(...).select(...).as_list() - @service.json - 
$.getJSON

But I've a problem using a count field, that produce a JSON output with a 
_extra field:

Controller:
@service.json
def json_test:
count=db.table.id.count()
dati=db(table.afield==4).select(f_lunghezza,count,groupby(f_lunghezza)).
as_list()
return dict(data=dati)



So if I open controller/json_test.json I get:
{data: [{_extra: {COUNT(*): 2}, table: {f_lunghezza: 9.5}},...}


qjplot has some problem with this kind of json format, so I had to use 
(client side) a js parser...

  ...
  $.each(data, function(index, value) {
 ticks.push(value['table']['f_lunghezza']);
 point.push(value['_extra']['COUNT(*)']);
  });
  ...


I'm looking for a (better) way to get, instead, the following json:
{data: [{table: {f_lunghezza: 9.5,count:2}},...}


There is a way?


Thanks to all


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] app design page takes a long time to load

2013-03-15 Thread Rocco
Dear all,

after I installed web2py version 2.4.2 stable the time to load the design 
page (pressing modify in the admin page) of a particular app is extremely 
increases.

Usually it takes more than 60 seconds to load, but, when done, all is 
working well as expected.
Using the app I don't have any delay and works fast.

I checked the cpu usage using the linux top command, and the web2py python 
process takes all the cpu resources when loading that app project page.

top - 11:10:03 up 3 days, 20:39,  3 users,  load average: 0.58, 0.50, 0.56
Tasks: 235 total,   1 running, 233 sleeping,   0 stopped,   1 zombie
Cpu(s): 27.7%us,  6.0%sy,  0.0%ni, 66.1%id,  0.2%wa,  0.0%hi,  0.1%si,  0.0%
st
Mem:   4039588k total,  3765996k used,   273592k free,   192028k buffers
Swap:  3998716k total,   685312k used,  3313404k free,   831252k cached


  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND   
 
 3511 rocco 20   0 1266m 321m 2624 S  104  8.2  54:44.70 python   

I tried to restart web2py, but with same results.

Any way to perform a debug? Any suggestions?

Thanks in advance for your reply, Rocco

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Multiple or in where clause using dal

2012-12-19 Thread Rocco
Dear all,

I need to extract multiple records from a table, the number of selected 
records is variable (from 1 to hundreds).

The user form returns a list of selected ids, f.e.:
myset=[1,15,22,44,56]

In the raw sql way, I used a for loop to generate the where clause of the 
sql statement, to get f.e.:

SELECT * from table
WHERE (id=1 or id=15 or id=22 or id=44 or id=56)

I expected to find some DAL tool to avoid the db.executesql usage, but I 
wasn't able to do it.

I hoped that I could pass the list as argument, in this way:

db(db.table.id==myset).select()
but doens't work...

any suggestions?

-- 





[web2py] Re: Multiple or in where clause using dal

2012-12-19 Thread Rocco
Thank you!

Il giorno mercoledì 19 dicembre 2012 10:41:33 UTC+1, Niphlod ha scritto:

 db(db.table.id.belongs(myset)).select()




-- 





[web2py] Re: DAL and Pivot Tables

2012-11-10 Thread Rocco
I found a solution, I don't know if it is the good one, but works enough 
for me.

My real data structure is slightly different about the above example:

db.define_table('ctd',
Field('station'),
Field('parameter'),
Field('value','integer'))

It contains oceanographic information about sea water.
This is a recordset example:

ctd.id station param. ctd.value
1 1 depth 5
2 1 depth 10
3 1 depth 15
4 1 depth 20
5 1 depth 25
6 1 C 44
7 1 C 56
8 1 C 66
9 1 C 62
10 1 C 77
11 1 q 13
12 1 q 22
13 1 q 41
14 1 q 63
15 1 q 52


This is the controller I used:
def ctd():   
   r=[]
   fields=[]
   for row in  db(db.ctd.station==1).select(db.ctd.parameter,distinct=True):
  d=[]
  fields.append(row.parameter)
  for col in db(db.ctd.station==1 and 
db.ctd.parameter==row.parameter).select(db.ctd.value):
 d.append(col.value)
  r.append(d)
   return dict(fields=fields, rows=r)

And this one is the view (default/ctd.html)
{{extend 'layout.html'}}
table
thead
tr
{{for f in fields:}}
{{=TH(f)}}
{{pass}}
/tr
/thead
tbody
{{for j in range(0,len(rows[0])):}}
tr
   {{for i in range(0,len(rows)):}}
   {{=TD(rows[i][j])}}
{{pass}}
/tr
{{pass}}
/tbody
/table

The result is what I wanted:

C depth q
44 5 13
56 10 22
66 15 41
62 20 63
77 25 52


If someone knows a better way... please tell us!

-- 





[web2py] DAL and Pivot Tables

2012-11-09 Thread Rocco
(I already post this question, but it was deleted in few seconds and no 
reason was mentioned. I try to repost it, removing formatting and external 
links... If something is wrong, please inform me :)

I have defined this model:

db.define_table('fruits_in_shop',
Field('shop_name'),
Field('species'),
Field('number','integer'))

With this kind of record inside:
fruits_in_shop.id fruits_in_shop.shop_name fruits_in_shop.species 
fruits_in_shop.number
1 Mark's shop apple 32
2 Mark's shop pear 22
3 John's Market banana 22
4 John's Market apple 36

I'm looking for a way to show the result as a pivot table:

Shop  applepear banana
Mark's shop 32  220
John's Market   32   0   22

I often used a mysql trick to get this result, but there is a way to get 
this result using DAL? 

Otherwise I suppose to perform sequential queries and store the results in 
a dictionary. 
(fruits-select distict fruit from table; for fruit in fruits: 
column-select * from table where fruit=fruit;) 
In this case, there is a (easy) way to convert that dictionary into a 
gluon.sql.Rows object?
Should I use its __init__ method?

-- 





[web2py] Pivot tables using DAL?

2012-11-09 Thread Rocco
Dear All,

I have defined this model:
db.define_table('fruits_in_shop',
Field('shop_name'),
Field('species'),
Field('number','integer'))

With this kind of record inside:
fruits_in_shop.idhttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.id
fruits_in_shop.shop_namehttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.shop_name
fruits_in_shop.specieshttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.species
fruits_in_shop.numberhttp://127.0.0.1:8000/welcome/appadmin/select/db?orderby=fruits_in_shop.number
1 http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/1Mark's 
shopapple322http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/2Mark's
 
shoppear223http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/3John's
 
Marketbanana224http://127.0.0.1:8000/welcome/appadmin/update/db/fruits_in_shop/4John's
 
Marketapple36

I'm looking for a way to show the result as a pivot table:

*Shop  applepear banana*
Mark's shop 32  220
John's* *Market   32   0   22

I often used a mysql trick to get this result (similar to this one: 
http://www.artfulsoftware.com/infotree/queries.php#78), but there is a way 
to get this result using DAL? 

Otherwise I suppose to perform sequential queries and store the results in 
a dictionary. 
(fruits-select distict fruit from table; for fruit in fruits: 
column-select * from table where fruit=fruit;) 
In this case, there is a (easy) way to convert that dictionary into a 
gluon.sql.Rows object?
Should I use its __init__ method?

Any help would be apprecciated :)

-- 





[web2py] SQLFORM: change field value after/in update

2011-11-26 Thread Rocco De Marco
Hi all, I'm a fresh newbie using w2p.
I would hope my question is not so stupid, but I've spended a lot of
time trying to resolve myself, without success...

I've this model:

db.define_table('mytable',
   Field('field1','string'),
   Field('field2'))
db.mytable.field2.requires = IS_IN_SET(['option1'],['option2'])

I've already a created record with field2=option1
I want to create a form where users can change the field1 value, but
the field2 value should be automatically setted to option2 only if the
record has been updated.

I tried with:

def update_mytable():
record=request.args[0]
form=SQLFORM(db.timbrata,
 record,
 onaccept=auth.archive,
 
onupdate=db(db.mytable.id==record).update(field2='option2'),
 deletable=False)
return dict (form=form)

But the filed2 is updated just when the form is showed, not, as I
expected, after an update.
Maybe I took a wrong way, someone could help?

Regards, Rocco


[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Rocco De Marco


On 26 Nov, 18:06, Anthony abasta...@gmail.com wrote:
 On Saturday, November 26, 2011 11:40:27 AM UTC-5, Rocco De Marco wrote:

  db.mytable.field2.requires = IS_IN_SET(['option1'],['option2'])

 I think you want:

 IS_IN_SET(['option1', 'option2'])


Yes, it is a my mistake...

  def update_mytable():

      record=request.args[0]
      form=SQLFORM(db.timbrata,
                       record,
                       onaccept=auth.archive,

  onupdate=db(db.mytable.id==record).update(field2='option2'),
                       deletable=False)

 I don't think SQLFORM takes an onupdate argument, and you would need to
 call SQLFORM.accepts, SQLFORM.validate, or SQLFORM.process after creating
 the SQLFORM in order to get validation/updating to happen. Perhaps you mean
 to use SQLFORM.grid() -- that does take an onupdate arg, but it must be a
 function (e.g., a lambda). But why are you automatically setting field2 to
 'option2' on update -- don't you want to let the user choose the option? If
 not, make sure field2 isn't shown in the form.


I'll try these things, starting with sqlform.grid(), that maybe is
what I'm looking for...

 I recommend giving the relevant sections of ch. 7 a good
 read:http://web2py.com/book/default/chapter/07

 Anthony

Many thanks,
Rocco


[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Rocco De Marco


On 26 Nov, 18:50, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 I THINK YOU WANT:

 def update_mytable():
     record=request.args[0]
     form=SQLFORM(db.timbrata,
                      record, deletable=False)
     form.process(onaccept=lambda form: ( \
             auth.archive(form),
             form.record_id and
 db(db.mytable.id==form.record_id).update(field2='option2')))
     return dict (form=form)

Massimo, many thanks. Now is clear.