doujiena0025
2015-05-26 16:01 阅读 36
已采纳

按常用id和日期对数组进行分组,并汇总到日历表

I've been ripping my hair out on this one. Struggling with understanding how I really want to attack this problem, even the basic logic...

I've got this dataset:

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
            (
            )

    )

)

The result I'm trying to wrap my head around is this (example):

___________________________________________________________________
|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|        |      |

Based on the date (first date in dataset is Monday) I want to populate the "Monday" column in the table. The data I wish to populate is the "dur" (duration) SUM of all of the "tid" (Task ID) for that date. Then for the next date in the dataset i wish to populate "Tuesday" column with the the same data applied for that date.

Is there any wise brains out there that can see trough this mess and give me pointers and (maybe) some sample code. I'm in deep sea with this one...

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanpiyao2734 duanpiyao2734 2015-05-26 17:18

    Algorithm:

    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
    

    What from this can't you do ?

    点赞 评论 复制链接分享

相关推荐