Problem with fluff

Hi all,

We are working on the new reports for the IntraHealth domain, and we
encountered some problems with calculations. Our first solution for this
was creating the fluff's and collecting all needed data to reports but
we need to emit several records to SQL for each document instance. We
investigated this issue and didn't found any solutions. It is possible
for now to emit several records for each document? Or maybe we should
use CTableMapping and 'Couch Views' for this instead?

I will be glad for any helpful suggestions.

Thanks,
Łukasz

Hi Lukasz

It is possible to emit multiple values from a document. Could you give an
example of what you're trying to do?

··· On 12 June 2014 19:48, Łukasz Wyszomirski wrote:

Hi all,

We are working on the new reports for the IntraHealth domain, and we
encountered some problems with calculations. Our first solution for this
was creating the fluff's and collecting all needed data to reports but we
need to emit several records to SQL for each document instance. We
investigated this issue and didn't found any solutions. It is possible for
now to emit several records for each document? Or maybe we should use
CTableMapping and 'Couch Views' for this instead?

I will be glad for any helpful suggestions.

Thanks,
Łukasz

--

--- You received this message because you are subscribed to the Google
Groups "CommCare Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Simon Kelly
Senior Engineer | Dimagi South Africa

Hi,

We must iterate by XFormInstance class - In this document we have a list
of products, and we want to emit for each product one record in SQL.
Below you can find some example of this xform:

We have a example document in couch:

{
doc_type: 'XFormInstance',
_id: '1'
...
form: {
...
created_date: '2014-02-11'
products: [
{
product_name: 'product_1',
field_1: 10
},
{
product_name: 'product_2',
field_1: 20
},...
]
}
}

In the SQL we would want to have something like this:

doc_id | date | product_name | field_1
1 | 2014-02-11 | product_1 | 10
1 | 2014-02-11 | product_2 | 20

Please let me know if this is clear now.

Regards,
Łukasz

··· On 13.06.2014 10:47, Simon Kelly wrote: > Hi Lukasz > > It is possible to emit multiple values from a document. Could you give > an example of what you're trying to do? > > > On 12 June 2014 19:48, Łukasz Wyszomirski <lwyszomirski@soldevelo.com > wrote: > > Hi all, > > We are working on the new reports for the IntraHealth domain, and > we encountered some problems with calculations. Our first solution > for this was creating the fluff's and collecting all needed data > to reports but we need to emit several records to SQL for each > document instance. We investigated this issue and didn't found any > solutions. It is possible for now to emit several records for each > document? Or maybe we should use CTableMapping and 'Couch Views' > for this instead? > > I will be glad for any helpful suggestions. > > Thanks, > Łukasz > > -- > > --- You received this message because you are subscribed to the > Google Groups "CommCare Developers" group. > To unsubscribe from this group and stop receiving emails from it, > send an email to commcare-developers+unsubscribe@googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > > > > > -- > Simon Kelly > Senior Engineer | Dimagi South Africa > -- > > --- > You received this message because you are subscribed to the Google > Groups "CommCare Developers" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to commcare-developers+unsubscribe@googlegroups.com > . > For more options, visit https://groups.google.com/d/optout.

You can do this in a calculator as follows:

class ProductCalculator(fluff.Calculator):
@fluff.date_emitter
def field_1(self, form):
for product in form.form.products:
yield {
"date": form.form.created_date,
"value": product.field_1
"group_by": [product.product_name]
}

class ProductIndicators(fluff.IndicatorDocument):

        document_class = XFormInstance
        group_by = ('product_name',)

        value_week = ProductCalculator(window=WEEK)

There is an example of this on the Fluff readme:

··· On 13 June 2014 11:30, Łukasz Wyszomirski wrote:

Hi,

We must iterate by XFormInstance class - In this document we have a list
of products, and we want to emit for each product one record in SQL. Below
you can find some example of this xform:

We have a example document in couch:

{
doc_type: 'XFormInstance',
_id: '1'
...
form: {
...
created_date: '2014-02-11'
products: [
{
product_name: 'product_1',
field_1: 10
},
{
product_name: 'product_2',
field_1: 20
},...
]
}
}

In the SQL we would want to have something like this:

doc_id | date | product_name | field_1
1 | 2014-02-11 | product_1 | 10
1 | 2014-02-11 | product_2 | 20

Please let me know if this is clear now.

Regards,
Łukasz

On 13.06.2014 10:47, Simon Kelly wrote:

Hi Lukasz

It is possible to emit multiple values from a document. Could you give
an example of what you're trying to do?

On 12 June 2014 19:48, Łukasz Wyszomirski lwyszomirski@soldevelo.com wrote:

Hi all,

We are working on the new reports for the IntraHealth domain, and we
encountered some problems with calculations. Our first solution for this
was creating the fluff's and collecting all needed data to reports but we
need to emit several records to SQL for each document instance. We
investigated this issue and didn't found any solutions. It is possible for
now to emit several records for each document? Or maybe we should use
CTableMapping and 'Couch Views' for this instead?

I will be glad for any helpful suggestions.

Thanks,
Łukasz

--

--- You received this message because you are subscribed to the Google
Groups "CommCare Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Simon Kelly
Senior Engineer | Dimagi South Africa


You received this message because you are subscribed to the Google Groups
"CommCare Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--


You received this message because you are subscribed to the Google Groups
"CommCare Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Simon Kelly
Senior Engineer | Dimagi South Africa