Fruch wrote:
>
> David Huynh-2 wrote:
>
>> Fruch wrote:
>>
>>> David Huynh-2 wrote:
>>>
>>>
>>>> Fruch wrote:
>>>>
>>>>
>>>>> David Huynh-2 wrote:
>>>>>
>>>>>
>>>>>
>>>>>> Try this
>>>>>>
>>>>>> <table ex:content="!person" border="2">
>>>>>> <tr ex:content=".monthsLabels"><td
>>>>>> ex:content="value"></td></tr>
>>>>>> <tr ex:content=".workload"><td ex:content="value"></td></tr>
>>>>>> </table>
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Fruch wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>> I have this item:
>>>>>>>
>>>>>>> { type : "Workload",
>>>>>>> label : "work1",
>>>>>>> person : "Israel
>>>>>>> Fruchter",
>>>>>>> onProject :
>>>>>>> "iQ2/MySky2",
>>>>>>> monthsLabels : ["Dec 07", "Jan
>>>>>>> 08", "Feb 08"],
>>>>>>> workload : ["0.5",
>>>>>>> "0.3", "0.4"]
>>>>>>> }
>>>>>>>
>>>>>>> I want to show inside "Israel Fruchter" len view "monthsLabels" and
>>>>>>> "workload" as a table.
>>>>>>>
>>>>>>> I tried this:
>>>>>>> <table ex:content="!person" border="2">
>>>>>>> <tr><td></td></tr>
>>>>>>> <tr><td></td></tr>
>>>>>>> </table>
>>>>>>>
>>>>>>> but what I've got is:
>>>>>>>
>>>>>>> /---------------------------/
>>>>>>> | Dec 07, Jan 08 and Feb 08 |
>>>>>>> /---------------------------/
>>>>>>> | 0.5, 0.3 and 0.4 |
>>>>>>> /---------------------------/
>>>>>>>
>>>>>>> any one got an idea how to show it like that:
>>>>>>>
>>>>>>> /--------------------------/
>>>>>>> | Dec 07 | Jan 08 | Feb 08 |
>>>>>>> /--------/--------/--------/
>>>>>>> | 0.5 | 0.3 | 0.4 |
>>>>>>> /--------------------------/
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> _______________________________________________
>>>>>> General mailing list
>>>>>> [email protected]
>>>>>> http://simile.mit.edu/mailman/listinfo/general
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> Now I need something a bit more complex...
>>>>> I have those two items
>>>>> { type : "Workload",
>>>>> label : "work1",
>>>>> person : "Israel
>>>>> Fruchter",
>>>>> onProject : "iQ2/MySky2",
>>>>> monthsLabels : ["Dec 07", "Jan 08",
>>>>> "Feb 08"],
>>>>> workload : ["0.5", "0.3",
>>>>> "0.4"]
>>>>> },
>>>>> { type : "Workload",
>>>>> label : "work2",
>>>>> person : "Israel
>>>>> Fruchter",
>>>>> onProject : "xApp",
>>>>> monthsLabels : ["Dec 07", "Jan 08",
>>>>> "Feb 08"],
>>>>> workload : ["0.5", "0.6",
>>>>> "0.8"]
>>>>> }
>>>>> and I want to show the a similar table like that: (summing the colums,
>>>>> and
>>>>> showing the .onProject)
>>>>>
>>>>> /--------------------------------------/
>>>>> | Project | Dec 07 | Jan 08 | Feb 08 |
>>>>> /-----------/--------/--------/--------/
>>>>> |iQ2/MySky2| 0.5 | 0.3 | 0.4 |
>>>>> /--------------------------------------/
>>>>> |xApp | 0.5 | 0.6 | 0.8 |
>>>>> /--------------------------------------/
>>>>> |Total | 1.0 | 0.9 | 1.2 |
>>>>> /--------------------------------------/
>>>>>
>>>>>
>>>>>
>>>> Are the monthsLabels arrays all the same?
>>>>
>>>> David
>>>>
>>>> _______________________________________________
>>>> General mailing list
>>>> [email protected]
>>>> http://simile.mit.edu/mailman/listinfo/general
>>>>
>>>>
>>>>
>>>>
>>> yes, that was my idea... (it will complicate things if they aren't)
>>>
>>>
>> This is not trivial... You might have to change the way you model the
>> data. But if you want to keep the data model, I'd try something like
>> this inside the lens template
>>
>> <table>
>> <tbody>
>> <tr ex:content="!person.monthsLabels"><td
>> ex:content="value"></td></tr>
>> </tbody>
>> <tbody ex:content="!person">
>> <tr ex:content="array-concat(.onProject, [EMAIL PROTECTED])"><td
>> ex:content="value"></td></tr>
>> </tbody>
>> <tbody>
>> <tr ex:content="array-concat('Total', array-add(!person,
>> [EMAIL PROTECTED]))"><td ex:content="value"></td></tr>
>> </tbody>
>> </table>
>>
>> in addition to this script inside <head> ... </head> after exhibit-api.js:
>>
>> <script>
>> Exhibit.Functions["array-concat"] = {
>> f: function(args) {
>> var a = [];
>> var valueType = null;
>>
>> if (args.length > 0) {
>> var valueType = args[0].valueType;
>> for (var i = 0; i < args.length; i++) {
>> var arg = args[i];
>> if (arg.size > 0) {
>> if (valueType == null) {
>> valueType = arg.valueType;
>> }
>> arg.forEachValue(function (v) {
>> a.push(v);
>> });
>> }
>> }
>> }
>> return new Exhibit.Expression._Collection(a, valueType
>> != null ? valueType : "text");
>> }
>> };
>>
>> Exhibit.Controls["array-add"] = {
>> f: function(
>> args,
>> roots,
>> rootValueTypes,
>> defaultRootName,
>> database
>> ) {
>> var collection = args[0].evaluate(roots, rootValueTypes,
>> defaultRootName, database);
>>
>> var oldValue = roots["value"];
>> var oldValueType = rootValueTypes["value"];
>> rootValueTypes["value"] = collection.valueType;
>>
>> var results = [];
>> var valueType = "text";
>>
>> collection.forEachValue(function(element) {
>> roots["value"] = element;
>>
>> var collection2 = args[1].evaluate(roots,
>> rootValueTypes, defaultRootName, database);
>> valueType = collection2.valueType;
>>
>> var i = 0;
>> collection2.forEachValue(function(v) {
>> if (i < results.length) {
>> results.push(v);
>> } else {
>> results[i] += v;
>> }
>> i++;
>> });
>> });
>>
>> roots["value"] = oldValue;
>> rootValueTypes["value"] = oldValueType;
>>
>> return new Exhibit.Expression._Collection(results,
>> valueType);
>> }
>> };
>> </script>
>>
>> David
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://simile.mit.edu/mailman/listinfo/general
>>
>>
>>
>
> it almost working: (the end result looked like that)
>
> Dec 07 Jan 08 Feb 08
> iQ2/MySky2 0.5 0.3 0.4
> xApp 0.5 0.3 0.4
> Total undefined0.5 undefined0.3 undefined0.4 0.5 0.3 0.4
>
Oh, my mistake. In the if statement, swap the two clauses:
if (i < results.length) {
results[i] += v;
} else {
results.push(v);
}
> You mentioned changing the data model, can you think of a better way to
> model it ?
> I need for each person the his work time in % for each month, and I need to
> be able to sum those values per month or even year (for each person, and for
> each project the time is accounted for)
>
> I had trouble finding a good model for it (even in a SQL Database)
>
I'll have to think further on that one.
David
_______________________________________________
General mailing list
[email protected]
http://simile.mit.edu/mailman/listinfo/general