首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按普通id和日期分组数组,并汇总到日历表

按普通id和日期分组数组,并汇总到日历表
EN

Stack Overflow用户
提问于 2015-05-26 16:01:12
回答 1查看 45关注 0票数 0

我一直在扯我的头发。很难理解我是如何解决这个问题的,甚至是基本的逻辑.

我有这个数据集:

代码语言:javascript
复制
Array
(
[0] => stdClass Object
    (
        [id] => 233773869
        [pid] => 9919304
        [tid] => 6754304
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-26T14:00:13+02:00
        [end] => 2015-05-26T15:21:23+02:00
        [updated] => 2015-05-26T15:21:27+02:00
        [dur] => 4870000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (AP)
        [project] => **HIDDENNAME**
        [project_color] => 13
        [project_hex_color] => #bc2d07
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[1] => stdClass Object
    (
        [id] => 233719747
        [pid] => 9886726
        [tid] => 6742747
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-26T13:25:05+02:00
        [end] => 2015-05-26T14:00:51+02:00
        [updated] => 2015-05-26T15:21:04+02:00
        [dur] => 2146000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[2] => stdClass Object
    (
        [id] => 233647389
        [pid] => 9886726
        [tid] => 6742728
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-26T09:30:00+02:00
        [end] => 2015-05-26T13:19:29+02:00
        [updated] => 2015-05-26T13:19:33+02:00
        [dur] => 13769000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
                [0] => mobile
            )

    )

[3] => stdClass Object
    (
        [id] => 233010371
        [pid] => 9886726
        [tid] => 6742769
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T15:50:46+02:00
        [end] => 2015-05-22T16:42:10+02:00
        [updated] => 2015-05-22T16:42:14+02:00
        [dur] => 3084000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[4] => stdClass Object
    (
        [id] => 232948438
        [pid] => 9918365
        [tid] => 6753985
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T13:40:32+02:00
        [end] => 2015-05-22T15:06:49+02:00
        [updated] => 2015-05-22T15:06:53+02:00
        [dur] => 5177000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (DS)
        [project] => **HIDDENNAME**
        [project_color] => 7
        [project_hex_color] => #268bb5
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[5] => stdClass Object
    (
        [id] => 232892530
        [pid] => 9888465
        [tid] => 6743039
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T11:40:16+02:00
        [end] => 2015-05-22T12:19:35+02:00
        [updated] => 2015-05-22T12:19:39+02:00
        [dur] => 2359000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt
        [project] => **HIDDENNAME**
        [project_color] => 5
        [project_hex_color] => #8ab734
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[6] => stdClass Object
    (
        [id] => 232878460
        [pid] => 9918425
        [tid] => 6754005
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T10:50:53+02:00
        [end] => 2015-05-22T11:40:11+02:00
        [updated] => 2015-05-22T11:40:15+02:00
        [dur] => 2958000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (MK)
        [project] => **HIDDENNAME**
        [project_color] => 13
        [project_hex_color] => #bc2d07
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[7] => stdClass Object
    (
        [id] => 232829038
        [pid] => 9918365
        [tid] => 6753985
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T08:15:19+02:00
        [end] => 2015-05-22T10:56:25+02:00
        [updated] => 2015-05-22T10:56:29+02:00
        [dur] => 9666000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (DS)
        [project] => **HIDDENNAME**
        [project_color] => 7
        [project_hex_color] => #268bb5
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[8] => stdClass Object
    (
        [id] => 232828575
        [pid] => 9886726
        [tid] => 6742747
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T08:13:10+02:00
        [end] => 2015-05-22T08:13:11+02:00
        [updated] => 2015-05-22T08:13:16+02:00
        [dur] => 1000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[9] => stdClass Object
    (
        [id] => 232828593
        [pid] => 9886726
        [tid] => 6742755
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T08:00:17+02:00
        [end] => 2015-05-22T08:13:26+02:00
        [updated] => 2015-05-22T08:13:27+02:00
        [dur] => 789000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[10] => stdClass Object
    (
        [id] => 232818407
        [pid] => 9886726
        [tid] => 6742747
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-22T06:35:36+02:00
        [end] => 2015-05-22T08:13:06+02:00
        [updated] => 2015-05-22T08:13:10+02:00
        [dur] => 5850000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[11] => stdClass Object
    (
        [id] => 232545676
        [pid] => 9886726
        [tid] => 6742755
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T14:30:37+02:00
        [end] => 2015-05-21T16:58:14+02:00
        [updated] => 2015-05-21T16:58:16+02:00
        [dur] => 8857000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[12] => stdClass Object
    (
        [id] => 232487297
        [pid] => 9886726
        [tid] => 6742755
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T13:50:22+02:00
        [end] => 2015-05-21T14:00:00+02:00
        [updated] => 2015-05-21T14:00:04+02:00
        [dur] => 578000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[13] => stdClass Object
    (
        [id] => 232477062
        [pid] => 9886726
        [tid] => 6742755
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T13:20:35+02:00
        [end] => 2015-05-21T13:50:19+02:00
        [updated] => 2015-05-21T13:50:22+02:00
        [dur] => 1784000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[14] => stdClass Object
    (
        [id] => 232450760
        [pid] => 9888465
        [tid] => 6754026
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T12:01:52+02:00
        [end] => 2015-05-21T13:03:24+02:00
        [updated] => 2015-05-21T13:03:27+02:00
        [dur] => 3692000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt
        [project] => **HIDDENNAME**
        [project_color] => 5
        [project_hex_color] => #8ab734
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[15] => stdClass Object
    (
        [id] => 232448981
        [pid] => 9886726
        [tid] => 6742747
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T11:00:38+02:00
        [end] => 2015-05-21T12:01:44+02:00
        [updated] => 2015-05-21T12:01:48+02:00
        [dur] => 3666000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[16] => stdClass Object
    (
        [id] => 232419408
        [pid] => 9888465
        [tid] => 6743039
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T10:33:44+02:00
        [end] => 2015-05-21T11:12:49+02:00
        [updated] => 2015-05-21T11:12:50+02:00
        [dur] => 2345000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt
        [project] => **HIDDENNAME**
        [project_color] => 5
        [project_hex_color] => #8ab734
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[17] => stdClass Object
    (
        [id] => 232392072
        [pid] => 9919304
        [tid] => 6754304
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T09:10:56+02:00
        [end] => 2015-05-21T10:33:31+02:00
        [updated] => 2015-05-21T11:18:36+02:00
        [dur] => 4955000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (AP)
        [project] => **HIDDENNAME**
        [project_color] => 13
        [project_hex_color] => #bc2d07
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[18] => stdClass Object
    (
        [id] => 232388704
        [pid] => 9886726
        [tid] => 6742728
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-21T09:00:49+02:00
        [end] => 2015-05-21T09:10:51+02:00
        [updated] => 2015-05-21T09:10:55+02:00
        [dur] => 602000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[19] => stdClass Object
    (
        [id] => 232068791
        [pid] => 9886726
        [tid] => 6742755
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-20T14:28:28+02:00
        [end] => 2015-05-20T16:06:54+02:00
        [updated] => 2015-05-20T16:06:59+02:00
        [dur] => 5906000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[20] => stdClass Object
    (
        [id] => 232028575
        [pid] => 9886726
        [tid] => 6742747
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-20T14:15:14+02:00
        [end] => 2015-05-20T14:15:35+02:00
        [updated] => 2015-05-20T14:15:35+02:00
        [dur] => 21868
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[21] => stdClass Object
    (
        [id] => 232028704
        [pid] => 9886726
        [tid] => 6742753
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-20T14:05:32+02:00
        [end] => 2015-05-20T14:28:28+02:00
        [updated] => 2015-05-20T15:35:02+02:00
        [dur] => 1376000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[22] => stdClass Object
    (
        [id] => 232018213
        [pid] => 9886726
        [tid] => 6742747
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-20T13:50:56+02:00
        [end] => 2015-05-20T14:15:07+02:00
        [updated] => 2015-05-20T14:15:10+02:00
        [dur] => 1451000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[23] => stdClass Object
    (
        [id] => 231971266
        [pid] => 9886726
        [tid] => 6742769
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-20T11:36:17+02:00
        [end] => 2015-05-20T13:41:47+02:00
        [updated] => 2015-05-20T13:41:51+02:00
        [dur] => 7530000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

[24] => stdClass Object
    (
        [id] => 231971175
        [pid] => 9886726
        [tid] => 6742755
        [uid] => 1502708
        [project] => **HIDDENNAME**
        [start] => 2015-05-20T11:00:04+02:00
        [end] => 2015-05-20T11:36:13+02:00
        [updated] => 2015-05-20T11:36:15+02:00
        [dur] => 2169000
        [user] => Fredrik Angell Moe
        [use_stop] => 1
        [client] => Internt (BDS)
        [project] => **HIDDENNAME**
        [project_color] => 0
        [project_hex_color] => #4dc3ff
        [project] => **HIDDENNAME**
        [billable] => 0
        [is_billable] => 
        [cur] => NOK
        [tags] => Array
            (
            )

    )

)

我试图把我的头绕过去的结果是这样(例如):

代码语言:javascript
复制
___________________________________________________________________
|Monday         |Tuesday          |Wednesday      |Thursday|Friday|
|---------------|-----------------|---------------|--------|------|
|tid:6754304    |tid:6742747      |               |        |      |
|dursum: 9825000|dursum: 11684868 |               |        |      |
|---------------|-----------------|---------------|--------|------|
|tid:6584532    |tid:6523745      |tid:5474124    |        |      |
|dursum: 9865000|dursum: 11684821 |dursum: 5221456|        |      |

基于日期( dataset中的第一个日期是星期一),我希望填充表中的“周一”列。我希望填充的数据是该日期所有"tid“(任务ID)的"dur”(持续时间)之和。然后,对于dataset中的下一个日期,我希望使用应用于该日期的相同数据填充“星期二”列。

有什么聪明的头脑可以看到这种混乱,给我指点和(也许)一些示例代码。我和这个在深海里..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-26 17:18:18

算法:

代码语言:javascript
复制
1. take today date
2. know day of the week as number
3. count monday and sunday dates
4. create empty array
5. walking along the array (foreach array as obj)
   if array[date] does not exist, add array[date] (obj->[start]) 
   if array[date][id] already exist, add dursum (obj->id obj->dur)
   else array[date][id] = current dursum 
6. format output

从这你不能做什么?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30463519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档