Re: Double arrays in models django

2010-04-11 Thread zimberlman
gave another tip for storing the matrix using an adjacent table,
coupled with many to many.
that's just how it is implemented in classes django,

class Answer (models.Model):
id_a = models.AutoField ('ID', primary_key = true)
answer = models.TextField ()
class Simptoms (models.Model):
id_s = models.AutoField ('ID', primary_key = true)
simptom = models.TextField ()

class Answer_Simptoms (models.Model):
id_a = models.ManyToManyField (Answer)
id_s = models.ManyToManyField (Simptoms)

But I think where I nakosyachil.
although, in principle, what I should be.

On 9 апр, 21:32, Bill Freeman  wrote:
> Will there be more than one matrix?  Or are you using "Name" to indicate
> matrix membership, as opposed to column names and row names?  If
> so, a foreign key on a matrix table will be more storage efficient, since
> matrix names will only need to be stored once.
>
> Also, doesn't a select to do a lookup of a data item always need to join
> on all three tables?  If you want to go this route, then you only really need
> one table, though, if there are multiple named matrices, a second table
> to hold the matrix name would be more efficient.
>
> Let's say, for the sake of argument, that are numbering your matrices,
> rows, and columns, rather than naming them, and avoid the extra table(s)
> and join(s).
>
> create table Data
> (
>   id int primary key,
>   matrix int not null,
>   row int not null,
>   col int not null,
>   data float not null
> )
>
> You can query this for an exact data item by specifying all of matrix, row, 
> and
> col in your where clause.   Or you can just specify matrix and row and get
> all of a col (perhaps order by col) to get one row.  Similar for
> getting a column.
>
> In my initial scheme, the Data table items, which greatly outnumber any of
> the other table's items, were slightly smaller each, having an id, a col int,
> and a data (of whatever type).  This has the cost that Data must be joined
> on Row, in turn joined on Matrix if matrices have a name, and getting one
> column is a more expensive operation (but still done in one where clause).
>
> The speed versus space tradoff is yours to make.
>
> Also, while it may be easier for you to think in terms of SQL, to wire this to
> Django, you should probably write it as a model rather than as create
> table SQL, so that you will see when  you are going somewhere difficult.
>
> For my first scheme above (remember, id is automatic):
>
> class Data(models.Model):
>     matrix = models.IntegerField()
>     row = models.IntegerField()
>     col = models.IntegerField()
>     data = models.FloatField()
>
> Now you can, for instance, do something like:
>
>   for d in Data.objects.filter(matrix=m, row=r).order_by('col'):
>
> to iterate over a row in order (leave off the order_by if order doesn't 
> matter),
> and:
>
>    d = Data.objects.get(matrix=m, row-r, col=c)
>
> to get an individual data object, which you can update using:
>
>     d.data = new_value
>     d.save()
>
> use filter instead of get if you want to allow a matrix to be sparse.
>
> I'll leave the three (or two, if matrices are numbered) table scheme as
> an exercise for you.
>
> Bill
>
>
>
> On Fri, Apr 9, 2010 at 3:50 AM, zimberlman  wrote:
> > create table Rows
> > (
> >  Id int primary key,
> >  Name text(255) not null
> > )
> > create table Cols
> > (
> >  Id int primary key,
> >  Name text(255) not null
> > )
>
> > create table Data
> > (
> >  RowId int not null foreign key references Rows(Id),
> >    ColId int not null foreign key references Cols(Id),
> >    Data
> > )
>
> > On 8 апр, 02:32, Bill Freeman  wrote:
> >> You need one matrix table, having a row for each matrix.
>
> >> You need one matrix_row table, having a row for each row of any matrix, 
> >> mostly
> >> containing a foreign key on the matrix table, showing of which matrix the 
> >> row is
> >> part, plus it's row number in that table.
>
> >> And you need one matrix_row_values table, having a foreign key on the
> >> matrix_row,
> >> indicating of which row it is a part, plus it's column number, and the 
> >> value.
>
> >> There is no run time table creation involved, and this can all be done
> >> with direct
> >> django models, and on any database the ORM supports (maybe not NoSQL
> >> databases, I'll have to think about that).  The access syntax wouldn't 
> >> look like
> >> 2D array access, but you could fix that with 

Re: Double arrays in models django

2010-04-09 Thread zimberlman
create table Rows
(
  Id int primary key,
  Name text(255) not null
)
create table Cols
(
  Id int primary key,
  Name text(255) not null
)

create table Data
(
  RowId int not null foreign key references Rows(Id),
ColId int not null foreign key references Cols(Id),
Data
)

On 8 апр, 02:32, Bill Freeman  wrote:
> You need one matrix table, having a row for each matrix.
>
> You need one matrix_row table, having a row for each row of any matrix, mostly
> containing a foreign key on the matrix table, showing of which matrix the row 
> is
> part, plus it's row number in that table.
>
> And you need one matrix_row_values table, having a foreign key on the
> matrix_row,
> indicating of which row it is a part, plus it's column number, and the value.
>
> There is no run time table creation involved, and this can all be done
> with direct
> django models, and on any database the ORM supports (maybe not NoSQL
> databases, I'll have to think about that).  The access syntax wouldn't look 
> like
> 2D array access, but you could fix that with a wrapper.
>
>
>
> On Wed, Apr 7, 2010 at 4:20 PM, zimberlman  wrote:
> > No, no.
> > I need to store the matrix and dual array is ideal for this would come
> > up.
> > The problem is that the matrix will grow in size, thousands of entries
> > only on i, and where that same number of j.
> > create table is not an option.
>
> > only if the matrix transform and drive the table. and my question is,
> > if you can not define arrays in the model, how can I convert a
> > matrix.
> > example is the matrix
> > a   b   c   d  e
> > 1   2   3   4  5
> > 11 22 33 44 55
> > converted into
> > a 1
> > a 11
> > b 2
> > b 22
> > c 3
> > c 33
> > d 4
> > d 44
> > e 5
> > e 55
>
> > this is for example, how do I implement this in the model? course in
> > the class will have to use functions, but is it possible?
>
> > On 8 апр, 01:28, pmains  wrote:
> >> If there is no Django model field for this, then one option would be
> >> to create your own model field (http://docs.djangoproject.com/en/dev/
> >> howto/custom-model-fields/). Of course, it would not be compatible
> >> with most SQL Database types.
>
> >> Of course, it may be easier to just rethink your data model. Would it
> >> be possible to create one or more additional tables to avoid using an
> >> unusual DB construct like a 2D array?
>
> >> Could you explain the problem in a little more detail? Saying that you
> >> want a 2-dimensional array is very abstract, but if we understand what
> >> problem you are trying to solve, what data you are attempting to
> >> model, it will be easier to give you useful suggestions.
>
> > double array that I want to keep count, it is ideally suited for the
> > incidence matrix of the graph.
> > required to store the connection to the knowledge base of question-
> > answering system.
> > which will lie on j IDs leading questions, and i will lie on
> > identifiers answers emerging from a set of leading questions.
> > and a double array is an ideal way to store data.
> > but I probably need to write your own model of the array for django in
> > this case, it is the only big problem at this time.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Double arrays in models django

2010-04-07 Thread zimberlman
I have now 2.21 at night, I live in Siberia.
city of Tyumen. so I will read the answers in 6 hours 8 only in the
morning when I wake up.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Double arrays in models django

2010-04-07 Thread zimberlman
No, no.
I need to store the matrix and dual array is ideal for this would come
up.
The problem is that the matrix will grow in size, thousands of entries
only on i, and where that same number of j.
create table is not an option.

only if the matrix transform and drive the table. and my question is,
if you can not define arrays in the model, how can I convert a
matrix.
example is the matrix
a   b   c   d  e
1   2   3   4  5
11 22 33 44 55
converted into
a 1
a 11
b 2
b 22
c 3
c 33
d 4
d 44
e 5
e 55

this is for example, how do I implement this in the model? course in
the class will have to use functions, but is it possible?

On 8 апр, 01:28, pmains  wrote:
> If there is no Django model field for this, then one option would be
> to create your own model field (http://docs.djangoproject.com/en/dev/
> howto/custom-model-fields/). Of course, it would not be compatible
> with most SQL Database types.
>
> Of course, it may be easier to just rethink your data model. Would it
> be possible to create one or more additional tables to avoid using an
> unusual DB construct like a 2D array?
>
> Could you explain the problem in a little more detail? Saying that you
> want a 2-dimensional array is very abstract, but if we understand what
> problem you are trying to solve, what data you are attempting to
> model, it will be easier to give you useful suggestions.


double array that I want to keep count, it is ideally suited for the
incidence matrix of the graph.
required to store the connection to the knowledge base of question-
answering system.
which will lie on j IDs leading questions, and i will lie on
identifiers answers emerging from a set of leading questions.
and a double array is an ideal way to store data.
but I probably need to write your own model of the array for django in
this case, it is the only big problem at this time.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Double arrays in models django

2010-04-07 Thread zimberlman
Hi, I need help.
I know that in PostgreSQL, there is a type of data as arrays, and
double.
But I was unpleasantly surprised why there is no such models in
django.
The question is how do I get out of this situation?
I need to keep a two-dimensional matrix, and two-dimensional array
would be ideal podoshol for this. And all because the matrix will grow
over time, and the number of columns will be several thousand.
I know that two-dimensional matrix can be stored in the table, but I
do not know how I implement this in the models.
Large please write in simple language, I had trouble reading in
English, I would be uncomfortable and then translate it into Russian.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.